Events 2.4.0 frontend, deploy and docs: Linked products, linked events, seo

- Site settings → Linked products (Connect, Show events from, Publish my
  events), help, command palette.
- Events from linked products on /events, the home and campus pages, and
  /events/linked/<product>/<id> (markdown with HTML off, canonical to the
  origin, no JSON-LD, not in the sitemap).
- Event page JSON-LD from @crosscode/seo; lib/eventSchema.ts removed.
- Readiness check for linked products' sync; e2e spec with a fake
  Church Website (not run yet: needs the e2e Postgres).
- crosscode: install and build the shared packages Events uses first
  (an older tag still builds as before); scripts/tests/events.bats.
- Release notes, changelogs, handovers, hub-protocol.md, and the plan's
  "Changes while building".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 12:58:50 +02:00
co-authored by Claude Opus 5.5
parent 8a930d07c6
commit 716d47242a
28 changed files with 929 additions and 130 deletions
@@ -0,0 +1,167 @@
"use client";
import React, { useEffect, useState } from "react";
import { Link2, RefreshCw } from "lucide-react";
import { useAuth } from "@/hooks/useAuth";
import { apiV2, type V2Result } from "@/lib/apiV2";
import { errorMessage } from "@/lib/utils";
type Overview = V2Result<"/linked-products", "get">["data"];
type Product = Overview["products"][number];
const when = (iso: string | null) =>
iso ? new Date(iso).toLocaleString("en-ZA", { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" }) : "never";
/** "2 hours ago", for "last synced". */
function ago(iso: string | null): string {
if (!iso) return "never";
const mins = Math.round((Date.now() - new Date(iso).getTime()) / 60000);
if (mins < 1) return "just now";
if (mins < 60) return `${mins} minute${mins === 1 ? "" : "s"} ago`;
const hours = Math.round(mins / 60);
if (hours < 48) return `${hours} hour${hours === 1 ? "" : "s"} ago`;
return `${Math.round(hours / 24)} days ago`;
}
/**
* Site settings → Linked products (2.4.0): the church's other Cross Code products (as the Hub
* lists them), Connect / Disconnect, "Show events from" each, and "Publish my events".
*/
export function LinkedProductsTab({ active }: { active: boolean }) {
const { token } = useAuth();
const [data, setData] = useState<Overview | null>(null);
const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null);
const [busy, setBusy] = useState<string | null>(null);
useEffect(() => {
if (!active || !token) return;
let alive = true;
apiV2("get", "/linked-products", { authToken: token })
.then(({ data: d }) => { if (alive) setData(d); })
.catch(e => { if (alive) setMsg({ ok: false, text: errorMessage(e) || "Could not load linked products." }); });
return () => { alive = false; };
}, [active, token]);
const run = async (key: string, call: () => Promise<{ data: Overview }>, ok: string | ((d: Overview) => string)) => {
setBusy(key);
setMsg(null);
try {
const { data: d } = await call();
setData(d);
setMsg({ ok: true, text: typeof ok === "function" ? ok(d) : ok });
} catch (e) {
setMsg({ ok: false, text: errorMessage(e) || "That didn't work." });
}
setBusy(null);
};
if (!token) return null;
if (!data) return msg ? <p className="text-sm text-red-700">{msg.text}</p> : <p className="text-sm text-gray-500">Loading…</p>;
const auth = { authToken: token };
const connect = (p: Product) => run(`c:${p.installId}`, () => apiV2("post", "/linked-products/{installId}/connect", { ...auth, params: { installId: p.installId } }), `Connected to ${p.name}.`);
const disconnect = (p: Product) => {
if (!window.confirm(`Disconnect ${p.name}? Its events stop showing here, and this site's events stop showing there.`)) return;
run(`d:${p.installId}`, () => apiV2("post", "/linked-products/{installId}/disconnect", { ...auth, params: { installId: p.installId } }) as Promise<{ data: Overview & { otherSideTold: boolean; problem: string | null } }>,
(d) => {
const r = d as Overview & { otherSideTold?: boolean; problem?: string | null };
return r.otherSideTold ? `Disconnected from ${p.name}.` : `Disconnected here. ${p.name} couldn't be told (${r.problem || "not reachable"}); disconnect it there too.`;
});
};
const showEvents = (p: Product, on: boolean) => run(`s:${p.installId}`, () => apiV2("put", "/linked-products/{installId}", { ...auth, params: { installId: p.installId }, body: { showEvents: on } }),
on ? `${p.name}'s events are fetched and shown on your events pages.` : `${p.name}'s events are no longer shown here.`);
const syncNow = (p: Product) => run(`y:${p.installId}`, () => apiV2("post", "/linked-products/{installId}/sync", { ...auth, params: { installId: p.installId } }), "Fetched.");
const publish = (on: boolean) => run("publish", () => apiV2("put", "/linked-products/settings", { ...auth, body: { publishEvents: on } }),
on ? "Your events are published for your other products." : "Your events are no longer published.");
return (
<div className="space-y-6">
<div>
<h2 className="flex items-center gap-2 text-lg font-semibold"><Link2 className="h-5 w-5 text-brand-600" aria-hidden /> Linked products</h2>
<p className="mt-1 text-sm text-gray-600">
Your church&apos;s other Cross Code products, such as the Church Website and Church App. Connect them to show your events there, and theirs here.
Registrations and payments always stay in Cross Events.
</p>
</div>
{msg && <p role="status" className={`text-sm ${msg.ok ? "text-green-700" : "text-red-700"}`}>{msg.text}</p>}
{!data.hubConnected && (
<div className="rounded-lg border bg-gray-50 p-4 text-sm text-gray-700">This site isn&apos;t connected to the Hub yet (Settings → Licence), so it doesn&apos;t know your other products.</div>
)}
{data.hubConnected && data.keyMismatch && (
<div className="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900">
The Hub has a different key for this site, so your other products can&apos;t check that messages really come from it. This happens after a server is rebuilt: ask your provider to clear the site&apos;s key on the Hub.
</div>
)}
<div className="rounded-lg border p-4">
<label className="flex items-start gap-3">
<input type="checkbox" className="mt-1" checked={data.publishEvents} disabled={busy === "publish"} onChange={e => publish(e.target.checked)} />
<span>
<span className="text-sm font-medium">Publish my events</span>
<span className="block text-sm text-gray-600">Your public events, as they appear on your events page, for your connected products to show. Never anyone&apos;s details.</span>
</span>
</label>
</div>
{data.hubConnected && data.products.length === 0 && (
<div className="rounded-lg border bg-gray-50 p-4 text-sm text-gray-700">
Your church has no other Cross Code products yet. When it has (for example the{" "}
<a href="https://crosscode.co.za" className="text-brand-700 underline" target="_blank" rel="noopener noreferrer">Church Website</a>), it shows here within 15 minutes.
</div>
)}
{data.products.length > 0 && (
<ul className="space-y-3">
{data.products.map(p => (
<li key={p.installId} className="rounded-lg border p-4" data-testid={`linked-${p.product}`}>
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<div className="font-medium">{p.name}</div>
<a href={p.url} target="_blank" rel="noopener noreferrer" className="text-sm text-brand-700 underline">{p.url.replace(/^https?:\/\//, "")}</a>
<div className="mt-1 text-sm text-gray-600">
{p.link
? <>Connected {when(p.link.connectedAt)}{p.link.connectedBy ? ` by ${p.link.connectedBy}` : ` by ${p.name}`}</>
: "Not connected"}
{!p.listed && <span className="ml-1 text-amber-800">· no longer listed by the Hub</span>}
</div>
</div>
<div className="flex gap-2">
{p.link ? (
<button type="button" className="rounded-lg border px-3 py-1.5 text-sm hover:bg-gray-50 disabled:opacity-50" disabled={!!busy} onClick={() => disconnect(p)}>Disconnect</button>
) : (
<button type="button" className="rounded-lg bg-brand-600 px-3 py-1.5 text-sm text-white hover:bg-brand-700 disabled:opacity-50" disabled={!!busy || !p.listed} onClick={() => connect(p)}>
{busy === `c:${p.installId}` ? "Connecting…" : "Connect"}
</button>
)}
</div>
</div>
{p.link && p.publishesEvents && (
<div className="mt-3 border-t pt-3">
<label className="flex items-start gap-3">
<input type="checkbox" className="mt-1" checked={p.link.showEvents} disabled={!!busy} onChange={e => showEvents(p, e.target.checked)} />
<span>
<span className="text-sm font-medium">Show events from {p.name}</span>
<span className="block text-sm text-gray-600">Its events appear on your events pages, marked as coming from it, with a link to their page there.</span>
</span>
</label>
{p.link.showEvents && (
<div className="mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-gray-600">
<span>{p.link.importedEvents} event{p.link.importedEvents === 1 ? "" : "s"} · last synced {ago(p.link.lastGoodAt)}</span>
<button type="button" className="inline-flex items-center gap-1 text-brand-700 underline disabled:opacity-50" disabled={!!busy} onClick={() => syncNow(p)}>
<RefreshCw className="h-3.5 w-3.5" aria-hidden /> Fetch now
</button>
{p.link.lastSyncError && <span className="w-full text-amber-800">Last try ({ago(p.link.lastSyncAt)}): {p.link.lastSyncError}. The events from the last good fetch keep showing.</span>}
</div>
)}
</div>
)}
</li>
))}
</ul>
)}
</div>
);
}
@@ -3,12 +3,14 @@
import React, { useState } from "react";
import { CalendarX } from "lucide-react";
import { EventCard } from "@/components/events/EventCard";
import { LinkedEventCard } from "@/components/events/LinkedEventCard";
import { mergeByStart, type LinkedEvent } from "@/lib/linkedEvents";
import { CampusFilter } from "@/components/shared/CampusFilter";
import { useCampuses } from "@/hooks/useCampuses";
import { useAuth } from "@/hooks/useAuth";
import { useExternalEffect } from "@/lib/hooks";
type GridEvent = React.ComponentProps<typeof EventCard>["event"] & { campusId?: string | null };
type GridEvent = React.ComponentProps<typeof EventCard>["event"] & { campusId?: string | null; nextSession?: { startsAt: string } | null };
// The visitor's campus choice, kept in this browser (like the cookie choice).
const STORAGE_KEY = "hope_events_campus";
@@ -23,8 +25,10 @@ function store(value: string) {
/**
* The public events grid with a campus filter (while campuses are on). A campus shows its own
* events plus church-wide ones. Starts on the visitor's last choice, else their home campus.
* Events from linked products (2.4.0) are mixed in by date; a campus also shows linked events for
* no campus or for a campus this site doesn't have.
*/
export function EventsGrid({ events }: { events: GridEvent[] }) {
export function EventsGrid({ events, linked = [] }: { events: GridEvent[]; linked?: LinkedEvent[] }) {
const { enabled, campuses } = useCampuses();
const { user } = useAuth();
const [campus, setCampus] = useState("");
@@ -39,20 +43,28 @@ export function EventsGrid({ events }: { events: GridEvent[] }) {
const choose = (value: string) => { setCampus(value); store(value); };
const shown = enabled && campus ? events.filter(e => !e.campusId || e.campusId === campus) : events;
const chosenSlug = campuses.find(c => c.id === campus)?.slug;
const slugs = new Set(campuses.map(c => c.slug));
const shownLinked = enabled && campus
? linked.filter(l => !l.event.campus || !slugs.has(l.event.campus.slug) || l.event.campus.slug === chosenSlug)
: linked;
const items = mergeByStart(shown, shownLinked, e => e.nextSession?.startsAt || e.startDate);
return (
<>
<div className="mb-6">
<CampusFilter value={campus} onChange={choose} id="events-campus" />
</div>
{shown.length === 0 ? (
{items.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">{events.length ? "No events at this campus right now — try another campus." : "No events available right now — check back soon."}</p>
<p className="text-gray-500 text-sm">{events.length + linked.length ? "No events at this campus right now — try another campus." : "No events available right now — check back soon."}</p>
</div>
) : (
<div className="grid gap-6 md:grid-cols-3 sm:grid-cols-2">
{shown.map(event => <EventCard key={event.id} event={event} />)}
{items.map(item => item.kind === "own"
? <EventCard key={item.event.id} event={item.event} />
: <LinkedEventCard key={item.event.key} item={item.event} />)}
</div>
)}
</>
@@ -0,0 +1,61 @@
import { Calendar, ExternalLink, MapPin } from "lucide-react";
import { ApiImage } from "@/components/shared/ApiImage";
import { formatDateTimeRange } from "@/lib/date";
import { fromLabel, linkedEventPath, type LinkedEvent } from "@/lib/linkedEvents";
/** The first paragraph of a markdown description as plain text, for a card. */
function teaser(e: LinkedEvent["event"]): string {
const text = e.summary || (e.description || "").split(/\n\s*\n/)[0] || "";
return text.replace(/\\([\\`*_[\]<>|~#+.!()-])/g, "$1").replace(/[*_`]/g, "").trim();
}
/**
* A card for an event from another of the church's products (Website, App): like EventCard, with
* a "From the Church Website" label. Details open its page here; registering happens where it comes from.
*/
export function LinkedEventCard({ item }: { item: LinkedEvent }) {
const e = item.event;
const r = e.registration;
const place = e.location?.name || e.location?.address || (e.location?.onlineUrl ? "Online" : null);
const action = r.mode === "origin" ? "Register" : r.mode === "external" ? "Register" : null;
return (
<div className="relative border rounded-xl overflow-hidden shadow-sm hover:shadow-md hover:border-brand-200 transition" data-testid="linked-event-card">
<a href={linkedEventPath(item)} className="block">
{e.imageUrl ? (
<ApiImage src={e.imageUrl} alt={e.title} className="h-48 w-full object-cover" />
) : (
<div className="h-48 w-full bg-brand-50 flex items-center justify-center">
<Calendar className="w-10 h-10 text-brand-200" />
</div>
)}
<div className="p-4">
<p className="text-xs font-medium uppercase tracking-wide text-brand-700">{fromLabel(item)}</p>
<h3 className="text-lg font-semibold hover:underline">{e.title}</h3>
{e.campus && <p className="text-xs text-gray-500 mt-0.5">{e.campus.name}</p>}
<p className="text-sm text-gray-500 flex items-center gap-1.5 mt-1">
<Calendar className="w-3.5 h-3.5 shrink-0" />
{formatDateTimeRange(e.startsAt, e.endsAt)}
</p>
{place && (
<p className="text-sm text-gray-500 flex items-center gap-1.5 mt-1">
<MapPin className="w-3.5 h-3.5 shrink-0" />
<span className="truncate">{place}</span>
</p>
)}
<p className="text-sm text-gray-600 mt-2 line-clamp-2">{teaser(e)}</p>
</div>
</a>
<div className="px-4 pb-4 flex gap-2">
<a href={linkedEventPath(item)} className="flex-1 text-center text-sm text-gray-700 border rounded-lg py-2 hover:bg-gray-50 transition-colors">
View details
</a>
{action && r.url && (
<a href={r.url} rel="noopener" className="flex-1 inline-flex items-center justify-center gap-1 text-center text-sm text-white bg-brand-600 rounded-lg py-2 hover:bg-brand-700 transition-colors">
{action} <ExternalLink className="w-3.5 h-3.5" aria-hidden />
</a>
)}
</div>
</div>
);
}