diff --git a/src/components/ui/dashboard/layout.tsx b/src/components/ui/dashboard/layout.tsx index 2a3b647..3fc4768 100644 --- a/src/components/ui/dashboard/layout.tsx +++ b/src/components/ui/dashboard/layout.tsx @@ -11,7 +11,9 @@ export const DashboardLayout = () => { return (
- +
+ +
diff --git a/src/components/ui/dashboard/sidebar-mobile.tsx b/src/components/ui/dashboard/sidebar-mobile.tsx index 944bd3c..e5fb658 100644 --- a/src/components/ui/dashboard/sidebar-mobile.tsx +++ b/src/components/ui/dashboard/sidebar-mobile.tsx @@ -1,33 +1,44 @@ -import { FC } from "react" -import { SidebarInterface } from "../../../types" -import { sidebarItems } from "../../../utility/sidebar" -import { SidebarItem } from "./sidebar-item" -import { CloseCircle, LogoutCurve } from "iconsax-react" +import { FC } from "react"; +import { SidebarInterface } from "../../../types"; +import { sidebarItems } from "../../../utility/sidebar"; +import { SidebarItem } from "./sidebar-item"; +import { CloseCircle, LogoutCurve } from "iconsax-react"; +import { useNavigate } from "react-router-dom"; type Props = { setShow: (value: boolean) => void, show: any, -} +}; export const SidebarMobile: FC = ({ setShow, show }) => { - const handleCloseSidebar = () => setShow(false) + const navigate = useNavigate() + const handleCloseSidebar = () => setShow(false); + const handleExit = () => { + window.localStorage.clear() + navigate("/auth/login") + } return ( - show &&
-
- -
- logo -
-
- {sidebarItems?.map((item: SidebarInterface) => )} -
-
- -

خروج

+ <> + {show && ( +
+ )} +
+
+ +
+ logo +
+
+ {sidebarItems?.map((item: SidebarInterface) => )} +
+
+ +

خروج

+
-
- ) -} \ No newline at end of file + + ); +}; diff --git a/src/components/ui/dashboard/sidebar.tsx b/src/components/ui/dashboard/sidebar.tsx index 2b1c776..4aaf004 100644 --- a/src/components/ui/dashboard/sidebar.tsx +++ b/src/components/ui/dashboard/sidebar.tsx @@ -2,8 +2,14 @@ import { LogoutCurve } from "iconsax-react" import { SidebarInterface } from "../../../types" import { sidebarItems } from "../../../utility/sidebar" import { SidebarItem } from "./sidebar-item" +import { useNavigate } from "react-router-dom" export const Sidebar = () => { + const navigate = useNavigate() + const handleExit = () => { + window.localStorage.clear() + navigate("/auth/login") + } return (
logo @@ -11,7 +17,7 @@ export const Sidebar = () => {
{sidebarItems?.map((item: SidebarInterface) => )}
-
+

خروج

diff --git a/src/guard/index.tsx b/src/guard/index.tsx new file mode 100644 index 0000000..3a552e2 --- /dev/null +++ b/src/guard/index.tsx @@ -0,0 +1,19 @@ +import { PropsWithChildren, useEffect } from "react" +import { useNavigate } from "react-router-dom" + +export const Guard = ({ children }: PropsWithChildren) => { + const navigate = useNavigate() + const token = window.localStorage.getItem("token") + + useEffect(() => { + if (!token || token?.length <= 0 || token === undefined || token === null) { + navigate("/auth/login") + } + }, [token , navigate]) + + return ( + <> + {children} + + ) +} \ No newline at end of file diff --git a/src/router/index.tsx b/src/router/index.tsx index 6e3ec8a..5e8bbd5 100644 --- a/src/router/index.tsx +++ b/src/router/index.tsx @@ -17,11 +17,12 @@ import { TransactionsPage } from "../pages/dashboard/transactions"; import { ScorePage } from "../pages/dashboard/score"; import { SubscriptionReportPage } from "../pages/dashboard/subscription-report"; import { AwardsPage } from "../pages/dashboard/awards"; +import { Guard } from "../guard"; export const router = createBrowserRouter([ { - element: , + element: , path: "/", children: [ {