"use client"; import IconButton from "@mui/material/IconButton"; import Menu from "@mui/material/Menu"; import MenuItem from "@mui/material/MenuItem"; import Avatar from "@mui/material/Avatar"; import React from "react"; import { AppBarProps } from "./AppBar"; import Divider from "@mui/material/Divider"; import Typography from "@mui/material/Typography"; import { useTranslation } from "react-i18next"; import { signOut } from "next-auth/react"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; type Props = Pick; const Profile: React.FC = ({ avatarImageSrc, profileName }) => { const [profileMenuAnchorEl, setProfileMenuAnchorEl] = React.useState(); const openProfileMenu: React.MouseEventHandler = ( event, ) => { setProfileMenuAnchorEl(event.currentTarget); }; const closeProfileMenu = () => { setProfileMenuAnchorEl(undefined); }; const { t, i18n: { language } } = useTranslation("login"); const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams() const onLangClick = React.useCallback((lang: string) => { const params = new URLSearchParams(searchParams.toString()) params.set("lang", lang) router.replace(`${pathname}?${params.toString()}`); setTimeout(() => { window.location.reload(); }, 80); }, [router, pathname, searchParams]); return ( <> {profileName} { router.replace("/changepassword") }}>{t("Change Password")} {language === "zh" && { onLangClick("en") }}>{t("Change To English Version")}} {language === "en" && { onLangClick("zh") }}>{t("Change To Chinese Version")}} signOut()}>{t("Sign out")} ); }; export default Profile;