-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* display user icon on login * display menu * add menu state * fixed profile export * Update www/src/components/auth/UserProfile.tsx Co-authored-by: Cyrus Diego <[email protected]> * style * display user's ccid Co-authored-by: Cyrus Diego <[email protected]>
- Loading branch information
1 parent
d1d7f57
commit 14c7643
Showing
2 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useAuth0 } from '@auth0/auth0-react'; | ||
import { IconButton, Menu, MenuItem, Typography } from '@material-ui/core'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { AccountCircle } from '@material-ui/icons'; | ||
import React, { FC, useRef, useState } from 'react'; | ||
|
||
const UserProfile: FC = () => { | ||
const classes = useStyles(); | ||
const userProfileIcon = useRef(null); | ||
const [isMenuOpen, setIsMenuOpen] = useState(false); | ||
const { logout } = useAuth0(); | ||
const { user } = useAuth0(); | ||
const ccid = user?.email?.split('@')[0] ?? ''; | ||
|
||
return ( | ||
<> | ||
<IconButton | ||
aria-label='account of current user' | ||
aria-controls='menu-appbar' | ||
aria-haspopup='true' | ||
color='inherit' | ||
ref={userProfileIcon} | ||
onClick={() => { | ||
setIsMenuOpen(true); | ||
}} | ||
> | ||
<AccountCircle color='secondary' /> | ||
</IconButton> | ||
<Menu | ||
id='menu-appbar' | ||
anchorEl={userProfileIcon.current} | ||
anchorOrigin={{ | ||
vertical: 'top', | ||
horizontal: 'right', | ||
}} | ||
keepMounted | ||
transformOrigin={{ | ||
vertical: 'top', | ||
horizontal: 'right', | ||
}} | ||
open={isMenuOpen} | ||
onClose={() => setIsMenuOpen(false)} | ||
className={classes.menu} | ||
> | ||
<Typography className={classes.menu_text}> Signed in as: {ccid} </Typography> | ||
<MenuItem onClick={() => logout()} className={classes.menu_text} style={{ marginBottom: '100px' }}> | ||
Settings | ||
</MenuItem> | ||
<MenuItem onClick={() => logout()} className={classes.menu_text}> | ||
Log out | ||
</MenuItem> | ||
</Menu> | ||
</> | ||
); | ||
}; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
menu: { | ||
'& .MuiPaper-root': { | ||
backgroundColor: theme.palette.primary.dark, | ||
}, | ||
}, | ||
menu_text: { | ||
color: theme.palette.text.secondary, | ||
fontSize: 20, | ||
fontWeight: 500, | ||
padding: '15px', | ||
}, | ||
})); | ||
|
||
export default UserProfile; |