aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/app/admin/layout.tsx
blob: 4b58971273035890fbe6bbf7cbd8be6049060a42 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from "react";
import { redirect } from "next/navigation";
import { AdminNotices } from "@/components/admin/AdminNotices";
import MobileSidebar from "@/components/shared/sidebar/MobileSidebar";
import Sidebar from "@/components/shared/sidebar/Sidebar";
import SidebarLayout from "@/components/shared/sidebar/SidebarLayout";
import { getServerAuthSession } from "@/server/auth";
import { TFunction } from "i18next";
import { Activity, ArrowLeft, Settings, Users } from "lucide-react";

const adminSidebarItems = (
  t: TFunction,
): {
  name: string;
  icon: React.ReactElement;
  path: string;
}[] => [
  {
    name: t("settings.back_to_app"),
    icon: <ArrowLeft size={18} />,
    path: "/dashboard/bookmarks",
  },
  {
    name: t("admin.server_stats.server_stats"),
    icon: <Activity size={18} />,
    path: "/admin/overview",
  },
  {
    name: t("admin.users_list.users_list"),
    icon: <Users size={18} />,
    path: "/admin/users",
  },
  {
    name: t("admin.background_jobs.background_jobs"),
    icon: <Settings size={18} />,
    path: "/admin/background_jobs",
  },
];

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

  return (
    <SidebarLayout
      sidebar={<Sidebar items={adminSidebarItems} />}
      mobileSidebar={<MobileSidebar items={adminSidebarItems} />}
    >
      <div className="flex flex-col gap-1">
        <AdminNotices />
        {children}
      </div>
    </SidebarLayout>
  );
}