feat(website): church details, settings, audit log, search engine data, safer editing

Church details saved through Accounts' church.update (live at once).
Settings: Search Console and Bing codes, Coming soon line, menu order.
Audit log and recent edits. A made share image, Event / VideoObject /
PodcastEpisode / BreadcrumbList structured data, permanent redirects
from old page addresses. Saves refused when someone else saved in
between; Ministry leaders' events; templates previewed with the
church's own content before choosing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 15:30:27 +02:00
co-authored by Claude Opus 5.5
parent d8ed238042
commit 085265392e
37 changed files with 951 additions and 91 deletions
@@ -0,0 +1,43 @@
"use client";
/** The audit log (§4, §10): who changed what, and when. Owners and Admins see it. */
import { useState } from "react";
import { api } from "@/admin/api";
import { Btn, Loading, Panel, Title, useAdmin, when } from "@/admin/ui";
type Entry = { at: string; who: string; action: string; detail: string | null };
export default function Audit() {
const first = useAdmin<Entry[]>("/audit");
const [more, setMore] = useState<Entry[]>([]);
const [done, setDone] = useState(false);
if (!first.data) return <Loading error={first.error} />;
const all = [...first.data, ...more];
return (
<>
<Title sub="Who changed what, newest first.">Audit log</Title>
<Panel>
{all.length === 0 && <p className="text-gray-600">Nothing yet.</p>}
<table className="w-full text-left text-sm">
<thead className="text-gray-600"><tr><th className="py-2 pr-4 font-medium">When</th><th className="py-2 pr-4 font-medium">Who</th><th className="py-2 font-medium">What</th></tr></thead>
<tbody className="divide-y divide-gray-200">
{all.map((e, i) => (
<tr key={`${e.at}-${i}`}>
<td className="whitespace-nowrap py-2 pr-4 text-gray-600">{when(e.at)}</td>
<td className="py-2 pr-4">{e.who}</td>
<td className="py-2">{e.action}{e.detail && <span className="text-gray-600">: {e.detail}</span>}</td>
</tr>
))}
</tbody>
</table>
{!done && all.length >= 100 && (
<Btn className="mt-4" onClick={async () => {
const next = await api<Entry[]>(`/audit?before=${encodeURIComponent(all.at(-1)!.at)}`);
if (!next.length) setDone(true);
setMore([...more, ...next]);
}}>Show older</Btn>
)}
</Panel>
</>
);
}
@@ -0,0 +1,127 @@
"use client";
/**
* Church details (§2, decision 10): the facts every one of the church's sites shows (name, colours,
* fonts and corners, logo, service times, contact, social links). They belong to the church's
* Accounts and are saved there; they're not drafts: they change on all its sites at once.
*/
import { useState } from "react";
import type { Church } from "@crosscode/contracts";
import { api, canEdit } from "@/admin/api";
import { ImagePicker } from "@/admin/media";
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin } from "@/admin/ui";
const DAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
const PAIRINGS: [string, string][] = [["", "Your template's choice"], ["classic", "Classic"], ["scholarly", "Scholarly"], ["editorial", "Editorial"], ["impact", "Impact"], ["contemporary", "Contemporary"], ["friendly", "Friendly"], ["warm", "Warm"], ["modern", "Modern"]];
const NETWORKS = ["facebook", "instagram", "youtube", "tiktok", "x", "spotify", "whatsapp-channel", "other"];
type ServiceTime = Church["serviceTimes"][number];
type Social = Church["social"][number];
type Address = NonNullable<Church["contact"]["address"]>;
export default function ChurchDetails() {
const me = useAdmin<{ user: { role: string } }>("/me");
const { data, error, reload } = useAdmin<{ church: Church | null; linked: boolean }>("/church");
const { busy, message, fields, run } = useAction();
const [edit, setEdit] = useState<Partial<Church> & { logoMediaId?: string | null } | null>(null);
if (!data || !me.data) return <Loading error={error ?? me.error} />;
if (!data.church) return <><Title>Church details</Title><Notice tone="warning">{data.linked ? "Your church's details can't be read from Accounts right now. Try again in a minute." : "This website isn't linked to your church's Accounts yet. It links by itself within 15 minutes of being installed."}</Notice></>;
const c: Church = { ...data.church, ...edit } as Church;
const editor = canEdit(me.data.user.role);
const set = (patch: Partial<Church>) => setEdit({ ...edit, ...patch });
const times = c.serviceTimes;
const setTime = (i: number, t: Partial<ServiceTime>) => set({ serviceTimes: times.map((x, j) => (j === i ? { ...x, ...t } : x)) });
const address: Address = c.contact.address ?? { line1: "", line2: null, suburb: null, city: "", province: null, postalCode: null, country: "ZA", geo: null };
const setAddress = (a: Partial<Address>) => set({ contact: { ...c.contact, address: { ...address, ...a } } });
const save = () => run(async () => {
// The media id only picks the logo here; Accounts keeps its address.
const changes = { ...(edit ?? {}) };
delete changes.logoMediaId;
await api("/church", { method: "PUT", body: { church: changes, ifUpdatedAt: data.church!.updatedAt } });
setEdit(null);
await reload();
}, "Saved: all your church's sites show it now.");
const err = (k: string) => fields[k];
return (
<>
<Title sub="These show on all your church's sites (this website, Cross Events, the sign-in pages). Changes here go live straight away: they aren't drafts."
actions={editor && edit && <><Btn onClick={() => setEdit(null)}>Undo</Btn><Btn kind="primary" busy={busy} onClick={save}>Save for all your sites</Btn></>}>
Church details
</Title>
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
<fieldset disabled={!editor} className="space-y-6">
<Panel title="Name and look">
<div className="grid gap-4 sm:grid-cols-2">
<Field label="Church name" error={err("name")}><input className={inputClass} value={c.name} maxLength={200} onChange={(e) => set({ name: e.target.value })} /></Field>
<Field label="Short name" hint="For tight spaces." error={err("shortName")}><input className={inputClass} value={c.shortName ?? ""} maxLength={30} onChange={(e) => set({ shortName: e.target.value || null })} /></Field>
<Field label="Main colour" error={err("branding.colours.primary")}><input type="color" className="h-10 w-20" value={c.branding.colours.primary} onChange={(e) => set({ branding: { ...c.branding, colours: { ...c.branding.colours, primary: e.target.value } } })} /></Field>
<Field label="Accent colour"><input type="color" className="h-10 w-20" value={c.branding.colours.accent ?? "#999999"} onChange={(e) => set({ branding: { ...c.branding, colours: { ...c.branding.colours, accent: e.target.value } } })} /></Field>
<Field label="Fonts" hint="Shared by all your sites. Your template suggests some.">
<select className={inputClass} value={c.branding.style?.fontPairing ?? ""} onChange={(e) => set({ branding: { ...c.branding, style: { fontPairing: (e.target.value || null) as never, corners: c.branding.style?.corners ?? null } } })}>
{PAIRINGS.map(([v, l]) => <option key={v} value={v}>{l}</option>)}
</select>
</Field>
<Field label="Corners">
<select className={inputClass} value={c.branding.style?.corners ?? ""} onChange={(e) => set({ branding: { ...c.branding, style: { fontPairing: c.branding.style?.fontPairing ?? null, corners: (e.target.value || null) as never } } })}>
<option value="">Your template&apos;s choice</option><option value="sharp">Sharp</option><option value="soft">Soft</option><option value="round">Round</option>
</select>
</Field>
<div className="sm:col-span-2">
{c.branding.logoUrl && <img src={c.branding.logoUrl} alt="Your logo" className="mb-2 h-12 w-auto" />}
<ImagePicker label="Logo (a photo from the media library)" value={edit?.logoMediaId ?? null}
onChange={(id) => run(async () => {
if (!id) return set({ branding: { ...c.branding, logoUrl: null }, logoMediaId: null } as never);
const media = await api<{ items: { id: string; url: string }[] }>("/media");
const url = media.items.find((m) => m.id === id)?.url;
set({ branding: { ...c.branding, logoUrl: url ? `${window.location.origin}${url}` : null }, logoMediaId: id } as never);
})} />
</div>
</div>
</Panel>
<Panel title="Service times">
<ul className="space-y-3">
{times.map((t, i) => (
<li key={i} className="grid gap-2 sm:grid-cols-[8rem_7rem_1fr_1fr_auto]">
<select aria-label="Day" className={inputClass} value={t.day} onChange={(e) => setTime(i, { day: e.target.value as ServiceTime["day"] })}>{DAYS.map((d) => <option key={d} value={d}>{d[0]!.toUpperCase() + d.slice(1)}</option>)}</select>
<input aria-label="Time" type="time" className={inputClass} value={t.time} onChange={(e) => setTime(i, { time: e.target.value })} />
<input aria-label="Name (e.g. Morning service)" placeholder="E.g. Morning service" className={inputClass} value={t.label ?? ""} maxLength={100} onChange={(e) => setTime(i, { label: e.target.value || null })} />
<input aria-label="Note" placeholder="E.g. Kids church during the service" className={inputClass} value={t.note ?? ""} maxLength={300} onChange={(e) => setTime(i, { note: e.target.value || null })} />
<Btn kind="danger" onClick={() => set({ serviceTimes: times.filter((_, j) => j !== i) })}>Remove</Btn>
</li>
))}
</ul>
{err("serviceTimes") && <p className="mt-2 text-xs text-red-700">{err("serviceTimes")}</p>}
<Btn className="mt-3" onClick={() => set({ serviceTimes: [...times, { day: "sunday", time: "09:00", label: null, campus: null, note: null }] })}>Add a service time</Btn>
</Panel>
<Panel title="Contact and address">
<div className="grid gap-4 sm:grid-cols-2">
<Field label="Email" error={err("contact.email")}><input type="email" className={inputClass} value={c.contact.email ?? ""} onChange={(e) => set({ contact: { ...c.contact, email: e.target.value || null } })} /></Field>
<Field label="Phone" hint="With the country code: +27125550123" error={err("contact.phone")}><input className={inputClass} value={c.contact.phone ?? ""} onChange={(e) => set({ contact: { ...c.contact, phone: e.target.value.replace(/\s+/g, "") || null } })} /></Field>
<Field label="WhatsApp" hint="With the country code" error={err("contact.whatsapp")}><input className={inputClass} value={c.contact.whatsapp ?? ""} onChange={(e) => set({ contact: { ...c.contact, whatsapp: e.target.value.replace(/\s+/g, "") || null } })} /></Field>
<div />
<Field label="Street address" error={err("contact.address.line1")}><input className={inputClass} value={address.line1} onChange={(e) => setAddress({ line1: e.target.value })} /></Field>
<Field label="Suburb"><input className={inputClass} value={address.suburb ?? ""} onChange={(e) => setAddress({ suburb: e.target.value || null })} /></Field>
<Field label="City" error={err("contact.address.city")}><input className={inputClass} value={address.city} onChange={(e) => setAddress({ city: e.target.value })} /></Field>
<Field label="Postal code"><input className={inputClass} value={address.postalCode ?? ""} onChange={(e) => setAddress({ postalCode: e.target.value || null })} /></Field>
</div>
</Panel>
<Panel title="Social links">
<ul className="space-y-2">
{c.social.map((s, i) => (
<li key={i} className="grid gap-2 sm:grid-cols-[12rem_1fr_auto]">
<select aria-label="Network" className={inputClass} value={s.network} onChange={(e) => set({ social: c.social.map((x, j) => (j === i ? { ...x, network: e.target.value as Social["network"] } : x)) })}>{NETWORKS.map((n) => <option key={n} value={n}>{n}</option>)}</select>
<input aria-label="Address" className={inputClass} value={s.url} onChange={(e) => set({ social: c.social.map((x, j) => (j === i ? { ...x, url: e.target.value } : x)) })} />
<Btn kind="danger" onClick={() => set({ social: c.social.filter((_, j) => j !== i) })}>Remove</Btn>
</li>
))}
</ul>
{err("social") && <p className="mt-2 text-xs text-red-700">{err("social")}</p>}
<Btn className="mt-3" onClick={() => set({ social: [...c.social, { network: "facebook", url: "https://" }] })}>Add a link</Btn>
</Panel>
</fieldset>
</>
);
}
@@ -3,15 +3,20 @@
/**
* Simple events (§8): title, date and time, place, description, a photo and an optional link (a
* sign-up form elsewhere, say). Registrations and payments are Cross Events'. Each publishes on its
* own (decision 9). Events from Cross Events show on the site by themselves once it's linked.
* own (decision 9). An event can belong to a ministry: its Ministry leader can add and change it,
* and an Editor publishes it (§10). Events from Cross Events show on the site by themselves.
*/
import { useState } from "react";
import { api, canEdit } from "@/admin/api";
import { ImagePicker } from "@/admin/media";
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui";
type Ev = { id: string; slug: string; title: string; startsAt: string; endsAt: string | null; allDay: boolean; location: string | null; description: string | null; imageId: string | null; image: string | null; link: string | null; cancelled: boolean; published: boolean };
type Form = { title: string; date: string; time: string; endDate: string; endTime: string; allDay: boolean; location: string; description: string; imageId: string | null; link: string };
type Ev = {
id: string; slug: string; title: string; startsAt: string; endsAt: string | null; allDay: boolean; location: string | null; description: string | null;
imageId: string | null; image: string | null; link: string | null; ministryId: string | null; cancelled: boolean; published: boolean; updatedAt: string;
};
type Form = { title: string; date: string; time: string; endDate: string; endTime: string; allDay: boolean; location: string; description: string; imageId: string | null; link: string; ministryId: string | null };
type Me = { user: { role: string; ministryId: string | null } };
/** "2026-12-05" + "18:30" in the browser's time zone (the church's, for its admins) → ISO with offset. */
const iso = (date: string, time: string) => (date ? new Date(`${date}T${time || "00:00"}`).toISOString() : null);
@@ -22,7 +27,7 @@ const local = (s: string | null) => {
return { d: `${x.getFullYear()}-${p(x.getMonth() + 1)}-${p(x.getDate())}`, t: `${p(x.getHours())}:${p(x.getMinutes())}` };
};
function EventForm({ initial, onSave, onCancel }: { initial: Form; onSave: (body: object) => Promise<unknown>; onCancel: () => void }) {
function EventForm({ initial, ministries, fixedMinistry, onSave, onCancel }: { initial: Form; ministries: { id: string; name: string }[]; fixedMinistry: string | null; onSave: (body: object) => Promise<unknown>; onCancel: () => void }) {
const [v, setV] = useState(initial);
const { busy, message, fields, run } = useAction();
const set = (k: keyof Form, x: unknown) => setV({ ...v, [k]: x });
@@ -39,11 +44,19 @@ function EventForm({ initial, onSave, onCancel }: { initial: Form; onSave: (body
<Field label="Where" error={fields.location}><input className={inputClass} value={v.location} maxLength={500} onChange={(e) => set("location", e.target.value)} /></Field>
<Field label="About it" error={fields.description}><textarea className={inputClass} rows={4} value={v.description} maxLength={8000} onChange={(e) => set("description", e.target.value)} /></Field>
<Field label="Link (optional)" hint="A sign-up form or more information elsewhere: https://…" error={fields.link}><input className={inputClass} value={v.link} onChange={(e) => set("link", e.target.value)} /></Field>
{!fixedMinistry && ministries.length > 0 && (
<Field label="Ministry (optional)" hint="Its Ministry leader can then change it too.">
<select className={inputClass} value={v.ministryId ?? ""} onChange={(e) => set("ministryId", e.target.value || null)}>
<option value="">None</option>
{ministries.map((m) => <option key={m.id} value={m.id}>{m.name}</option>)}
</select>
</Field>
)}
<ImagePicker label="Photo" value={v.imageId} onChange={(id) => set("imageId", id)} />
<div className="flex gap-2">
<Btn kind="primary" busy={busy} onClick={() => run(() => onSave({
title: v.title, startsAt: iso(v.date, v.allDay ? "00:00" : v.time), endsAt: v.endDate ? iso(v.endDate, v.allDay ? "23:59" : v.endTime) : null,
allDay: v.allDay, location: v.location || null, description: v.description || null, imageId: v.imageId, link: v.link || null,
allDay: v.allDay, location: v.location || null, description: v.description || null, imageId: v.imageId, link: v.link || null, ministryId: fixedMinistry ?? v.ministryId,
}))}>Save</Btn>
<Btn onClick={onCancel}>Cancel</Btn>
</div>
@@ -52,31 +65,41 @@ function EventForm({ initial, onSave, onCancel }: { initial: Form; onSave: (body
);
}
const empty: Form = { title: "", date: "", time: "10:00", endDate: "", endTime: "", allDay: false, location: "", description: "", imageId: null, link: "" };
const empty: Form = { title: "", date: "", time: "10:00", endDate: "", endTime: "", allDay: false, location: "", description: "", imageId: null, link: "", ministryId: null };
export default function Events() {
const me = useAdmin<{ user: { role: string } }>("/me");
const me = useAdmin<Me>("/me");
const { data, error, reload } = useAdmin<Ev[]>("/events");
const ministries = useAdmin<{ id: string; name: string }[]>("/ministries");
const [editing, setEditing] = useState<string | null>(null);
const { busy, message, run } = useAction();
if (!data || !me.data) return <Loading error={error ?? me.error} />;
const editor = canEdit(me.data.user.role);
const leaderOf = me.data.user.role === "ministry_leader" ? me.data.user.ministryId : null;
const mayWrite = (e: Ev | null) => editor || (!!leaderOf && (!e || e.ministryId === leaderOf));
const nameOf = (id: string | null) => ministries.data?.find((m) => m.id === id)?.name;
const toForm = (e: Ev): Form => {
const s = local(e.startsAt);
const f = local(e.endsAt);
return { title: e.title, date: s.d, time: s.t, endDate: f.d, endTime: f.t, allDay: e.allDay, location: e.location ?? "", description: e.description ?? "", imageId: e.imageId, link: e.link ?? "" };
return { title: e.title, date: s.d, time: s.t, endDate: f.d, endTime: f.t, allDay: e.allDay, location: e.location ?? "", description: e.description ?? "", imageId: e.imageId, link: e.link ?? "", ministryId: e.ministryId };
};
const state = (e: Ev, change: object, done: string) => run(async () => { await api(`/events/${e.id}/state`, { body: change }); await reload(); }, done);
const form = (e: Ev | null) => (
<EventForm initial={e ? toForm(e) : { ...empty, ministryId: leaderOf }} ministries={ministries.data ?? []} fixedMinistry={leaderOf} onCancel={() => setEditing(null)}
onSave={async (b) => {
await api(e ? `/events/${e.id}` : "/events", { method: e ? "PUT" : "POST", body: e ? { ...b, ifUpdatedAt: e.updatedAt } : b });
setEditing(null);
await reload();
}} />
);
return (
<>
<Title sub="Simple events made here. Events with registration and payment belong in Cross Events; they show here by themselves once it's linked.">Events</Title>
<Title sub={leaderOf ? `You can add and change ${nameOf(leaderOf) ?? "your ministry"}'s events; an editor publishes them.` : "Simple events made here. Events with registration and payment belong in Cross Events; they show here by themselves once it's linked."}>Events</Title>
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
<div className="space-y-6">
{editor && (
{mayWrite(null) && (
<Panel title="Add an event">
{editing === "new"
? <EventForm initial={empty} onCancel={() => setEditing(null)} onSave={async (b) => { await api("/events", { body: b }); setEditing(null); await reload(); }} />
: <Btn kind="primary" onClick={() => setEditing("new")}>Add an event</Btn>}
{editing === "new" ? form(null) : <Btn kind="primary" onClick={() => setEditing("new")}>Add an event</Btn>}
</Panel>
)}
<Panel title="Your events">
@@ -84,23 +107,23 @@ export default function Events() {
<ul className="divide-y divide-gray-200">
{data.map((e) => (
<li key={e.id} className="py-3">
{editing === e.id ? (
<EventForm initial={toForm(e)} onCancel={() => setEditing(null)} onSave={async (b) => { await api(`/events/${e.id}`, { method: "PUT", body: b }); setEditing(null); await reload(); }} />
) : (
{editing === e.id ? form(e) : (
<div className="flex flex-wrap items-center gap-4">
<div className="min-w-0 flex-1">
<p className="font-medium">{e.title}</p>
<p className="text-sm text-gray-600">{when(e.startsAt)}{e.location && ` · ${e.location}`}</p>
<p className="text-sm text-gray-600">{when(e.startsAt)}{e.location && ` · ${e.location}`}{e.ministryId && nameOf(e.ministryId) && ` · ${nameOf(e.ministryId)}`}</p>
<p className="text-xs">{e.cancelled ? <span className="text-red-700">Cancelled</span> : e.published ? <span className="text-green-800">On the site</span> : <span className="text-gray-500">Not published</span>}</p>
</div>
{editor && (
<div className="flex flex-wrap gap-2">
<Btn onClick={() => setEditing(e.id)}>Edit</Btn>
<Btn busy={busy} onClick={() => state(e, { published: !e.published }, e.published ? "Taken off the site." : "On the site now.")}>{e.published ? "Unpublish" : "Publish"}</Btn>
<Btn busy={busy} onClick={() => state(e, { cancelled: !e.cancelled }, e.cancelled ? "Back on." : "Cancelled: it's off the site.")}>{e.cancelled ? "Not cancelled" : "Cancel it"}</Btn>
<Btn kind="danger" busy={busy} onClick={() => run(async () => { await api(`/events/${e.id}`, { method: "DELETE" }); await reload(); }, "Removed.")}>Remove</Btn>
</div>
)}
<div className="flex flex-wrap gap-2">
{mayWrite(e) && <Btn onClick={() => setEditing(e.id)}>Edit</Btn>}
{editor && (
<>
<Btn busy={busy} onClick={() => state(e, { published: !e.published }, e.published ? "Taken off the site." : "On the site now.")}>{e.published ? "Unpublish" : "Publish"}</Btn>
<Btn busy={busy} onClick={() => state(e, { cancelled: !e.cancelled }, e.cancelled ? "Back on." : "Cancelled: it's off the site.")}>{e.cancelled ? "Not cancelled" : "Cancel it"}</Btn>
<Btn kind="danger" busy={busy} onClick={() => run(async () => { await api(`/events/${e.id}`, { method: "DELETE" }); await reload(); }, "Removed.")}>Remove</Btn>
</>
)}
</div>
</div>
)}
</li>
@@ -10,6 +10,7 @@ type Overview = {
storage: Storage;
colourNotes: string[];
checklist: { key: string; label: string; done: boolean; href: string | null }[];
recent: { at: string; who: string; action: string; detail: string | null }[];
};
/** The dashboard (§10): the setup checklist, what's waiting to be published, storage. */
@@ -37,6 +38,13 @@ export default function Dashboard() {
<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="Recent edits">
{data.recent.length === 0 ? <p className="text-gray-600">None yet.</p> : (
<ul className="space-y-2 text-sm">
{data.recent.map((e, i) => <li key={i}><span className="font-medium">{e.who}</span> {e.action.charAt(0).toLowerCase() + e.action.slice(1)}{e.detail && <>: {e.detail}</>} <span className="text-gray-500">({when(e.at)})</span></li>)}
</ul>
)}
</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>
@@ -12,8 +12,8 @@ import { BLOCK_FIELDS, DataForm, SECTION_FIELDS } from "@/admin/fields";
import { ImagePicker } from "@/admin/media";
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin } from "@/admin/ui";
type Section = { id: string; type: string; variant: string | null; hidden: boolean; data: Record<string, unknown> };
type PageData = { id: string; kind: string; slug: string; title: string; seoTitle: string | null; description: string | null; navLabel: string | null; inNav: boolean; imageId: string | null; sections: Section[] };
type Section = { id: string; type: string; variant: string | null; hidden: boolean; data: Record<string, unknown>; updatedAt: string };
type PageData = { id: string; kind: string; slug: string; title: string; seoTitle: string | null; description: string | null; navLabel: string | null; inNav: boolean; imageId: string | null; updatedAt: string; sections: Section[] };
const HOME_ORDER = ["hero", "serviceTimes", "welcome", "ministries", "team", "events", "latestMessage", "invitation"];
const LISTS: Record<string, string> = {
@@ -55,7 +55,7 @@ export default function EditPage() {
if (!page) return <Loading error={error} />;
const f = { ...page, ...form };
const saveDetails = () => details.run(async () => {
const p = await api<PageData>(`/pages/${id}`, { method: "PUT", body: { title: f.title, slug: f.slug, seoTitle: f.seoTitle, description: f.description, navLabel: f.navLabel, inNav: f.inNav, imageId: f.imageId } });
const p = await api<PageData>(`/pages/${id}`, { method: "PUT", body: { title: f.title, slug: f.slug, seoTitle: f.seoTitle, description: f.description, navLabel: f.navLabel, inNav: f.inNav, imageId: f.imageId, ifUpdatedAt: page.updatedAt } });
setData(p);
setForm(null);
}, "Saved as a draft.");
@@ -97,7 +97,7 @@ export default function EditPage() {
{HOME_ORDER.map((type) => {
const s = page.sections.find((x) => x.type === type);
const spec = SECTION_FIELDS[type]!;
return <SectionEditor key={type} title={spec.name} fields={spec.fields} initial={s?.data ?? {}} onSave={async (data) => setData(await api<PageData>(`/pages/${id}/home/${type}`, { method: "PUT", body: { data } }))} />;
return <SectionEditor key={type} title={spec.name} fields={spec.fields} initial={s?.data ?? {}} onSave={async (data) => setData(await api<PageData>(`/pages/${id}/home/${type}`, { method: "PUT", body: { data, ifUpdatedAt: s?.updatedAt } }))} />;
})}
</>
) : (
@@ -108,7 +108,7 @@ export default function EditPage() {
if (!spec) return null;
return (
<SectionEditor key={s.id} title={`${spec.name}${s.hidden ? " (hidden)" : ""}`} fields={spec.fields} initial={s.data}
onSave={async (data) => setData(await api<PageData>(`/pages/${id}/blocks/${s.id}`, { method: "PUT", body: { data } }))}
onSave={async (data) => setData(await api<PageData>(`/pages/${id}/blocks/${s.id}`, { method: "PUT", body: { data, ifUpdatedAt: s.updatedAt } }))}
extra={<>
<Btn onClick={() => blockCall(`/blocks/${s.id}/move`, "POST", { direction: "up" })} disabled={i === 0} aria-label="Move up">↑</Btn>
<Btn onClick={() => blockCall(`/blocks/${s.id}/move`, "POST", { direction: "down" })} disabled={i === page.sections.length - 1} aria-label="Move down">↓</Btn>
@@ -0,0 +1,69 @@
"use client";
/**
* Settings (§10): the Coming soon line, search engine verification (live at once), and the menu's
* order (a draft, published with the site).
*/
import Link from "next/link";
import { useState } from "react";
import { api, canEdit } from "@/admin/api";
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin } from "@/admin/ui";
type Settings = { comingSoonText: string; googleVerification: string | null; bingVerification: string | null };
type PageRow = { id: string; kind: string; title: string; inNav: boolean };
export default function SettingsPage() {
const me = useAdmin<{ user: { role: string } }>("/me");
const settings = useAdmin<Settings>("/settings");
const pages = useAdmin<PageRow[]>("/pages");
const [form, setForm] = useState<Partial<Settings>>({});
const { busy, message, fields, run } = useAction();
if (!settings.data || !pages.data || !me.data) return <Loading error={settings.error ?? pages.error} />;
const editor = canEdit(me.data.user.role);
const s = { ...settings.data, ...form };
const menu = pages.data.filter((p) => p.kind !== "home");
const move = (i: number, d: -1 | 1) => run(async () => {
const list = [...menu];
[list[i], list[i + d]] = [list[i + d]!, list[i]!];
await api("/pages-order", { method: "PUT", body: { ids: list.map((p) => p.id) } });
await pages.reload();
}, "Saved as a draft: publish to change the menu.");
return (
<>
<Title sub="How your site is found, and its menu.">Settings</Title>
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
<fieldset disabled={!editor} className="space-y-6">
<Panel title="Search engines">
<p className="mb-3 text-sm text-gray-600">To see how people find your site, add it to Google Search Console and Bing Webmaster Tools. They give you a code to prove the site is yours: paste it here (the whole tag is fine), save, then press Verify there. This goes live straight away.</p>
<div className="grid gap-4 sm:grid-cols-2">
<Field label="Google Search Console code" error={fields.googleVerification}><input className={inputClass} value={s.googleVerification ?? ""} onChange={(e) => setForm({ ...form, googleVerification: e.target.value })} /></Field>
<Field label="Bing Webmaster Tools code" error={fields.bingVerification}><input className={inputClass} value={s.bingVerification ?? ""} onChange={(e) => setForm({ ...form, bingVerification: e.target.value })} /></Field>
</div>
<p className="mt-3 text-sm text-gray-600">A Google Business Profile helps people find your church on Google Maps: set one up at business.google.com with the same address as your church details.</p>
</Panel>
<Panel title="Coming soon">
<Field label="The line under “Coming soon”" hint="Shown until you first publish your site." error={fields.comingSoonText}>
<input className={inputClass} value={s.comingSoonText} maxLength={300} onChange={(e) => setForm({ ...form, comingSoonText: e.target.value })} />
</Field>
</Panel>
{editor && Object.keys(form).length > 0 && (
<Btn kind="primary" busy={busy} onClick={() => run(async () => { settings.setData(await api<Settings>("/settings", { method: "PUT", body: form })); setForm({}); }, "Saved.")}>Save settings</Btn>
)}
<Panel title="Menu order">
<p className="mb-3 text-sm text-gray-600">Pages in the menu, in this order. Which pages show is set on each page (<Link href="/admin/pages" className="underline">Pages</Link>).</p>
<ul className="divide-y divide-gray-200">
{menu.map((p, i) => (
<li key={p.id} className="flex items-center justify-between gap-3 py-2">
<span>{p.title}{!p.inNav && <span className="text-sm text-gray-500"> (not in the menu)</span>}</span>
<span className="flex gap-1">
<Btn onClick={() => move(i, -1)} disabled={busy || i === 0} aria-label={`Move ${p.title} up`}>↑</Btn>
<Btn onClick={() => move(i, 1)} disabled={busy || i === menu.length - 1} aria-label={`Move ${p.title} down`}>↓</Btn>
</span>
</li>
))}
</ul>
</Panel>
</fieldset>
</>
);
}
@@ -64,12 +64,16 @@ export default function TemplatePage() {
<Panel title="Template">
<div className="grid gap-3 sm:grid-cols-2">
{TEMPLATES.map((t) => (
<button key={t.id} type="button" disabled={busy} onClick={() => t.id !== design.template && save({ template: t.id }, `Switched to ${t.name}. Your own choices are kept; the rest moved to ${t.name}'s defaults.`)}
aria-pressed={t.id === design.template}
className={cx("rounded-lg border-2 p-4 text-left", t.id === design.template ? "border-brand bg-brand-tint" : "border-gray-200 hover:border-gray-400")}>
<div key={t.id} className={cx("rounded-lg border-2 p-4", t.id === design.template ? "border-brand bg-brand-tint" : "border-gray-200")}>
<span className="block font-semibold">{t.name}{t.id === design.template && " (in use)"}</span>
<span className="mt-1 block text-sm text-gray-600">{t.text}</span>
</button>
{t.id !== design.template && (
<div className="mt-3 flex flex-wrap gap-2">
<a href={`/preview/start?template=${t.id}`} className="rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm font-semibold hover:bg-gray-50">Preview with your content</a>
<Btn busy={busy} onClick={() => save({ template: t.id }, `Switched to ${t.name}. Your own choices are kept; the rest moved to ${t.name}'s defaults.`)}>Use {t.name}</Btn>
</div>
)}
</div>
))}
</div>
</Panel>