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>
128 lines
10 KiB
TypeScript
128 lines
10 KiB
TypeScript
"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'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>
|
|
</>
|
|
);
|
|
}
|