1- import { ExitToApp } from '@mui/icons-material' ;
1+ import { ExitToApp , ManageAccounts } from '@mui/icons-material' ;
22import AccountCircle from '@mui/icons-material/AccountCircle' ;
33import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined' ;
44import SupervisedUserCircleIcon from '@mui/icons-material/SupervisedUserCircle' ;
55import SwitchAccountOutlinedIcon from '@mui/icons-material/SwitchAccountOutlined' ;
6+ import { Chip , Divider } from '@mui/material' ;
67import Badge from '@mui/material/Badge' ;
78import Box from '@mui/material/Box' ;
89import Button from '@mui/material/Button' ;
@@ -12,26 +13,37 @@ import IconButton from '@mui/material/IconButton';
1213import Menu from '@mui/material/Menu' ;
1314import MenuItem from '@mui/material/MenuItem' ;
1415import Tooltip from '@mui/material/Tooltip' ;
15- import React , { useContext , useEffect , useState } from 'react' ;
16- import { useSearchParams } from 'react-router-dom' ;
16+ import React , { useContext , useEffect , useMemo , useState } from 'react' ;
17+ import { useNavigate , useSearchParams } from 'react-router-dom' ;
1718
1819import ImpersonateButton from 'components/common/ImpersonateButton' ;
1920import StyledDialog from 'components/common/StyledDialog' ;
2021import UOLoader from 'components/common/UOLoader' ;
22+ import { SettingsContext } from 'context/SettingsContextProvider' ;
2123import { UserContext } from 'context/UserContextProvider' ;
24+ import { SettingsId } from 'generated/sdk' ;
2225import { getUniqueArrayBy } from 'utils/helperFunctions' ;
2326
27+ import ProfileInfo from './ProfileInfo' ;
2428import RoleSelection from './RoleSelection' ;
2529
2630const AccountActionButton = ( ) => {
31+ const navigate = useNavigate ( ) ;
2732 const [ isLoggingOut , setIsLoggingOut ] = useState ( false ) ;
2833 const [ show , setShow ] = useState ( false ) ;
29- const { roles, handleLogout, impersonatingUserId } = useContext ( UserContext ) ;
34+ const { user } = useContext ( UserContext ) ;
35+ const settingsContext = useContext ( SettingsContext ) ;
36+ const { roles, currentRole, handleLogout, impersonatingUserId } =
37+ useContext ( UserContext ) ;
3038 const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
31-
3239 const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
33-
3440 const hasMultipleRoles = getUniqueArrayBy ( roles , 'id' ) . length > 1 ;
41+ const humanReadableActiveRole = useMemo (
42+ ( ) =>
43+ roles . find ( ( { shortCode } ) => shortCode . toUpperCase ( ) === currentRole )
44+ ?. title ?? 'Unknown' ,
45+ [ roles , currentRole ]
46+ ) ;
3547
3648 useEffect ( ( ) => {
3749 if ( searchParams . get ( 'selectRoles' ) ) {
@@ -46,6 +58,10 @@ const AccountActionButton = () => {
4658
4759 const isUserImpersonated = typeof impersonatingUserId === 'number' ;
4860
61+ const externalProfileLink = settingsContext . settingsMap . get (
62+ SettingsId . PROFILE_PAGE_LINK
63+ ) ?. settingsValue ;
64+
4965 const handleClick = ( event : React . MouseEvent < HTMLButtonElement > ) => {
5066 setAnchorEl ( event . currentTarget ) ;
5167 } ;
@@ -63,6 +79,15 @@ const AccountActionButton = () => {
6379 } ) ;
6480 } ;
6581
82+ const handleManageAccountClick = ( ) => {
83+ handleClose ( ) ;
84+ if ( externalProfileLink ) {
85+ window . open ( externalProfileLink , '_blank' , 'noopener,noreferrer' ) ;
86+ } else {
87+ navigate ( `/ProfilePage/${ user . id } ` ) ;
88+ }
89+ } ;
90+
6691 return (
6792 < >
6893 < StyledDialog
@@ -121,6 +146,18 @@ const AccountActionButton = () => {
121146 open = { Boolean ( anchorEl ) }
122147 onClose = { handleClose }
123148 >
149+ < ProfileInfo />
150+ < Divider style = { { marginBottom : '7px' } } />
151+ < MenuItem
152+ onClick = { handleManageAccountClick }
153+ disabled = { isLoggingOut }
154+ data-cy = "manage-account-button"
155+ >
156+ < Box paddingRight = { 1 } paddingTop = { 1 } >
157+ < ManageAccounts />
158+ </ Box >
159+ Manage account
160+ </ MenuItem >
124161 { hasMultipleRoles && (
125162 < MenuItem
126163 onClick = { ( ) => {
@@ -132,7 +169,26 @@ const AccountActionButton = () => {
132169 < Box paddingRight = { 1 } paddingTop = { 1 } >
133170 < SupervisedUserCircleIcon />
134171 </ Box >
135- Roles
172+ < Box
173+ sx = { {
174+ display : 'flex' ,
175+ justifyContent : 'space-between' ,
176+ alignItems : 'center' ,
177+ flex : 1 ,
178+ } }
179+ >
180+ < Box > Roles</ Box >
181+ < Chip
182+ label = { humanReadableActiveRole }
183+ color = "primary"
184+ size = "small"
185+ sx = { {
186+ fontSize : '10px' ,
187+ height : 'inherit' ,
188+ lineHeight : 2 ,
189+ } }
190+ />
191+ </ Box >
136192 </ MenuItem >
137193 ) }
138194 { isUserImpersonated && (
0 commit comments