import * as React from 'react'; import { styled, createTheme, ThemeProvider } from '@mui/material/styles'; import CssBaseline from '@mui/material/CssBaseline'; import MuiDrawer from '@mui/material/Drawer'; import Box from '@mui/material/Box'; import MuiAppBar, { AppBarProps as MuiAppBarProps } from '@mui/material/AppBar'; import Toolbar from '@mui/material/Toolbar'; import List from '@mui/material/List'; import Typography from '@mui/material/Typography'; import Divider from '@mui/material/Divider'; import IconButton from '@mui/material/IconButton'; import Container from '@mui/material/Container'; import MenuIcon from '@mui/icons-material/Menu'; import { Api, Assignment, Cloud, Factory, Home, People, Shield, Storage, } from '@mui/icons-material'; import { ListItem, ListItemButton, ListItemIcon, ListItemText, } from '@mui/material'; import { Outlet, useNavigate } from 'react-router-dom'; import { UserData } from '../interfaces/auth'; import { getUserData, useAuthStore } from '../store/auth'; import { useTheme } from '@emotion/react'; import AccountMenu from '../components/AccountMenu'; const drawerWidth: number = 240; interface AppBarProps extends MuiAppBarProps { open?: boolean; } const AppBar = styled(MuiAppBar, { shouldForwardProp: (prop) => prop !== 'open', })(({ theme, open }) => ({ zIndex: theme.zIndex.drawer + 1, transition: theme.transitions.create(['width', 'margin'], { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.leavingScreen, }), ...(open && { marginLeft: drawerWidth, width: `calc(100% - ${drawerWidth}px)`, transition: theme.transitions.create(['width', 'margin'], { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.enteringScreen, }), }), })); const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== 'open' })( ({ theme, open }) => ({ '& .MuiDrawer-paper': { position: 'relative', whiteSpace: 'nowrap', width: drawerWidth, transition: theme.transitions.create('width', { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.enteringScreen, }), boxSizing: 'border-box', ...(!open && { overflowX: 'hidden', transition: theme.transitions.create('width', { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.leavingScreen, }), width: theme.spacing(7), [theme.breakpoints.up('sm')]: { //width: theme.spacing(9), }, }), }, }), ); const pages = [ { label: "Главная", path: "/", icon: }, { label: "Пользователи", path: "/user", icon: }, { label: "Роли", path: "/role", icon: }, { label: "Документы", path: "/documents", icon: }, { label: "Отчеты", path: "/reports", icon: }, { label: "Серверы", path: "/servers", icon: }, { label: "Котельные", path: "/boilers", icon: }, { label: "API Test", path: "/api-test", icon: }, ] export default function DashboardLayout() { const theme = useTheme() const innerTheme = createTheme(theme) const [open, setOpen] = React.useState(true); const toggleDrawer = () => { setOpen(!open); }; const authStore = useAuthStore(); const navigate = useNavigate() const getPageTitle = () => { const currentPath = location.pathname; const allPages = [...pages]; const currentPage = allPages.find(page => page.path === currentPath); return currentPage ? currentPage.label : "Dashboard"; }; const [userData, setUserData] = React.useState(); React.useEffect(() => { if (authStore) { const stored = getUserData() if (stored) { setUserData(stored) } } }, [authStore]) return ( {getPageTitle()} {userData?.name} {userData?.surname} {userData?.login} {/* */} {pages.map((item, index) => ( { navigate(item.path) }} style={{ background: location.pathname === item.path ? innerTheme.palette.action.selected : "transparent" }} selected={location.pathname === item.path} > {item.icon} ))} theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[900], flexGrow: 1, maxHeight: "100vh", overflow: 'auto', }} > ); }