Hub 2.25.0: demo clients, and demo data for the Church Website
- A customer can be a demo client: every install a demo site (Accounts included, and any later install), never billed (billing off, no invoice drafted, sent or made by hand). Migration: Customer.isDemo, demoSince. - Any install can be marked as a demo site; Events and the Website have demo data. The Website's eight demo churches need agent 1.6.0. - Contracts 1.19.0 vendored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import { AddressCard, AddressModal } from "@/components/customer/AddressCard";
|
||||
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 { ProductCard } from "@/components/customer/ProductCard";
|
||||
import { AddProductModal } from "@/components/customer/AddProductModal";
|
||||
import { NextInvoiceModal } from "@/components/customer/NextInvoice";
|
||||
@@ -145,6 +146,7 @@ export default function CustomerPage() {
|
||||
{popup === "schedule" && b && <ScheduleModal b={b} onClose={close} onDone={done} />}
|
||||
{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 === "update" && <ChurchUpdateModal customerId={id} name={c.name} onClose={close} onDone={done} />}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -78,7 +78,7 @@ export default function CustomersPage() {
|
||||
{paged.rows.length === 0 && <tr><td colSpan={3} className="p-3 text-slate-500">No customers match.</td></tr>}
|
||||
{paged.rows.map(c => (
|
||||
<tr key={c.id} className="border-t hover:bg-slate-50">
|
||||
<td className="p-3"><Link href={`/customers/${c.id}`} className="font-medium text-indigo-700 hover:underline">{c.name}</Link><div className="text-xs text-slate-500">{[c.contactName, c.email].filter(Boolean).join(" · ")}</div></td>
|
||||
<td className="p-3"><Link href={`/customers/${c.id}`} className="font-medium text-indigo-700 hover:underline">{c.name}</Link>{c.isDemo && <span className="ml-1 rounded bg-sky-100 px-1.5 text-xs text-sky-800">demo</span>}<div className="text-xs text-slate-500">{[c.contactName, c.email].filter(Boolean).join(" · ")}</div></td>
|
||||
<td className="p-3">{c.licences.length ? [...c.licences].sort(byProduct).map(l => <span key={l.id} className="mr-2 inline-flex items-center gap-1 text-xs">{PRODUCT_NAMES[l.product]} <Badge value={l.status} /></span>) : <span className="text-xs text-slate-400">none</span>}</td>
|
||||
<td className="p-3">{c.installs.length ? c.installs.map(i => <div key={i.id} className="text-xs"><span className="text-slate-500">{PRODUCT_NAMES[i.product]}:</span> {i.url} <span className="text-slate-400">· {ago(i.lastHeartbeatAt)}</span></div>) : <span className="text-xs text-slate-400">not connected</span>}</td>
|
||||
</tr>
|
||||
|
||||
@@ -11,7 +11,7 @@ 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";
|
||||
export type HeaderAction = "payment" | "oneoff" | "add" | "preview" | "address" | "ai" | "history" | "demo";
|
||||
|
||||
/**
|
||||
* Hub 2.14.0: always at the top of the customer page: who the church is, what it has, what it
|
||||
@@ -37,15 +37,17 @@ export function CustomerHeader({ c, b, preview, canAdd, onAction, onArchive }: {
|
||||
<h1 className="flex flex-wrap items-center gap-2 text-2xl font-semibold">
|
||||
<span className="break-words">{c.name}</span>
|
||||
{b?.founding && <span title="Founding church (35% off)" className="inline-flex items-center gap-1 rounded-full bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-800 ring-1 ring-inset ring-amber-200"><Star className="h-3.5 w-3.5 fill-amber-400 text-amber-400" /> Founding</span>}
|
||||
{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>
|
||||
</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>
|
||||
<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("oneoff")}><FilePlus className="h-4 w-4" /> One-off invoice</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") },
|
||||
c.archivedAt ? { label: "Restore", onClick: () => onArchive(false) } : { label: "Archive…", onClick: () => onArchive(true) },
|
||||
]} />
|
||||
</div>
|
||||
@@ -59,8 +61,8 @@ export function CustomerHeader({ c, b, preview, canAdd, onAction, onArchive }: {
|
||||
value={b ? money(b.balanceCents) : "…"}
|
||||
sub={overdue.length ? `${overdue.length} overdue` : b && b.balanceCents <= 0 ? "Nothing owing" : undefined} />
|
||||
<Stat label="Next invoice" small onClick={() => onAction("preview")}
|
||||
value={!b ? "…" : b.billingCycle === "none" ? "Not billed" : b.nextInvoiceDate ? day(b.nextInvoiceDate) : "Not set"}
|
||||
sub={b && b.billingCycle !== "none" ? (estimate != null ? `About ${money(estimate)} · see it` : preview?.billed && preview.empty ? "Nothing to charge yet" : "See it") : "Set up billing"} />
|
||||
value={!b ? "…" : b.isDemo ? "Not billed (demo)" : b.billingCycle === "none" ? "Not billed" : b.nextInvoiceDate ? day(b.nextInvoiceDate) : "Not set"}
|
||||
sub={b?.isDemo ? "A demo client" : b && b.billingCycle !== "none" ? (estimate != null ? `About ${money(estimate)} · see it` : preview?.billed && preview.empty ? "Nothing to charge yet" : "See it") : "Set up billing"} />
|
||||
<Stat label="Address" small onClick={() => onAction("address")}
|
||||
value={b ? ADDRESS_OPTIONS[b.addressType].label : "…"}
|
||||
sub={b?.domain || "No domain yet"} />
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { post, withWarnings } from "@/components/install/shared";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import type { Done } from "./shared";
|
||||
|
||||
/**
|
||||
* Hub 2.25.0: make a customer a demo client (a church used for showing Cross Code), or an ordinary
|
||||
* one again. A demo client's installs are all demo sites, Accounts included, and it isn't billed.
|
||||
*/
|
||||
export function DemoClientModal({ c, onClose, onDone }: { c: Customer; onClose: () => void; onDone: Done }) {
|
||||
const [confirmName, setConfirmName] = useState("");
|
||||
const { busy, error, run } = useSubmit();
|
||||
|
||||
const submit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
run(async () => {
|
||||
const r = await post<{ sites: number; warnings?: string[] }>(`/api/admin/customers/${c.id}/demo`, { isDemo: !c.isDemo, confirm: confirmName });
|
||||
const sites = `${r.sites} install${r.sites === 1 ? "" : "s"}`;
|
||||
onDone({ type: "ok", text: withWarnings(c.isDemo
|
||||
? `${c.name} is an ordinary customer again: ${sites} no longer demo sites. Billing stays off until you set it up.`
|
||||
: `${c.name} is a demo client: ${sites} marked as demo sites, and it isn't billed.`, r) });
|
||||
});
|
||||
};
|
||||
|
||||
if (c.isDemo) return (
|
||||
<Modal title="Make it an ordinary customer" onClose={onClose}>
|
||||
<form onSubmit={submit} className="space-y-4">
|
||||
<p className="text-sm text-slate-500">Its installs stop being demo sites, so no more demo data can be loaded on them. Billing stays "not invoiced" until you set up its schedule.</p>
|
||||
<FormError error={error} />
|
||||
<ModalButtons busy={busy} busyLabel="Working…" onCancel={onClose} label="Not a demo client any more" />
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
return (
|
||||
<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>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>
|
||||
<div><label className="label" htmlFor="dc-c">Type {c.name}</label><input id="dc-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="Make it a demo client" danger disabled={confirmName.trim() !== c.name.trim()} />
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import { changed, type CustomerBillingData, type Done } from "./shared";
|
||||
export function ScheduleCard({ b, onEdit }: { b: CustomerBillingData; onEdit: () => void }) {
|
||||
const off = b.billingCycle === "none";
|
||||
return (
|
||||
<ReadCard title="Billing schedule" onEdit={onEdit}>
|
||||
<ReadCard title="Billing schedule" onEdit={b.isDemo ? undefined : onEdit}>
|
||||
<Fields>
|
||||
<Field label="Billing">{CYCLE[b.billingCycle]}</Field>
|
||||
<Field label="Billing">{b.isDemo ? "Not billed: a demo client" : CYCLE[b.billingCycle]}</Field>
|
||||
{!off && <Field label="Billing started">{b.billingStart && day(b.billingStart)}</Field>}
|
||||
{!off && <Field label="Next invoice">{b.nextInvoiceDate && day(b.nextInvoiceDate)}</Field>}
|
||||
{!off && <Field label="Next tier review">{b.reviewDate && day(b.reviewDate)}</Field>}
|
||||
|
||||
@@ -20,6 +20,8 @@ export type AddressType = "own_domain" | "crosscode" | "included";
|
||||
|
||||
export type CustomerBillingData = {
|
||||
id: string; name: string; billingEmail: string | null; billingAddress: string | null; founding: boolean; foundingSince: string | null; foundingNote: string | null;
|
||||
/** Hub 2.25.0: a demo client (never billed). */
|
||||
isDemo?: boolean;
|
||||
billingCycle: BillingCycle; billingStart: string | null; nextInvoiceDate: string | null; reviewDate: string | null;
|
||||
addressType: AddressType; domain: string | null; addressCustomCents: number | null; addressMonthlyCents: number; domainRenewsOn: string | null;
|
||||
sendsTo: string | null; balanceCents: number; licences: BillingLicence[]; invoices: Invoice[]; payments: Payment[]; licenceChanges: LicenceChange[]; emails: BillingEmail[];
|
||||
|
||||
@@ -4,22 +4,41 @@ import React, { useState } from "react";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { post, withWarnings, type Done, type Install } from "./shared";
|
||||
|
||||
const PROFILES = [
|
||||
{ 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" },
|
||||
];
|
||||
/** Each product's demo data sets (contracts `DEMO_PROFILES` and, 2.25.0, `WEBSITE_DEMO_PROFILES`). */
|
||||
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" },
|
||||
],
|
||||
website: [
|
||||
{ key: "heritage-parish", label: "Heritage: a parish church with a long history" },
|
||||
{ key: "heritage-city", label: "Heritage: a city-centre church (other layouts)" },
|
||||
{ key: "bold-youth", label: "Bold: a young, music-led church" },
|
||||
{ key: "bold-plant", label: "Bold: a new church plant (other layouts)" },
|
||||
{ key: "community-family", label: "Community: a family church" },
|
||||
{ key: "community-town", label: "Community: a country-town church (other layouts)" },
|
||||
{ key: "clean-modern", label: "Clean: a contemporary church" },
|
||||
{ key: "clean-campus", label: "Clean: a church near the university (other layouts)" },
|
||||
],
|
||||
};
|
||||
|
||||
/** Whether a product has demo data to load (Accounts and the App are only tagged). */
|
||||
export const hasDemoData = (product: string) => product in PROFILES;
|
||||
|
||||
/**
|
||||
* An Events site used for showing Cross Events: 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.
|
||||
* 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.
|
||||
*/
|
||||
export function DemoModal({ x, onClose, onDone }: { x: Install; onClose: () => void; onDone: Done }) {
|
||||
const [profile, setProfile] = useState("events");
|
||||
const profiles = PROFILES[x.product] || [];
|
||||
const [profile, setProfile] = useState(profiles[0]?.key || "");
|
||||
const [confirmName, setConfirmName] = useState("");
|
||||
const { busy, error, run } = useSubmit();
|
||||
const typed = confirmName === x.shortName;
|
||||
const website = x.product === "website";
|
||||
|
||||
const mark = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -30,7 +49,8 @@ export function DemoModal({ x, onClose, onDone }: { x: Install; onClose: () => v
|
||||
};
|
||||
const seed = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!window.confirm(`Replace ALL of ${x.shortName}'s data with the "${profile}" demo? A backup is taken first; one admin account is kept.`)) return;
|
||||
const what = website ? "content (pages, ministries, messages, events, pictures)" : "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 });
|
||||
onDone({ type: "ok", text: withWarnings("Queued: the agent loads the demo data on its next poll (see Jobs). You get an email when it's done.", r) });
|
||||
@@ -44,7 +64,12 @@ export function DemoModal({ x, onClose, onDone }: { x: Install; onClose: () => v
|
||||
if (!x.isDemo) return (
|
||||
<Modal title="Mark as a demo site" onClose={onClose} dirty={!!confirmName}>
|
||||
<form onSubmit={mark} className="space-y-4">
|
||||
<p className="text-sm text-slate-500">A demo site's data can be replaced with demo data from the Hub. Only mark sites used for showing Cross Events, never a church's real site.</p>
|
||||
<p className="text-sm text-slate-500">
|
||||
{hasDemoData(x.product)
|
||||
? "A demo site's data can be replaced with demo data from the Hub. "
|
||||
: "This product has no demo data: marking it only tags it as a demo site. "}
|
||||
Only mark sites used for showing Cross Code, never a church's real site.
|
||||
</p>
|
||||
{confirmField}
|
||||
<FormError error={error} />
|
||||
<ModalButtons busy={busy} busyLabel="Working…" onCancel={onClose} label="Mark as a demo site" disabled={!typed} />
|
||||
@@ -53,14 +78,18 @@ export function DemoModal({ x, onClose, onDone }: { x: Install; onClose: () => v
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal title="Load demo data" onClose={onClose} dirty={!!confirmName || profile !== "events"}>
|
||||
<Modal title="Load demo data" onClose={onClose} dirty={!!confirmName || profile !== profiles[0]?.key}>
|
||||
<form onSubmit={seed} className="space-y-4">
|
||||
<p className="text-sm text-slate-500">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.</p>
|
||||
<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.</>}
|
||||
</p>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<label className="label" htmlFor="d-p">Demo</label>
|
||||
<select id="d-p" className="input" value={profile} onChange={e => setProfile(e.target.value)}>
|
||||
{PROFILES.map(p => <option key={p.key} value={p.key}>{p.label}</option>)}
|
||||
{profiles.map(p => <option key={p.key} value={p.key}>{p.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
{confirmField}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ago } from "@/lib/format";
|
||||
import { Menu, Stat } from "@/components/ui";
|
||||
import { StatusPill } from "@/components/servers";
|
||||
import { productName, running, type Detail } from "./shared";
|
||||
import { hasDemoData } from "./DemoModal";
|
||||
|
||||
/** What the header's buttons, menu and tiles open. */
|
||||
export type InstallAction = "update" | "adopt" | "demo" | "undemo" | "uninstall" | "record" | "forget";
|
||||
@@ -41,10 +42,10 @@ 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") },
|
||||
x.product === "events" && running(x) && (x.isDemo
|
||||
? { label: "Load demo data…", onClick: () => onAction("demo") }
|
||||
: { label: "Mark as a demo site…", onClick: () => onAction("demo") }),
|
||||
x.product === "events" && running(x) && x.isDemo && { label: "It isn't a demo site any more", onClick: () => onAction("undemo") },
|
||||
// 2.25.0: any product can be a demo site; Events and the Website have 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") },
|
||||
running(x) && { label: `Uninstall ${productName(x.product)}…`, onClick: () => onAction("uninstall"), danger: true },
|
||||
d.stale.stale && { label: "Remove from the Hub…", onClick: () => onAction("forget"), danger: true },
|
||||
d.canRemoveRecord && { label: "Remove the record…", onClick: () => onAction("record"), danger: true },
|
||||
|
||||
@@ -28,7 +28,7 @@ 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;
|
||||
liveAt: string | null; createdAt: string;
|
||||
server?: { id: string; name: string }; customer?: { id: string; name: string };
|
||||
server?: { id: string; name: string }; customer?: { id: string; name: string; isDemo?: boolean };
|
||||
install?: { id: string; version: string | null; lastHeartbeatAt: string | null; url: string } | null;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ export type Customer = {
|
||||
createdAt: string;
|
||||
/** Hub 2.12.0: archived (left out of the customer list until restored). */
|
||||
archivedAt?: string | null;
|
||||
/** 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.0: the church's AI allowance, shared by all its installs. */
|
||||
aiMonthlyCapCents: number;
|
||||
aiMarkupPercent: number | null;
|
||||
|
||||
Reference in New Issue
Block a user