import { Dashboard as DashboardIcon, Logout as LogoutIcon, } from '@mui/icons-material'; import { Drawer, List, ListItem, ListItemButton, styled } from '@mui/material'; import { Dispatch, SetStateAction } from 'react'; import { OLD_ICON } from '../lib/consts/DEFAULT_THEME'; import { ICONS, ICON_SIZE } from '../lib/consts/ICONS'; import api from '../lib/api'; import Divider from './Divider'; import FlexBox from './FlexBox'; import handleAPIError from '../lib/handleAPIError'; import { BodyText } from './Text'; import useCookieJar from '../hooks/useCookieJar'; const PREFIX = 'AnvilDrawer'; const classes = { actionIcon: `${PREFIX}-actionIcon`, list: `${PREFIX}-list`, }; const StyledDrawer = styled(Drawer)(() => ({ [`& .${classes.list}`]: { width: '200px', }, [`& .${classes.actionIcon}`]: { fontSize: '2.3em', color: OLD_ICON, }, })); interface DrawerProps { open: boolean; setOpen: Dispatch>; } const AnvilDrawer = ({ open, setOpen }: DrawerProps): JSX.Element => { const { getSessionUser } = useCookieJar(); const sessionUser = getSessionUser(); return ( setOpen(!open)} >
{sessionUser ? <>Welcome, {sessionUser.name} : 'Unregistered'} Dashboard {ICONS.map( (icon): JSX.Element => ( {icon.text} {icon.text} ), )} { api .put('/auth/logout') .then(() => { window.location.replace('/login'); }) .catch((error) => { handleAPIError(error); }); }} > Logout
); }; export default AnvilDrawer;