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
+43 -21
View File
@@ -1,26 +1,48 @@
import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { loadMe, ROLE_NAMES, signInHref } from "@/lib/admin";
"use client";
export const metadata: Metadata = { title: "Admin", robots: { index: false, follow: false } };
export const dynamic = "force-dynamic";
import Link from "next/link";
import { StorageMeter, type Storage } from "@/admin/media";
import { Loading, Notice, Panel, Title, useAdmin, when } from "@/admin/ui";
// The admin (docs/WEBSITE-1.0-PLAN.md §10), signed in through the church's Accounts. The screens
// (template and style, pages, messages, events, publish) come next.
export default async function Admin() {
const me = await loadMe();
if (!me) redirect(signInHref("/admin"));
type Overview = {
pending: number;
lastPublished: { number: number; at: string } | null;
storage: Storage;
colourNotes: string[];
checklist: { key: string; label: string; done: boolean; href: string | null }[];
};
/** The dashboard (§10): the setup checklist, what's waiting to be published, storage. */
export default function Dashboard() {
const { data, error } = useAdmin<Overview>("/overview");
if (!data) return <Loading error={error} />;
return (
<main className="mx-auto max-w-xl px-4 py-16">
<h1 className="text-2xl font-semibold">Website admin</h1>
<p className="mt-2 text-gray-600">
Signed in as {me.user.name} ({me.user.email}), {ROLE_NAMES[me.user.role]}.
</p>
<form method="post" action="/api/auth/signout" className="mt-6">
<button type="submit" className="rounded border border-gray-300 px-4 py-2 text-sm hover:bg-gray-50">
Sign out
</button>
</form>
</main>
<>
<Title sub={data.lastPublished ? `Last published ${when(data.lastPublished.at)} (version ${data.lastPublished.number}).` : "Your site shows Coming soon until you publish it."}>Dashboard</Title>
<div className="grid gap-6 lg:grid-cols-2">
<Panel title="Getting your site ready">
<ol className="space-y-3">
{data.checklist.map((c) => (
<li key={c.key} className="flex items-start gap-3">
<span aria-hidden="true" className={c.done ? "text-green-700" : "text-gray-400"}>{c.done ? "✓" : "○"}</span>
<span className={c.done ? "text-gray-500 line-through" : ""}>{c.href ? <Link href={c.href} className="underline-offset-4 hover:underline">{c.label}</Link> : c.label}</span>
<span className="sr-only">{c.done ? "(done)" : "(to do)"}</span>
</li>
))}
</ol>
</Panel>
<div className="space-y-6">
<Panel title="Waiting to be published">
{data.pending ? (
<p>{data.pending} {data.pending === 1 ? "change" : "changes"}. <Link href="/admin/publish" className="font-semibold text-brand-text underline-offset-4 hover:underline">Review and publish</Link></p>
) : <p className="text-gray-600">Nothing: the site shows everything you&apos;ve done.</p>}
</Panel>
<Panel title="Storage"><StorageMeter s={data.storage} /></Panel>
{data.colourNotes.length > 0 && (
<Notice tone="info"><p className="font-semibold">About your colours</p><ul className="mt-1 list-disc pl-5">{data.colourNotes.map((n) => <li key={n}>{n}</li>)}</ul></Notice>
)}
</div>
</div>
</>
);
}