import config from "@payload-config"; import { getPayload } from "payload"; import { headers as nextHeaders } from "next/headers"; import Link from "next/link"; import { isPayloadUser } from "@/utils/access-control/isPayloadUser"; import { hasPermission } from "@/utils/access-control/hasPermission"; import { LedgerRow, NoticeState, PageShell } from "@/components/frontend/operations"; import type { SurfaceUser } from "@/lib/operations/surface"; import { CancelButton } from "@/components/frontend/operations/reservations/ReservationCancelButton"; import type { OperationReservation } from "@/payload-types"; import { getReservationDetail } from "../surface"; type PayloadType = Awaited>; function relationId(value: unknown): number | null { if (typeof value === "number") return value; if (value !== null && typeof value === "object" && "id" in (value as { id: unknown })) { const id = (value as { id: unknown }).id; return typeof id === "number" ? id : null; } return null; } function relationLabel(value: unknown): string { if ( typeof value === "object" && value !== null && "codeName" in (value as { codeName?: unknown }) ) { const codeName = (value as { codeName?: unknown }).codeName; if (typeof codeName === "string" && codeName) return codeName; } return String(relationId(value) ?? "n/a"); } export interface ReservationDetail { reservation: OperationReservation | null; canCancel: boolean; } /** * Full detail for a single reservation, fetched through collection access * control (default access + the explicit session user, never overrideAccess). * Returns null for an unknown id so the page can render a not-found notice. * canCancel is true only when the row is still reserved AND the viewer holds * operation-reservations:update. */ function Section({ title, children }: { title: string; children: React.ReactNode }) { return (

{title}

{children}
); } function kvRow(label: string, value: React.ReactNode) { return (
{label} {value}
); } export const metadata = { title: "Reservation Detail: Polaris Task Force", }; export default async function ReservationDetailPage({ params, }: { params: Promise<{ id: string }>; }) { const { id } = await params; const payload = await getPayload({ config }); const { user: authUser } = await payload.auth({ headers: await nextHeaders(), canSetHeaders: false, }); const user = isPayloadUser(authUser) ? authUser : null; const surfaceUser: SurfaceUser = user ? { id: user.id } : null; const { reservation, canCancel } = await getReservationDetail(payload, surfaceUser, id); if (reservation === null) { return (
Back to reservations } />
); } const personnel = reservation.personnel ?? []; const vehicles = reservation.vehicles ?? []; const cargo = reservation.cargo ?? []; const budget = reservation.budget; const readoutCells = [ { label: "Key", value: reservation.reservationKey }, { label: "Operation", value: reservation.operationId }, { label: "Status", value: reservation.status }, { label: "Expires", value: reservation.expiresAt ?? "n/a" }, ]; return (
Back to reservations
{personnel.length === 0 ? ( ) : (
    {personnel.map((member) => (
  • {relationLabel(member.user)} · id {relationId(member.user)} {member.slot ?? "slot"}
  • ))}
)}
{vehicles.length === 0 ? ( ) : (
    {vehicles.map((vehicle) => (
  • {relationLabel(vehicle.vehicle)} · id {relationId(vehicle.vehicle)}
  • ))}
)}
{cargo.length === 0 ? ( ) : (
    {cargo.map((line) => (
  • {relationLabel(line.resource)} · id {relationId(line.resource)} {line.amount}
  • ))}
)}
{budget?.amount != null || budget?.account != null ? (
{kvRow( "Account", budget.account != null ? `${relationLabel(budget.account)} · id ${relationId(budget.account)}` : "n/a", )} {kvRow("Amount", budget.amount ?? "n/a")}
) : ( )}
{kvRow( "Origin", reservation.origin != null ? relationLabel(reservation.origin) : "n/a", )} {kvRow( "Destination", reservation.destination != null ? relationLabel(reservation.destination) : "n/a", )}
{kvRow( "Created by", reservation.createdBy != null ? relationLabel(reservation.createdBy) : "n/a", )} {kvRow("Created at", reservation.createdAt)} {kvRow("Expires", reservation.expiresAt ?? "n/a")}
{reservation.status !== "reserved" && (
              {JSON.stringify(reservation.settlement, null, 2)}
            
)} {canCancel && reservation.status === "reserved" ? ( ) : null}
); }