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>
);
}