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>
54 lines
2.8 KiB
TypeScript
54 lines
2.8 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { api } from "@/admin/api";
|
|
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin } from "@/admin/ui";
|
|
|
|
type PageRow = { id: string; kind: string; slug: string; title: string; inNav: boolean; path: string };
|
|
|
|
const KINDS: Record<string, string> = { home: "Home", visit: "Plan your visit", about: "About", leadership: "Leadership", ministries: "Ministries", events: "Events", messages: "Messages", give: "Give", contact: "Contact", terms: "Terms", safeguarding: "Safeguarding", custom: "Your own page" };
|
|
|
|
/** Pages (§6): the fixed ones and the church's own, built from blocks. */
|
|
export default function Pages() {
|
|
const { data, error } = useAdmin<PageRow[]>("/pages");
|
|
const router = useRouter();
|
|
const [title, setTitle] = useState("");
|
|
const [slug, setSlug] = useState("");
|
|
const { busy, message, fields, run } = useAction();
|
|
if (!data) return <Loading error={error} />;
|
|
const create = () => run(async () => {
|
|
const p = await api<{ id: string }>("/pages", { body: { title, slug } });
|
|
router.push(`/admin/pages/${p.id}`);
|
|
});
|
|
return (
|
|
<>
|
|
<Title sub="Each page is a draft until you publish.">Pages</Title>
|
|
<div className="grid gap-6 lg:grid-cols-[2fr_1fr]">
|
|
<Panel>
|
|
<ul className="divide-y divide-gray-200">
|
|
{data.map((p) => (
|
|
<li key={p.id} className="flex items-center justify-between gap-3 py-3">
|
|
<div>
|
|
<Link href={`/admin/pages/${p.id}`} className="font-medium underline-offset-4 hover:underline">{p.title}</Link>
|
|
<p className="text-xs text-gray-500">{KINDS[p.kind] ?? p.kind} · {p.path}{!p.inNav && p.kind !== "home" && " · not in the menu"}</p>
|
|
</div>
|
|
<Link href={`/admin/pages/${p.id}`} className="text-sm font-semibold text-brand-text">Edit</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</Panel>
|
|
<Panel title="Add a page">
|
|
<div className="space-y-3">
|
|
<Field label="Title" error={fields.title}><input className={inputClass} value={title} maxLength={120} onChange={(e) => { setTitle(e.target.value); setSlug(e.target.value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "")); }} /></Field>
|
|
<Field label="Address" hint={`Your site/${slug || "…"}`} error={fields.slug}><input className={inputClass} value={slug} maxLength={80} onChange={(e) => setSlug(e.target.value)} /></Field>
|
|
<Btn kind="primary" busy={busy} onClick={create} disabled={!title || !slug}>Add page</Btn>
|
|
{message && <Notice tone={message.tone}>{message.text}</Notice>}
|
|
</div>
|
|
</Panel>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|