- The 192 places the rules flagged are fixed and the rules are errors again (npx eslint src: nothing). lib/hooks.ts: useStateSync (state that follows other state, set while rendering), useExternalEffect (API loads and browser reads), useNow; lib/navigation.ts hardNavigate for full reloads after sign-out or identity switches; other pages use the router. Resets moved into the handlers that cause them. - The banner shows and hides at its times on open pages. - HANDOVER, roadmap, README, FEATURES, SETTINGS, CHANGELOG updated; 2.0.0 section drafted in WHATS-NEW. e2e 102/102 (PayFast sandbox skipped); production build passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
5.0 KiB
TypeScript
97 lines
5.0 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 { apiFetchListForPrerender, ApiError } from "@/lib/api";
|
|
import { mapsSearchUrl } from "@/lib/maps";
|
|
import { CalendarX, MapPin, Mail, Phone, User, ArrowLeft } from "lucide-react";
|
|
import type { Campus } from "@/hooks/useCampuses";
|
|
import { apiV2Data } from "@/lib/apiV2";
|
|
|
|
export const revalidate = 60;
|
|
|
|
type Event = React.ComponentProps<typeof EventCard>["event"] & { cashupStatus?: string; nextSession?: { startsAt: string } | null };
|
|
|
|
async function loadCampus(slug: string): Promise<Campus | null> {
|
|
try {
|
|
return await (apiV2Data("get", "/campuses/by-slug/{slug}", { params: { slug }, nextOptions: { next: { revalidate } } }) as Promise<Campus>);
|
|
} catch (e) {
|
|
// 404: no such campus, archived, or campuses are off.
|
|
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 campus = await loadCampus(slug);
|
|
if (!campus) return {};
|
|
return {
|
|
title: `${campus.name} — events`,
|
|
description: `Upcoming events at ${campus.name}${campus.address ? `, ${campus.address}` : ""}.`,
|
|
alternates: { canonical: `/campus/${campus.slug}` },
|
|
};
|
|
}
|
|
|
|
/** A campus's own page: its details and upcoming events (its own plus church-wide ones). */
|
|
export default async function CampusPage({ params }: { params: Promise<{ slug: string }> }) {
|
|
const { slug } = await params;
|
|
const campus = await loadCampus(slug);
|
|
if (!campus) notFound();
|
|
|
|
const events = await apiFetchListForPrerender<Event>(`/api/v2/event-listing?campus=${encodeURIComponent(campus.slug)}`, { nextOptions: { next: { revalidate } } });
|
|
// A server component renders once per request (or revalidation): this is that render's time.
|
|
// eslint-disable-next-line react-hooks/purity
|
|
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" style={campus.colour ? { borderTop: `4px solid ${campus.colour}` } : undefined}>
|
|
<div className="flex items-start gap-4">
|
|
{campus.logoUrl && <ApiImage src={campus.logoUrl} alt="" className="w-16 h-16 object-contain rounded-lg shrink-0" />}
|
|
<div className="min-w-0">
|
|
<h1 className="text-2xl sm:text-3xl font-bold text-gray-900">{campus.name}</h1>
|
|
<div className="mt-2 space-y-1 text-sm text-gray-600">
|
|
{campus.address && (
|
|
<p className="flex items-center gap-1.5">
|
|
<MapPin className="w-4 h-4 shrink-0" />
|
|
<a href={mapsSearchUrl(campus.address)} target="_blank" rel="noopener noreferrer" className="hover:underline">{campus.address}</a>
|
|
</p>
|
|
)}
|
|
{campus.contactName && <p className="flex items-center gap-1.5"><User className="w-4 h-4 shrink-0" /> {campus.contactName}</p>}
|
|
{campus.contactEmail && <p className="flex items-center gap-1.5"><Mail className="w-4 h-4 shrink-0" /> <a href={`mailto:${campus.contactEmail}`} className="hover:underline">{campus.contactEmail}</a></p>}
|
|
{campus.contactPhone && <p className="flex items-center gap-1.5"><Phone className="w-4 h-4 shrink-0" /> <a href={`tel:${campus.contactPhone}`} className="hover:underline">{campus.contactPhone}</a></p>}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h2 className="text-xl font-semibold text-gray-900 mb-1">Upcoming events</h2>
|
|
<p className="text-sm text-gray-500 mb-6">Events at {campus.name}, and church-wide events for every campus.</p>
|
|
{upcoming.length === 0 ? (
|
|
<div className="text-center py-16 border rounded-xl bg-gray-50">
|
|
<CalendarX className="w-8 h-8 text-gray-300 mx-auto mb-2" />
|
|
<p className="text-gray-500 text-sm">No upcoming events at {campus.name} right now — check back soon.</p>
|
|
</div>
|
|
) : (
|
|
<div className="grid gap-6 md:grid-cols-3 sm:grid-cols-2">
|
|
{upcoming.map(event => <EventCard key={event.id} event={event} />)}
|
|
</div>
|
|
)}
|
|
</main>
|
|
<Footer />
|
|
</div>
|
|
);
|
|
}
|