2024-05-20 04:17:09 +04:00
|
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
|
|
import PropTypes from 'prop-types'
|
2024-05-20 16:46:25 +04:00
|
|
|
|
import {useState} from 'react'
|
2024-05-20 04:17:09 +04:00
|
|
|
|
import {signOut} from 'next-auth/react'
|
|
|
|
|
|
import {useRouter} from 'next/navigation'
|
|
|
|
|
|
import Box from '@mui/material/Box'
|
|
|
|
|
|
import Stack from '@mui/material/Stack'
|
|
|
|
|
|
import Fab from '@mui/material/Fab'
|
2024-05-20 14:43:29 +04:00
|
|
|
|
import {styled} from '@mui/material/styles'
|
|
|
|
|
|
import Tooltip, {tooltipClasses} from '@mui/material/Tooltip'
|
2024-05-20 04:17:09 +04:00
|
|
|
|
import LogoutIcon from '@mui/icons-material/Logout'
|
|
|
|
|
|
import LoginIcon from '@mui/icons-material/Login'
|
|
|
|
|
|
import PersonAddIcon from '@mui/icons-material/PersonAdd'
|
2024-05-20 16:46:25 +04:00
|
|
|
|
import ConfirmationAlert from './confirmation-alert.js'
|
2024-05-20 04:17:09 +04:00
|
|
|
|
|
2024-05-20 14:43:29 +04:00
|
|
|
|
const LightTooltip = styled(({className, ...props}) => (
|
|
|
|
|
|
<Tooltip {...props} classes={{popper: className}} />
|
|
|
|
|
|
))(({theme}) => ({
|
|
|
|
|
|
[`& .${tooltipClasses.tooltip}`]: {
|
|
|
|
|
|
backgroundColor: theme.palette.common.white,
|
|
|
|
|
|
color: 'rgba(0, 0, 0, 0.87)',
|
|
|
|
|
|
boxShadow: theme.shadows[1],
|
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
|
},
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
2024-09-15 18:04:04 +04:00
|
|
|
|
export default function Sign({session, navButton}) {
|
2024-05-20 04:17:09 +04:00
|
|
|
|
const router = useRouter()
|
2024-05-20 16:46:25 +04:00
|
|
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
const handleSignout = () => {
|
|
|
|
|
|
setIsOpen(false)
|
|
|
|
|
|
signOut()
|
|
|
|
|
|
}
|
2024-05-20 04:17:09 +04:00
|
|
|
|
|
|
|
|
|
|
return (
|
2024-05-20 16:46:25 +04:00
|
|
|
|
<>
|
2024-06-20 14:06:07 +04:00
|
|
|
|
<Box sx={{display: 'flex', justifyContent: session ? 'start' : 'center', marginTop: 2}}>
|
2024-05-20 16:46:25 +04:00
|
|
|
|
{session ? (
|
2024-06-20 14:06:07 +04:00
|
|
|
|
<Stack direction='row' spacing={2}>
|
|
|
|
|
|
<LightTooltip title='Se déconnecter' placement='right'>
|
|
|
|
|
|
<Fab size='large' color='error' onClick={() => setIsOpen(true)}>
|
|
|
|
|
|
<LogoutIcon fontSize='large' />
|
|
|
|
|
|
</Fab>
|
|
|
|
|
|
</LightTooltip>
|
2024-09-15 18:04:04 +04:00
|
|
|
|
<LightTooltip title={navButton.title} placement='right'>
|
|
|
|
|
|
<Fab sx={{mr: 3}} size='large' color={navButton.color} onClick={() => router.push(navButton.path)}>
|
|
|
|
|
|
{navButton.icon}
|
2024-06-20 14:06:07 +04:00
|
|
|
|
</Fab>
|
|
|
|
|
|
</LightTooltip>
|
|
|
|
|
|
</Stack>
|
2024-05-20 16:46:25 +04:00
|
|
|
|
) : (
|
|
|
|
|
|
<Stack direction='row' spacing={2}>
|
|
|
|
|
|
<LightTooltip title='Se connecter' placement='left'>
|
|
|
|
|
|
<Fab size='large' color='success' onClick={() => router.push('/login')}>
|
|
|
|
|
|
<LoginIcon fontSize='large' />
|
|
|
|
|
|
</Fab>
|
|
|
|
|
|
</LightTooltip>
|
|
|
|
|
|
<LightTooltip title='S’enregistrer' placement='right'>
|
|
|
|
|
|
<Fab size='large' color='success' onClick={() => router.push('/register')}>
|
|
|
|
|
|
<PersonAddIcon fontSize='large' />
|
|
|
|
|
|
</Fab>
|
|
|
|
|
|
</LightTooltip>
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<ConfirmationAlert
|
|
|
|
|
|
title='Se déconnecter'
|
|
|
|
|
|
description='Vous êtes sur le point de vous déconnecter. Voulez-vous continuer ?'
|
|
|
|
|
|
isOpen={isOpen}
|
|
|
|
|
|
setIsOpen={setIsOpen}
|
|
|
|
|
|
handleConfirmation={handleSignout}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</>
|
2024-05-20 04:17:09 +04:00
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Sign.propTypes = {
|
2024-09-15 18:04:04 +04:00
|
|
|
|
session: PropTypes.object,
|
|
|
|
|
|
navButton: PropTypes.object.isRequired
|
2024-05-20 04:17:09 +04:00
|
|
|
|
}
|