fix sidebar - complete auth layout

This commit is contained in:
Alihaghighattalab
2024-08-17 17:08:25 +03:30
parent ddf6bcd287
commit 86b5b41abf
5 changed files with 64 additions and 25 deletions
+3 -1
View File
@@ -11,7 +11,9 @@ export const DashboardLayout = () => {
return ( return (
<div className="w-full min-h-screen flex flex-col lg:flex-row"> <div className="w-full min-h-screen flex flex-col lg:flex-row">
<Sidebar /> <Sidebar />
<SidebarMobile show={show} setShow={setShow} /> <div className="w-screen min-w-full h-full lg:hidden bg-red-900">
<SidebarMobile show={show} setShow={setShow} />
</div>
<div className="w-full min-h-screen p-4 pb-0 xl:p-[30px] xl:pb-0 flex flex-col overflow-y-auto"> <div className="w-full min-h-screen p-4 pb-0 xl:p-[30px] xl:pb-0 flex flex-col overflow-y-auto">
<Header setShow={handleSidebar} /> <Header setShow={handleSidebar} />
<div className="flex-grow w-full"> <div className="flex-grow w-full">
+33 -22
View File
@@ -1,33 +1,44 @@
import { FC } from "react" import { FC } from "react";
import { SidebarInterface } from "../../../types" import { SidebarInterface } from "../../../types";
import { sidebarItems } from "../../../utility/sidebar" import { sidebarItems } from "../../../utility/sidebar";
import { SidebarItem } from "./sidebar-item" import { SidebarItem } from "./sidebar-item";
import { CloseCircle, LogoutCurve } from "iconsax-react" import { CloseCircle, LogoutCurve } from "iconsax-react";
import { useNavigate } from "react-router-dom";
type Props = { type Props = {
setShow: (value: boolean) => void, setShow: (value: boolean) => void,
show: any, show: any,
} };
export const SidebarMobile: FC<Props> = ({ setShow, show }) => { export const SidebarMobile: FC<Props> = ({ setShow, show }) => {
const handleCloseSidebar = () => setShow(false) const navigate = useNavigate()
const handleCloseSidebar = () => setShow(false);
const handleExit = () => {
window.localStorage.clear()
navigate("/auth/login")
}
return ( return (
show && <div className="lg:hidden fixed top-0 left-full !z-50 h-screen transition-transform -translate-x-full bg-auth-form w-max"> <>
<div className="relative p-4 h-full"> {show && (
<CloseCircle color="gray" variant="Bold" className="size-7 text-white absolute top-2 right-2" onClick={handleCloseSidebar} /> <div className="fixed inset-0 bg-black bg-opacity-50 z-40" onClick={handleCloseSidebar}></div>
<div className="lg:hidden w-full h-full max-w-max p-[21px] flex flex-col gap-y-[44px] items-center xl:max-w-fit bg-secondry-color"> )}
<img src="/svgs/logo/logo.svg" alt="logo" className="auth-logo-size" /> <div className={`lg:hidden fixed top-0 left-full !z-50 h-screen transition ease-in-out duration-1000 ${show ? '-translate-x-full' : ''} bg-auth-form w-max`}>
<div className="h-full flex flex-col justify-between"> <div className="relative p-4 h-full">
<div className="flex flex-col gap-y-3"> <CloseCircle color="gray" variant="Bold" className="size-7 text-white absolute top-2 right-2" onClick={handleCloseSidebar} />
{sidebarItems?.map((item: SidebarInterface) => <SidebarItem key={item?.name} item={item} />)} <div className="lg:hidden w-full h-full max-w-max p-[21px] flex flex-col gap-y-[44px] items-center xl:max-w-fit bg-secondry-color">
</div> <img src="/svgs/logo/logo.svg" alt="logo" className="auth-logo-size" />
<div className="w-full flex flex-row gap-x-3 items-center rounded-[20px] p-3 min-w-52 cursor-pointer"> <div className="h-full flex flex-col justify-between">
<LogoutCurve color="#777577" className="size-[27px]" /> <div className="flex flex-col gap-y-3">
<p className="font-normal text-base text-secondary-text-color">خروج</p> {sidebarItems?.map((item: SidebarInterface) => <SidebarItem key={item?.name} item={item} />)}
</div>
<div className="w-full flex flex-row gap-x-3 items-center rounded-[20px] p-3 min-w-52 cursor-pointer" onClick={handleExit}>
<LogoutCurve color="#777577" className="size-[27px]" />
<p className="font-normal text-base text-secondary-text-color">خروج</p>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </>
) );
} };
+7 -1
View File
@@ -2,8 +2,14 @@ import { LogoutCurve } from "iconsax-react"
import { SidebarInterface } from "../../../types" import { SidebarInterface } from "../../../types"
import { sidebarItems } from "../../../utility/sidebar" import { sidebarItems } from "../../../utility/sidebar"
import { SidebarItem } from "./sidebar-item" import { SidebarItem } from "./sidebar-item"
import { useNavigate } from "react-router-dom"
export const Sidebar = () => { export const Sidebar = () => {
const navigate = useNavigate()
const handleExit = () => {
window.localStorage.clear()
navigate("/auth/login")
}
return ( return (
<div className="hidden lg:flex bg-auth-form min-w-[318px] max-w-[318px] flex-col items-center py-[42px] gap-y-20"> <div className="hidden lg:flex bg-auth-form min-w-[318px] max-w-[318px] flex-col items-center py-[42px] gap-y-20">
<img src="/svgs/logo/logo.svg" alt="logo" className="auth-logo-size" /> <img src="/svgs/logo/logo.svg" alt="logo" className="auth-logo-size" />
@@ -11,7 +17,7 @@ export const Sidebar = () => {
<div className="flex flex-col gap-y-3"> <div className="flex flex-col gap-y-3">
{sidebarItems?.map((item: SidebarInterface) => <SidebarItem key={item?.name} item={item} />)} {sidebarItems?.map((item: SidebarInterface) => <SidebarItem key={item?.name} item={item} />)}
</div> </div>
<div className="w-full flex flex-row gap-x-3 items-center rounded-[20px] p-3 min-w-52 cursor-pointer"> <div className="w-full flex flex-row gap-x-3 items-center rounded-[20px] p-3 min-w-52 cursor-pointer" onClick={handleExit}>
<LogoutCurve color="#777577" className="size-[27px]" /> <LogoutCurve color="#777577" className="size-[27px]" />
<p className="font-normal text-base text-secondary-text-color">خروج</p> <p className="font-normal text-base text-secondary-text-color">خروج</p>
</div> </div>
+19
View File
@@ -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}
</>
)
}
+2 -1
View File
@@ -17,11 +17,12 @@ import { TransactionsPage } from "../pages/dashboard/transactions";
import { ScorePage } from "../pages/dashboard/score"; import { ScorePage } from "../pages/dashboard/score";
import { SubscriptionReportPage } from "../pages/dashboard/subscription-report"; import { SubscriptionReportPage } from "../pages/dashboard/subscription-report";
import { AwardsPage } from "../pages/dashboard/awards"; import { AwardsPage } from "../pages/dashboard/awards";
import { Guard } from "../guard";
export const router = createBrowserRouter([ export const router = createBrowserRouter([
{ {
element: <DashboardLayout />, element: <Guard><DashboardLayout /></Guard>,
path: "/", path: "/",
children: [ children: [
{ {