aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/app/admin/layout.tsx
blob: 0d876736cb29ec0e0cbf2fcb08eef93a7b4fe374 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { redirect } from "next/navigation";
import { AdminCard } from "@/components/admin/AdminCard";
import { AdminNotices } from "@/components/admin/AdminNotices";
import MobileAdminSidebar from "@/components/admin/sidebar/MobileSidebar";
import AdminSidebar from "@/components/admin/sidebar/Sidebar";
import Header from "@/components/dashboard/header/Header";
import { Separator } from "@/components/ui/separator";
import { getServerAuthSession } from "@/server/auth";

export default async function AdminLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const session = await getServerAuthSession();
  if (!session || session.user.role !== "admin") {
    redirect("/");
  }

  return (
    <div>
      <Header />
      <div className="flex min-h-[calc(100vh-64px)] w-screen flex-col sm:h-[calc(100vh-64px)] sm:flex-row">
        <div className="hidden flex-none sm:flex">
          <AdminSidebar />
        </div>
        <main className="flex-1 bg-muted sm:overflow-y-auto">
          <div className="block w-full sm:hidden">
            <MobileAdminSidebar />
            <Separator />
          </div>
          <div className="min-h-30 container flex flex-col gap-1 p-4">
            <AdminNotices />
            <AdminCard>{children}</AdminCard>
          </div>
        </main>
      </div>
    </div>
  );
}