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

feat: add user name in login menu

parent 8338eb6ceaef
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
Pipeline #229823 passed
import { useState } from "react"; import { useState } from "react";
import { useClient } from "@/context/ClientContext";
import { import {
AppBar, AppBar,
Box, Box,
...@@ -9,7 +10,8 @@ ...@@ -9,7 +10,8 @@
Toolbar, Toolbar,
Typography, Typography,
} from "@mui/material"; } from "@mui/material";
import AccountCircle from "@mui/icons-material/AccountCircle";
import { AccountCircle, Logout } from "@mui/icons-material";
import Link from "next/link"; import Link from "next/link";
import Image from "next/image"; import Image from "next/image";
import { usePathname } from "next/navigation"; import { usePathname } from "next/navigation";
...@@ -20,4 +22,8 @@ ...@@ -20,4 +22,8 @@
const loggedIn = pathname !== "/login"; const loggedIn = pathname !== "/login";
const logout = useApiLogout(); const logout = useApiLogout();
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const client = useClient();
const [currentUserName, setCurrentUserName] = useState<string | undefined>(
undefined,
);
...@@ -23,3 +29,3 @@ ...@@ -23,3 +29,3 @@
const handleMenu = (event: React.MouseEvent<HTMLElement>) => { const handleMenu = async (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget); setAnchorEl(event.currentTarget);
...@@ -25,4 +31,6 @@ ...@@ -25,4 +31,6 @@
setAnchorEl(event.currentTarget); setAnchorEl(event.currentTarget);
const currentUser = await client.currentUser();
setCurrentUserName(currentUser.login);
}; };
const handleClose = () => { const handleClose = () => {
...@@ -82,7 +90,14 @@ ...@@ -82,7 +90,14 @@
open={Boolean(anchorEl)} open={Boolean(anchorEl)}
onClose={handleClose} onClose={handleClose}
> >
<MenuItem onClick={logout}>Déconnexion</MenuItem> <Typography style={{ textAlign: "center" }}>
{currentUserName}
</Typography>
<MenuItem divider />
<MenuItem onClick={logout}>
<Logout fontSize="small" />
Déconnexion
</MenuItem>
</Menu> </Menu>
</> </>
) : null} ) : null}
......
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