Add base authenticated route
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import { mdiMessageTextFast } from "@mdi/js";
|
||||
import Icon from "@mdi/react";
|
||||
import Box from "@mui/material/Box";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import Toolbar from "@mui/material/Toolbar";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import * as React from "react";
|
||||
import { Outlet } from "react-router";
|
||||
import DashboardHeader from "./DashboardHeader";
|
||||
import DashboardSidebar from "./DashboardSidebar";
|
||||
|
||||
export default function BaseAuthenticatedPage(): React.ReactElement {
|
||||
const theme = useTheme();
|
||||
|
||||
const [isDesktopNavigationExpanded, setIsDesktopNavigationExpanded] =
|
||||
React.useState(true);
|
||||
const [isMobileNavigationExpanded, setIsMobileNavigationExpanded] =
|
||||
React.useState(false);
|
||||
|
||||
const isOverMdViewport = useMediaQuery(theme.breakpoints.up("md"));
|
||||
|
||||
const isNavigationExpanded = isOverMdViewport
|
||||
? isDesktopNavigationExpanded
|
||||
: isMobileNavigationExpanded;
|
||||
|
||||
const setIsNavigationExpanded = React.useCallback(
|
||||
(newExpanded: boolean) => {
|
||||
if (isOverMdViewport) {
|
||||
setIsDesktopNavigationExpanded(newExpanded);
|
||||
} else {
|
||||
setIsMobileNavigationExpanded(newExpanded);
|
||||
}
|
||||
},
|
||||
[
|
||||
isOverMdViewport,
|
||||
setIsDesktopNavigationExpanded,
|
||||
setIsMobileNavigationExpanded,
|
||||
]
|
||||
);
|
||||
|
||||
const handleToggleHeaderMenu = React.useCallback(
|
||||
(isExpanded: boolean) => {
|
||||
setIsNavigationExpanded(isExpanded);
|
||||
},
|
||||
[setIsNavigationExpanded]
|
||||
);
|
||||
|
||||
const layoutRef = React.useRef<HTMLDivElement>(null);
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={layoutRef}
|
||||
sx={{
|
||||
position: "relative",
|
||||
display: "flex",
|
||||
overflow: "hidden",
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<DashboardHeader
|
||||
logo={<Icon path={mdiMessageTextFast} size="2em" color={"white"} />}
|
||||
title=""
|
||||
menuOpen={isNavigationExpanded}
|
||||
onToggleMenu={handleToggleHeaderMenu}
|
||||
/>
|
||||
<DashboardSidebar
|
||||
expanded={isNavigationExpanded}
|
||||
setExpanded={setIsNavigationExpanded}
|
||||
container={layoutRef?.current ?? undefined}
|
||||
/>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
}}
|
||||
>
|
||||
<Toolbar sx={{ displayPrint: "none" }} />
|
||||
<Box
|
||||
component="main"
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
flex: 1,
|
||||
overflow: "auto",
|
||||
padding: "50px",
|
||||
}}
|
||||
>
|
||||
<Outlet />
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user