Campuses frontend, docs and e2e (1.43.0)
CI / Backend tests (push) Canceled after 0s
CI / Frontend lint, typecheck, build (push) Canceled after 0s
CI / End-to-end tests (push) Canceled after 0s
CI / Deploy tagged release (push) Canceled after 0s

Site settings -> Campuses tab; campus picker in the event editor; campus
filter and badges on the events list, public events page (remembered,
starts on home campus) and reports/dashboards; /campus/<slug> pages and
sitemap; home campus on the profile; "Everyone at a campus" in email and
WhatsApp broadcasts. Help, FEATURES, SETTINGS, API docs, protocol doc
(campusCount), handover and roadmap updated; campuses seeded for e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 16:45:43 +02:00
co-authored by Claude Opus 5.5
parent 955f8d9831
commit a6909ce506
41 changed files with 942 additions and 47 deletions
@@ -0,0 +1,66 @@
"use client";
import React, { useState } from "react";
import { Users } from "lucide-react";
import { apiFetch } from "@/lib/api";
import { useAuth } from "@/hooks/useAuth";
import { useCampuses } from "@/hooks/useCampuses";
import { errorMessage } from "@/lib/utils";
/**
* "Everyone at campus X" for the email/WhatsApp broadcast composers: adds the people whose
* home campus is X — and, ticked, people registered for X's events in the last 12 months — to
* the selected users. News consent is still checked when the message is sent. Renders
* nothing while campuses are off.
*/
export function CampusAudiencePicker({ selectedIds, onChange }: { selectedIds: string[]; onChange: (ids: string[]) => void }) {
const { token } = useAuth();
const { enabled, campuses } = useCampuses();
const [campusId, setCampusId] = useState("");
const [registrants, setRegistrants] = useState(true);
const [busy, setBusy] = useState(false);
const [note, setNote] = useState<{ ok: boolean; text: string } | null>(null);
if (!enabled || campuses.length === 0) return null;
const add = async () => {
if (!campusId) return;
setBusy(true);
setNote(null);
try {
const res = await apiFetch<{ campus: { name: string }; users: { id: string }[] }>(`/api/campuses/${campusId}/audience${registrants ? "?registrants=true" : ""}`, { authToken: token });
const ids = res.users.map(u => u.id);
const merged = Array.from(new Set([...selectedIds, ...ids]));
onChange(merged);
const added = merged.length - selectedIds.length;
const people = (n: number) => `${n} ${n === 1 ? "person" : "people"}`;
setNote({
ok: true,
text: ids.length === 0 ? `Nobody at ${res.campus.name} yet.`
: added === ids.length ? `Added ${people(added)} at ${res.campus.name}.`
: `Added ${people(added)} at ${res.campus.name} — ${ids.length - added} already selected.`,
});
} catch (e) {
setNote({ ok: false, text: errorMessage(e) || "Could not load the campus's people." });
} finally {
setBusy(false);
}
};
return (
<div className="border rounded-lg p-3 bg-gray-50 space-y-2">
<p className="text-xs font-medium text-gray-700 flex items-center gap-1.5"><Users className="w-3.5 h-3.5" /> Everyone at a campus</p>
<div className="flex flex-wrap items-center gap-2">
<select className="border rounded px-2 py-1.5 text-sm bg-white" value={campusId} onChange={e => setCampusId(e.target.value)} aria-label="Campus">
<option value="">Choose a campus…</option>
{campuses.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}
</select>
<button type="button" onClick={add} disabled={!campusId || busy} className="px-3 py-1.5 rounded border text-sm bg-white hover:bg-gray-100 disabled:opacity-50">{busy ? "Adding…" : "Add them"}</button>
</div>
<label className="flex items-start gap-2 text-xs text-gray-600">
<input type="checkbox" className="mt-0.5" checked={registrants} onChange={e => setRegistrants(e.target.checked)} />
Also people who registered for this campus&apos;s events in the last 12 months (not only those who chose it as their home campus)
</label>
{note && <p className={`text-xs ${note.ok ? "text-green-700" : "text-red-700"}`}>{note.text}</p>}
</div>
);
}
@@ -0,0 +1,58 @@
"use client";
import React from "react";
import Link from "next/link";
import { MapPin } from "lucide-react";
import { useCampuses, type EventCampus } from "@/hooks/useCampuses";
/**
* A campus dropdown for lists and reports. Renders nothing while campuses are off.
* Values: "" = every campus (church-wide total), "all" = only events for all campuses
* (when `withChurchWide`), otherwise a campus id.
*/
export function CampusFilter({ value, onChange, withChurchWide = false, everyLabel = "All campuses", className = "", id = "campus-filter" }: {
value: string;
onChange: (value: string) => void;
withChurchWide?: boolean;
everyLabel?: string;
className?: string;
id?: string;
}) {
const { enabled, campuses } = useCampuses();
if (!enabled || campuses.length === 0) return null;
return (
<label className={`inline-flex items-center gap-2 text-sm ${className}`} htmlFor={id}>
<span className="sr-only">Campus</span>
<MapPin className="w-4 h-4 text-gray-400" aria-hidden />
<select id={id} className="border rounded px-2 py-1.5 text-sm bg-white" value={value} onChange={e => onChange(e.target.value)}>
<option value="">{everyLabel}</option>
{campuses.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}
{withChurchWide && <option value="all">Church-wide events only</option>}
</select>
</label>
);
}
/** Does an event pass a CampusFilter value? */
export function matchesCampus(ev: { campusId?: string | null }, value: string): boolean {
if (!value) return true;
if (value === "all") return !ev.campusId;
return ev.campusId === value;
}
/**
* The campus an event belongs to, as a small label (`link`: to the campus page). Nothing for
* church-wide events or while campuses are off.
*/
export function CampusBadge({ campus, className = "", link = false }: { campus?: EventCampus | null; className?: string; link?: boolean }) {
const { enabled } = useCampuses();
if (!enabled || !campus) return null;
const cls = `inline-flex items-center gap-1 text-[11px] px-1.5 py-0.5 rounded bg-gray-100 text-gray-700 ${link ? "hover:bg-gray-200" : ""} ${className}`;
const inner = (
<>
<span className="w-2 h-2 rounded-full border" style={{ background: campus.colour || "transparent" }} aria-hidden />
{campus.name}
</>
);
return link ? <Link href={`/campus/${campus.slug}`} className={cls}>{inner}</Link> : <span className={cls}>{inner}</span>;
}