2022-11-24 13:48:18 +00:00
|
|
|
// react
|
2022-12-02 14:12:58 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
// next
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// hooks
|
|
|
|
import useUser from "lib/hooks/useUser";
|
2022-11-19 14:21:26 +00:00
|
|
|
// layouts
|
|
|
|
import Container from "layouts/Container";
|
2022-11-24 13:48:18 +00:00
|
|
|
import Sidebar from "layouts/Navbar/Sidebar";
|
|
|
|
// components
|
|
|
|
import CreateProjectModal from "components/project/CreateProjectModal";
|
2022-11-19 14:21:26 +00:00
|
|
|
// types
|
|
|
|
import type { Props } from "./types";
|
|
|
|
|
|
|
|
const AdminLayout: React.FC<Props> = ({ meta, children }) => {
|
2022-11-24 13:48:18 +00:00
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
2022-12-02 14:12:58 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const { user, isUserLoading } = useUser();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isUserLoading && (!user || user === null)) router.push("/signin");
|
|
|
|
}, [isUserLoading, user, router]);
|
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
return (
|
|
|
|
<Container meta={meta}>
|
2022-11-24 13:48:18 +00:00
|
|
|
<CreateProjectModal isOpen={isOpen} setIsOpen={setIsOpen} />
|
|
|
|
<div className="h-screen w-full flex overflow-x-hidden">
|
|
|
|
<Sidebar />
|
|
|
|
<main className="h-full w-full min-w-0 p-5 bg-primary overflow-y-auto">{children}</main>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AdminLayout;
|