You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.6KB

  1. import { Box, Typography, styled } from "@mui/material";
  2. import { Outlet } from "react-router-dom";
  3. import Navigator from "./navigator";
  4. import useResponsive from "hooks/useResponsive";
  5. import { useContext, useEffect, useMemo, useState } from "react";
  6. import Header from "./header";
  7. import useWindowSize from "hooks/useWindowSize";
  8. import {
  9. DashboardLayoutContext,
  10. DashboardLayoutContextProvider,
  11. } from "contexts/DashboardLayoutContext";
  12. import useDashboard from "hooks/useDashBoard";
  13. import useAuth from "hooks/useAuth";
  14. import useNavigateCustom from "hooks/useNavigateCustom";
  15. import { getPath } from "routes/path";
  16. import { PageID } from "pages";
  17. import useBackDrop from "hooks/useBackDrop";
  18. function Copyright() {
  19. return (
  20. <Typography variant="body2" color="text.secondary" align="center">
  21. {"Copyright ©Satellite-Technologies Co., Ltd."}
  22. {new Date().getFullYear()}. All Rights Reserved.
  23. </Typography>
  24. );
  25. }
  26. function App() {
  27. const { initialized, authenticated } = useAuth();
  28. const { navigateWhenChanged } = useNavigateCustom();
  29. const { setShowBackDrop } = useBackDrop();
  30. const [mobileOpen, setMobileOpen] = useState(false);
  31. const { drawerWidth, innerWidth, contentsWidth } = useDashboard();
  32. const handleDrawerToggle = () => {
  33. setMobileOpen(!mobileOpen);
  34. };
  35. useEffect(() => {
  36. setShowBackDrop(!initialized);
  37. if (initialized && !authenticated) {
  38. navigateWhenChanged(getPath(PageID.PAGE_403));
  39. }
  40. }, [initialized, authenticated]);
  41. if (!initialized) {
  42. return null;
  43. }
  44. return (
  45. <Box sx={{ display: "flex", minHeight: "100vh" }}>
  46. <Box
  47. component="nav"
  48. sx={{ width: { sm: drawerWidth }, flexShrink: { md: 0 } }}
  49. >
  50. <Navigator
  51. PaperProps={{ style: { width: drawerWidth } }}
  52. variant="temporary"
  53. open={mobileOpen}
  54. onClose={handleDrawerToggle}
  55. />
  56. <Navigator
  57. PaperProps={{ style: { width: drawerWidth } }}
  58. sx={{ display: { sm: "block", xs: "none" } }}
  59. />
  60. </Box>
  61. <Box
  62. sx={{
  63. flex: 1,
  64. display: "flex",
  65. flexDirection: "column",
  66. maxWidth: contentsWidth,
  67. }}
  68. >
  69. <Header onDrawerToggle={handleDrawerToggle} />
  70. <Box component="main" sx={{ flex: 1, pt: 1, pb: 6, px: 4 }}>
  71. <Outlet />
  72. </Box>
  73. <Box component="footer" sx={{ p: 2 }}>
  74. <Copyright />
  75. </Box>
  76. </Box>
  77. </Box>
  78. );
  79. }
  80. export default function DashBoardLayout() {
  81. return (
  82. <DashboardLayoutContextProvider>
  83. <App />
  84. </DashboardLayoutContextProvider>
  85. );
  86. }