- Website: an icon sidebar in groups (Your site, Content, Go live, Team), a dashboard with cards and a tile per part of the admin, steps to the first publish across the top of every admin page, and a live preview beside the page editor and Template and style (computer or phone width, folds away, reloads on save). A framed request (Sec-Fetch-Dest: iframe) with an admin session reads the drafts, so no preview cookie is set. /preview/start takes ?to=. The page editor has Content and Page details tabs. - Accounts: /admin is an overview (cards, "Needs you", a tile per section); People moved to /admin/people; the sidebar shows the part you're in, grouped, with a count on Deletion requests; People redesigned, with a confirm before Deactivate; Email and WhatsApp split into two cards. - Both: darker grey labels for contrast; lucide-react in the Website. - e2e: the live preview shows drafts while the site stays live; axe on the page editor. - docs: VERSIONS, changelogs, WHATS-NEW. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
9.8 KiB
TypeScript
147 lines
9.8 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 Link from "next/link";
|
|
import { useState } from "react";
|
|
import { ArrowDown, ArrowUp, Check, Eye, LayoutTemplate, ListOrdered, Palette, SlidersHorizontal } from "lucide-react";
|
|
import { api } from "@/admin/api";
|
|
import { WithPreview } from "@/admin/LivePreview";
|
|
import { Btn, cx, Field, inputClass, Loading, Notice, Panel, Tabs, 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();
|
|
const [tab, setTab] = useState<"template" | "home" | "style">("template");
|
|
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 (
|
|
<WithPreview path="/" version={JSON.stringify(design)}>
|
|
<Title icon={Palette} sub="How your whole site looks. Changes here are drafts: the preview shows them, then publish.">Template and style</Title>
|
|
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
|
|
<Tabs label="Template and style" value={tab} onChange={setTab} tabs={[
|
|
{ id: "template", label: "Template", icon: LayoutTemplate },
|
|
{ id: "home", label: "Home page layout", icon: ListOrdered },
|
|
{ id: "style", label: "Style", icon: SlidersHorizontal },
|
|
]} />
|
|
|
|
{tab === "template" && (
|
|
<Panel title="Template" icon={LayoutTemplate} sub="Your content stays the same whichever you choose; only the look changes.">
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
{TEMPLATES.map((t) => {
|
|
const inUse = t.id === design.template;
|
|
return (
|
|
<div key={t.id} className={cx("rounded-xl border-2 p-4", inUse ? "border-brand bg-brand-tint" : "border-gray-200")}>
|
|
<span className="flex items-center justify-between gap-2 font-semibold">{t.name}{inUse && <span className="inline-flex items-center gap-1 rounded-full bg-brand px-2 py-0.5 text-xs text-brand-on"><Check className="h-3 w-3" aria-hidden />In use</span>}</span>
|
|
<span className="mt-1 block text-sm text-gray-600">{t.text}</span>
|
|
{!inUse && (
|
|
<div className="mt-3 flex flex-wrap gap-2">
|
|
<a href={`/preview/start?template=${t.id}`} className="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm font-semibold hover:bg-gray-50"><Eye className="h-4 w-4" aria-hidden />Try it 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>
|
|
)}
|
|
|
|
{tab === "home" && (
|
|
<Panel title="Home page: sections and layouts" icon={ListOrdered} sub={<>Every layout works in every template; the first ones listed suit {TEMPLATES.find((t) => t.id === design.template)?.name} best. What each section says is on the home page, under Pages.</>}>
|
|
<ul className="divide-y divide-gray-100">
|
|
{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={cx("flex flex-wrap items-center gap-3 py-3", e.hidden && "opacity-60")}>
|
|
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-gray-100 text-xs font-semibold text-gray-600" aria-hidden>{i + 1}</span>
|
|
<span className="w-36 font-medium">{SECTIONS[e.section]}</span>
|
|
<select aria-label={`${SECTIONS[e.section]} layout`} className={`${inputClass} w-52`} 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 kind="icon" onClick={() => move(i, -1)} disabled={busy || i === 0} aria-label={`Move ${SECTIONS[e.section]} up`} title="Move up"><ArrowUp className="h-4 w-4" aria-hidden /></Btn>
|
|
<Btn kind="icon" onClick={() => move(i, 1)} disabled={busy || i === design.home.length - 1} aria-label={`Move ${SECTIONS[e.section]} down`} title="Move down"><ArrowDown className="h-4 w-4" aria-hidden /></Btn>
|
|
</span>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
</Panel>
|
|
)}
|
|
|
|
{tab === "style" && (
|
|
<Panel title="Style" icon={SlidersHorizontal} sub="The finishing touches, on every page.">
|
|
<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((st) => (
|
|
<Field key={st.key} label={st.label}>
|
|
<select className={inputClass} value={design.style[st.key]} disabled={busy} onChange={(e) => save({ style: { [st.key]: e.target.value } })}>
|
|
{Object.entries(st.options).map(([v, label]) => <option key={v} value={v}>{label}</option>)}
|
|
</select>
|
|
</Field>
|
|
))}
|
|
</div>
|
|
<p className="mt-4 text-sm text-gray-600">Colours, fonts and corners are your church's brand style, shared with your Events and sign-in pages: change them in <Link href="/admin/church" className="font-semibold underline">Church details</Link>.</p>
|
|
</Panel>
|
|
)}
|
|
</WithPreview>
|
|
);
|
|
}
|