diff --git a/src/app/(frontend)/helpdesk/[id]/page.tsx b/src/app/(frontend)/helpdesk/[id]/page.tsx new file mode 100644 index 0000000..a50dbb2 --- /dev/null +++ b/src/app/(frontend)/helpdesk/[id]/page.tsx @@ -0,0 +1,83 @@ +import config from "@payload-config"; +import { headers as nextHeaders } from "next/headers"; +import { notFound, redirect } from "next/navigation"; +import { getPayload } from "payload"; +import type { Ticket } from "@/payload-types"; +import { TicketDetail } from "@/components/frontend/helpdesk/TicketDetail"; +import hasRoles from "@/utils/access-control/hasRoles"; +import { ArrowLeftIcon, LifeBuoyIcon } from "lucide-react"; +import Link from "next/link"; + +export const metadata = { + title: "Ticket — Polaris Task Force", +}; + +interface TicketPageProps { + params: Promise<{ id: string }>; +} + +export default async function TicketPage({ params }: TicketPageProps) { + const { id } = await params; + const payload = await getPayload({ config }); + const { user } = await payload.auth({ + headers: await nextHeaders(), + canSetHeaders: false, + }); + + if (!user) { + redirect("/login"); + } + + const ticket = await payload + .findByID({ + collection: "tickets", + id: Number(id), + depth: 2, + }) + .catch(() => null); + + if (!ticket) { + notFound(); + } + + const typedTicket = ticket as unknown as Ticket; + const isStaff = hasRoles(["admin", "developer"], user); + const assigneeOptions = isStaff + ? ( + await payload.find({ + collection: "users", + sort: "username", + limit: 100, + depth: 0, + }) + ).docs.map((staffUser) => ({ + id: staffUser.id, + label: staffUser.payloadDisplayName || staffUser.username, + })) + : []; + + return ( +
Submit and track support requests.
+