diff options
author | Lena <lena.becker-3@mni.thm.de> | 2021-03-05 18:54:10 +0100 |
---|---|---|
committer | Sascha <GlancingMind@outlook.com> | 2021-04-13 19:07:57 +0200 |
commit | cef44db8c73c27c1da8dc5e0a9f2e47e0c096075 (patch) | |
tree | fc3884474d68a60f5dab828b2c5871fbe1db8da4 /webui/src/components/CurrentIdentity | |
parent | 62fb09a53cc626ac581f33b466a1cdf14eb6ed89 (diff) | |
download | git-bug-cef44db8c73c27c1da8dc5e0a9f2e47e0c096075.tar.gz |
Add popup menu fpr user informations #12
Diffstat (limited to 'webui/src/components/CurrentIdentity')
-rw-r--r-- | webui/src/components/CurrentIdentity/CurrentIdentity.graphql | 2 | ||||
-rw-r--r-- | webui/src/components/CurrentIdentity/CurrentIdentity.tsx | 63 |
2 files changed, 62 insertions, 3 deletions
diff --git a/webui/src/components/CurrentIdentity/CurrentIdentity.graphql b/webui/src/components/CurrentIdentity/CurrentIdentity.graphql index 2794a40f..9af786b7 100644 --- a/webui/src/components/CurrentIdentity/CurrentIdentity.graphql +++ b/webui/src/components/CurrentIdentity/CurrentIdentity.graphql @@ -1,6 +1,8 @@ query CurrentIdentity { repository { userIdentity { + humanId + email displayName avatarUrl } diff --git a/webui/src/components/CurrentIdentity/CurrentIdentity.tsx b/webui/src/components/CurrentIdentity/CurrentIdentity.tsx index 8cd3585b..68e65a99 100644 --- a/webui/src/components/CurrentIdentity/CurrentIdentity.tsx +++ b/webui/src/components/CurrentIdentity/CurrentIdentity.tsx @@ -1,5 +1,14 @@ import React from 'react'; +import { + Button, + ClickAwayListener, + Grow, + MenuItem, + MenuList, + Paper, + Popper, +} from '@material-ui/core'; import Avatar from '@material-ui/core/Avatar'; import { makeStyles } from '@material-ui/core/styles'; @@ -15,14 +24,62 @@ const CurrentIdentity = () => { const classes = useStyles(); const { loading, error, data } = useCurrentIdentityQuery(); + const [open, setOpen] = React.useState(false); + const anchorRef = React.useRef<HTMLButtonElement>(null); + if (error || loading || !data?.repository?.userIdentity) return null; const user = data.repository.userIdentity; + const handleToggle = () => { + setOpen((prevOpen) => !prevOpen); + }; + + const handleClose = (event: any) => { + if (anchorRef.current && anchorRef.current.contains(event.target)) { + return; + } + setOpen(false); + }; + return ( <> - <Avatar src={user.avatarUrl ? user.avatarUrl : undefined}> - {user.displayName.charAt(0).toUpperCase()} - </Avatar> + <Button + ref={anchorRef} + aria-controls={open ? 'menu-list-grow' : undefined} + aria-haspopup="true" + onClick={handleToggle} + > + <Avatar src={user.avatarUrl ? user.avatarUrl : undefined}> + {user.displayName.charAt(0).toUpperCase()} + </Avatar> + </Button> + <Popper + open={open} + anchorEl={anchorRef.current} + role={undefined} + transition + disablePortal + > + {({ TransitionProps, placement }) => ( + <Grow + {...TransitionProps} + style={{ + transformOrigin: + placement === 'bottom' ? 'center top' : 'center bottom', + }} + > + <Paper> + <ClickAwayListener onClickAway={handleClose}> + <MenuList autoFocusItem={open} id="menu-list-grow"> + <MenuItem>Display Name: {user.displayName}</MenuItem> + <MenuItem>Human Id: {user.humanId}</MenuItem> + <MenuItem>Email: {user.email}</MenuItem> + </MenuList> + </ClickAwayListener> + </Paper> + </Grow> + )} + </Popper> <div className={classes.displayName}>{user.displayName}</div> </> ); |