Hub 2.12.0: one product uninstalled at a time, stale installs removed, customers archived
- Uninstalls name the product (agent 1.5.0); a whole-church uninstall marks every product of the church on that server removed. Older agents are refused while the church has others. - A second product's uninstall joins one already planned (one export and one uninstall) or gets its own time; the last product removes the whole church. Accounts goes last. - Remove an install from the Hub after 24 hours without a heartbeat (POST .../forget). - Archive and restore customers (migration 20261123090000_customer_archive). - Several addresses for a customer's email and billing email, with a + button. - Statements show R0 invoices' amounts. Vendors contracts 1.16.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.11.0",
|
||||
"version": "2.12.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.11.0",
|
||||
"version": "2.12.0",
|
||||
"dependencies": {
|
||||
"lucide-react": "^0.536.0",
|
||||
"next": "^15.5.24",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.11.0",
|
||||
"version": "2.12.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 3200",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useParams } from "next/navigation";
|
||||
import { ArrowLeft, Copy, KeyRound } from "lucide-react";
|
||||
import { Archive, ArchiveRestore, ArrowLeft, Copy, KeyRound } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, fmtDate } from "@/lib/format";
|
||||
import { PLANS_BY_PRODUCT } from "@/lib/tiers";
|
||||
@@ -11,6 +11,7 @@ import { KEY_WHERE, PRODUCTS, PRODUCT_NAMES, byProduct, type Product } from "@/l
|
||||
import type { Customer, Licence, LicenceStatus } from "@/lib/types";
|
||||
import { Badge, Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { CustomerBilling } from "@/components/billing/CustomerBilling";
|
||||
import { EmailList } from "@/components/EmailList";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
const dateInput = (d: string | null) => (d ? d.slice(0, 10) : "");
|
||||
@@ -170,10 +171,24 @@ export default function CustomerPage() {
|
||||
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
|
||||
};
|
||||
|
||||
// Hub 2.12.0: archive (left out of the list and pickers) or restore.
|
||||
const setArchivedState = async (archive: boolean) => {
|
||||
if (archive && !confirm(`Archive ${c.name}? It's left out of the customer list until you restore it (Customers → Archived). Nothing else changes.`)) return;
|
||||
try {
|
||||
await api(`/api/admin/customers/${id}/${archive ? "archive" : "restore"}`, { method: "POST" });
|
||||
setMsg({ type: "ok", text: archive ? "Archived. Find it under Customers → Archived." : "Restored: it's in the customer list again." });
|
||||
load();
|
||||
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Link href="/customers" className="mb-2 inline-flex items-center gap-1 text-sm text-slate-500 hover:underline"><ArrowLeft className="h-4 w-4" /> Customers</Link>
|
||||
<PageTitle title={c.name} subtitle={`Customer since ${fmtDate(c.createdAt, false)}`} />
|
||||
<PageTitle title={c.name}
|
||||
subtitle={c.archivedAt ? `Archived ${fmtDate(c.archivedAt, false)} · customer since ${fmtDate(c.createdAt, false)}` : `Customer since ${fmtDate(c.createdAt, false)}`}
|
||||
actions={c.archivedAt
|
||||
? <button className="btn-secondary" onClick={() => setArchivedState(false)}><ArchiveRestore className="h-4 w-4" /> Restore</button>
|
||||
: <button className="btn-secondary" onClick={() => setArchivedState(true)}><Archive className="h-4 w-4" /> Archive</button>} />
|
||||
<div className="mb-4"><Message msg={msg} /></div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-[1fr_2fr]">
|
||||
@@ -181,7 +196,7 @@ export default function CustomerPage() {
|
||||
<h2 className="font-semibold">Details</h2>
|
||||
<div><label className="label">Name</label><input className="input" value={form.name} onChange={e => setForm({ ...form, name: e.target.value })} required /></div>
|
||||
<div><label className="label">Contact person</label><input className="input" value={form.contactName} onChange={e => setForm({ ...form, contactName: e.target.value })} /></div>
|
||||
<div><label className="label">Email</label><input type="email" className="input" value={form.email} onChange={e => setForm({ ...form, email: e.target.value })} /></div>
|
||||
<EmailList id="c-email" label="Email" value={form.email} onChange={email => setForm({ ...form, email })} placeholder="office@church.org" />
|
||||
<div><label className="label">Phone</label><input className="input" value={form.phone} onChange={e => setForm({ ...form, phone: e.target.value })} /></div>
|
||||
<div><label className="label">Notes</label><textarea className="input" rows={4} value={form.notes} onChange={e => setForm({ ...form, notes: e.target.value })} placeholder="Plan, billing, anything worth remembering" /></div>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
|
||||
@@ -10,6 +10,7 @@ import { matches, usePaged } from "@/lib/paging";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { PRODUCT_NAMES, byProduct } from "@/lib/products";
|
||||
import { Badge, Loading, Message, PageTitle, Pager, SearchInput } from "@/components/ui";
|
||||
import { EmailList } from "@/components/EmailList";
|
||||
|
||||
export default function CustomersPage() {
|
||||
const router = useRouter();
|
||||
@@ -19,10 +20,15 @@ export default function CustomersPage() {
|
||||
const [msg, setMsg] = useState<{ type: "ok" | "err"; text: string } | null>(null);
|
||||
|
||||
const [query, setQuery] = useState("");
|
||||
// Hub 2.12.0: archived customers are only shown here, on their own.
|
||||
const [archived, setArchived] = useState(false);
|
||||
const shown = useMemo(() => (list || []).filter(c => matches(query, c.name, c.contactName, c.email, c.phone, ...c.installs.map(i => i.url))), [list, query]);
|
||||
const paged = usePaged(shown, query);
|
||||
const paged = usePaged(shown, `${archived}|${query}`);
|
||||
|
||||
const load = useCallback(() => api<Customer[]>("/api/admin/customers").then(setList).catch(e => setMsg({ type: "err", text: errorText(e) })), []);
|
||||
const load = useCallback(() => {
|
||||
setList(null);
|
||||
return api<Customer[]>(`/api/admin/customers${archived ? "?archived=1" : ""}`).then(setList).catch(e => setMsg({ type: "err", text: errorText(e) }));
|
||||
}, [archived]);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
|
||||
const add = async (e: React.FormEvent) => {
|
||||
@@ -40,15 +46,21 @@ export default function CustomersPage() {
|
||||
<form onSubmit={add} className="card mb-6 grid gap-3 md:grid-cols-2">
|
||||
<div className="md:col-span-2"><label className="label" htmlFor="name">Name</label><input id="name" className="input" value={form.name} onChange={e => setForm({ ...form, name: e.target.value })} required placeholder="Hope Family Church" /></div>
|
||||
<div><label className="label" htmlFor="contact">Contact person</label><input id="contact" className="input" value={form.contactName} onChange={e => setForm({ ...form, contactName: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="email">Email</label><input id="email" type="email" className="input" value={form.email} onChange={e => setForm({ ...form, email: e.target.value })} /></div>
|
||||
<EmailList id="email" label="Email" value={form.email} onChange={email => setForm({ ...form, email })} placeholder="office@church.org" />
|
||||
<div><label className="label" htmlFor="phone">Phone</label><input id="phone" className="input" value={form.phone} onChange={e => setForm({ ...form, phone: e.target.value })} /></div>
|
||||
<div className="flex items-end gap-2"><button className="btn-primary">Save</button><button type="button" className="btn-secondary" onClick={() => setAdding(false)}>Cancel</button></div>
|
||||
</form>
|
||||
)}
|
||||
<Message msg={msg} />
|
||||
{!list ? <Loading /> : list.length === 0 ? <p className="text-sm text-slate-500">No customers yet.</p> : (
|
||||
<div className="mb-3 flex flex-wrap items-center gap-3">
|
||||
<div className="inline-flex rounded-lg border border-slate-200 p-0.5 text-sm" role="group" aria-label="Which customers">
|
||||
<button type="button" aria-pressed={!archived} className={`rounded-md px-3 py-1 ${!archived ? "bg-indigo-50 font-medium text-indigo-700" : "text-slate-600"}`} onClick={() => setArchived(false)}>Active</button>
|
||||
<button type="button" aria-pressed={archived} className={`rounded-md px-3 py-1 ${archived ? "bg-indigo-50 font-medium text-indigo-700" : "text-slate-600"}`} onClick={() => setArchived(true)}>Archived</button>
|
||||
</div>
|
||||
{!!list?.length && <SearchInput className="w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search name, contact or site" />}
|
||||
</div>
|
||||
{!list ? <Loading /> : list.length === 0 ? <p className="text-sm text-slate-500">{archived ? "No archived customers." : "No customers yet."}</p> : (
|
||||
<>
|
||||
<SearchInput className="mb-3 w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search name, contact or site" />
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-left text-xs text-slate-500"><tr><th className="p-3">Customer</th><th className="p-3">Licences</th><th className="p-3">Site</th></tr></thead>
|
||||
|
||||
@@ -17,8 +17,20 @@ type Detail = {
|
||||
deployment: Deployment & { server: ServerSummary; jobs: Job[]; exports: { id: string; bytes: number; expiresAt: string; downloadedAt: string | null; deletedAt: string | null }[]; install: { version: string | null; url: string; lastHeartbeatAt: string | null } | null };
|
||||
fastPanel: string;
|
||||
canRemoveRecord: boolean;
|
||||
/** 2.12.0: no heartbeat for 24 hours, so it can be removed from the Hub. */
|
||||
stale: { since: string | null; stale: boolean };
|
||||
/** 2.12.0: what an uninstall removes: this product only (agent 1.5.0+), or the whole church. */
|
||||
uninstall: {
|
||||
onlyThisProduct: boolean; minAgent: string; others: { id: string; product: string; domain: string; status: string }[];
|
||||
/** The church's uninstalls not run yet; `products` null: the whole church. `joinable`: this one can still be added to it. */
|
||||
pending: { jobId: string; notBefore: string; products: string[] | null; joinable: boolean }[];
|
||||
/** Every other product is being uninstalled: this one takes the whole church with it. */
|
||||
lastProduct: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
const productName = (p: string) => PRODUCT_NAMES[p as keyof typeof PRODUCT_NAMES] || p;
|
||||
|
||||
const H = 60 * 60 * 1000;
|
||||
|
||||
/** One install on a server: proxy, updates, adopt, uninstall (§7–9). */
|
||||
@@ -33,6 +45,9 @@ export default function DeploymentPage() {
|
||||
const [adopt, setAdopt] = useState({ eventsDir: "", version: "", address: "", at: toInput(new Date(Date.now() + 5 * H)) });
|
||||
const [un, setUn] = useState({ at: toInput(new Date(Date.now() + 7 * 24 * H)), totp: "", confirm: "" });
|
||||
const [demo, setDemo] = useState({ profile: "events", confirm: "", markConfirm: "" });
|
||||
const [forget, setForget] = useState("");
|
||||
// 2.12.0: with another product's uninstall pending, join it (the default) or a time of its own.
|
||||
const [joining, setJoining] = useState(true);
|
||||
|
||||
const [releases, setReleases] = useState<Release[]>([]);
|
||||
// Hub 2.6.0: every job of this install, a page at a time (it showed the last 50).
|
||||
@@ -98,14 +113,33 @@ export default function DeploymentPage() {
|
||||
} catch (e) { setMsg({ type: "err", text: errorText(e) }); }
|
||||
};
|
||||
|
||||
const removeFromHub = () => withBusy(removeFromHubNow);
|
||||
const removeFromHubNow = async () => {
|
||||
if (!d || !window.confirm(`Remove ${d.deployment.domain} from the Hub? Nothing runs on the server: use this only when the site is already gone from it.`)) return;
|
||||
setMsg(null);
|
||||
try {
|
||||
await api(`/api/admin/deployments/${id}/forget`, { method: "POST", body: { confirm: forget } });
|
||||
router.push("/servers/installs");
|
||||
} catch (e) { setMsg({ type: "err", text: errorText(e) }); }
|
||||
};
|
||||
|
||||
if (!d) return <div><ServersNav active="/servers/installs" />{msg ? <Message msg={msg} /> : <Loading />}</div>;
|
||||
const x = d.deployment;
|
||||
const minAt = upd.emergency ? 15 * 60 * 1000 : 4 * H;
|
||||
const plan = d.uninstall;
|
||||
const othersStaying = plan.others.filter(o => o.status !== "uninstalling");
|
||||
// Accounts goes last: the church's other products sign in through it.
|
||||
const accountsInUse = x.product === "accounts" && othersStaying.length > 0;
|
||||
const wholeChurch = !plan.onlyThisProduct && plan.others.length > 0;
|
||||
// 2.12.0: the church's uninstalls not run yet (by product), and the one this could join.
|
||||
const pendingRuns = plan.pending.filter(p => p.products);
|
||||
const joinable = pendingRuns.find(p => p.joinable) || null;
|
||||
const lastNow = plan.onlyThisProduct && plan.lastProduct;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<PageTitle title={`${x.customer?.name} (${x.shortName})`} subtitle={<>{x.domain} · on <Link className="text-indigo-700 hover:underline" href={`/servers/${x.serverId}`}>{x.server.name}</Link> · ports web {x.webPort}, api {x.apiPort} · version {x.install?.version || x.version || "–"} <StatusPill status={x.status} /></>} />
|
||||
<PageTitle title={`${x.customer?.name} (${x.shortName})`} subtitle={<>{x.domain} · on <Link className="text-indigo-700 hover:underline" href={`/servers/${x.serverId}`}>{x.server.name}</Link> · ports web {x.webPort}, api {x.apiPort} · version {x.install?.version || x.version || "–"} <StatusPill status={d.stale.stale ? "stale" : x.status} /></>} />
|
||||
<ServersNav active="/servers/installs" />
|
||||
<Message msg={msg} />
|
||||
{/* Hub 2.6.0: whether the site has registered with the Hub (its banners, licence and heartbeats need it). */}
|
||||
@@ -228,14 +262,52 @@ export default function DeploymentPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Hub 2.12.0: gone from its server without the Hub (uninstalled by hand, server rebuilt …). */}
|
||||
{d.stale.stale && (
|
||||
<form className="card grid gap-3 border-red-200 md:grid-cols-[1fr_auto] md:items-end" onSubmit={e => { e.preventDefault(); removeFromHub(); }}>
|
||||
<div className="md:col-span-2">
|
||||
<h2 className="font-medium text-red-800">Remove from the Hub</h2>
|
||||
<p className="mt-1 text-sm text-slate-500">No heartbeat since {d.stale.since ? `${fmtDate(d.stale.since)} (${ago(d.stale.since)})` : "it was made"}. If the site is no longer on {x.server.name} (uninstalled by hand, or the server was rebuilt), remove it here: nothing runs on the server, what was planned for it is cancelled, its ports are freed after 30 days and its licence's heartbeats are refused. If it's still there, uninstall it instead.</p>
|
||||
</div>
|
||||
<div><label className="label" htmlFor="f-c">Type {x.shortName}</label><input id="f-c" className="input" value={forget} onChange={e => setForget(e.target.value)} /></div>
|
||||
<button className="btn-danger" disabled={forget !== x.shortName || busy}>Remove from the Hub</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{["live", "waiting_for_proxy"].includes(x.status) && (
|
||||
<form className="card grid gap-3 border-red-200 md:grid-cols-3" onSubmit={e => { e.preventDefault(); if (window.confirm(`Uninstall ${x.shortName} on ${un.at.replace("T", " ")}? The church gets its data first.`)) act(`/api/admin/deployments/${x.id}/uninstall`, { at: fromInput(un.at), totp: un.totp, confirm: un.confirm }, "Uninstall planned: the site admin was emailed and sees a banner. The export runs first."); }}>
|
||||
<h2 className="font-medium text-red-800 md:col-span-3">Uninstall</h2>
|
||||
<p className="text-sm text-slate-500 md:col-span-3">At the time: the church's data is exported (encrypted; the link goes to the site admin), then the site, its tunnels and database are removed. The final backup stays on the server for 30 days.</p>
|
||||
<div><label className="label" htmlFor="x-at">When</label><input id="x-at" type="datetime-local" className="input" value={un.at} onChange={e => setUn({ ...un, at: e.target.value })} /></div>
|
||||
<form className="card grid gap-3 border-red-200 md:grid-cols-3" onSubmit={e => {
|
||||
e.preventDefault();
|
||||
const together = joining && joinable;
|
||||
const when = together ? fmtDate(together.notBefore) : un.at.replace("T", " ");
|
||||
if (!window.confirm(`Uninstall ${productName(x.product)} of ${x.shortName} on ${when}${together ? `, together with ${together.products!.map(productName).join(" and ")}` : ""}?${lastNow ? ` It's the church's last product here, so the whole church goes.` : ""} The church gets its data first.`)) return;
|
||||
act(`/api/admin/deployments/${x.id}/uninstall`, { at: together ? undefined : fromInput(un.at), totp: un.totp, confirm: un.confirm, ...(pendingRuns.length ? { join: !!together, joinJobId: together ? together.jobId : undefined } : {}) },
|
||||
together ? "Added to that uninstall: one export and one uninstall for both. The site admin was emailed and sees a banner." : "Uninstall planned: the site admin was emailed and sees a banner. The export runs first.");
|
||||
}}>
|
||||
<h2 className="font-medium text-red-800 md:col-span-3">Uninstall {productName(x.product)}</h2>
|
||||
<p className="text-sm text-slate-500 md:col-span-3">At the time: {productName(x.product)}'s data is exported (encrypted; the link goes to the site admin), then {x.domain}, its tunnels and database are removed. The final backup stays on the server for 30 days.{plan.onlyThisProduct && plan.others.length > 0 && !plan.lastProduct && <> The church keeps {plan.others.map(o => `${productName(o.product)} (${o.domain})`).join(" and ")}.</>}</p>
|
||||
{/* Hub 2.12.0: another product of the church is already planned for uninstall. */}
|
||||
{plan.onlyThisProduct && pendingRuns.length > 0 && (
|
||||
<fieldset className="space-y-2 rounded-lg border border-slate-200 p-3 text-sm md:col-span-3">
|
||||
<legend className="px-1 font-medium">{pendingRuns.map(p => `${p.products!.map(productName).join(" and ")} on ${fmtDate(p.notBefore)}`).join("; ")}: already planned for uninstall</legend>
|
||||
<label className={`flex items-start gap-2 ${joinable ? "" : "text-slate-400"}`}>
|
||||
<input type="radio" name="x-join" className="mt-1" checked={joining && !!joinable} disabled={!joinable} onChange={() => setJoining(true)} />
|
||||
<span>Add {productName(x.product)} to that uninstall{joinable ? ` on ${fmtDate(joinable.notBefore)}` : ""}: one export and one uninstall for both{plan.lastProduct ? ", which removes the whole church" : ""}.{!joinable && " (Not possible: it has already started.)"}{joinable && new Date(joinable.notBefore).getTime() - Date.now() < 4 * H && " (Under 4 hours away: the church wouldn't get notice in time, so the Hub will refuse.)"}</span>
|
||||
</label>
|
||||
<label className="flex items-start gap-2">
|
||||
<input type="radio" name="x-join" className="mt-1" checked={!joining || !joinable} onChange={() => setJoining(false)} />
|
||||
<span>At its own time (below).{plan.lastProduct && " It's then the church's last product here, so it removes the whole church (its folder and app user) when it runs."}</span>
|
||||
</label>
|
||||
</fieldset>
|
||||
)}
|
||||
{plan.onlyThisProduct && plan.lastProduct && !pendingRuns.length && <p className="text-sm text-slate-600 md:col-span-3">This is the church's last product here: the uninstall removes the whole church (its folder and app user).</p>}
|
||||
{wholeChurch && <p className="text-sm font-medium text-red-800 md:col-span-3">The agent on {x.server.name} is {x.server.agentVersion || "an unknown version"}: it can only remove the whole church, with {plan.others.map(o => productName(o.product)).join(" and ")}. Update the agent to {plan.minAgent} or later first.</p>}
|
||||
{accountsInUse && <p className="text-sm font-medium text-amber-800 md:col-span-3">{othersStaying.map(o => productName(o.product)).join(" and ")} signs in through Accounts: uninstall {othersStaying.length === 1 ? "it" : "them"} first, then Accounts (at the same time or later).</p>}
|
||||
{joining && joinable
|
||||
? <div><span className="label">When</span><p className="mt-2 text-sm">{fmtDate(joinable.notBefore)}, with {joinable.products!.map(productName).join(" and ")}</p></div>
|
||||
: <div><label className="label" htmlFor="x-at">When</label><input id="x-at" type="datetime-local" className="input" value={un.at} onChange={e => setUn({ ...un, at: e.target.value })} /></div>}
|
||||
<div><label className="label" htmlFor="x-c">Type {x.shortName}</label><input id="x-c" className="input" required value={un.confirm} onChange={e => setUn({ ...un, confirm: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="x-t">Two-factor code</label><input id="x-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={un.totp} onChange={e => setUn({ ...un, totp: e.target.value })} /></div>
|
||||
<div className="md:col-span-3"><button className="btn-danger" disabled={un.confirm !== x.shortName || busy}>Plan the uninstall</button></div>
|
||||
<div className="md:col-span-3"><button className="btn-danger" disabled={un.confirm !== x.shortName || busy || wholeChurch || accountsInUse}>Plan the uninstall</button></div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ago } from "@/lib/format";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import { Loading, Message, PageTitle, Pager, SearchInput } from "@/components/ui";
|
||||
import { ServersNav, StatusPill, pct, type Deployment, type ServerSummary } from "@/components/servers";
|
||||
import { ServersNav, StatusPill, pct, shownStatus, type Deployment, type ServerSummary } from "@/components/servers";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
type Customer = { id: string; name: string; domain?: string | null };
|
||||
@@ -162,7 +162,7 @@ export default function InstallsPage() {
|
||||
<table className="w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-4 py-1">Church</th><th>Product</th><th>Domain</th><th>Server</th><th>Version</th><th>Last heartbeat</th><th>Status</th></tr></thead>
|
||||
<tbody>{paged.rows.map(d => (
|
||||
<tr key={d.id} className="border-t"><td className="px-4 py-1.5"><Link className="text-indigo-700 hover:underline" href={`/servers/installs/${d.id}`}>{d.customer?.name} ({d.shortName})</Link>{d.isDemo && <span className="ml-1 rounded bg-sky-100 px-1.5 text-xs text-sky-800">demo</span>}</td><td>{PRODUCT_NAMES[d.product as keyof typeof PRODUCT_NAMES] || d.product}</td><td>{d.domain}</td><td>{d.server?.name}</td><td>{d.install?.version || d.version || "–"}</td><td>{d.installId ? ago(d.install?.lastHeartbeatAt) : <span className="text-amber-800">not registered</span>}</td><td><StatusPill status={d.status} /></td></tr>
|
||||
<tr key={d.id} className="border-t"><td className="px-4 py-1.5"><Link className="text-indigo-700 hover:underline" href={`/servers/installs/${d.id}`}>{d.customer?.name} ({d.shortName})</Link>{d.isDemo && <span className="ml-1 rounded bg-sky-100 px-1.5 text-xs text-sky-800">demo</span>}</td><td>{PRODUCT_NAMES[d.product as keyof typeof PRODUCT_NAMES] || d.product}</td><td>{d.domain}</td><td>{d.server?.name}</td><td>{d.install?.version || d.version || "–"}</td><td>{d.installId ? ago(d.install?.lastHeartbeatAt) : <span className="text-amber-800">not registered</span>}</td><td><StatusPill status={shownStatus(d)} /></td></tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
{!list.length ? <p className="px-4 py-3 text-sm text-slate-500">No installs on servers yet.</p> : !shown.length && <p className="px-4 py-3 text-sm text-slate-500">No installs match.</p>}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { Plus, X } from "lucide-react";
|
||||
|
||||
/** The addresses in a stored value ("a@x.org, b@x.org"). */
|
||||
export const emailsOf = (value: string | null | undefined) => String(value || "").split(/[\s,;]+/).map(s => s.trim()).filter(Boolean);
|
||||
|
||||
/**
|
||||
* Hub 2.12.0: one or more email addresses, one per row, with + to add another. The value is the
|
||||
* comma-separated list the API stores ("a@x.org, b@x.org"); empty rows are dropped when saved.
|
||||
*/
|
||||
export function EmailList({ id, label, value, onChange, placeholder, max = 10 }: {
|
||||
id: string; label: string; value: string; onChange: (v: string) => void; placeholder?: string; max?: number;
|
||||
}) {
|
||||
// Keep an empty row while typing: split on commas only, so a half-typed address stays put.
|
||||
const rows = value === "" ? [""] : value.split(",").map(s => s.trim());
|
||||
const set = (next: string[]) => onChange(next.join(", "));
|
||||
return (
|
||||
<div>
|
||||
<label className="label" htmlFor={`${id}-0`}>{label}</label>
|
||||
<div className="space-y-2">
|
||||
{rows.map((r, i) => (
|
||||
<div key={i} className="flex gap-2">
|
||||
<input id={`${id}-${i}`} type="email" className="input" value={r} placeholder={i === 0 ? placeholder : "another@church.org"}
|
||||
aria-label={i === 0 ? undefined : `${label} ${i + 1}`}
|
||||
onChange={e => set(rows.map((x, j) => (j === i ? e.target.value.replace(/[,;\s]/g, "") : x)))} />
|
||||
{rows.length > 1 && (
|
||||
<button type="button" className="btn-secondary px-2" aria-label={`Remove ${r || "this address"}`} onClick={() => set(rows.filter((_, j) => j !== i))}><X className="h-4 w-4" /></button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{rows.length < max && (
|
||||
<button type="button" className="mt-2 inline-flex items-center gap-1 text-sm text-indigo-600 hover:underline" onClick={() => set([...rows, ""])}>
|
||||
<Plus className="h-4 w-4" /> Add another address
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { fmtDate } from "@/lib/format";
|
||||
import { CYCLE, EMAIL_KIND, METHOD, StateBadge, centsFrom, day, money, randInput, todayYmd, type BillingCycle, type BillingEmail, type Invoice, type LicenceChange, type Line, type Payment, type PlanChange } from "@/lib/billing";
|
||||
import { PRODUCT_NAMES, byProduct, type Product } from "@/lib/products";
|
||||
import { RecordPayment } from "./RecordPayment";
|
||||
import { EmailList } from "@/components/EmailList";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
/** A plan of a product: the Events tiers have an income ceiling (upTo), the App tiers a member band. */
|
||||
@@ -303,7 +304,10 @@ export function CustomerBilling({ customerId }: { customerId: string }) {
|
||||
<div><label className="label" htmlFor="f-note">Note</label><input id="f-note" className="input" value={form.foundingNote} onChange={e => setForm({ ...form, foundingNote: e.target.value })} placeholder="e.g. Founding church 3 of 10" /></div>
|
||||
</div>
|
||||
)}
|
||||
<div><label className="label" htmlFor="b-email">Billing email</label><input id="b-email" type="email" className="input" value={form.billingEmail} onChange={e => setForm({ ...form, billingEmail: e.target.value })} placeholder={c.sendsTo || ""} /><p className="mt-1 text-xs text-slate-500">Blank: the site's admin contact, then the customer's email. Now going to {c.sendsTo || "nobody (add one)"}.</p></div>
|
||||
<div>
|
||||
<EmailList id="b-email" label="Billing email" value={form.billingEmail} onChange={billingEmail => setForm({ ...form, billingEmail })} placeholder={c.sendsTo || "accounts@church.org"} />
|
||||
<p className="mt-1 text-xs text-slate-500">Invoices, statements and receipts go to every address here. Blank: the site's admin contact, then the customer's email. Now going to {c.sendsTo || "nobody (add one)"}.</p>
|
||||
</div>
|
||||
<div><label className="label" htmlFor="b-addr">Postal address (on invoices)</label><textarea id="b-addr" className="input" rows={2} value={form.billingAddress} onChange={e => setForm({ ...form, billingAddress: e.target.value })} /></div>
|
||||
<button className="btn-secondary">Save billing details</button>
|
||||
</form>
|
||||
|
||||
@@ -49,6 +49,8 @@ const STATUS: Record<string, [string, string]> = {
|
||||
// deployments
|
||||
installing: ["Installing", "blue"], waiting_for_proxy: ["Waiting for proxy", "amber"], live: ["Live", "green"], failed: ["Failed", "red"],
|
||||
uninstalling: ["Uninstalling", "amber"], removed: ["Removed", "grey"],
|
||||
// 2.12.0: on the Hub as live, but no heartbeat for 24 hours
|
||||
stale: ["No heartbeat", "red"],
|
||||
// servers: busy = running a job the Hub handed it (agents before 1.1.1 go quiet then)
|
||||
busy: ["Running a job", "blue"],
|
||||
// jobs
|
||||
@@ -64,6 +66,19 @@ export function StatusPill({ status }: { status: string }) {
|
||||
return <span className={`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ring-1 ring-inset ${TONE[tone]}`}>{label}</span>;
|
||||
}
|
||||
|
||||
/** Hub 2.12.0: an install can be removed from the Hub after this long without a heartbeat. */
|
||||
export const STALE_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
/** When an install was last heard from: its last heartbeat, else when it went live or was made (as the Hub counts it). */
|
||||
export const lastHeardAt = (d: Deployment) => d.install?.lastHeartbeatAt || d.liveAt || d.createdAt || null;
|
||||
|
||||
/** The status to show: "stale" for an install still on the Hub that's sent nothing for 24 hours. */
|
||||
export function shownStatus(d: Deployment, now = Date.now()) {
|
||||
if (["removed", "failed", "installing"].includes(d.status)) return d.status;
|
||||
const at = lastHeardAt(d);
|
||||
return at && now - new Date(at).getTime() >= STALE_MS ? "stale" : d.status;
|
||||
}
|
||||
|
||||
export const pct = (n: number | null | undefined) => (n == null ? "–" : `${Math.round(n)}%`);
|
||||
|
||||
// <input type="datetime-local"> works in the browser's time; the API takes ISO.
|
||||
|
||||
@@ -40,6 +40,8 @@ export type Customer = {
|
||||
phone: string | null;
|
||||
notes: string | null;
|
||||
createdAt: string;
|
||||
/** Hub 2.12.0: archived (left out of the customer list until restored). */
|
||||
archivedAt?: 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