-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAppToolbar.tsx
More file actions
111 lines (102 loc) · 3.61 KB
/
Copy pathAppToolbar.tsx
File metadata and controls
111 lines (102 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* eslint-disable @typescript-eslint/no-var-requires */
import MenuIcon from '@mui/icons-material/Menu';
import { Box } from '@mui/material';
import AppBar from '@mui/material/AppBar';
import IconButton from '@mui/material/IconButton';
import { useTheme } from '@mui/material/styles';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import useMediaQuery from '@mui/material/useMediaQuery';
import PropTypes from 'prop-types';
import React, { useContext, useEffect, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { SettingsContext } from 'context/SettingsContextProvider';
import { SettingsId } from 'generated/sdk';
import AccountActionButton from './AccountActionButton';
const drawerWidth = 250;
type AppToolbarProps = {
/** Content of the information modal. */
open: boolean;
/** Text of the button link in the information modal. */
handleDrawerOpen: () => void;
header: string;
};
const AppToolbar = ({ open, handleDrawerOpen, header }: AppToolbarProps) => {
const { settingsMap } = useContext(SettingsContext);
const location = useLocation();
const isTabletOrMobile = useMediaQuery('(max-width: 1224px)');
const isPortraitMode = useMediaQuery('(orientation: portrait)');
const [logo, setLogo] = useState('');
const theme = useTheme();
if (location.pathname === '/') document.title = 'User Office Dashboard';
const logoFilename = settingsMap.get(
SettingsId.HEADER_LOGO_FILENAME
)?.settingsValue;
useEffect(() => {
setLogo('/images/' + logoFilename);
}, [logoFilename]);
return (
<AppBar
position="fixed"
sx={{
zIndex: isTabletOrMobile
? theme.zIndex.drawer
: theme.zIndex.drawer + 1,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
...(open && {
marginLeft: isTabletOrMobile ? 0 : drawerWidth,
width: isTabletOrMobile ? '100%' : `calc(100% - ${drawerWidth}px)`,
transition: isTabletOrMobile
? 'none'
: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
}),
}}
>
<Toolbar>
<Box sx={{ display: 'flex', flexGrow: 1, alignItems: 'center' }}>
<IconButton
edge="start"
color="inherit"
aria-label="Open drawer"
onClick={handleDrawerOpen}
sx={{
...(open && {
marginRight: '220px',
display: isTabletOrMobile ? 'inline-flex' : 'none',
}),
}}
data-cy="open-drawer"
>
<MenuIcon />
</IconButton>
{(!isTabletOrMobile || !isPortraitMode) && logo && (
<Link className={'header-logo-container'} to="/">
<img
src={logo}
alt="Institution logo"
className={'header-logo'}
/>
</Link>
)}
{(!isTabletOrMobile || !isPortraitMode) && (
<Typography component="h1" variant="h6" color="inherit" noWrap>
{location.pathname === '/' ? 'Dashboard' : header}
</Typography>
)}
</Box>
<AccountActionButton />
</Toolbar>
</AppBar>
);
};
AppToolbar.propTypes = {
open: PropTypes.bool.isRequired,
handleDrawerOpen: PropTypes.func.isRequired,
};
export default AppToolbar;