// Layout for dashboard with responsive drawer import { Outlet, useLocation, useNavigate } from "react-router-dom" import * as React from 'react'; import AppBar from '@mui/material/AppBar'; import Box from '@mui/material/Box'; import CssBaseline from '@mui/material/CssBaseline'; import Divider from '@mui/material/Divider'; import Drawer from '@mui/material/Drawer'; import IconButton from '@mui/material/IconButton'; import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import MenuIcon from '@mui/icons-material/Menu'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; import { Api, ExitToApp, Home, People, Settings, Shield } from "@mui/icons-material"; import { getUserData, useAuthStore } from "../store/auth"; import { UserData } from "../interfaces/auth"; const drawerWidth = 240; export default function DashboardLayoutResponsive() { const [open, setOpen] = React.useState(true); const authStore = useAuthStore(); const [userData, setUserData] = React.useState(); const location = useLocation() const navigate = useNavigate() //const { window } = props; const [mobileOpen, setMobileOpen] = React.useState(false); const [isClosing, setIsClosing] = React.useState(false); const handleDrawerClose = () => { setIsClosing(true); setMobileOpen(false); }; const handleDrawerTransitionEnd = () => { setIsClosing(false); }; const handleDrawerToggle = () => { if (!isClosing) { setMobileOpen(!mobileOpen); } }; const pages = [ { label: "Главная", path: "/", icon: }, { label: "Пользователи", path: "/user", icon: }, { label: "Роли", path: "/role", icon: }, { label: "API Test", path: "/api-test", icon: }, ] const misc = [ { label: "Настройки", path: "/settings", icon: }, { label: "Выход", path: "/signOut", icon: } ] const getPageTitle = () => { const currentPath = location.pathname; const allPages = [...pages, ...misc]; const currentPage = allPages.find(page => page.path === currentPath); return currentPage ? currentPage.label : "Dashboard"; }; const toggleDrawer = () => { setOpen(!open); }; const drawer = (
{userData?.name} {userData?.surname} {userData?.login} {pages.map((item, index) => ( { navigate(item.path) }} selected={location.pathname === item.path} > {item.icon} ))} {misc.map((item, index) => ( { navigate(item.path) }} selected={location.pathname === item.path} > {item.icon} ))}
); React.useEffect(() => { if (authStore) { const stored = getUserData() if (stored) { setUserData(stored) } } }, [authStore]) return ( {getPageTitle()} {/* The implementation can be swapped with js to avoid SEO duplication of links. */} {drawer} {drawer} ); }