2023-02-08 17:58:55 -06:00
|
|
|
import Navbar from "@/components/Navbar";
|
|
|
|
import Sidebar from "@/components/Sidebar";
|
2023-07-16 10:51:24 -05:00
|
|
|
import { ReactNode, useEffect } from "react";
|
2023-02-08 17:58:55 -06:00
|
|
|
import { useSession } from "next-auth/react";
|
2023-02-13 15:22:47 -06:00
|
|
|
import Loader from "../components/Loader";
|
2023-04-30 15:54:40 -05:00
|
|
|
import useRedirect from "@/hooks/useRedirect";
|
2023-02-08 17:58:55 -06:00
|
|
|
import { useRouter } from "next/router";
|
2023-06-12 23:46:32 -05:00
|
|
|
import ModalManagement from "@/components/ModalManagement";
|
2023-07-16 10:51:24 -05:00
|
|
|
import useModalStore from "@/store/modals";
|
2023-02-08 17:58:55 -06:00
|
|
|
|
2023-02-13 15:22:47 -06:00
|
|
|
interface Props {
|
2023-02-08 17:58:55 -06:00
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function MainLayout({ children }: Props) {
|
2023-07-15 21:15:43 -05:00
|
|
|
const { status, data } = useSession();
|
2023-02-08 17:58:55 -06:00
|
|
|
const router = useRouter();
|
2023-04-30 15:54:40 -05:00
|
|
|
const redirect = useRedirect();
|
2023-02-08 17:58:55 -06:00
|
|
|
const routeExists = router.route === "/_error" ? false : true;
|
|
|
|
|
2023-07-16 10:51:24 -05:00
|
|
|
const { modal } = useModalStore();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
modal
|
|
|
|
? (document.body.style.overflow = "hidden")
|
|
|
|
: (document.body.style.overflow = "auto");
|
|
|
|
}, [modal]);
|
|
|
|
|
2023-04-30 15:54:40 -05:00
|
|
|
if (status === "authenticated" && !redirect && routeExists)
|
2023-02-08 17:58:55 -06:00
|
|
|
return (
|
2023-06-12 23:46:32 -05:00
|
|
|
<>
|
|
|
|
<ModalManagement />
|
|
|
|
|
|
|
|
<div className="flex">
|
|
|
|
<div className="hidden lg:block">
|
2023-07-30 15:37:56 -05:00
|
|
|
<Sidebar className="fixed top-0" />
|
2023-06-12 23:46:32 -05:00
|
|
|
</div>
|
2023-04-30 15:54:40 -05:00
|
|
|
|
2023-06-12 23:46:32 -05:00
|
|
|
<div className="w-full lg:ml-64 xl:ml-80">
|
|
|
|
<Navbar />
|
|
|
|
{children}
|
|
|
|
</div>
|
2023-02-08 17:58:55 -06:00
|
|
|
</div>
|
2023-06-12 23:46:32 -05:00
|
|
|
</>
|
2023-02-08 17:58:55 -06:00
|
|
|
);
|
2023-04-30 15:54:40 -05:00
|
|
|
else if ((status === "unauthenticated" && !redirect) || !routeExists)
|
2023-03-28 02:31:50 -05:00
|
|
|
return <>{children}</>;
|
2023-05-01 05:07:01 -05:00
|
|
|
else return <></>;
|
2023-02-08 17:58:55 -06:00
|
|
|
}
|