import { useState, useRef, useEffect } from 'react'; import { useSelector } from 'react-redux'; import { useNavigate } from 'react-router-dom'; // material-ui import { useTheme } from '@mui/material/styles'; import { Avatar, Chip, ClickAwayListener, List, ListItemButton, ListItemIcon, ListItemText, Paper, Popper, Typography } from '@mui/material'; // project imports import MainCard from 'ui-component/cards/MainCard'; import Transitions from 'ui-component/extended/Transitions'; import User1 from 'assets/images/users/user-round.svg'; import useLogin from 'hooks/useLogin'; // assets import { IconLogout, IconSettings, IconUserScan } from '@tabler/icons-react'; // ==============================|| PROFILE MENU ||============================== // const ProfileSection = () => { const theme = useTheme(); const navigate = useNavigate(); const customization = useSelector((state) => state.customization); const { logout } = useLogin(); const [open, setOpen] = useState(false); /** * anchorRef is used on different componets and specifying one type leads to other components throwing an error * */ const anchorRef = useRef(null); const handleLogout = async () => { logout(); }; const handleClose = (event) => { if (anchorRef.current && anchorRef.current.contains(event.target)) { return; } setOpen(false); }; const handleToggle = () => { setOpen((prevOpen) => !prevOpen); }; const prevOpen = useRef(open); useEffect(() => { if (prevOpen.current === true && open === false) { anchorRef.current.focus(); } prevOpen.current = open; }, [open]); return ( <> } label={} variant="outlined" ref={anchorRef} aria-controls={open ? 'menu-list-grow' : undefined} aria-haspopup="true" onClick={handleToggle} color="primary" /> {({ TransitionProps }) => ( navigate('/panel/profile')}> 设置} /> 登出} /> )} ); }; export default ProfileSection;