Hub 2.26.0: the Church App, demo scenarios and devotionals
The App installs from New install on app.<address>, with Accounts 1.9.0 first, and is in every product list and filter (installs, Updates). Every product has demo data; a demo client loads a whole demo scenario in one seed-scenario job (agent 1.7.0), and installs show whether they are out of step with it. The Website's and App's .env from the Hub. Devotionals: written or imported from CSV up to 3 months ahead in the free translations (KJV, BSB), and GET /api/v2/devotionals for App licences. An alert when an App's active-member band is above its tier. Contracts 1.23.0 vendored. Migration 20261130120000_app_scenarios_devotionals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { AiCard, AiModal } from "@/components/customer/AiCard";
|
||||
import { SitesCard } from "@/components/customer/SitesCard";
|
||||
import { ChurchUpdateModal } from "@/components/customer/ChurchUpdateModal";
|
||||
import { DemoClientModal } from "@/components/customer/DemoClientModal";
|
||||
import { ScenarioModal } from "@/components/customer/ScenarioModal";
|
||||
import { ProductCard } from "@/components/customer/ProductCard";
|
||||
import { AddProductModal } from "@/components/customer/AddProductModal";
|
||||
import { NextInvoiceModal } from "@/components/customer/NextInvoice";
|
||||
@@ -147,6 +148,7 @@ export default function CustomerPage() {
|
||||
{popup === "address" && b && <AddressModal b={b} onClose={close} onDone={done} />}
|
||||
{popup === "ai" && <AiModal c={c} onClose={close} onDone={done} />}
|
||||
{popup === "demo" && <DemoClientModal c={c} onClose={close} onDone={done} />}
|
||||
{popup === "scenario" && c.isDemo && <ScenarioModal c={c} onClose={close} onDone={done} />}
|
||||
{popup === "update" && <ChurchUpdateModal customerId={id} name={c.name} onClose={close} onDone={done} />}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
"use client";
|
||||
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Download, Plus, Upload } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { FormError, Loading, Modal, ModalButtons, PageMessage, PageTitle, Stat, useSubmit } from "@/components/ui";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
type Translation = { id: string; name: string; language: string; copyright: string; acknowledgement: string };
|
||||
type Passage = { reference: string; translation: string; text: string; location: unknown };
|
||||
type Devotional = { id: string; date: string; title: string; passage: Passage; body: string; prayer: string | null; author: string | null; updatedAt: string };
|
||||
type Overview = {
|
||||
today: string; latest: string; aheadMonths: number; devotionals: Devotional[]; empty: string[];
|
||||
translations: Translation[]; csv: { columns: string[]; template: string };
|
||||
};
|
||||
type CsvIssue = { column: string | null; message: string };
|
||||
type CsvRow = { line: number; devotional: { date: string; title: string; passage: Passage } | null; errors: CsvIssue[]; warnings: CsvIssue[]; taken: boolean };
|
||||
type CsvResult = { fileError: string | null; rows: CsvRow[] };
|
||||
|
||||
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
||||
const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
||||
const longDate = (d: string) => new Date(`${d}T12:00:00Z`).toLocaleDateString("en-ZA", { weekday: "short", day: "numeric", month: "long", year: "numeric", timeZone: "UTC" });
|
||||
|
||||
/** The months from today's to the last day's, each as its days (null before the 1st, Monday first). */
|
||||
function months(from: string, to: string) {
|
||||
const out: { label: string; days: (string | null)[] }[] = [];
|
||||
let [y, m] = from.split("-").map(Number);
|
||||
const [ty, tm] = to.split("-").map(Number);
|
||||
while (y < ty || (y === ty && m <= tm)) {
|
||||
const first = new Date(Date.UTC(y, m - 1, 1));
|
||||
const count = new Date(Date.UTC(y, m, 0)).getUTCDate();
|
||||
const pad = (first.getUTCDay() + 6) % 7;
|
||||
const days: (string | null)[] = Array(pad).fill(null);
|
||||
for (let d = 1; d <= count; d++) days.push(`${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`);
|
||||
out.push({ label: `${MONTHS[m - 1]} ${y}`, days });
|
||||
m++;
|
||||
if (m > 12) { m = 1; y++; }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The days from today to 3 months ahead: filled ones open their devotional, empty ones a new one. */
|
||||
function Calendar({ o, onOpen }: { o: Overview; onOpen: (date: string, d: Devotional | null) => void }) {
|
||||
const byDate = useMemo(() => new Map(o.devotionals.map(d => [d.date, d])), [o]);
|
||||
return (
|
||||
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
||||
{months(o.today, o.latest).map(month => (
|
||||
<div key={month.label} className="card p-3">
|
||||
<p className="mb-2 text-sm font-medium">{month.label}</p>
|
||||
<div className="grid grid-cols-7 gap-1 text-center text-xs">
|
||||
{DAYS.map(d => <span key={d} className="text-slate-400">{d}</span>)}
|
||||
{month.days.map((day, i) => {
|
||||
if (!day) return <span key={`pad-${i}`} />;
|
||||
const inRange = day >= o.today && day <= o.latest;
|
||||
const d = byDate.get(day) || null;
|
||||
const label = `${longDate(day)}: ${d ? d.title : inRange ? "no devotional yet" : "outside the 3 months"}`;
|
||||
return (
|
||||
<button key={day} type="button" disabled={!inRange} title={label} aria-label={label} onClick={() => onOpen(day, d)}
|
||||
className={`rounded py-1 ${!inRange ? "text-slate-300" : d ? "bg-emerald-100 font-medium text-emerald-900 hover:bg-emerald-200" : "bg-amber-50 text-amber-900 ring-1 ring-inset ring-amber-200 hover:bg-amber-100"} ${day === o.today ? "outline outline-2 outline-indigo-500" : ""}`}>
|
||||
{Number(day.slice(8))}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type Form = { date: string; title: string; reference: string; translation: string; passageText: string; body: string; prayer: string; author: string };
|
||||
|
||||
/** Write or edit one devotional. The passage is quoted as written, never by AI (BIBLE-PERMISSIONS.md). */
|
||||
function DevotionalModal({ o, date, existing, onClose, onDone }: { o: Overview; date: string; existing: Devotional | null; onClose: () => void; onDone: (m: Msg) => void }) {
|
||||
const first: Form = existing
|
||||
? { date: existing.date, title: existing.title, reference: existing.passage.reference, translation: existing.passage.translation, passageText: existing.passage.text, body: existing.body, prayer: existing.prayer || "", author: existing.author || "" }
|
||||
: { date, title: "", reference: "", translation: o.translations[0]?.id || "BSB", passageText: "", body: "", prayer: "", author: "Cross Code" };
|
||||
const [form, setForm] = useState<Form>(first);
|
||||
const { busy, error, run } = useSubmit();
|
||||
const f = (k: keyof Form) => ({ value: form[k], onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => setForm({ ...form, [k]: e.target.value }) });
|
||||
const translation = o.translations.find(t => t.id === form.translation);
|
||||
const dirty = (Object.keys(first) as (keyof Form)[]).some(k => form[k] !== first[k]);
|
||||
|
||||
const save = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
run(async () => {
|
||||
const r = await api<{ devotional: Devotional; warnings: string[] }>(existing ? `/api/admin/devotionals/${existing.id}` : "/api/admin/devotionals", { method: existing ? "PUT" : "POST", body: form });
|
||||
onDone({ type: "ok", text: `${existing ? "Saved" : "Added"}: ${r.devotional.title} on ${longDate(r.devotional.date)}.${r.warnings.length ? ` ${r.warnings.join(" ")}` : ""}` });
|
||||
});
|
||||
};
|
||||
const remove = () => {
|
||||
if (!existing || !window.confirm(`Delete "${existing.title}" (${longDate(existing.date)})? Apps drop it at their next nightly fetch.`)) return;
|
||||
run(async () => {
|
||||
await api(`/api/admin/devotionals/${existing.id}`, { method: "DELETE" });
|
||||
onDone({ type: "ok", text: `Deleted: ${existing.title}.` });
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal title={existing ? "Edit devotional" : "Write a devotional"} onClose={onClose} dirty={dirty} wide>
|
||||
<form onSubmit={save} className="grid gap-3 md:grid-cols-2">
|
||||
<div><label className="label" htmlFor="dv-date">Date</label><input id="dv-date" type="date" className="input" required min={existing ? undefined : o.today} max={o.latest} {...f("date")} /></div>
|
||||
<div><label className="label" htmlFor="dv-title">Title</label><input id="dv-title" className="input" required maxLength={200} {...f("title")} /></div>
|
||||
<div><label className="label" htmlFor="dv-ref">Passage</label><input id="dv-ref" className="input" required placeholder="1 Corinthians 13:4-7" maxLength={100} {...f("reference")} /><p className="mt-1 text-xs text-slate-500">The passage it's about, not whole chapters: more than 25 verses gets a warning.</p></div>
|
||||
<div>
|
||||
<label className="label" htmlFor="dv-tr">Translation</label>
|
||||
<select id="dv-tr" className="input" {...f("translation")}>
|
||||
{o.translations.map(t => <option key={t.id} value={t.id}>{t.name} ({t.id})</option>)}
|
||||
</select>
|
||||
<p className="mt-1 text-xs text-slate-500">Only the free translations until a publisher gives written permission.</p>
|
||||
</div>
|
||||
<div className="md:col-span-2">
|
||||
<label className="label" htmlFor="dv-text">The passage's text</label>
|
||||
<textarea id="dv-text" className="input min-h-24" required maxLength={10000} {...f("passageText")} />
|
||||
{translation && <p className="mt-1 text-xs text-slate-500">Shown under it in the App, email and WhatsApp: {translation.copyright}</p>}
|
||||
</div>
|
||||
<div className="md:col-span-2"><label className="label" htmlFor="dv-body">Devotional</label><textarea id="dv-body" className="input min-h-40" required maxLength={20000} {...f("body")} /><p className="mt-1 text-xs text-slate-500">Markdown: a blank line between paragraphs, **bold**, *italic*.</p></div>
|
||||
<div className="md:col-span-2"><label className="label" htmlFor="dv-prayer">Prayer (optional)</label><textarea id="dv-prayer" className="input min-h-16" maxLength={5000} {...f("prayer")} /></div>
|
||||
<div><label className="label" htmlFor="dv-author">Author (optional)</label><input id="dv-author" className="input" maxLength={200} {...f("author")} /></div>
|
||||
<div className="md:col-span-2"><FormError error={error} /></div>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 md:col-span-2">
|
||||
{existing ? <button type="button" className="btn-secondary text-red-700" disabled={busy} onClick={remove}>Delete</button> : <span />}
|
||||
<ModalButtons busy={busy} onCancel={onClose} label={existing ? "Save" : "Add"} />
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
/** Import CSV: choose a file, see every row checked, then import the valid ones. */
|
||||
function ImportModal({ o, onClose, onDone }: { o: Overview; onClose: () => void; onDone: (m: Msg) => void }) {
|
||||
const [csv, setCsv] = useState<string | null>(null);
|
||||
const [fileName, setFileName] = useState("");
|
||||
const [result, setResult] = useState<CsvResult | null>(null);
|
||||
const [replace, setReplace] = useState(false);
|
||||
const { busy, error, run } = useSubmit();
|
||||
|
||||
const choose = async (file: File | undefined) => {
|
||||
setResult(null);
|
||||
if (!file) return;
|
||||
const text = await file.text();
|
||||
setCsv(text);
|
||||
setFileName(file.name);
|
||||
run(async () => setResult(await api<CsvResult>("/api/admin/devotionals/import/preview", { method: "POST", body: { csv: text } })));
|
||||
};
|
||||
const valid = result?.rows.filter(r => r.devotional) || [];
|
||||
const taken = valid.filter(r => r.taken).length;
|
||||
const importing = replace ? valid.length : valid.length - taken;
|
||||
|
||||
const submit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
run(async () => {
|
||||
const r = await api<{ created: number; replaced: number; skipped: number; invalid: number }>("/api/admin/devotionals/import", { method: "POST", body: { csv, replace } });
|
||||
onDone({ type: "ok", text: `Imported ${r.created} new${r.replaced ? `, replaced ${r.replaced}` : ""}${r.skipped ? `, skipped ${r.skipped} day${r.skipped === 1 ? "" : "s"} already filled` : ""}${r.invalid ? `; ${r.invalid} row${r.invalid === 1 ? "" : "s"} with errors left out` : ""}.` });
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal title="Import devotionals from CSV" onClose={onClose} dirty={!!csv} wide>
|
||||
<form onSubmit={submit} className="space-y-4">
|
||||
<p className="text-sm text-slate-500">
|
||||
Columns: {o.csv.columns.join(", ")} (prayer and author may be empty). Dates as YYYY-MM-DD, up to {longDate(o.latest)}; translations {o.translations.map(t => t.id).join(" or ")}. Nothing is saved until you import.
|
||||
</p>
|
||||
<div>
|
||||
<label className="label" htmlFor="im-file">CSV file</label>
|
||||
<input id="im-file" type="file" accept=".csv,text/csv" className="block text-sm" onChange={e => choose(e.target.files?.[0])} />
|
||||
</div>
|
||||
{busy && !result && <Loading />}
|
||||
{result?.fileError && <FormError error={`${fileName}: ${result.fileError}`} />}
|
||||
{result && !result.fileError && (
|
||||
<>
|
||||
<p className="text-sm">{valid.length} of {result.rows.length} rows can be imported{taken ? `; ${taken} are for days that already have one` : ""}.</p>
|
||||
<div className="max-h-80 overflow-y-auto rounded-lg border border-slate-200">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white"><tr className="text-left text-xs text-slate-500"><th className="px-2 py-1">Line</th><th>Date</th><th>Title</th><th>Check</th></tr></thead>
|
||||
<tbody>{result.rows.map(r => (
|
||||
<tr key={r.line} className="border-t align-top">
|
||||
<td className="px-2 py-1">{r.line}</td>
|
||||
<td className="whitespace-nowrap pr-2">{r.devotional?.date || ""}</td>
|
||||
<td className="pr-2">{r.devotional ? `${r.devotional.title} · ${r.devotional.passage.reference} (${r.devotional.passage.translation})` : ""}</td>
|
||||
<td className="py-1 pr-2">
|
||||
{r.errors.map((x, i) => <p key={`e${i}`} className="text-red-700">{x.message}</p>)}
|
||||
{r.warnings.map((x, i) => <p key={`w${i}`} className="text-amber-800">{x.message}</p>)}
|
||||
{r.devotional && r.taken && <p className="text-amber-800">That day already has one</p>}
|
||||
{r.devotional && !r.taken && !r.warnings.length && <p className="text-emerald-700">OK</p>}
|
||||
</td>
|
||||
</tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{taken > 0 && <label className="flex items-center gap-2 text-sm"><input type="checkbox" checked={replace} onChange={e => setReplace(e.target.checked)} /> Replace the {taken} day{taken === 1 ? "" : "s"} already filled (otherwise they're skipped)</label>}
|
||||
</>
|
||||
)}
|
||||
<FormError error={error} />
|
||||
<ModalButtons busy={busy} busyLabel="Working…" onCancel={onClose} label={`Import ${importing} devotional${importing === 1 ? "" : "s"}`} disabled={!result || !!result.fileError || importing === 0} />
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hub 2.26.0 (APP-1.0-PLAN §6): Cross Code's devotionals, for every Church App set to "From Cross
|
||||
* Code". Written or imported up to 3 months ahead, in the free translations (KJV, BSB). Apps fetch
|
||||
* the next 3 months once a night, so a change here reaches them by the next morning.
|
||||
*/
|
||||
export default function DevotionalsPage() {
|
||||
const [o, setO] = useState<Overview | null>(null);
|
||||
const [msg, setMsg] = useState<Msg>(null);
|
||||
const [popup, setPopup] = useState<{ kind: "edit"; date: string; d: Devotional | null } | { kind: "import" } | null>(null);
|
||||
|
||||
const load = useCallback(() => api<Overview>("/api/admin/devotionals").then(setO).catch(e => setMsg({ type: "err", text: errorText(e) })), []);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
const done = (m: Msg) => { setPopup(null); setMsg(m); load(); };
|
||||
|
||||
const downloadTemplate = () => {
|
||||
if (!o) return;
|
||||
const url = URL.createObjectURL(new Blob([o.csv.template], { type: "text/csv;charset=utf-8" }));
|
||||
const a = Object.assign(document.createElement("a"), { href: url, download: "cross-code-devotionals-template.csv" });
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const total = o ? o.devotionals.length + o.empty.length : 0;
|
||||
return (
|
||||
<div>
|
||||
<PageTitle title="Devotionals" subtitle="Cross Code's devotionals for every Church App set to “From Cross Code”: up to 3 months ahead, in the King James Version or the Berean Standard Bible. Apps fetch them every night."
|
||||
actions={o && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button type="button" className="btn-secondary" onClick={downloadTemplate}><Download className="h-4 w-4" /> Template</button>
|
||||
<button type="button" className="btn-secondary" onClick={() => setPopup({ kind: "import" })}><Upload className="h-4 w-4" /> Import CSV</button>
|
||||
<button type="button" className="btn-primary" onClick={() => setPopup({ kind: "edit", date: o.empty[0] || o.today, d: null })}><Plus className="h-4 w-4" /> Write a devotional</button>
|
||||
</div>
|
||||
)} />
|
||||
<PageMessage msg={msg} onClose={() => setMsg(null)} />
|
||||
{!o ? (msg ? null : <Loading />) : (
|
||||
<div className="space-y-6">
|
||||
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
|
||||
<Stat label="Filled" value={`${o.devotionals.length} of ${total} days`} tone={o.empty.length ? "amber" : undefined} />
|
||||
<Stat label="Next empty day" small value={o.empty[0] ? longDate(o.empty[0]) : "None"} onClick={o.empty[0] ? () => setPopup({ kind: "edit", date: o.empty[0], d: null }) : undefined} />
|
||||
<Stat label="Filled until" small value={(() => { const gap = o.empty[0]; const until = o.devotionals.filter(d => !gap || d.date < gap).at(-1); return until ? longDate(until.date) : "Not today yet"; })()} />
|
||||
<Stat label="Up to" small value={longDate(o.latest)} sub={`${o.aheadMonths} months ahead`} />
|
||||
</div>
|
||||
<Calendar o={o} onOpen={(date, d) => setPopup({ kind: "edit", date, d })} />
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-4 py-2">Date</th><th>Title</th><th>Passage</th><th>Author</th></tr></thead>
|
||||
<tbody>{o.devotionals.map(d => (
|
||||
<tr key={d.id} className="border-t">
|
||||
<td className="whitespace-nowrap px-4 py-1.5">{longDate(d.date)}</td>
|
||||
<td><button type="button" className="text-left text-indigo-700 hover:underline" onClick={() => setPopup({ kind: "edit", date: d.date, d })}>{d.title}</button></td>
|
||||
<td className="whitespace-nowrap pr-2">{d.passage.reference} ({d.passage.translation})</td>
|
||||
<td className="pr-4">{d.author || ""}</td>
|
||||
</tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
{!o.devotionals.length && <p className="px-4 py-3 text-sm text-slate-500">None yet. Write one, or import a CSV (download the template to start).</p>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{o && popup?.kind === "edit" && <DevotionalModal o={o} date={popup.date} existing={popup.d} onClose={() => setPopup(null)} onDone={done} />}
|
||||
{o && popup?.kind === "import" && <ImportModal o={o} onClose={() => setPopup(null)} onDone={done} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { LayoutDashboard, Building2, BellRing, Settings, LogOut, Rocket, Megaphone, Receipt, Server } from "lucide-react";
|
||||
import { LayoutDashboard, Building2, BellRing, BookOpen, Settings, LogOut, Rocket, Megaphone, Receipt, Server } from "lucide-react";
|
||||
import { api, getToken, setToken } from "@/lib/api";
|
||||
import { Logo } from "@/components/ui";
|
||||
|
||||
@@ -17,6 +17,8 @@ const NAV = [
|
||||
{ href: "/alerts", label: "Alerts", icon: BellRing },
|
||||
{ href: "/releases", label: "Releases", icon: Rocket },
|
||||
{ href: "/notices", label: "Notices", icon: Megaphone },
|
||||
// 2.26.0: Cross Code's devotionals for the Church App.
|
||||
{ href: "/devotionals", label: "Devotionals", icon: BookOpen },
|
||||
{ href: "/settings", label: "Settings", icon: Settings },
|
||||
];
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@ export default function DeploymentPage() {
|
||||
if (!d) return <div><ServersNav active="/servers/installs" />{msg ? <Message msg={msg} /> : <Loading />}</div>;
|
||||
const x = d.deployment;
|
||||
const plan = uninstallPlan(d);
|
||||
const hasEnv = ["events", "accounts"].includes(x.product) && running(x);
|
||||
// 2.26.0: every product's .env (the Website's from agent 1.6.0, the App's from 1.7.0).
|
||||
const hasEnv = ["events", "accounts", "website", "app"].includes(x.product) && running(x);
|
||||
const tabs: { key: Tab; label: string }[] = [
|
||||
{ key: "jobs", label: "Jobs" },
|
||||
...(hasEnv ? [{ key: "settings" as const, label: "Settings (.env)" }] : []),
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Link2, Plus } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago } from "@/lib/format";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import { PRODUCTS, PRODUCT_NAMES } from "@/lib/products";
|
||||
import type { Release } from "@/lib/types";
|
||||
import { ReleaseSelect } from "@/components/ReleaseSelect";
|
||||
import { FormError, Loading, Modal, ModalButtons, PageMessage, PageTitle, Pager, SearchInput, useSubmit } from "@/components/ui";
|
||||
@@ -17,7 +17,7 @@ type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
type Customer = { id: string; name: string; domain?: string | null };
|
||||
type InstallRow = { id: string; name: string; url: string; customer: { id: string; name: string } | null; version: string | null };
|
||||
|
||||
/** The Accounts domain the Hub makes when none is given (backend accountsDomainFor). */
|
||||
/** The Accounts domain the Hub makes when none is given (backend accountsDomainFor): app.hope.co.za → accounts.hope.co.za. */
|
||||
function accountsPlaceholder(product: string, domain: string) {
|
||||
if (!domain) return "accounts.hope.co.za";
|
||||
return product === "website" ? `accounts.${domain.replace(/^www\./, "")}` : domain.replace(/^[^.]+./, "accounts.");
|
||||
@@ -43,11 +43,11 @@ function NewInstallModal({ servers, onClose }: { servers: ServerSummary[]; onClo
|
||||
e.preventDefault();
|
||||
run(async () => {
|
||||
const r = await api<{ deployment: Deployment; warnings: string[]; checkingPorts?: boolean; alsoInstalling?: { product: string; domain: string; version: string } }>("/api/admin/deployments", { method: "POST", body: { ...form, version: form.version || undefined, accountsDomain: form.accountsDomain || undefined } });
|
||||
// Hub 2.5.0: Cross Events 3.x for a church without Accounts installs Accounts first.
|
||||
// Hub 2.5.0: Cross Events 3.x (2.21.0 the Website, 2.26.0 the App) for a church without Accounts installs Accounts first.
|
||||
const notes = [
|
||||
// Hub 2.11.0: the ports are checked on the central server and this one first.
|
||||
...(r.checkingPorts ? ["The ports are being checked on the central server and this server first; the install starts on ports free on both (about a minute)."] : []),
|
||||
...(r.alsoInstalling ? [`Accounts ${r.alsoInstalling.version} is installed first at ${r.alsoInstalling.domain}; Cross Events follows when it has finished.`] : []),
|
||||
...(r.alsoInstalling ? [`Accounts ${r.alsoInstalling.version} is installed first at ${r.alsoInstalling.domain}; ${PRODUCT_NAMES[form.product as keyof typeof PRODUCT_NAMES] || "the product"} follows when it has finished.`] : []),
|
||||
...r.warnings,
|
||||
];
|
||||
router.push(`/servers/installs/${r.deployment.id}${notes.length ? `?warn=${encodeURIComponent(notes.join(" "))}` : ""}`);
|
||||
@@ -64,20 +64,23 @@ function NewInstallModal({ servers, onClose }: { servers: ServerSummary[]; onClo
|
||||
<option value="events">Cross Events</option>
|
||||
<option value="accounts">Accounts (the church's sign-in)</option>
|
||||
<option value="website">Church Website</option>
|
||||
<option value="app">Church App</option>
|
||||
</select>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
{form.product === "accounts"
|
||||
? "Install Accounts before the Website, the App or Cross Events 3.0. Use the church's short name to add it next to its Events on the same server."
|
||||
: form.product === "website"
|
||||
? "On the church's own address: www.hope.co.za (its bare domain is sent to www.), or a Cross Code address like hope.crosscode.co.za. A church that already has a product here keeps its short name."
|
||||
: "A church that already has a product here keeps its short name: the new one is added next to it on the same server."}
|
||||
: form.product === "app"
|
||||
? "On app. in front of the church's address: app.hope.co.za, or app.hope.crosscode.co.za. It needs the church's Accounts 1.9.0 or later; a church that already has a product here keeps its short name."
|
||||
: "A church that already has a product here keeps its short name: the new one is added next to it on the same server."}
|
||||
</p>
|
||||
</div>
|
||||
<div><label className="label" htmlFor="n-cust">Customer</label><select id="n-cust" className="input" required {...f("customerId")}><option value="">Choose…</option>{customers.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}</select></div>
|
||||
<div><label className="label" htmlFor="n-short">Short name</label><input id="n-short" className="input" required pattern="[a-z][a-z0-9-]{1,30}" placeholder="hope" {...f("shortName")} /><p className="mt-1 text-xs text-slate-500">Folders, database and tunnels: a-z, 0-9 and -.</p></div>
|
||||
<div><label className="label" htmlFor="n-domain">Domain</label><input id="n-domain" className="input" required placeholder={form.product === "accounts" ? "accounts.hope.co.za" : form.product === "website" ? "www.hope.co.za" : "events.hope.co.za"} {...f("domain")} /></div>
|
||||
{(form.product === "events" || form.product === "website") && (
|
||||
<div><label className="label" htmlFor="n-acc">Accounts domain</label><input id="n-acc" className="input" placeholder={accountsPlaceholder(form.product, form.domain)} {...f("accountsDomain")} /><p className="mt-1 text-xs text-slate-500">{form.product === "website" ? "The Website" : "Cross Events 3"} signs in through the church's Accounts: a church without it gets it installed first, here.</p></div>
|
||||
<div><label className="label" htmlFor="n-domain">Domain</label><input id="n-domain" className="input" required placeholder={form.product === "accounts" ? "accounts.hope.co.za" : form.product === "website" ? "www.hope.co.za" : form.product === "app" ? "app.hope.co.za" : "events.hope.co.za"} {...f("domain")} /></div>
|
||||
{form.product !== "accounts" && (
|
||||
<div><label className="label" htmlFor="n-acc">Accounts domain</label><input id="n-acc" className="input" placeholder={accountsPlaceholder(form.product, form.domain)} {...f("accountsDomain")} /><p className="mt-1 text-xs text-slate-500">{form.product === "website" ? "The Website" : form.product === "app" ? "The App" : "Cross Events 3"} signs in through the church's Accounts: a church without it gets it installed first, here.</p></div>
|
||||
)}
|
||||
<div><label className="label" htmlFor="n-tz">Time zone</label><input id="n-tz" className="input" placeholder="Africa/Johannesburg" {...f("timezone")} /></div>
|
||||
<div><label className="label" htmlFor="n-an">Site admin name</label><input id="n-an" className="input" {...f("adminName")} /></div>
|
||||
@@ -184,9 +187,7 @@ export default function InstallsPage() {
|
||||
<div className="flex flex-wrap gap-2 p-4">
|
||||
<select className="input w-48" aria-label="Product" value={product} onChange={e => setProduct(e.target.value)}>
|
||||
<option value="">Every product</option>
|
||||
<option value="events">{PRODUCT_NAMES.events}</option>
|
||||
<option value="accounts">{PRODUCT_NAMES.accounts}</option>
|
||||
<option value="website">{PRODUCT_NAMES.website}</option>
|
||||
{PRODUCTS.map(p => <option key={p} value={p}>{PRODUCT_NAMES[p]}</option>)}
|
||||
</select>
|
||||
<SearchInput className="w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search a church, domain or server" />
|
||||
</div>
|
||||
|
||||
@@ -95,7 +95,7 @@ export default function UpdatesPage() {
|
||||
|
||||
{!all ? <Loading /> : (
|
||||
<form className="card space-y-4" onSubmit={submit}>
|
||||
<Tabs tabs={UPDATABLE.filter(p => p !== "app" || (all || []).some(d => d.product === p)).map(p => ({ key: p, label: `${PRODUCT_NAMES[p]} (${(all || []).filter(d => d.product === p).length})` }))} active={product} onChange={pick} />
|
||||
<Tabs tabs={UPDATABLE.map(p => ({ key: p, label: `${PRODUCT_NAMES[p]} (${(all || []).filter(d => d.product === p).length})` }))} active={product} onChange={pick} />
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<span className="text-slate-500">Select:</span>
|
||||
<button type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen(deployments.map(d => d.id))}>All live {name} ({deployments.length})</button>
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
|
||||
import React from "react";
|
||||
import Link from "next/link";
|
||||
import { ArrowLeft, FilePlus, KeyRound, Plus, Star } from "lucide-react";
|
||||
import { ArrowLeft, FilePlus, KeyRound, Plus, Sparkles, Star } from "lucide-react";
|
||||
import { day, money } from "@/lib/billing";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { PRODUCT_NAMES, byProduct } from "@/lib/products";
|
||||
import { scenarioName } from "@/lib/scenarios";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { Menu, Stat } from "@/components/ui";
|
||||
import { ADDRESS_OPTIONS, type CustomerBillingData, type Preview } from "./shared";
|
||||
|
||||
/** What the header's tiles open, and its buttons. */
|
||||
export type HeaderAction = "payment" | "oneoff" | "add" | "preview" | "address" | "ai" | "history" | "demo";
|
||||
export type HeaderAction = "payment" | "oneoff" | "add" | "preview" | "address" | "ai" | "history" | "demo" | "scenario";
|
||||
|
||||
/**
|
||||
* Hub 2.14.0: always at the top of the customer page: who the church is, what it has, what it
|
||||
@@ -40,11 +41,16 @@ export function CustomerHeader({ c, b, preview, canAdd, onAction, onArchive }: {
|
||||
{c.isDemo && <span title="Every install is a demo site, and it isn't billed" className="rounded-full bg-indigo-50 px-2 py-0.5 text-xs font-medium text-indigo-700 ring-1 ring-inset ring-indigo-200">Demo client</span>}
|
||||
{c.archivedAt && <span className="rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-600 ring-1 ring-inset ring-slate-200">Archived {fmtDate(c.archivedAt, false)}</span>}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-slate-500">Customer since {fmtDate(c.createdAt, false)}</p>
|
||||
<p className="mt-1 text-sm text-slate-500">
|
||||
Customer since {fmtDate(c.createdAt, false)}
|
||||
{/* 2.26.0: the demo scenario last loaded on its installs. */}
|
||||
{c.isDemo && (c.demoScenarioJobId ? " · A demo scenario is loading" : c.demoScenario ? ` · Demo scenario: ${scenarioName(c.demoScenario)}${c.demoScenarioAt ? `, loaded ${fmtDate(c.demoScenarioAt)}` : ""}` : "")}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button type="button" className="btn-primary" onClick={() => onAction("payment")}><Plus className="h-4 w-4" /> Record payment</button>
|
||||
{!c.isDemo && <button type="button" className="btn-secondary" onClick={() => onAction("oneoff")}><FilePlus className="h-4 w-4" /> One-off invoice</button>}
|
||||
{c.isDemo && <button type="button" className="btn-secondary" onClick={() => onAction("scenario")}><Sparkles className="h-4 w-4" /> Load a demo scenario</button>}
|
||||
{canAdd && <button type="button" className="btn-secondary" onClick={() => onAction("add")}><KeyRound className="h-4 w-4" /> Add product</button>}
|
||||
<Menu label="More actions for this customer" items={[
|
||||
c.isDemo ? { label: "Not a demo client any more…", onClick: () => onAction("demo") } : { label: "Make it a demo client…", onClick: () => onAction("demo") },
|
||||
|
||||
@@ -39,7 +39,7 @@ export function DemoClientModal({ c, onClose, onDone }: { c: Customer; onClose:
|
||||
<Modal title="Make it a demo client" onClose={onClose} dirty={!!confirmName}>
|
||||
<form onSubmit={submit} className="space-y-4">
|
||||
<ul className="list-disc space-y-1 pl-5 text-sm text-slate-500">
|
||||
<li>Every install of {c.name} becomes a demo site, Accounts included, and so does any it gets later. Demo data can then be loaded on its Events and Website.</li>
|
||||
<li>Every install of {c.name} becomes a demo site, Accounts included, and so does any it gets later. Demo data can then be loaded on each of them, or a whole demo scenario on all of them at once.</li>
|
||||
<li>It isn't billed: billing is set to "not invoiced", and no invoice of it is drafted or sent.</li>
|
||||
<li>Only for churches used for showing Cross Code, never a real customer.</li>
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { PRODUCT_NAMES, type Product } from "@/lib/products";
|
||||
import { scenarioName } from "@/lib/scenarios";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { FormError, Loading, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { post } from "@/components/install/shared";
|
||||
import type { Done } from "./shared";
|
||||
|
||||
type Scenario = { key: string; church: string; label: string; description: string; campuses: number; language: "en" | "af"; appActiveMembers: string };
|
||||
type PlanInstall = { id: string; product: Product; domain: string; version: string | null; minVersion: string | null; tooOld: boolean; covered: boolean; profile: string | null; demoScenario: string | null; outOfStep: boolean };
|
||||
export type ScenarioPlan = {
|
||||
customer: { demoScenario: string | null; demoScenarioAt: string | null; demoScenarioJobId: string | null };
|
||||
scenario: Scenario | null; shortName: string | null; server: { name: string; agentVersion: string | null } | null;
|
||||
installs: PlanInstall[]; notCovered: Product[]; problems: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Hub 2.26.0 (APP-1.0-PLAN §12): load a demo scenario on a demo client. Pick one of the eight
|
||||
* churches, see which installs it replaces (Accounts first) and anything that stops it, type the
|
||||
* short name once. One seed-scenario job: the server loads every product the church has there.
|
||||
*/
|
||||
export function ScenarioModal({ c, onClose, onDone }: { c: Customer; onClose: () => void; onDone: Done }) {
|
||||
const [scenarios, setScenarios] = useState<Scenario[] | null>(null);
|
||||
const [key, setKey] = useState(c.demoScenario || "");
|
||||
const [plan, setPlan] = useState<ScenarioPlan | null>(null);
|
||||
const [planError, setPlanError] = useState<string | null>(null);
|
||||
const [confirmName, setConfirmName] = useState("");
|
||||
const { busy, error, run } = useSubmit();
|
||||
|
||||
useEffect(() => {
|
||||
api<Scenario[]>("/api/admin/demo-scenarios").then(list => { setScenarios(list); setKey(k => k || list[0]?.key || ""); }).catch(e => setPlanError(errorText(e)));
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (!key) return;
|
||||
setPlan(null);
|
||||
api<ScenarioPlan>(`/api/admin/customers/${c.id}/scenario?scenario=${encodeURIComponent(key)}`).then(p => { setPlan(p); setPlanError(null); }).catch(e => setPlanError(errorText(e)));
|
||||
}, [c.id, key]);
|
||||
|
||||
const submit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!plan?.scenario) return;
|
||||
if (!window.confirm(`Replace the demo data of every install of ${plan.shortName} with ${plan.scenario.church}? Each product takes a backup first.`)) return;
|
||||
run(async () => {
|
||||
await post(`/api/admin/customers/${c.id}/scenario`, { scenario: key, confirm: confirmName });
|
||||
onDone({ type: "ok", text: `Queued: the agent loads ${plan.scenario!.church} on its next poll, Accounts first (see Jobs). You get an email when it's done.` });
|
||||
});
|
||||
};
|
||||
|
||||
const chosen = scenarios?.find(s => s.key === key);
|
||||
const blocked = !plan || plan.problems.length > 0;
|
||||
return (
|
||||
<Modal title="Load a demo scenario" onClose={onClose} dirty={!!confirmName} wide>
|
||||
{!scenarios ? (planError ? <FormError error={planError} /> : <Loading />) : (
|
||||
<form onSubmit={submit} className="space-y-4">
|
||||
<p className="text-sm text-slate-500">
|
||||
Every product {c.name} has gets the same demo church: Accounts' church profile (name, logo, colours, details) and people, then Cross Events, the Website and the App around them. Demo logins use the password Demo@1234.
|
||||
</p>
|
||||
<div>
|
||||
<label className="label" htmlFor="sc-k">Scenario</label>
|
||||
<select id="sc-k" className="input" value={key} onChange={e => setKey(e.target.value)}>
|
||||
{scenarios.map(s => <option key={s.key} value={s.key}>{s.label}</option>)}
|
||||
</select>
|
||||
{chosen && <p className="mt-1 text-xs text-slate-500">{chosen.description} {chosen.campuses > 1 ? `${chosen.campuses} campuses. ` : ""}{chosen.language === "af" ? "Mostly Afrikaans. " : ""}App active members {chosen.appActiveMembers}.</p>}
|
||||
</div>
|
||||
|
||||
{planError && <FormError error={planError} />}
|
||||
{!plan && !planError && <Loading />}
|
||||
{plan && (
|
||||
<>
|
||||
<div>
|
||||
<p className="label">It replaces, in this order{plan.server ? ` (on ${plan.server.name})` : ""}</p>
|
||||
<ol className="list-decimal space-y-1 pl-5 text-sm">
|
||||
{plan.installs.map(i => (
|
||||
<li key={i.id}>
|
||||
<span className="font-medium">{PRODUCT_NAMES[i.product]}</span> · {i.domain} · {i.version || "version unknown"}
|
||||
{i.tooOld && <span className="ml-1 text-red-700">needs {i.minVersion} or later</span>}
|
||||
{!i.covered && <span className="ml-1 text-amber-800">not in this scenario</span>}
|
||||
{i.outOfStep && <span className="ml-1 text-amber-800">out of step now</span>}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
{plan.installs.length < 4 && <p className="mt-1 text-xs text-slate-500">Products it doesn't have are skipped.</p>}
|
||||
</div>
|
||||
{plan.customer.demoScenario && <p className="text-xs text-slate-500">Last loaded: {scenarioName(plan.customer.demoScenario)}{plan.customer.demoScenarioAt ? `, ${fmtDate(plan.customer.demoScenarioAt)}` : ""}.</p>}
|
||||
{plan.problems.length > 0 && (
|
||||
<div className="rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-800">
|
||||
<p className="font-medium">It can't be loaded yet:</p>
|
||||
<ul className="mt-1 list-disc space-y-0.5 pl-5">{plan.problems.map(p => <li key={p}>{p}</li>)}</ul>
|
||||
</div>
|
||||
)}
|
||||
{!blocked && plan.shortName && (
|
||||
<div><label className="label" htmlFor="sc-c">Type {plan.shortName}</label><input id="sc-c" className="input" autoComplete="off" value={confirmName} onChange={e => setConfirmName(e.target.value)} /></div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<FormError error={error} />
|
||||
<ModalButtons busy={busy} busyLabel="Working…" onCancel={onClose} label="Load the scenario" danger disabled={blocked || confirmName !== plan?.shortName} />
|
||||
</form>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -2,16 +2,27 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { DEMO_SCENARIOS, DEMO_SCENARIO_MIN_VERSIONS } from "@/lib/scenarios";
|
||||
import { post, withWarnings, type Done, type Install } from "./shared";
|
||||
|
||||
/** Each product's demo data sets (contracts `DEMO_PROFILES` and, 2.25.0, `WEBSITE_DEMO_PROFILES`). */
|
||||
/** 2.26.0: a scenario's church, as one product's demo (Events 3.8.0, the App and Accounts). */
|
||||
const scenarioProfiles = (product: "events" | "app" | "accounts") =>
|
||||
DEMO_SCENARIOS.map(s => ({ key: s.key, label: `${s.church}: ${s.kind}${product === "events" ? " (Events 3.8.0+)" : ""}` }));
|
||||
|
||||
/**
|
||||
* Each product's demo data sets (contracts `EVENTS_DEMO_PROFILES`, `WEBSITE_DEMO_PROFILES`, and,
|
||||
* 2.26.0, `APP_DEMO_PROFILES` and `ACCOUNTS_DEMO_PROFILES`: one per scenario church).
|
||||
*/
|
||||
const PROFILES: Record<string, { key: string; label: string }[]> = {
|
||||
events: [
|
||||
{ key: "small", label: "Small church: the essentials" },
|
||||
{ key: "events", label: "Events and conferences" },
|
||||
{ key: "ministry", label: "Weekly ministry: courses, kids, volunteers" },
|
||||
{ key: "multicampus", label: "Three campuses" },
|
||||
...scenarioProfiles("events"),
|
||||
],
|
||||
app: scenarioProfiles("app"),
|
||||
accounts: scenarioProfiles("accounts"),
|
||||
website: [
|
||||
{ key: "heritage-parish", label: "Heritage: a parish church with a long history" },
|
||||
{ key: "heritage-city", label: "Heritage: a city-centre church (other layouts)" },
|
||||
@@ -24,13 +35,14 @@ const PROFILES: Record<string, { key: string; label: string }[]> = {
|
||||
],
|
||||
};
|
||||
|
||||
/** Whether a product has demo data to load (Accounts and the App are only tagged). */
|
||||
/** Whether a product has demo data to load (2.26.0: every product). */
|
||||
export const hasDemoData = (product: string) => product in PROFILES;
|
||||
|
||||
/**
|
||||
* An install used for showing Cross Code: mark it as a demo site, or (once it is one) replace its
|
||||
* data with a demo set. Unmarking is a menu item on the page. 2.25.0: the Website's eight demo
|
||||
* churches; Accounts and the App can be marked (a tag) but have no demo data.
|
||||
* churches. 2.26.0: the App's and Accounts' (a scenario's church on its own; the customer page loads
|
||||
* a whole scenario on every product at once).
|
||||
*/
|
||||
export function DemoModal({ x, onClose, onDone }: { x: Install; onClose: () => void; onDone: Done }) {
|
||||
const profiles = PROFILES[x.product] || [];
|
||||
@@ -49,7 +61,9 @@ export function DemoModal({ x, onClose, onDone }: { x: Install; onClose: () => v
|
||||
};
|
||||
const seed = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const what = website ? "content (pages, ministries, messages, events, pictures)" : "data";
|
||||
const what = website ? "content (pages, ministries, messages, events, pictures)"
|
||||
: x.product === "app" ? "content (prayer wall, campaigns, devotionals, announcements, events)"
|
||||
: x.product === "accounts" ? "church profile and demo people" : "data";
|
||||
if (!window.confirm(`Replace ALL of ${x.shortName}'s ${what} with the "${profile}" demo? A backup is taken first.`)) return;
|
||||
run(async () => {
|
||||
const r = await post(`/api/admin/deployments/${x.id}/seed-demo`, { profile, confirm: confirmName });
|
||||
@@ -83,8 +97,13 @@ export function DemoModal({ x, onClose, onDone }: { x: Install; onClose: () => v
|
||||
<p className="text-sm text-slate-500">
|
||||
{website
|
||||
? "Replaces the site's content with a demo church on its template, and publishes it. The church's profile (name, logo, colours, service times, contact), the site settings, the site icon and the admins stay, and the demo's text uses the church's name. Needs agent 1.6.0 and Website 1.3.0."
|
||||
: <>Replaces everything (events, people, payments) with a demo set, keeping the site settings and {x.adminEmail || "the site's first admin"}. Demo logins use the password Demo@1234.</>}
|
||||
: x.product === "app"
|
||||
? `Replaces the App's content (prayer wall, campaign, testimonies, devotionals, announcements, events) with the church's, around its demo people. Admins and settings stay. Needs agent 1.7.0 and App ${DEMO_SCENARIO_MIN_VERSIONS.app}.`
|
||||
: x.product === "accounts"
|
||||
? `Replaces the church profile (name, logo, icon, colours, details) with the demo church's and its demo people (password Demo@1234); real people and admins stay. Every linked product shows the new profile. Needs agent 1.7.0 and Accounts ${DEMO_SCENARIO_MIN_VERSIONS.accounts}.`
|
||||
: <>Replaces everything (events, people, payments) with a demo set, keeping the site settings and {x.adminEmail || "the site's first admin"}. Demo logins use the password Demo@1234. The named churches need Events {DEMO_SCENARIO_MIN_VERSIONS.events}.</>}
|
||||
</p>
|
||||
{x.customer?.isDemo && <p className="rounded-lg border border-sky-200 bg-sky-50 p-3 text-sm text-sky-900">One product on its own is out of step with the others. To load the same church on all of them, use <strong>Load a demo scenario</strong> on the customer.</p>}
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<label className="label" htmlFor="d-p">Demo</label>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ArrowLeft, RefreshCw } from "lucide-react";
|
||||
import { ago } from "@/lib/format";
|
||||
import { Menu, Stat } from "@/components/ui";
|
||||
import { StatusPill } from "@/components/servers";
|
||||
import { scenarioName } from "@/lib/scenarios";
|
||||
import { productName, running, type Detail } from "./shared";
|
||||
import { hasDemoData } from "./DemoModal";
|
||||
|
||||
@@ -33,6 +34,10 @@ export function InstallHeader({ d, onAction }: { d: Detail; onAction: (a: Instal
|
||||
<span className="break-words">{x.customer?.name} ({x.shortName})</span>
|
||||
<StatusPill status={d.stale.stale ? "stale" : x.status} />
|
||||
{x.isDemo && <span className="rounded-full bg-indigo-50 px-2 py-0.5 text-xs font-medium text-indigo-700 ring-1 ring-inset ring-indigo-200">Demo site</span>}
|
||||
{/* 2.26.0: whether its demo data is its customer's scenario, or one product's demo loaded on its own. */}
|
||||
{x.isDemo && x.customer?.demoScenario && (x.demoScenario === x.customer.demoScenario
|
||||
? <span title={scenarioName(x.customer.demoScenario)} className="rounded-full bg-sky-50 px-2 py-0.5 text-xs font-medium text-sky-800 ring-1 ring-inset ring-sky-200">Scenario: {scenarioName(x.customer.demoScenario).split(" (")[0]}</span>
|
||||
: <span title="Its demo data isn't the scenario its customer last loaded. Load the scenario again from the customer." className="rounded-full bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-800 ring-1 ring-inset ring-amber-200">Out of step with the scenario</span>)}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-slate-500">
|
||||
{productName(x.product)} · {x.customer ? <Link className="text-indigo-700 hover:underline" href={`/customers/${x.customerId}`}>customer</Link> : "customer"}
|
||||
@@ -42,7 +47,7 @@ export function InstallHeader({ d, onAction }: { d: Detail; onAction: (a: Instal
|
||||
{live && <button type="button" className="btn-primary" onClick={() => onAction("update")}><RefreshCw className="h-4 w-4" /> Schedule update</button>}
|
||||
<Menu label="More actions for this install" items={[
|
||||
live && x.install?.version?.startsWith("2.1.") && { label: "Move onto the monorepo…", onClick: () => onAction("adopt") },
|
||||
// 2.25.0: any product can be a demo site; Events and the Website have demo data.
|
||||
// 2.25.0: any product can be a demo site; 2.26.0: every product has demo data.
|
||||
running(x) && !x.isDemo && { label: "Mark as a demo site…", onClick: () => onAction("demo") },
|
||||
running(x) && x.isDemo && hasDemoData(x.product) && { label: "Load demo data…", onClick: () => onAction("demo") },
|
||||
running(x) && x.isDemo && !x.customer?.isDemo && { label: "It isn't a demo site any more", onClick: () => onAction("undemo") },
|
||||
|
||||
@@ -27,8 +27,10 @@ export type ServerSummary = {
|
||||
export type Deployment = {
|
||||
id: string; serverId: string; customerId: string; installId: string | null; product: string; shortName: string; domain: string;
|
||||
webPort: number; apiPort: number; status: string; version: string | null; adminName: string | null; adminEmail: string | null; isDemo?: boolean;
|
||||
/** 2.26.0: the demo scenario its data is from (null after one product's demo on its own). */
|
||||
demoScenario?: string | null;
|
||||
liveAt: string | null; createdAt: string;
|
||||
server?: { id: string; name: string }; customer?: { id: string; name: string; isDemo?: boolean };
|
||||
server?: { id: string; name: string }; customer?: { id: string; name: string; isDemo?: boolean; demoScenario?: string | null };
|
||||
install?: { id: string; version: string | null; lastHeartbeatAt: string | null; url: string } | null;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// The demo scenarios (Hub 2.26.0, contracts agent.DEMO_SCENARIOS; APP-1.0-PLAN §12): eight preset
|
||||
// churches, one per Website demo profile. The same keys as the backend's list
|
||||
// (GET /api/admin/demo-scenarios has the descriptions); every church in them is fictional.
|
||||
|
||||
import type { Product } from "./products";
|
||||
|
||||
export const DEMO_SCENARIOS = [
|
||||
{ key: "heritage-parish", church: "St Columba's", kind: "Heritage: a parish church" },
|
||||
{ key: "heritage-city", church: "Grace Cathedral", kind: "Heritage: a city-centre church" },
|
||||
{ key: "bold-youth", church: "Ignite Church", kind: "Bold: young and music-led" },
|
||||
{ key: "bold-plant", church: "Harbour City", kind: "Bold: a new church plant" },
|
||||
{ key: "community-family", church: "Acacia Hill", kind: "Community: a family church" },
|
||||
{ key: "community-town", church: "Karoo Gemeenskapskerk", kind: "Community: a country-town church" },
|
||||
{ key: "clean-modern", church: "Northpoint", kind: "Clean: a contemporary church" },
|
||||
{ key: "clean-campus", church: "Riverside", kind: "Clean: three campuses near the university" },
|
||||
] as const;
|
||||
|
||||
export type DemoScenarioKey = (typeof DEMO_SCENARIOS)[number]["key"];
|
||||
|
||||
/** The first release of each product that loads a scenario (contracts DEMO_SCENARIO_MIN_VERSIONS). */
|
||||
export const DEMO_SCENARIO_MIN_VERSIONS: Record<Product, string> = { accounts: "1.9.0", events: "3.8.0", website: "1.8.0", app: "1.0.0" };
|
||||
|
||||
/** "Acacia Hill (Community: a family church)", or the key for one the Hub doesn't know. */
|
||||
export const scenarioName = (key: string | null | undefined) => {
|
||||
const s = DEMO_SCENARIOS.find(x => x.key === key);
|
||||
return s ? `${s.church} (${s.kind})` : key || "";
|
||||
};
|
||||
@@ -47,6 +47,10 @@ export type Customer = {
|
||||
/** Hub 2.25.0: a demo client: all its installs are demo sites, and it isn't billed. */
|
||||
isDemo?: boolean;
|
||||
demoSince?: string | null;
|
||||
/** Hub 2.26.0: the demo scenario last loaded on its installs, when, and the job loading one now. */
|
||||
demoScenario?: string | null;
|
||||
demoScenarioAt?: string | null;
|
||||
demoScenarioJobId?: string | null;
|
||||
/** Hub 2.0: the church's AI allowance, shared by all its installs. */
|
||||
aiMonthlyCapCents: number;
|
||||
aiMarkupPercent: number | null;
|
||||
|
||||
Reference in New Issue
Block a user