-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dashboard auth-checkout updated (#38)
- Loading branch information
1 parent
54a48d8
commit c9e3a75
Showing
1 changed file
with
57 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,60 @@ | ||
import { | ||
AppShell, | ||
Box, | ||
ScrollArea | ||
} from '@mantine/core'; | ||
import { Outlet } from 'react-router-dom' | ||
import Footer from '../components/shared/Footer'; | ||
import XHeader from '../components/layouts/Header'; | ||
import { XSidebar } from '../components/layouts/Sidebar'; | ||
import { useMediaQuery, useDisclosure } from '@mantine/hooks'; | ||
import { AppShell, Box, ScrollArea } from "@mantine/core"; | ||
import { Outlet } from "react-router-dom"; | ||
import Footer from "../components/shared/Footer"; | ||
import XHeader from "../components/layouts/Header"; | ||
import { XSidebar } from "../components/layouts/Sidebar"; | ||
import { useMediaQuery, useDisclosure } from "@mantine/hooks"; | ||
import { useEffect } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
export function MainLayout() { | ||
const isMobile = useMediaQuery('(min-width: 500px)'); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [_, { toggle }] = useDisclosure(false); | ||
const isMobile = useMediaQuery("(min-width: 500px)"); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [_, { toggle }] = useDisclosure(false); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<AppShell | ||
padding="md" | ||
navbar={isMobile ? <XSidebar toggle={toggle} /> : <></>} | ||
header={<XHeader />} | ||
styles={(theme) => ({ | ||
main: { backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.colors.gray[0], minHeight: 'auto', }, | ||
})} | ||
footer={ | ||
<Footer />} | ||
> | ||
<Box h={'85vh'} style={{ paddingBottom: "2vh" }} component={ScrollArea}> | ||
<Outlet /> | ||
</Box> | ||
</AppShell> | ||
); | ||
} | ||
useEffect(() => { | ||
const authItem: string | null = localStorage.getItem("auth"); | ||
|
||
// Check if authItem is not null and parse it | ||
if (authItem !== null) { | ||
const tokenPresent: { | ||
accessToken: string; | ||
user: { | ||
id: number; | ||
create_time: string; | ||
email: string; | ||
username: string; | ||
}; | ||
} = JSON.parse(authItem); | ||
|
||
if (!tokenPresent.accessToken) { | ||
navigate("/auth/login"); | ||
} | ||
} else { | ||
navigate("/auth/login"); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<AppShell | ||
padding="md" | ||
navbar={isMobile ? <XSidebar toggle={toggle} /> : <></>} | ||
header={<XHeader />} | ||
styles={(theme) => ({ | ||
main: { | ||
backgroundColor: | ||
theme.colorScheme === "dark" | ||
? theme.colors.dark[8] | ||
: theme.colors.gray[0], | ||
minHeight: "auto", | ||
}, | ||
})} | ||
footer={<Footer />} | ||
> | ||
<Box h={"85vh"} style={{ paddingBottom: "2vh" }} component={ScrollArea}> | ||
<Outlet /> | ||
</Box> | ||
</AppShell> | ||
); | ||
} |