import { PERMS } from "@/lib/permission-slugs"; import type { HousekeepingPageInput } from "../../../route-handlers"; import { contentQuery } from "../queries/content-queries"; import { type ContentCommandField, ContentCommandForm, } from "./content-command-form"; import { ContentPageFrame, type ContentPageProps, parseContentListInput, } from "./content-page-frame"; export function ContentEngagementPage({ context, result, routeId, }: ContentPageProps) { const canEvents = context.has(PERMS.EVENTS_EDIT); const canPolls = context.has(PERMS.POLLS_EDIT); const canPrefixes = context.has(PERMS.PREFIXES_EDIT); const creatingEvent = routeId === "content.engagement.event-create"; const creatingPoll = routeId === "content.engagement.poll-create"; const eventFields: readonly ContentCommandField[] = [ { name: "id", label: "Event ID", type: "identifier", required: !creatingEvent, }, { name: "title", label: "Title", type: "text", required: creatingEvent, maxLength: 255, }, { name: "description", label: "Description", type: "textarea", required: creatingEvent, maxLength: 20_000, }, { name: "typeId", label: "Event type ID", type: "identifier", required: creatingEvent, }, { name: "roomId", label: "Room ID", type: "identifier" }, { name: "startsAt", label: "Starts at", type: "text", required: creatingEvent, maxLength: 50, }, { name: "endsAt", label: "Ends at", type: "text", maxLength: 50 }, { name: "maxPlayers", label: "Maximum players", type: "number", min: 1 }, { name: "isRecurring", label: "Recurring", type: "checkbox" }, { name: "recurrenceRule", label: "Recurrence rule", type: "text", maxLength: 255, }, { name: "status", label: "Status", type: "select", options: [ { value: "draft", label: "Draft" }, { value: "published", label: "Published" }, { value: "cancelled", label: "Cancelled" }, { value: "completed", label: "Completed" }, ], }, { name: "image", label: "Image URL", type: "text", maxLength: 500 }, ]; const pollFields: readonly ContentCommandField[] = [ { name: "id", label: "Poll ID", type: "identifier", required: !creatingPoll, }, { name: "title", label: "Title", type: "text", required: creatingPoll, maxLength: 255, }, { name: "description", label: "Description", type: "textarea", maxLength: 2_000, }, { name: "status", label: "Status", type: "select", options: [ { value: "draft", label: "Draft" }, { value: "active", label: "Active" }, { value: "closed", label: "Closed" }, ], }, { name: "showResults", label: "Show results", type: "checkbox" }, { name: "multipleChoice", label: "Allow multiple choices", type: "checkbox", }, { name: "startsAt", label: "Starts at", type: "text", maxLength: 50 }, { name: "endsAt", label: "Ends at", type: "text", maxLength: 50 }, ]; return ( {canEvents && routeId === "content.engagement.event-types" ? ( ) : null} {canEvents && routeId?.includes("event") && routeId !== "content.engagement.event-types" ? ( <> ) : null} {canPolls && routeId?.includes("poll") ? ( <> ) : null} {canPrefixes && routeId === "content.engagement.prefixes" ? ( <> ) : null} } /> ); } export async function renderContentEngagementPage( input: HousekeepingPageInput, ) { const routeId = input.match.routeId as ContentPageProps["routeId"]; const result = await contentQuery.run(input.context, { routeId: routeId ?? "content.engagement.events", params: input.match.params, list: parseContentListInput(input.searchParams ?? {}), }); return ( ); }