import React from 'react'; import { useNavigate } from 'react-router-dom'; import { useSelector } from 'react-redux'; // material-ui import { useTheme } from '@mui/material/styles'; import { Avatar, Box, Card, CardContent, Chip, ClickAwayListener, Divider, Grid, InputAdornment, List, ListItemButton, ListItemIcon, ListItemText, OutlinedInput, Paper, Popper, Stack, Switch, Typography } from '@mui/material'; // third-party import PerfectScrollbar from 'react-perfect-scrollbar'; // project imports import MainCard from 'ui-component/cards/MainCard'; import Transitions from 'ui-component/extended/Transitions'; import UpgradePlanCard from './UpgradePlanCard'; import useAuth from 'hooks/useAuth'; import { DefaultRootStateProps } from 'types'; import User1 from 'assets/images/users/user-round.svg'; // assets import { IconLogout, IconSearch, IconSettings, IconUser } from '@tabler/icons'; // ==============================|| PROFILE MENU ||============================== // const ProfileSection = () => { const theme = useTheme(); const customization = useSelector((state: DefaultRootStateProps) => state.customization); const navigate = useNavigate(); const [sdm, setSdm] = React.useState(true); const [value, setValue] = React.useState(''); const [notification, setNotification] = React.useState(false); const [selectedIndex, setSelectedIndex] = React.useState(-1); const { logout, user } = useAuth(); const [open, setOpen] = React.useState(false); /** * anchorRef is used on different components and specifying one type leads to other components throwing an error * */ const anchorRef = React.useRef(null); const handleLogout = async () => { try { await logout(); } catch (err) { console.error(err); } }; const handleListItemClick = (event: React.MouseEvent, index: number, route: string = '') => { setSelectedIndex(index); handleClose(event); if (route && route !== '') { navigate(route); } }; const handleToggle = () => { setOpen((prevOpen) => !prevOpen); }; const handleClose = (event: React.MouseEvent | MouseEvent | TouchEvent) => { if (anchorRef.current && anchorRef.current.contains(event.target)) { return; } setOpen(false); }; const prevOpen = React.useRef(open); React.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 }) => ( Good Morning, {user?.name} Project Admin setValue(e.target.value)} placeholder="Search profile options" startAdornment={ } aria-describedby="search-helper-text" inputProps={{ 'aria-label': 'weight' }} /> Start DND Mode setSdm(e.target.checked)} name="sdm" size="small" /> Allow Notifications setNotification(e.target.checked)} name="sdm" size="small" /> ) => handleListItemClick(event, 0, '/user/account-profile/profile1') } > Account Settings} /> ) => handleListItemClick(event, 1, '/user/social-profile/posts') } > Social Profile } /> Logout} /> )} ); }; export default ProfileSection;