-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMenuBar.jsx
More file actions
136 lines (122 loc) · 5.94 KB
/
MenuBar.jsx
File metadata and controls
136 lines (122 loc) · 5.94 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { useState, useEffect, use } from 'react'
import { AppBar, Toolbar, Drawer, Box, Typography, MenuList, MenuItem, ListItemIcon, ListItemText, Button, Link, Select } from '@mui/material'
import IconButton from '@mui/material/IconButton';
import SchoolIcon from '@mui/icons-material/School';
import PeopleIcon from '@mui/icons-material/People';
import BarChartIcon from '@mui/icons-material/BarChart';
import Diversity3Icon from '@mui/icons-material/Diversity3';
import MenuIcon from '@mui/icons-material/Menu';
import logoHorizontalLightUrl from '../assets/logo-h-light.png'
import logoHorizontalDarkUrl from '../assets/logo-h-dark.png'
import logoVerticalLightUrl from '../assets/logo-v-light.png'
import logoVerticalDarkUrl from '../assets/logo-v-dark.png'
import { getCookie } from '../utils.js';
import { useThemeContext } from '../theme/ThemeContext.jsx';
import { useTheme, useMediaQuery } from "@mui/material";
import ThemeSwitcher from './ThemeSwitcher.jsx';
const apiBaseUrl = localStorage.getItem('apiBaseUrl');
const platformBaseUrl = localStorage.getItem('platformBaseUrl');
function OrganizationsSelect({organizations, activeOrganizationId, changeOrganizationCallback, sx}) {
return (
<Select
value={activeOrganizationId || ""}
onChange={(e) => changeOrganizationCallback(e.target.value)}
displayEmpty
inputProps={{ 'aria-label': 'Select organization' }}
sx={{
ml: 1,
fontSize: 16,
'& .MuiSelect-select': {
paddingTop: '8px',
paddingBottom: '8px',
},
'& .MuiSvgIcon-root': {
top: 'calc(50% - 12px)',
},
...sx
}}
>
{organizations.map((org) => (
<MenuItem key={org.id} value={org.id}>
{org.name}
</MenuItem>
))}
</Select>
)
}
function MenuBar({activeOrganizationId, changeOrganizationCallback, showOrganizationSwitcher, drawerWidth}) {
const [menuOpen, setMenuOpen] = useState(false)
const [organizations, setOrganizations] = useState([])
const theme = useTheme();
const isMdUpScreen = useMediaQuery(theme.breakpoints.up('md'));
const drawerVariant = isMdUpScreen ? "permanent" : "temporary";
const logoHorizontalUrl = theme.palette.mode === 'light' ? logoHorizontalLightUrl : logoHorizontalDarkUrl;
const logoVerticalUrl = theme.palette.mode === 'light' ? logoVerticalLightUrl : logoVerticalDarkUrl;
useEffect(() => {
fetch(apiBaseUrl + '/organizations/', {
method: 'GET',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCookie('csrftoken'),
},
})
.then(response => response.json())
.then(data => {
setOrganizations(data.organizations);
})
.catch(error => {
console.error('Error fetching organizations:', error);
});
}, []);
let pages = []
if (localStorage.getItem('isPlatformAdmin') == 'true') {
pages.push(
{ name: 'Organizations', icon: <Diversity3Icon fontSize="small" />, href: platformBaseUrl + '/organizations/'},
);
}
pages.push({ name: 'Course Management', icon: <SchoolIcon fontSize="small" />, href: platformBaseUrl + '/courses/' });
pages.push({ name: 'Learners', icon: <PeopleIcon fontSize="small" />, href: platformBaseUrl + '/users/' });
pages.push({ name: 'Analytics', icon: <BarChartIcon fontSize="small" />, href: platformBaseUrl + '/analytics/' });
const toggleMenuDrawer = (newOpen) => () => {
setMenuOpen(newOpen);
};
return (
<Box component="nav"sx={{ width: { sm: drawerWidth }, flexShrink: { sm: 0 } }}>
<AppBar sx={{boxShadow: 0, backgroundColor: 'background.nav', borderBottom: {xs: '1px solid', md: 'none'}, borderColor: {xs: 'primary.main', md: 'none'} }}>
<Box my={1} ml={5} sx={{ height: {xs: "57px", md: "30px"}}}>
<img src={logoHorizontalUrl} alt="Logo" style={{maxHeight: "57px", height: "100%"}} />
</Box>
<Box sx={{display: { xs: 'flex'}, right: 0, position: "absolute" }}>
<ThemeSwitcher />
<Box m={1} paddingTop="7px">
<IconButton aria-controls="menu-appbar" onClick={toggleMenuDrawer(true)} sx={{ display: { xs: 'inline-block', md: 'none' }}}>
<MenuIcon />
</IconButton>
</Box>
</Box>
</AppBar>
<Drawer variant={drawerVariant} onClose={toggleMenuDrawer(false)} display={{md: "none" }} open={menuOpen} sx={{ '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth } }}
slotProps={{ backdrop: { sx: { backgroundColor: 'rgba(251, 251, 255, 0.57)', backdropFilter: 'blur(5px)' }}, paper: { sx: { boxShadow: '2px 0px 8px rgba(0, 0, 0, 0.1)'}}}}>
<Box my={2} textAlign="center">
<img src={logoVerticalUrl} alt="Logo" style={{ width: "50%" }} />
</Box>
{
showOrganizationSwitcher && <OrganizationsSelect organizations={organizations} activeOrganizationId={activeOrganizationId} changeOrganizationCallback={changeOrganizationCallback} sx={{ m: 2 }} />
}
<MenuList>
{ pages.map((page) => (
<MenuItem key={page.name}>
<Link href={page.href} underline="none" color="inherit" sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
<ListItemIcon>
{page.icon}
</ListItemIcon>
<ListItemText>{page.name}</ListItemText>
</Link>
</MenuItem>
)) }
</MenuList>
</Drawer>
</Box>)
}
export default MenuBar