blob: 83736011a01e1ed079a1c35a156a8b3fd9f6f94e [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
simond47ef9e2022-09-28 22:24:28 -040018import { Box, Button, Menu, MenuItem } from '@mui/material';
simon6b9ddfb2022-10-03 00:04:50 -040019import { MouseEvent, useState } from 'react';
simon4e7445c2022-11-16 21:18:46 -050020import { useTranslation } from 'react-i18next';
simon5da8ca62022-11-09 15:21:25 -050021import { useNavigate } from 'react-router-dom';
simon07b4eb02022-09-29 17:50:26 -040022
simon416d0792022-11-03 02:46:18 -040023import { useAuthContext } from '../contexts/AuthProvider';
Larbi Gharibe9af9732021-03-31 15:08:01 +010024
25export default function Header() {
simon4e7445c2022-11-16 21:18:46 -050026 const { t } = useTranslation();
simon5da8ca62022-11-09 15:21:25 -050027 const { logout } = useAuthContext();
simon416d0792022-11-03 02:46:18 -040028
simond47ef9e2022-09-28 22:24:28 -040029 const navigate = useNavigate();
simon6b9ddfb2022-10-03 00:04:50 -040030 const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
31 const handleClick = (event: MouseEvent<HTMLButtonElement>) => setAnchorEl(event.currentTarget);
simond47ef9e2022-09-28 22:24:28 -040032 const handleClose = () => setAnchorEl(null);
Larbi Gharibe9af9732021-03-31 15:08:01 +010033
Michelle Sepkap Simee580f422022-10-31 23:27:04 -040034 const goToContacts = () => navigate(`/contacts`);
Michelle Sepkap Simee580f422022-10-31 23:27:04 -040035
Adrien Béraud150b4782021-04-21 19:40:59 -040036 return (
37 <Box>
38 <Button aria-controls="simple-menu" aria-haspopup="true" onClick={handleClick}>
39 Menu
40 </Button>
simond47ef9e2022-09-28 22:24:28 -040041 <Menu id="simple-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}>
idillon531b6f22022-09-16 14:02:00 -040042 <MenuItem onClick={goToContacts}>Contacts</MenuItem>
simon5da8ca62022-11-09 15:21:25 -050043 <MenuItem onClick={() => navigate('/settings')}>Account settings</MenuItem>
simon4e7445c2022-11-16 21:18:46 -050044 <MenuItem onClick={logout}>{t('logout')}</MenuItem>
Adrien Béraud150b4782021-04-21 19:40:59 -040045 </Menu>
simond47ef9e2022-09-28 22:24:28 -040046 </Box>
47 );
48}