import React, { KeyboardEvent, MouseEvent, useRef, useState, useEffect } from 'react'; import Button from '@material-ui/core/Button'; import ClickAwayListener from '@material-ui/core/ClickAwayListener'; import Grow from '@material-ui/core/Grow'; import Paper from '@material-ui/core/Paper'; import Popper from '@material-ui/core/Popper'; import MenuItem from '@material-ui/core/MenuItem'; import MenuList from '@material-ui/core/MenuList'; import ProfileModal from './index'; import { useHistory } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import Avatar from '@material-ui/core/Avatar'; import SupervisedUserCircleIcon from '@material-ui/icons/SupervisedUserCircle'; interface Props { avatarUrl: any; logoutUser: any; auth: any; } const MenuListComposition = (props: Props): any => { const history = useHistory(); const { avatarUrl, logoutUser, auth } = props; const [open, setOpen] = useState(false); const [modalOpen, setModalOpen] = useState(false); const anchorRef = useRef(null); const { t } = useTranslation(); const handleToggle = (): any => { setOpen((prevOpen) => !prevOpen); }; const handleModal = (): any => { setModalOpen(true); setOpen(false); }; const handleClose = (event: MouseEvent): any => { if ( anchorRef.current && anchorRef.current.contains(event.target as HTMLElement) ) { return; } setOpen(false); }; const handleLogout = (): any => { logoutUser(); setOpen(false); }; const handleListKeyDown = (event: KeyboardEvent): any => { if (event.key === 'Tab') { event.preventDefault(); setOpen(false); } }; // const handleContacts = () => { // history.push('/friends/friends') // } const handleAdminConsole = (): any => { // eslint-disable-next-line @typescript-eslint/no-floating-promises history.push('/admin'); }; const modalClose = (): any => { setModalOpen(false); }; const prevOpen = useRef(open); useEffect(() => { if (prevOpen.current && !open) { anchorRef.current.focus(); } prevOpen.current = open; }, [open]); return (
{({ TransitionProps, placement }) => ( {t('user:profile.profileDropdown.profile')} {/* Contacts */} {auth.get('user').userRole === 'admin' && {t('user:profile.profileDropdown.adminConsole')} } {t('user:profile.profileDropdown.logout')} )}
); }; export default MenuListComposition;