Files
pawol.nu/components/cgu/cgu-dialog.js
T

83 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-09-21 21:28:04 +02:00
import {useRef, useEffect} from 'react'
2022-01-19 06:35:04 +04:00
import {styled} from '@mui/material/styles'
2021-06-14 23:28:37 +02:00
import PropTypes from 'prop-types'
2022-01-19 07:06:26 +04:00
import {Button, Dialog, DialogActions, DialogContent, DialogTitle, Typography} from '@mui/material'
import {useRouter} from 'next/navigation'
2021-09-21 21:28:04 +02:00
import Cgu from '.'
2021-06-14 23:28:37 +02:00
2022-01-19 06:35:04 +04:00
const PREFIX = 'cgu-dialog'
const classes = {
dialog: `${PREFIX}-dialog`
}
2021-06-14 23:28:37 +02:00
2022-01-19 06:35:04 +04:00
const Root = styled('div')(() => ({
[`& .${classes.dialog}`]: {
2021-06-14 23:28:37 +02:00
zIndex: 9999
}
}))
2022-01-19 06:35:04 +04:00
const CGU_DOWNLOAD_LINK = process.env.NEXT_PUBLIC_CGU_DOWNLOAD_LINK
2021-06-14 23:28:37 +02:00
export default function CGUDialog({open, setOpen}) {
const router = useRouter()
const handleClose = () => {
setOpen(false)
}
2021-06-15 20:19:34 +02:00
const handleClick = event => {
2021-06-14 23:28:37 +02:00
event.preventDefault()
router.push(CGU_DOWNLOAD_LINK)
}
2021-09-21 21:28:04 +02:00
const descriptionElementRef = useRef(null)
useEffect(() => {
2021-06-14 23:28:37 +02:00
if (open) {
const {current: descriptionElement} = descriptionElementRef
if (descriptionElement !== null) {
descriptionElement.focus()
}
}
}, [open])
return (
2022-01-19 06:35:04 +04:00
<Root>
2021-06-14 23:28:37 +02:00
<Dialog
open={open}
scroll='paper'
aria-labelledby='scroll-dialog-title'
aria-describedby='scroll-dialog-description'
className={classes.dialog}
onClose={handleClose}
>
<DialogTitle id='scroll-dialog-title'>CGU et politique de confidentialité</DialogTitle>
<DialogContent dividers>
<Typography
ref={descriptionElementRef}
2022-03-06 10:05:44 +04:00
component='div'
2021-06-14 23:28:37 +02:00
variant='inherit'
id='scroll-dialog-description'
tabIndex={-1}
>
<Cgu />
</Typography>
</DialogContent>
<DialogActions>
2021-06-15 20:19:34 +02:00
<Button color='primary' onClick={handleClick}>
Voir au format pdf
2021-06-14 23:28:37 +02:00
</Button>
<Button color='primary' onClick={handleClose}>
Fermer
</Button>
</DialogActions>
</Dialog>
2022-01-19 06:35:04 +04:00
</Root>
2021-06-14 23:28:37 +02:00
)
}
CGUDialog.propTypes = {
open: PropTypes.bool.isRequired,
setOpen: PropTypes.func.isRequired
}