import config from "@payload-config"; import { getPayload } from "payload"; import { headers as nextHeaders } from "next/headers"; import Link from "next/link"; import { notFound } from "next/navigation"; import { ArrowLeft } from "lucide-react"; import { PollVotePanel } from "@/components/frontend/polls/PollVotePanel"; import { loadUserPermissions } from "@/utils/access-control/loadUserPermissions"; import { advancePoll } from "@/lib/polls/service"; import { buildPollView } from "@/lib/polls/surface"; import type { Poll } from "@/payload-types"; export const metadata = { title: "Poll: Polaris Task Force", }; export default async function PollPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const pollId = Number(id); if (!Number.isInteger(pollId)) notFound(); const headers = await nextHeaders(); const payload = await getPayload({ config }); const { user } = await payload.auth({ headers, canSetHeaders: false }); // The (frontend) layout renders LandingPage for guests; this only guards the // authed render path's types. if (!user || user.collection !== "users") return null; // Opening the page settles anything that is due, so a poll closes on time // even when the bot is down. const poll = (await advancePoll(payload, { pollId })) as Poll | null; if (!poll || !poll.id) notFound(); const { isSuperuser } = await loadUserPermissions(payload, user); const roleDocs = (user as { roleDocs?: (number | { id: number })[] | null }).roleDocs ?? []; const view = await buildPollView(payload, poll, { userId: Number(user.id), isSuperuser, roleIds: roleDocs.map((ref) => (typeof ref === "number" ? ref : ref.id)), }); return (