Archived
A pass sells a ticket at each of several events in a series for one price. Supervisors set passes up on the Event series page (events and ticket per event; fixed once sold). Buying on the series page registers the buyer at every event at once with one checkout (free passes give tickets straight away; Pay now if online payment isn't possible). The price is split over the events in proportion to their normal prices: each registration line is priced at its share and the webhook records one Payment per event, so cashups stay per event. Pass registrations aren't repriced, take no coupons and can't be edited. Migration 20261028150000_season_pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
5.3 KiB
TypeScript
111 lines
5.3 KiB
TypeScript
import { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
import { Navbar } from "@/components/layout/Navbar";
|
|
import { Footer } from "@/components/layout/Footer";
|
|
import { EventCard } from "@/components/events/EventCard";
|
|
import { ApiImage } from "@/components/shared/ApiImage";
|
|
import { CampusBadge } from "@/components/shared/CampusFilter";
|
|
import { FollowSeriesButton } from "@/components/events/FollowSeriesButton";
|
|
import { SeasonPassOffers } from "@/components/series/SeasonPassOffers";
|
|
import { Suspense } from "react";
|
|
import { apiFetch, apiFetchListForPrerender, ApiError } from "@/lib/api";
|
|
import { formatDateTimeRange } from "@/lib/date";
|
|
import { ArrowLeft, CalendarX, Layers } from "lucide-react";
|
|
import type { Event as FullEvent, SeasonPassView } from "@/types";
|
|
|
|
export const revalidate = 60;
|
|
|
|
type Event = React.ComponentProps<typeof EventCard>["event"] & { cashupStatus?: string; nextSession?: { startsAt: string } | null };
|
|
type PastEvent = { id: string; title: string; startDate: string; endDate: string; campus?: FullEvent["campus"] };
|
|
type Series = { id: string; name: string; slug: string; description: string | null; picture: string | null; past: PastEvent[]; passes?: SeasonPassView[] };
|
|
|
|
async function loadSeries(slug: string): Promise<Series | null> {
|
|
try {
|
|
return await apiFetch<Series>(`/api/series/by-slug/${encodeURIComponent(slug)}`, { nextOptions: { next: { revalidate } } });
|
|
} catch (e) {
|
|
if (e instanceof ApiError && e.status === 404) return null;
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
|
const { slug } = await params;
|
|
const series = await loadSeries(slug);
|
|
if (!series) return {};
|
|
return {
|
|
title: series.name,
|
|
description: series.description || `Every ${series.name} event, past and upcoming.`,
|
|
alternates: { canonical: `/series/${series.slug}` },
|
|
};
|
|
}
|
|
|
|
/** A series' page: what it is, the upcoming events in it (any campus), and past ones. */
|
|
export default async function SeriesPage({ params }: { params: Promise<{ slug: string }> }) {
|
|
const { slug } = await params;
|
|
const series = await loadSeries(slug);
|
|
if (!series) notFound();
|
|
|
|
const events = await apiFetchListForPrerender<Event>(`/api/events?series=${encodeURIComponent(series.slug)}`, { nextOptions: { next: { revalidate } } });
|
|
const now = Date.now();
|
|
const upcoming = (events || [])
|
|
.filter(e => e.cashupStatus !== "closed" && new Date(e.endDate || e.startDate).getTime() > now)
|
|
.sort((a, b) => new Date(a.nextSession?.startsAt || a.startDate).getTime() - new Date(b.nextSession?.startsAt || b.startDate).getTime());
|
|
|
|
return (
|
|
<div className="min-h-screen flex flex-col">
|
|
<Navbar />
|
|
<main className="flex-1 py-10 px-4 max-w-7xl mx-auto w-full">
|
|
<Link href="/events" className="inline-flex items-center gap-1 text-sm text-gray-500 hover:text-gray-700 mb-4">
|
|
<ArrowLeft className="w-4 h-4" /> All events
|
|
</Link>
|
|
<div className="border rounded-2xl p-6 mb-8 bg-white shadow-sm flex flex-col sm:flex-row gap-6">
|
|
{series.picture && <ApiImage src={series.picture} alt="" className="w-full sm:w-56 aspect-video object-cover rounded-xl shrink-0" />}
|
|
<div className="min-w-0 flex-1">
|
|
<p className="text-xs uppercase tracking-wide text-brand-700 flex items-center gap-1"><Layers className="w-3.5 h-3.5" /> Series</p>
|
|
<h1 className="text-2xl sm:text-3xl font-bold text-gray-900 mt-1">{series.name}</h1>
|
|
{series.description && <p className="text-gray-700 mt-2 whitespace-pre-line">{series.description}</p>}
|
|
<div className="mt-4">
|
|
<FollowSeriesButton slug={series.slug} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<Suspense fallback={null}>
|
|
<SeasonPassOffers slug={series.slug} passes={series.passes || []} />
|
|
</Suspense>
|
|
|
|
<h2 className="text-xl font-semibold text-gray-900 mb-4">Coming up</h2>
|
|
{upcoming.length === 0 ? (
|
|
<div className="text-center py-12 border rounded-xl bg-gray-50 mb-10">
|
|
<CalendarX className="w-8 h-8 text-gray-300 mx-auto mb-2" />
|
|
<p className="text-gray-500 text-sm">Nothing planned yet — follow the series to hear when the next one is out.</p>
|
|
</div>
|
|
) : (
|
|
<div className="grid gap-6 md:grid-cols-3 sm:grid-cols-2 mb-10">
|
|
{upcoming.map(event => <EventCard key={event.id} event={event} />)}
|
|
</div>
|
|
)}
|
|
|
|
{series.past.length > 0 && (
|
|
<>
|
|
<h2 className="text-xl font-semibold text-gray-900 mb-3">Past events</h2>
|
|
<ul className="border rounded-xl bg-white divide-y" data-testid="series-past">
|
|
{series.past.map(e => (
|
|
<li key={e.id} className="px-4 py-3 flex flex-wrap items-center justify-between gap-2">
|
|
<span className="font-medium text-gray-800">{e.title}</span>
|
|
<span className="text-sm text-gray-500 flex items-center gap-2">
|
|
<CampusBadge campus={e.campus} className="text-[10px]" />
|
|
{formatDateTimeRange(e.startDate, e.endDate)}
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</>
|
|
)}
|
|
</main>
|
|
<Footer />
|
|
</div>
|
|
);
|
|
}
|