feat(website): the admin, with drafts, preview, publish and restore

Admin API and screens: dashboard and setup checklist, template and
style, pages and blocks, ministries, leadership, media library with
the storage limit, publish and history. Pending changes with who and
when, discard one, one Publish, restore any version (each version
keeps the working copy's rows, never sent to visitors). Preview on
the site's own addresses with a bar (widths, back, publish); shared
preview links for 7 days or until revoked. Roles checked, same-origin
changes only. Publish refreshes the public pages at once
(WEBSITE_CONTENT_CACHE_SECONDS). E2E on a production build: the
admin's flows and axe on every screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:30:29 +02:00
co-authored by Claude Opus 5.5
parent 3caa1d1e1a
commit 84c5b0c08e
44 changed files with 2404 additions and 65 deletions
+25 -5
View File
@@ -1,3 +1,4 @@
import { cookies } from "next/headers";
import { cache } from "react";
import type { Image, Published, SiteContent, Template } from "./types";
@@ -13,14 +14,33 @@ const FALLBACK: SiteContent = {
};
/**
* The site as visitors see it: one fetch per request (React `cache`), kept by Next for 30 seconds,
* so Publish shows within half a minute. While the backend can't answer: Coming soon, never an
* error page.
* The site as visitors see it: one fetch per request (React `cache`), kept by Next for
* WEBSITE_CONTENT_CACHE_SECONDS (30; tag `site-content`, which Publish clears at once through
* app/revalidate). While the backend can't answer: Coming soon, never an error page.
*/
export const loadContent = cache(async (): Promise<SiteContent> => {
// Previewing (§4): the working copy, if the backend agrees this is an admin or a live share link.
const jar = await cookies();
const preview = jar.get("ccw_preview")?.value;
if (preview) {
try {
const session = jar.get("ccw_session")?.value;
const res = await fetch(`${api}/api/v1/site/preview`, {
cache: "no-store",
headers: {
...(session ? { Cookie: `ccw_session=${encodeURIComponent(session)}` } : {}),
...(preview !== "admin" ? { "x-preview-token": preview } : {}),
},
});
if (res.ok) return (await res.json()) as SiteContent;
} catch {
// Falls back to the live site.
}
}
try {
// In development (and the e2e run) always fresh, so a Publish shows at once.
const res = await fetch(`${api}/api/v1/site/content`, process.env.NODE_ENV === "production" ? { next: { revalidate: 30 } } : { cache: "no-store" });
// Not kept in development, or when set to 0 (the e2e run changes content behind Next's back).
const seconds = process.env.NODE_ENV === "production" ? Number(process.env.WEBSITE_CONTENT_CACHE_SECONDS ?? 30) : 0;
const res = await fetch(`${api}/api/v1/site/content`, seconds > 0 ? { next: { revalidate: seconds, tags: ["site-content"] } } : { cache: "no-store" });
if (res.ok) return (await res.json()) as SiteContent;
} catch {
// Starting or down.