- 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>
53 lines
2.8 KiB
TypeScript
53 lines
2.8 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 "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>
|
|
);
|
|
}
|