2024-08-14 15:36:25 +07:00
|
|
|
import { PageContext } from "@/context/page-context";
|
2024-08-16 01:23:55 +07:00
|
|
|
import { Suspense, useContext } from "react";
|
|
|
|
import { Outlet, useNavigate } from "react-router-dom";
|
|
|
|
import Sidebar from "../containers/sidebar";
|
|
|
|
import { ArrowLeft } from "lucide-react";
|
|
|
|
import Button from "../ui/button";
|
2024-08-14 15:36:25 +07:00
|
|
|
|
|
|
|
const MainLayout = () => {
|
|
|
|
return (
|
|
|
|
<div className="flex flex-row items-stretch h-screen overflow-hidden">
|
|
|
|
<Sidebar />
|
|
|
|
|
|
|
|
<div className="flex-1 flex flex-col overflow-hidden">
|
|
|
|
<Header />
|
|
|
|
|
|
|
|
<main className="flex-1 overflow-y-auto p-4 md:p-8">
|
2024-08-16 01:23:55 +07:00
|
|
|
<Suspense>
|
2024-08-14 15:36:25 +07:00
|
|
|
<Outlet />
|
2024-08-16 01:23:55 +07:00
|
|
|
</Suspense>
|
2024-08-14 15:36:25 +07:00
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const Header = () => {
|
|
|
|
const page = useContext(PageContext);
|
2024-08-16 01:23:55 +07:00
|
|
|
const navigate = useNavigate();
|
2024-08-14 15:36:25 +07:00
|
|
|
|
|
|
|
return (
|
2024-08-16 01:23:55 +07:00
|
|
|
<header className="bg-base-100 px-4 h-16 md:px-8 md:h-20 flex flex-row items-center gap-4">
|
|
|
|
{page?.prev ? (
|
|
|
|
<Button
|
|
|
|
href={page.prev}
|
|
|
|
onClick={() => navigate(page.prev!, { replace: true })}
|
|
|
|
color="ghost"
|
|
|
|
shape="circle"
|
|
|
|
className="-ml-4"
|
|
|
|
>
|
|
|
|
<ArrowLeft />
|
|
|
|
</Button>
|
|
|
|
) : null}
|
2024-08-16 23:10:19 +07:00
|
|
|
|
|
|
|
<h1 className="text-xl flex-1 truncate">{page?.title || "Dashboard"}</h1>
|
|
|
|
|
|
|
|
{page?.actions}
|
2024-08-14 15:36:25 +07:00
|
|
|
</header>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MainLayout;
|