import { Metadata } from "next"; import { notFound } from "next/navigation"; import { Navbar } from "@/components/layout/Navbar"; import { Footer } from "@/components/layout/Footer"; import ClientActions from "@/app/events/[id]/ClientActions"; import { ContactButton } from "@/components/events/ContactButton"; import { LocationMap } from "@/components/events/LocationMap"; import { JoinWaitlistButton } from "@/components/events/JoinWaitlistButton"; import { soldOutLines } from "@/lib/waitlist"; import { SponsorSpot } from "@/components/events/SponsorSpot"; import { FunnelTracker } from "@/components/events/FunnelTracker"; import { CampusBadge } from "@/components/shared/CampusFilter"; import { Calendar, Ticket, Paperclip, Sparkles } from "lucide-react"; export const revalidate = 60; type OptionVariant = { id: string; name: string; price: number | null; stockLimit?: number; availableCount?: number; order?: number }; type EventOption = { id: string; name: string; price: number; stockLimit?: number; availableCount?: number; isMainTicket?: boolean; sessionMode?: "all" | "pick"; earlyBirdTiers?: { id: string; deadline: string; price: number; stockLimit?: number }[]; variants?: OptionVariant[]; }; type EventAttachment = { id: string; originalName: string; url: string; size: number; mimeType: string }; type Event = { id: string; title: string; description?: string; startDate: string; endDate: string; registrationDeadline?: string | null; goLiveAt?: string; price: number; picture?: string; eventOptions?: EventOption[]; attachments?: EventAttachment[]; requiresAuth?: boolean; requiresRegistration?: boolean; contactName?: string | null; contactPhone?: string | null; contactEmail?: string | null; location?: string | null; campus?: { id: string; name: string; slug: string; colour: string | null } | null; waitlistEnabled?: boolean; allowSponsorships?: boolean; bundles?: PublicBundle[]; scheduleType?: "single" | "sessions"; attendanceMode?: "whole" | "pick"; sessions?: EventSession[]; registrationClosesAt?: string; lateJoin?: LateJoinInfo | null; series?: EventSeriesRef | null; nextInSeries?: NextInSeries | null; }; import { apiFetch, ApiError, resolveToApiOrigin } from "@/lib/api"; import { ApiImage } from "@/components/shared/ApiImage"; import { formatDateTimeRange } from "@/lib/date"; import { BundleOffers } from "@/components/shared/BundleDeals"; import type { EventSeriesRef, EventSession, LateJoinInfo, NextInSeries, PublicBundle } from "@/types"; import { SeriesLinks } from "@/components/events/SeriesLinks"; import { isPickOption, latePrice, registrationClosesAt, scheduleSummary } from "@/lib/sessions"; import { SessionSchedule } from "@/components/events/SessionSchedule"; import { appUrl, appName } from "@/lib/siteConfig"; import { getServerSettings } from "@/lib/serverSettings"; import { eventJsonLd, jsonLdString } from "@/lib/eventSchema"; // Tiered low-stock threshold: larger events use a smaller percentage. // Math.round avoids Math.ceil inflating the threshold (e.g. ceil(1.5)=2 made // a 10-ticket event warn at 20% when the stated threshold was 15%). function lowStockThreshold(stockLimit: number): number { let pct: number; if (stockLimit <= 50) pct = 0.20; else if (stockLimit <= 200) pct = 0.15; else if (stockLimit <= 1000) pct = 0.10; else pct = 0.05; return Math.round(stockLimit * pct); } function RegisterCta({ event }: { event: Event }) { if (event.requiresRegistration === false) { return ( ); } const now = new Date(); const goLive = event.goLiveAt ? new Date(event.goLiveAt) : null; const notYetOpen = goLive ? now < goLive : false; // Multi-day events close when the first session starts (or later with late joining). const closed = now >= registrationClosesAt(event); const limitedOpts = (event.eventOptions || []).filter(o => (o.stockLimit ?? 0) > 0); const eventSoldOut = limitedOpts.length > 0 && limitedOpts.every(o => o.availableCount !== undefined && o.availableCount <= 0); if (notYetOpen) { return ( ); } if (closed) { return ( ); } if (eventSoldOut) { if (event.waitlistEnabled) { return (
Sold out
); } return ( ); } return ( Register ); } // Next dedupes an identical fetch (same URL + cache options) made during the same // request, so calling this again from the page component below is free. async function loadEvent(id: string): Promise { try { return await apiFetch(`/api/events/${id}`, { nextOptions: { next: { revalidate } } }); } catch (e) { if (e instanceof ApiError && e.status === 404) return null; throw e; } } export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise { const { id } = await params; const event = await loadEvent(id); if (!event) return {}; const description = event.description ? event.description.slice(0, 200) : `${event.title} — ${formatDateTimeRange(event.startDate, event.endDate)}`; const imageUrl = event.picture ? resolveToApiOrigin(event.picture) : null; return { title: event.title, description, // One address per event for search engines, however the page was reached // (?utm_source=…, ?src=…, an alias link). alternates: { canonical: `/events/${event.id}` }, openGraph: { title: event.title, description, type: "website", url: `/events/${event.id}`, ...(imageUrl ? { images: [{ url: imageUrl }] } : {}), }, twitter: { card: "summary_large_image", title: event.title, description, ...(imageUrl ? { images: [imageUrl] } : {}), }, }; } export default async function EventDetailPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const event = await loadEvent(id); if (!event) notFound(); const settings = await getServerSettings(); const siteUrl = appUrl.replace(/\/$/, ""); const jsonLd = eventJsonLd(event, { pageUrl: `${siteUrl}/events/${event.id}`, imageUrl: event.picture ? resolveToApiOrigin(event.picture) : null, organizerName: settings.org_name || appName, siteUrl, }); return (