FPSMS-frontend
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 

63 строки
1.9 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("common");
  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={{ vertical: "bottom", horizontal: "right" }}
  34. transformOrigin={{ vertical: "top", horizontal: "right" }}
  35. keepMounted
  36. open={Boolean(profileMenuAnchorEl)}
  37. onClose={closeProfileMenu}
  38. MenuListProps={{
  39. dense: true,
  40. disablePadding: false,
  41. sx: { py: 0, minWidth: 180 },
  42. }}
  43. PaperProps={{ variant: "outlined" }}
  44. >
  45. <Typography sx={{ px: 2, py: 1.5, fontWeight: 600, color: "text.secondary", fontSize: "0.875rem" }}>
  46. {profileName}
  47. </Typography>
  48. <Divider />
  49. <MenuItem onClick={() => signOut()} sx={{ py: 1.5, fontSize: "0.875rem" }}>
  50. {t("Sign out")}
  51. </MenuItem>
  52. </Menu>
  53. </>
  54. );
  55. };
  56. export default Profile;