A new install had no pages, so the home page and its live preview showed only the header and footer (found on cross-demo2). The backend now adds the fixed pages with starter text at startup. Settings -> Site icon sets the favicon, with a default from the church's colour and initial. The Latest message's Card layout has its name; the media picker's placeholder has enough contrast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
5.6 KiB
TypeScript
84 lines
5.6 KiB
TypeScript
"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";
|
||
import { AppWindow, Hourglass, ListOrdered, Search, Settings } from "lucide-react";
|
||
import { ImagePicker } from "@/admin/media";
|
||
|
||
type Settings = { comingSoonText: string; googleVerification: string | null; bingVerification: string | null; faviconId: 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 icon={Settings} 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 icon={Search} 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 icon={AppWindow} title="Site icon">
|
||
<p className="mb-3 text-sm text-gray-600">The little picture in the browser tab and bookmarks. Choose a square picture (512 × 512 pixels is best; a PNG can have a see-through background). Without one, your site uses your church's icon, or your church's initial on its colour. This goes live straight away.</p>
|
||
<div className="flex flex-wrap items-end gap-6">
|
||
<ImagePicker label="Icon" value={s.faviconId} onChange={(faviconId) => setForm({ ...form, faviconId })} />
|
||
{/* What the site shows now (the default when none is chosen). */}
|
||
<div className="text-sm text-gray-600">
|
||
<span className="block font-medium text-gray-800">In use now</span>
|
||
<img src={`/site-icon?saved=${encodeURIComponent(settings.data.faviconId ?? "none")}`} alt="" width={32} height={32} className="mt-1 h-8 w-8 rounded" />
|
||
</div>
|
||
</div>
|
||
{fields.faviconId && <p className="mt-2 text-sm text-red-700">{fields.faviconId}</p>}
|
||
</Panel>
|
||
<Panel icon={Hourglass} 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 icon={ListOrdered} 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>
|
||
</>
|
||
);
|
||
}
|