1 | 'use client';
|
---|
2 |
|
---|
3 | import { useEffect } from 'react';
|
---|
4 | // @mui
|
---|
5 | import Box from '@mui/material/Box';
|
---|
6 | import Stack from '@mui/material/Stack';
|
---|
7 | import Drawer from '@mui/material/Drawer';
|
---|
8 | // hooks
|
---|
9 | import { useResponsive } from 'src/hooks/use-responsive';
|
---|
10 | import { useAuthContext } from 'src/auth/hooks';
|
---|
11 | // components
|
---|
12 | import Logo from 'src/components/logo';
|
---|
13 | import Scrollbar from 'src/components/scrollbar';
|
---|
14 | import { usePathname } from 'src/routes/hooks';
|
---|
15 | import { NavSectionVertical } from 'src/components/nav-section';
|
---|
16 | //
|
---|
17 | import { NAV } from '../config-layout';
|
---|
18 | import { useNavData } from './config-navigation';
|
---|
19 | import { NavToggleButton } from '../_common';
|
---|
20 |
|
---|
21 | // ----------------------------------------------------------------------
|
---|
22 |
|
---|
23 | type Props = {
|
---|
24 | openNav: boolean;
|
---|
25 | onCloseNav: VoidFunction;
|
---|
26 | };
|
---|
27 |
|
---|
28 | export default function NavVertical({ openNav, onCloseNav }: Props) {
|
---|
29 | const { user } = useAuthContext();
|
---|
30 |
|
---|
31 | const pathname = usePathname();
|
---|
32 |
|
---|
33 | const lgUp = useResponsive('up', 'lg');
|
---|
34 |
|
---|
35 | const navData = useNavData();
|
---|
36 |
|
---|
37 | useEffect(() => {
|
---|
38 | if (openNav) {
|
---|
39 | onCloseNav();
|
---|
40 | }
|
---|
41 | // eslint-disable-next-line react-hooks/exhaustive-deps
|
---|
42 | }, [pathname]);
|
---|
43 |
|
---|
44 | const renderContent = (
|
---|
45 | <Scrollbar
|
---|
46 | sx={{
|
---|
47 | height: 1,
|
---|
48 | '& .simplebar-content': {
|
---|
49 | height: 1,
|
---|
50 | display: 'flex',
|
---|
51 | flexDirection: 'column',
|
---|
52 | },
|
---|
53 | }}
|
---|
54 | >
|
---|
55 | <Logo sx={{ mt: 3, ml: 4, mb: 1 }} />
|
---|
56 |
|
---|
57 | <NavSectionVertical
|
---|
58 | data={navData}
|
---|
59 | config={{
|
---|
60 | currentRole: user?.role || 'ADMIN',
|
---|
61 | }}
|
---|
62 | />
|
---|
63 |
|
---|
64 | <Box sx={{ flexGrow: 1 }} />
|
---|
65 |
|
---|
66 | {/* <NavUpgrade /> */}
|
---|
67 | </Scrollbar>
|
---|
68 | );
|
---|
69 |
|
---|
70 | return (
|
---|
71 | <Box
|
---|
72 | component="nav"
|
---|
73 | sx={{
|
---|
74 | flexShrink: { lg: 0 },
|
---|
75 | width: { lg: NAV.W_VERTICAL },
|
---|
76 | }}
|
---|
77 | >
|
---|
78 | <NavToggleButton />
|
---|
79 |
|
---|
80 | {lgUp ? (
|
---|
81 | <Stack
|
---|
82 | sx={{
|
---|
83 | height: 1,
|
---|
84 | position: 'fixed',
|
---|
85 | width: NAV.W_VERTICAL,
|
---|
86 | borderRight: (theme) => `dashed 1px ${theme.palette.divider}`,
|
---|
87 | }}
|
---|
88 | >
|
---|
89 | {renderContent}
|
---|
90 | </Stack>
|
---|
91 | ) : (
|
---|
92 | <Drawer
|
---|
93 | open={openNav}
|
---|
94 | onClose={onCloseNav}
|
---|
95 | PaperProps={{
|
---|
96 | sx: {
|
---|
97 | width: NAV.W_VERTICAL,
|
---|
98 | },
|
---|
99 | }}
|
---|
100 | >
|
---|
101 | {renderContent}
|
---|
102 | </Drawer>
|
---|
103 | )}
|
---|
104 | </Box>
|
---|
105 | );
|
---|
106 | }
|
---|