@cccsaurora/howler-ui 2.14.0-dev.199 → 2.14.0-dev.208
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Box, ClickAwayListener, Divider, Fade, IconButton, List, ListItem, ListItemButton, ListItemIcon, ListItemText, ListSubheader, Paper, Popper, styled, Typography, useTheme } from '@mui/material';
|
|
3
3
|
import { useAppConfigs, useAppUser } from '@cccsaurora/howler-ui/commons/components/app/hooks';
|
|
4
4
|
import AppAvatar, {} from '@cccsaurora/howler-ui/commons/components/display/AppAvatar';
|
|
5
5
|
import ThemeSelection from '@cccsaurora/howler-ui/commons/components/topnav/ThemeSelection';
|
|
6
|
-
import { memo, useCallback, useRef, useState } from 'react';
|
|
6
|
+
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
|
-
import { Link } from 'react-router-dom';
|
|
8
|
+
import { Link, useLocation } from 'react-router-dom';
|
|
9
9
|
export const AppUserAvatar = styled(AppAvatar)(({ theme }) => ({
|
|
10
10
|
width: theme.spacing(5),
|
|
11
11
|
height: theme.spacing(5),
|
|
@@ -20,6 +20,7 @@ const UserProfile = () => {
|
|
|
20
20
|
const configs = useAppConfigs();
|
|
21
21
|
const { user } = useAppUser();
|
|
22
22
|
const anchorRef = useRef();
|
|
23
|
+
const location = useLocation();
|
|
23
24
|
const [open, setOpen] = useState(false);
|
|
24
25
|
const onProfileClick = useCallback(() => setOpen(_open => !_open), []);
|
|
25
26
|
const onClickAway = useCallback(() => setOpen(false), []);
|
|
@@ -36,14 +37,22 @@ const UserProfile = () => {
|
|
|
36
37
|
}
|
|
37
38
|
return null;
|
|
38
39
|
}, [t]);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
// This effect checks to see if the result of pressing a button was a navigation
|
|
42
|
+
// if so, close the settings bar.
|
|
43
|
+
if (open) {
|
|
44
|
+
setOpen(false);
|
|
45
|
+
}
|
|
46
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
|
+
}, [location.pathname]);
|
|
48
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconButton, { ref: anchorRef, edge: "end", sx: {
|
|
49
|
+
padding: 0,
|
|
50
|
+
marginLeft: theme.spacing(1),
|
|
51
|
+
marginRight: theme.spacing(1)
|
|
52
|
+
}, onClick: onProfileClick, size: "large", children: _jsx(AppUserAvatar, { alt: user.name, url: user.avatar, email: user.email, children: user.name
|
|
44
53
|
.split(' ', 2)
|
|
45
54
|
.map(n => n[0].toUpperCase())
|
|
46
|
-
.join('') }), _jsx(Popper, { sx: { zIndex: theme.zIndex.appBar + 200, minWidth: '280px' }, open: open, anchorEl: anchorRef.current, placement: "bottom-end", transition: true, children: ({ TransitionProps }) => (_jsx(Fade, { ...TransitionProps, timeout: 250, children: _jsxs(Paper, { style: { padding: theme.spacing(1) }, elevation: 4, children: [_jsx(List, { disablePadding: true, children: _jsx(ListItem, { disableGutters: true, dense: true, children: _jsxs(Box, { sx: {
|
|
55
|
+
.join('') }) }), _jsx(ClickAwayListener, { onClickAway: onClickAway, children: _jsx(Popper, { sx: { zIndex: theme.zIndex.appBar + 200, minWidth: '280px' }, open: open, anchorEl: anchorRef.current, placement: "bottom-end", transition: true, children: ({ TransitionProps }) => (_jsx(Fade, { ...TransitionProps, timeout: 250, children: _jsxs(Paper, { style: { padding: theme.spacing(1) }, elevation: 4, children: [_jsx(List, { disablePadding: true, children: _jsx(ListItem, { disableGutters: true, dense: true, children: _jsxs(Box, { sx: {
|
|
47
56
|
display: 'flex',
|
|
48
57
|
paddingTop: 2,
|
|
49
58
|
paddingBottom: 2,
|
|
@@ -54,6 +63,6 @@ const UserProfile = () => {
|
|
|
54
63
|
.split(' ', 2)
|
|
55
64
|
.map(n => n[0].toUpperCase())
|
|
56
65
|
.join('') }), _jsxs(Box, { sx: { paddingLeft: 2 }, children: [_jsx(Typography, { variant: "body1", noWrap: true, children: _jsx("b", { children: user.name }) }), _jsx(Typography, { variant: "caption", noWrap: true, children: user.email })] })] }) }) }), renderMenu('usermenu', configs.preferences.topnav.userMenu, configs.preferences.topnav.userMenuTitle, configs.preferences.topnav.userMenuI18nKey), user.is_admin &&
|
|
57
|
-
renderMenu('adminmenu', configs.preferences.topnav.adminMenu, configs.preferences.topnav.adminMenuTitle, configs.preferences.topnav.adminMenuI18nKey), renderThemeSelection(configs.preferences.topnav.themeSelectionMode === 'profile')] }) })) })
|
|
66
|
+
renderMenu('adminmenu', configs.preferences.topnav.adminMenu, configs.preferences.topnav.adminMenuTitle, configs.preferences.topnav.adminMenuI18nKey), renderThemeSelection(configs.preferences.topnav.themeSelectionMode === 'profile')] }) })) }) })] }));
|
|
58
67
|
};
|
|
59
68
|
export default memo(UserProfile);
|