FPSMS-frontend
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

62 wiersze
1.8 KiB

  1. "use client";
  2. import IconButton from "@mui/material/IconButton";
  3. import Menu from "@mui/material/Menu";
  4. import MenuItem from "@mui/material/MenuItem";
  5. import Avatar from "@mui/material/Avatar";
  6. import React from "react";
  7. import { AppBarProps } from "./AppBar";
  8. import Divider from "@mui/material/Divider";
  9. import Typography from "@mui/material/Typography";
  10. import { useTranslation } from "react-i18next";
  11. import { signOut } from "next-auth/react";
  12. type Props = Pick<AppBarProps, "avatarImageSrc" | "profileName">;
  13. const Profile: React.FC<Props> = ({ avatarImageSrc, profileName }) => {
  14. const [profileMenuAnchorEl, setProfileMenuAnchorEl] =
  15. React.useState<HTMLButtonElement>();
  16. const openProfileMenu: React.MouseEventHandler<HTMLButtonElement> = (
  17. event,
  18. ) => {
  19. setProfileMenuAnchorEl(event.currentTarget);
  20. };
  21. const closeProfileMenu = () => {
  22. setProfileMenuAnchorEl(undefined);
  23. };
  24. const { t } = useTranslation("login");
  25. return (
  26. <>
  27. <IconButton aria-label="profile" onClick={openProfileMenu}>
  28. <Avatar src={avatarImageSrc} />
  29. </IconButton>
  30. <Menu
  31. id="profile-menu"
  32. anchorEl={profileMenuAnchorEl}
  33. anchorOrigin={{
  34. vertical: "bottom",
  35. horizontal: "right",
  36. }}
  37. keepMounted
  38. transformOrigin={{
  39. vertical: "top",
  40. horizontal: "right",
  41. }}
  42. open={Boolean(profileMenuAnchorEl)}
  43. onClose={closeProfileMenu}
  44. MenuListProps={{ dense: true, disablePadding: true }}
  45. >
  46. <Typography sx={{ mx: "1.5rem", my: "0.5rem" }} fontWeight="bold">
  47. {profileName}
  48. </Typography>
  49. <Divider />
  50. <MenuItem onClick={() => signOut()}>{t("Sign out")}</MenuItem>
  51. </Menu>
  52. </>
  53. );
  54. };
  55. export default Profile;