-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathlayout.tsx
More file actions
111 lines (107 loc) · 3.27 KB
/
layout.tsx
File metadata and controls
111 lines (107 loc) · 3.27 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import c from "config";
import Image from "next/image";
import Link from "next/link";
import { Button } from "@/components/shadcn/ui/button";
import DashNavItem from "@/components/dash/shared/DashNavItem";
import FullScreenMessage from "@/components/shared/FullScreenMessage";
import ProfileButton from "@/components/shared/ProfileButton";
import React, { Suspense } from "react";
import ClientToast from "@/components/shared/ClientToast";
import { isUserAdmin, userHasPermission } from "../../lib/utils/server/admin";
import { PermissionType } from "@/lib/constants/permission";
import { getCurrentUser } from "@/lib/utils/server/user";
interface AdminLayoutProps {
children: React.ReactNode;
}
export default async function AdminLayout({ children }: AdminLayoutProps) {
const user = await getCurrentUser();
if (!isUserAdmin(user)) {
console.log("Denying admin access to user", user);
return (
<FullScreenMessage
title="Access Denied"
message="You are not an admin. If you belive this is a mistake, please contact a administrator."
/>
);
}
return (
<>
<ClientToast duration={2500} position="top-right" />
<div className="fixed z-20 grid h-16 w-full grid-cols-2 bg-nav px-5">
<div className="flex items-center gap-x-4">
<Link href={"/"} className="mr-5 flex items-center gap-x-2">
<Image
src={c.icon.svg}
alt={c.hackathonName + " Logo"}
width={32}
height={32}
/>
<div className="h-[45%] w-[2px] rotate-[25deg] bg-muted-foreground" />
<h2 className="font-bold tracking-tight">Admin</h2>
</Link>
</div>
<div className="hidden items-center justify-end gap-x-4 md:flex">
<Link href={"/"}>
<Button
variant={"outline"}
className="bg-nav hover:bg-background"
>
Home
</Button>
</Link>
<Link href={c.links.guide}>
<Button
variant={"outline"}
className="bg-nav hover:bg-background"
>
Survival Guide
</Button>
</Link>
<Link href={c.links.discord}>
<Button
variant={"outline"}
className="bg-nav hover:bg-background"
>
Discord
</Button>
</Link>
<ProfileButton />
</div>
<div className="flex items-center justify-end gap-x-4 md:hidden"></div>
</div>
<div className="fixed z-20 mt-16 flex h-12 w-full border-b border-b-border bg-nav px-5">
{Object.entries(c.dashPaths.admin).map(([name, path]) => {
// Gate specific admin nav items by permission
if (
name === "Users" &&
!userHasPermission(user, PermissionType.VIEW_USERS)
)
return null;
if (
name === "Events" &&
!userHasPermission(user, PermissionType.VIEW_EVENTS)
)
return null;
if (
name === "Roles" &&
!userHasPermission(user, PermissionType.VIEW_ROLES)
)
return null;
if (
name === "Toggles" &&
!userHasPermission(user, PermissionType.MANAGE_NAVLINKS)
)
return null;
if (
name === "Emails" &&
!userHasPermission(user, PermissionType.SEND_EMAILS)
)
return null;
// Keep other configured admin paths visible by default
return <DashNavItem key={name} name={name} path={path} />;
})}
</div>
<Suspense fallback={<p>Loading...</p>}>{children}</Suspense>
</>
);
}