// ** React Imports import { useState, SyntheticEvent, Fragment, useEffect } from 'react' // ** Next Import import { useRouter } from 'next/router' // ** MUI Imports import Box from '@mui/material/Box' import Menu from '@mui/material/Menu' import Badge from '@mui/material/Badge' import Avatar from '@mui/material/Avatar' import Divider from '@mui/material/Divider' import MenuItem from '@mui/material/MenuItem' import { styled } from '@mui/material/styles' import Typography from '@mui/material/Typography' // ** Icons Imports import CogOutline from 'mdi-material-ui/CogOutline' import CurrencyUsd from 'mdi-material-ui/CurrencyUsd' import EmailOutline from 'mdi-material-ui/EmailOutline' import LogoutVariant from 'mdi-material-ui/LogoutVariant' import AccountOutline from 'mdi-material-ui/AccountOutline' import MessageOutline from 'mdi-material-ui/MessageOutline' import HelpCircleOutline from 'mdi-material-ui/HelpCircleOutline' import { useUser } from '@auth0/nextjs-auth0/client' // ** Styled Components const BadgeContentSpan = styled('span')(({ theme }) => ({ width: 8, height: 8, borderRadius: '50%', backgroundColor: theme.palette.success.main, boxShadow: `0 0 0 2px ${theme.palette.background.paper}` })) const UserDropdown = () => { const { user, isLoading } = useUser(); const [appUser, setAppUser] = useState(null); useEffect(() => { getData() }, []); const getData = async () => { var userResponse = await fetch('/api/me'); var user = await userResponse.json(); setAppUser(user); } // ** States const [anchorEl, setAnchorEl] = useState(null) // ** Hooks const router = useRouter() const handleDropdownOpen = (event: SyntheticEvent) => { setAnchorEl(event.currentTarget) } const handleDropdownClose = (url?: string) => { if (url) { router.push(url) } setAnchorEl(null) } const styles = { py: 2, px: 4, width: '100%', display: 'flex', alignItems: 'center', color: 'text.primary', textDecoration: 'none', '& svg': { fontSize: '1.375rem', color: 'text.secondary' } } return ( (!isLoading && user && appUser) ? ( } anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }} > handleDropdownClose()} sx={{ '& .MuiMenu-paper': { width: 230, marginTop: 4 } }} anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }} transformOrigin={{ vertical: 'top', horizontal: 'right' }} > } anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }} > {appUser["displayName"]} Welcome back! router.push("/dashboard/settings")}> Settings handleDropdownClose('/api/auth/logout')}> Logout ): null ) } export default UserDropdown