-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathpage.tsx
More file actions
60 lines (56 loc) · 1.67 KB
/
Copy pathpage.tsx
File metadata and controls
60 lines (56 loc) · 1.67 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
"use server";
import { EventDataTable } from "@/components/events/shared/EventDataTable";
import { columns } from "@/components/events/shared/EventColumns";
import { Button } from "@/components/shadcn/ui/button";
import { PlusCircle } from "lucide-react";
import Link from "next/link";
import { getAllEvents } from "db/functions";
import FullScreenMessage from "@/components/shared/FullScreenMessage";
import { userHasPermission } from "@/lib/utils/server/admin";
import { PermissionType } from "@/lib/constants/permission";
import { notFound } from "next/navigation";
import { getCurrentUser } from "@/lib/utils/server/user";
export default async function Page() {
const user = await getCurrentUser();
if (!userHasPermission(user, PermissionType.VIEW_EVENTS)) {
return notFound();
}
const events = await getAllEvents();
const isUserAuthorized = userHasPermission(
user,
PermissionType.CREATE_EVENTS,
);
return (
<div className="mx-auto max-w-7xl px-5">
<div className="mb-5 grid w-full grid-cols-2">
<div className="flex items-center">
<div>
<h2 className="text-3xl font-bold tracking-tight">
Events
</h2>
<p className="text-sm text-muted-foreground">
{events.length} Event{events.length != 1 && "s"}
</p>
</div>
</div>
{isUserAuthorized && (
<div className="flex items-center justify-end">
<Link href="/admin/events/new">
<Button className="flex gap-x-1">
<PlusCircle />
New Event
</Button>
</Link>
</div>
)}
</div>
<EventDataTable
columns={columns}
data={events.map((ev) => ({
...ev,
isUserAdmin: isUserAuthorized,
}))}
/>
</div>
);
}