Skip to content
Snippets Groups Projects
Commit 8338eb6ceaef authored by Olivier Giorgis's avatar Olivier Giorgis
Browse files

feat: display an “account” button at the top right instead of the “logout” button

parent 0e57e360a70c
No related branches found
No related tags found
1 merge request!25feat: display an “account” button at the top right instead of the “logout” button
import { AppBar, Box, Button, Stack, Toolbar, Typography } from "@mui/material";
import { useState } from "react";
import {
AppBar,
Box,
IconButton,
Menu,
MenuItem,
Stack,
Toolbar,
Typography,
} from "@mui/material";
import AccountCircle from "@mui/icons-material/AccountCircle";
import Link from "next/link";
import Image from "next/image";
import { usePathname } from "next/navigation";
......@@ -8,6 +19,15 @@
const pathname = usePathname();
const loggedIn = pathname !== "/login";
const logout = useApiLogout();
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const handleMenu = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
<AppBar position="static">
......@@ -44,9 +64,27 @@
</Link>
<Box flex={1} />
{loggedIn ? (
<Button onClick={logout} variant={"contained"} color={"error"}>
{"Déconnexion"}
</Button>
<>
<IconButton
size="large"
aria-label="account of current user"
aria-controls="menu-appbar"
aria-haspopup="true"
onClick={handleMenu}
color="inherit"
>
<AccountCircle />
</IconButton>
<Menu
id="current-user-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem onClick={logout}>Déconnexion</MenuItem>
</Menu>
</>
) : null}
</Toolbar>
</AppBar>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment