Files
events-hub/frontend/src/components/customer/DemoClientModal.tsx
T
joshuaandClaude Opus 5.5 16f69afa6f 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>
2026-11-30 22:24:28 +02:00

53 lines
2.9 KiB
TypeScript

"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 &quot;not invoiced&quot; 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 each of them, or a whole demo scenario on all of them at once.</li>
<li>It isn&apos;t billed: billing is set to &quot;not invoiced&quot;, 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>
);
}