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>
129 lines
8.1 KiB
TypeScript
129 lines
8.1 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* Template and style (WEBSITE-1.0-PLAN §3): the template, each homepage section's layout
|
|
* (recommended first), the homepage order, and the style settings. Fonts and corners are the
|
|
* church's brand style, shared with its other sites, so they're set in its church profile.
|
|
*/
|
|
import { api } from "@/admin/api";
|
|
import { Btn, cx, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin } from "@/admin/ui";
|
|
|
|
type Design = { template: string; variants: Record<string, string>; home: { section: string; hidden: boolean }[]; style: Record<string, string> };
|
|
type Options = { variants: Record<string, Record<string, string[]>>; headers: Record<string, string[]> };
|
|
|
|
const TEMPLATES = [
|
|
{ id: "heritage", name: "Heritage", text: "Traditional and dignified: centred, framed images, serif headings." },
|
|
{ id: "bold", name: "Bold", text: "Modern and energetic: full-screen photos, big headlines, bands." },
|
|
{ id: "community", name: "Community", text: "Warm and friendly: cards, rounded shapes, faces up front." },
|
|
{ id: "clean", name: "Clean", text: "Minimal and calm: lots of space, good without photos." },
|
|
];
|
|
|
|
const SECTIONS: Record<string, string> = { hero: "Top of the page", serviceTimes: "Service times", welcome: "Welcome", ministries: "Ministries", team: "Team", events: "Upcoming events", latestMessage: "Latest message", invitation: "Invitation" };
|
|
const VARIANT_NAMES: Record<string, string> = {
|
|
photo: "Photo", video: "Video", collage: "Collage", split: "Split", text: "Text only", panel: "Panel", strip: "Inline strip", map: "With map",
|
|
"image-text": "Image and text", pastor: "With pastor", cards: "Cards", list: "List", bands: "Alternating bands", faces: "Faces", featured: "Featured",
|
|
calendar: "Calendar strip", compact: "Compact", banner: "Banner", centred: "Centred", image: "Image background",
|
|
};
|
|
const ALL_VARIANTS: Record<string, string[]> = {
|
|
hero: ["photo", "video", "collage", "split", "text"], serviceTimes: ["panel", "strip", "map"], welcome: ["text", "image-text", "pastor"], ministries: ["cards", "list", "bands"],
|
|
team: ["faces", "list", "featured"], events: ["cards", "list", "calendar"], latestMessage: ["video", "card", "compact"], invitation: ["banner", "centred", "image"],
|
|
};
|
|
const HEADER_NAMES: Record<string, string> = {
|
|
centred: "Centred", "centred-top-bar": "Centred, with a top bar", transparent: "Over the photo, solid when scrolling", solid: "Solid",
|
|
"logo-left-button": "Logo left, with a Plan your visit button", "logo-left-tinted": "Logo left, on a tinted bar", small: "Small", "small-menu": "Small, menu on every screen",
|
|
};
|
|
const STYLE = [
|
|
{ key: "sectionColour", label: "Section colour", options: { light: "Light", tinted: "Tinted (your colour, softly)", mixed: "Mixed, with dark bands" } },
|
|
{ key: "spacing", label: "Spacing", options: { airy: "Airy", compact: "Compact" } },
|
|
{ key: "buttons", label: "Buttons", options: { solid: "Solid", outline: "Outline", pill: "Pill" } },
|
|
{ key: "images", label: "Photos", options: { natural: "Natural", mono: "Black and white", duotone: "Duotone in your colour" } },
|
|
];
|
|
|
|
export default function TemplatePage() {
|
|
const { data, error, setData } = useAdmin<{ design: Design; options: Options }>("/design");
|
|
const { busy, message, run } = useAction();
|
|
if (!data) return <Loading error={error} />;
|
|
const { design, options } = data;
|
|
const save = (patch: Partial<Design> & { template?: string }, done = "Saved. Preview to see it, then publish.") => run(async () => {
|
|
const r = await api<{ design: Design; moved: { what: string }[] }>("/design", { method: "PUT", body: patch });
|
|
setData({ ...data, design: r.design });
|
|
return r;
|
|
}, done);
|
|
const move = (i: number, d: -1 | 1) => {
|
|
const home = [...design.home];
|
|
const j = i + d;
|
|
if (j < 0 || j >= home.length) return;
|
|
[home[i], home[j]] = [home[j]!, home[i]!];
|
|
save({ home });
|
|
};
|
|
return (
|
|
<>
|
|
<Title sub="Changes here are drafts: preview them, then publish.">Template and style</Title>
|
|
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
|
|
<div className="space-y-6">
|
|
<Panel title="Template">
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
{TEMPLATES.map((t) => (
|
|
<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>
|
|
{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>
|
|
|
|
<Panel title="Home page: sections and layouts">
|
|
<p className="mb-4 text-sm text-gray-600">Every layout works in every template; the first ones listed suit {TEMPLATES.find((t) => t.id === design.template)?.name} best.</p>
|
|
<ul className="divide-y divide-gray-200">
|
|
{design.home.map((e, i) => {
|
|
const recommended = options.variants[design.template]?.[e.section] ?? [];
|
|
const ordered = [...recommended, ...ALL_VARIANTS[e.section]!.filter((v) => !recommended.includes(v))];
|
|
return (
|
|
<li key={e.section} className="flex flex-wrap items-center gap-3 py-3">
|
|
<span className="w-40 font-medium">{SECTIONS[e.section]}</span>
|
|
<select aria-label={`${SECTIONS[e.section]} layout`} className={`${inputClass} w-56`} value={design.variants[e.section]} disabled={busy}
|
|
onChange={(ev) => save({ variants: { [e.section]: ev.target.value } })}>
|
|
{ordered.map((v) => <option key={v} value={v}>{VARIANT_NAMES[v]}{recommended.includes(v) ? " (suits this template)" : ""}</option>)}
|
|
</select>
|
|
<label className="flex items-center gap-2 text-sm">
|
|
<input type="checkbox" checked={!e.hidden} disabled={busy} onChange={(ev) => save({ home: design.home.map((x) => (x.section === e.section ? { ...x, hidden: !ev.target.checked } : x)) })} />
|
|
Show
|
|
</label>
|
|
<span className="ml-auto flex gap-1">
|
|
<Btn onClick={() => move(i, -1)} disabled={busy || i === 0} aria-label={`Move ${SECTIONS[e.section]} up`}>↑</Btn>
|
|
<Btn onClick={() => move(i, 1)} disabled={busy || i === design.home.length - 1} aria-label={`Move ${SECTIONS[e.section]} down`}>↓</Btn>
|
|
</span>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
</Panel>
|
|
|
|
<Panel title="Style">
|
|
<div className="grid gap-4 sm:grid-cols-2">
|
|
<Field label="Header">
|
|
<select className={inputClass} value={design.style.header} disabled={busy} onChange={(e) => save({ style: { header: e.target.value } })}>
|
|
{(options.headers[design.template] ?? []).map((h) => <option key={h} value={h}>{HEADER_NAMES[h] ?? h}</option>)}
|
|
</select>
|
|
</Field>
|
|
{STYLE.map((s) => (
|
|
<Field key={s.key} label={s.label}>
|
|
<select className={inputClass} value={design.style[s.key]} disabled={busy} onChange={(e) => save({ style: { [s.key]: e.target.value } })}>
|
|
{Object.entries(s.options).map(([v, label]) => <option key={v} value={v}>{label}</option>)}
|
|
</select>
|
|
</Field>
|
|
))}
|
|
</div>
|
|
<p className="mt-4 text-sm text-gray-600">Fonts and corners are your church's brand style, shared with your Events and sign-in pages: change them in your church profile.</p>
|
|
</Panel>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|