- Events: the Accounts profile's name, logo, icon, colours and contact details win over Events' own settings while Accounts is connected (pages, emails, WhatsApp, PDFs); Settings shows them read-only with a link to Accounts. The Accounts logo is copied for PDFs (PNG and JPEG). Fixes Events keeping its old church after a demo scenario load. - Website: a background per homepage section in the church's colours; "More info" instead of "Register" for events without registration; the shared colour field. - Accounts: the shared colour field in Church profile. - @crosscode/ui 0.4.0: ColourField and isHexColour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
168 lines
12 KiB
TypeScript
168 lines
12 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 HomeEntry = { section: string; hidden: boolean; background?: string };
|
|
type Design = { template: string; variants: Record<string, string>; home: HomeEntry[]; style: Record<string, string> };
|
|
|
|
/** A section's own background (backend variants.ts SECTION_BACKGROUNDS), each from the church's colours; "" follows Style → Section colour. */
|
|
const BACKGROUNDS: { id: string; name: string; swatch: string }[] = [
|
|
{ id: "", name: "As the style sets it", swatch: "repeating-linear-gradient(45deg, #fff 0 4px, rgb(var(--brand-tint)) 4px 8px)" },
|
|
{ id: "light", name: "White", swatch: "#fff" },
|
|
{ id: "tint", name: "Soft main colour", swatch: "rgb(var(--brand-tint))" },
|
|
{ id: "accent", name: "Soft accent colour", swatch: "linear-gradient(rgb(var(--accent) / 0.12), rgb(var(--accent) / 0.12)), #fff" },
|
|
{ id: "brand", name: "Main colour", swatch: "rgb(var(--brand))" },
|
|
{ id: "dark", name: "Deep main colour", swatch: "linear-gradient(rgb(0 0 0 / 0.35), rgb(0 0 0 / 0.35)), rgb(var(--brand-dark))" },
|
|
];
|
|
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", card: "Card", 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. Each section can have its own background in your church's colours (a layout with a photo or band keeps its own). 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>
|
|
{/* The top of the page draws its own background (photo, colour or plain). */}
|
|
{e.section !== "hero" && (
|
|
<span className="flex items-center gap-2">
|
|
<span className="h-6 w-6 shrink-0 rounded border border-gray-300" style={{ background: BACKGROUNDS.find((b) => b.id === (e.background ?? ""))?.swatch }} aria-hidden />
|
|
<select aria-label={`${SECTIONS[e.section]} background`} title="Background" className={`${inputClass} w-48`} value={e.background ?? ""} disabled={busy}
|
|
onChange={(ev) => save({ home: design.home.map(({ background: _b, ...x }) => (x.section === e.section ? (ev.target.value ? { ...x, background: ev.target.value } : x) : { ...x, ...(_b ? { background: _b } : {}) })) })}>
|
|
{BACKGROUNDS.map((b) => <option key={b.id} value={b.id}>{b.id ? b.name : `Background: ${b.name.toLowerCase()}`}</option>)}
|
|
</select>
|
|
</span>
|
|
)}
|
|
<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>
|
|
);
|
|
}
|