The owner shares an event by email; a co-host gets full access inside it but can't delete it or change who it's shared with. Shares are keyed by email so an admin can be added before their first login, and RLS (not the UI) is what enforces the owner-only parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.1 KiB
TypeScript
81 lines
3.1 KiB
TypeScript
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
|
|
import { CohostsEditor } from "@/components/admin/cohosts-editor";
|
|
import { EventDetailsForm } from "@/components/admin/event-details-form";
|
|
import { GamesEditor } from "@/components/admin/games-editor";
|
|
import { SharePanel } from "@/components/admin/share-panel";
|
|
import { TeamsEditor } from "@/components/admin/teams-editor";
|
|
import { buttonClass } from "@/components/ui/button";
|
|
import { requireAdmin } from "@/lib/auth";
|
|
import { loadEventSetup } from "@/lib/queries/event";
|
|
import { idSchema } from "@/lib/tokens";
|
|
|
|
export default async function EventSetupPage(props: PageProps<"/admin/events/[eventId]">) {
|
|
const { supabase, userId } = await requireAdmin();
|
|
const { eventId } = await props.params;
|
|
if (!idSchema.safeParse(eventId).success) notFound();
|
|
|
|
const [setup, cohosts] = await Promise.all([
|
|
loadEventSetup(supabase, eventId),
|
|
supabase.from("event_cohosts").select("id, email").eq("event_id", eventId).order("created_at"),
|
|
]);
|
|
if (!setup) notFound();
|
|
if (cohosts.error) throw new Error(`Could not load the co-hosts: ${cohosts.error.message}`);
|
|
const { event, teams, games } = setup;
|
|
|
|
return (
|
|
<div className="mx-auto flex max-w-5xl flex-col gap-8">
|
|
<div>
|
|
<Link href="/admin" className="inline-flex min-h-11 items-center text-sm underline underline-offset-4">
|
|
← All game nights
|
|
</Link>
|
|
<div className="mt-1 flex flex-wrap items-center justify-between gap-3">
|
|
<h1 className="font-display text-4xl font-bold">{event.name}</h1>
|
|
<Link href={`/admin/events/${event.id}/live`} className={`${buttonClass("primary")} ml-auto`}>
|
|
Control room
|
|
</Link>
|
|
<a
|
|
href={`/s/${event.scoreboard_token}`}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className={buttonClass("secondary")}
|
|
>
|
|
Open scoreboard
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<section className="rounded-lg border border-ink/15 bg-white p-4">
|
|
<h2 className="text-xl font-bold">Details</h2>
|
|
<EventDetailsForm
|
|
key={event.updated_at}
|
|
eventId={event.id}
|
|
name={event.name}
|
|
eventDate={event.event_date ?? ""}
|
|
/>
|
|
</section>
|
|
|
|
<section className="rounded-lg border border-ink/15 bg-white p-4">
|
|
<h2 className="text-xl font-bold">Teams</h2>
|
|
<TeamsEditor eventId={event.id} teams={teams} />
|
|
</section>
|
|
|
|
<section>
|
|
<h2 className="text-xl font-bold">Games</h2>
|
|
<GamesEditor eventId={event.id} games={games} />
|
|
</section>
|
|
|
|
<section className="rounded-lg border border-ink/15 bg-white p-4">
|
|
<h2 className="text-xl font-bold">Share links</h2>
|
|
<SharePanel scoreboardToken={event.scoreboard_token} teams={teams} games={games} />
|
|
</section>
|
|
|
|
<section className="rounded-lg border border-ink/15 bg-white p-4">
|
|
<h2 className="text-xl font-bold">Co-hosts</h2>
|
|
<CohostsEditor eventId={event.id} cohosts={cohosts.data} isOwner={event.owner_id === userId} />
|
|
</section>
|
|
</div>
|
|
);
|
|
}
|