Hub 2.24.0: update everything at a church to latest

A customer's Sites card has "Update everything to latest": every product
that's behind, in one batch (Accounts first, one at a time, stopping at the
first failure), scheduled or as an emergency, planned whole or not at all.
Later products keep Accounts at the version the batch updates it to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 08:20:21 +02:00
co-authored by Claude Opus 5.5
parent 6ccf492810
commit 2f2e7138ba
11 changed files with 314 additions and 19 deletions
@@ -16,6 +16,7 @@ import { ScheduleCard, ScheduleModal } from "@/components/customer/ScheduleCard"
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 { ProductCard } from "@/components/customer/ProductCard";
import { AddProductModal } from "@/components/customer/AddProductModal";
import { NextInvoiceModal } from "@/components/customer/NextInvoice";
@@ -29,7 +30,7 @@ const TABS: { key: Tab; label: string }[] = [
{ key: "products", label: "Products" },
{ key: "invoices", label: "Invoices and payments" },
];
type Popup = Exclude<HeaderAction, "history"> | "schedule" | null;
type Popup = Exclude<HeaderAction, "history"> | "schedule" | "update" | null;
/** The tab in the address (?tab=products); the old #billing link opens Invoices and payments. */
function tabFromUrl(): Tab {
@@ -103,7 +104,7 @@ export default function CustomerPage() {
<div className="grid gap-4 lg:grid-cols-2">
<div className="space-y-4">
{b && <DetailsCard c={c} b={b} onDone={done} />}
<SitesCard c={c} />
<SitesCard c={c} onUpdateAll={() => setPopup("update")} />
</div>
<div className="space-y-4">
{b && <ScheduleCard b={b} onEdit={() => setPopup("schedule")} />}
@@ -144,6 +145,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 === "update" && <ChurchUpdateModal customerId={id} name={c.name} onClose={close} onDone={done} />}
</>
);
}
@@ -0,0 +1,97 @@
"use client";
import React, { useEffect, useState } from "react";
import { api, errorText } from "@/lib/api";
import { PRODUCT_NAMES } from "@/lib/products";
import { FormError, Loading, Modal, ModalButtons, useSubmit } from "@/components/ui";
import { fromInput, toInput } from "@/components/servers";
import { H, changed, post, withWarnings } from "@/components/install/shared";
import type { Done } from "./shared";
type PlanRow = { id: string; product: keyof typeof PRODUCT_NAMES; domain: string; current: string | null; latest: string | null; behind: boolean; ready: boolean; why: string | null };
/**
* Hub 2.24.0: every product of a church to its latest release, in one batch (Accounts first, one
* at a time, stopping at the first failure). Planned like one install's update: at a time at least
* 4 hours away, or an emergency with a reason and a two-factor code, at least 15 minutes away or
* as soon as possible. Each site's admin is emailed and sees a banner.
*/
export function ChurchUpdateModal({ customerId, name, onClose, onDone }: { customerId: string; name: string; onClose: () => void; onDone: Done }) {
const [plan, setPlan] = useState<PlanRow[] | null>(null);
const [loadError, setLoadError] = useState<string | null>(null);
const [form0] = useState(() => ({ at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" }));
const [f, setF] = useState(form0);
const { busy, error, run } = useSubmit();
useEffect(() => {
api<{ products: PlanRow[] }>(`/api/admin/customers/${customerId}/update-plan`).then(r => setPlan(r.products)).catch(e => setLoadError(errorText(e)));
}, [customerId]);
const asap = f.emergency && f.asap;
const minAt = f.emergency ? 15 * 60 * 1000 : 4 * H;
const todo = plan?.filter(p => p.ready) || [];
const blocked = plan?.filter(p => p.behind && !p.ready) || [];
const save = (e: React.FormEvent) => {
e.preventDefault();
run(async () => {
const r = await post<{ warnings: string[]; updates: unknown[] }>(`/api/admin/customers/${customerId}/update-all`, { at: asap ? undefined : fromInput(f.at), asap, emergency: f.emergency, reason: f.reason || null, totp: f.totp || null });
const n = r.updates.length;
onDone({ type: "ok", text: withWarnings(`${n} product${n === 1 ? "" : "s"} ${asap ? "updating now, one at a time" : "planned, one after the other"}. Each site's admin was emailed and sees a banner.`, r) });
});
};
return (
<Modal title={`Update everything at ${name} to latest`} onClose={onClose} dirty={changed(f, form0)} wide>
{!plan ? (loadError ? <FormError error={loadError} /> : <Loading />) : (
<form onSubmit={save} className="space-y-4">
<ul className="divide-y divide-slate-100 rounded-lg border border-slate-200 text-sm">
{plan.map(p => (
<li key={p.id} className="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5 px-3 py-2">
<span className="min-w-0"><span className="font-medium">{PRODUCT_NAMES[p.product] || p.product}</span> <span className="break-all text-slate-500">{p.domain}</span></span>
{p.ready
? <span className="font-medium text-indigo-700">{p.current || "unknown"} → {p.latest}</span>
: <span className={p.behind ? "text-amber-700" : "text-slate-500"}>{p.current || "unknown"} · {p.why}</span>}
</li>
))}
</ul>
{blocked.length > 0 && <p role="alert" className="text-sm text-amber-800">Some products can&apos;t be updated now (see above). Wait for, or cancel, their update first: nothing is planned until every product that&apos;s behind can be.</p>}
{todo.length === 0 && blocked.length === 0 && <p className="text-sm text-slate-600">Everything is on its latest release already.</p>}
{todo.length > 0 && blocked.length === 0 && (
<>
<p className="text-sm text-slate-600">One at a time, in this order{todo.length > 1 ? `, starting ${asap ? "now" : "at the time below"}` : ""}. If one fails, the rest wait and their admins are told it&apos;s postponed.</p>
{asap
? <div><span className="label">When</span><p className="mt-2 text-sm">As soon as possible: the agent starts within a minute.</p></div>
: <div>
<label className="label" htmlFor="cu-at">When</label>
<input id="cu-at" type="datetime-local" className="input sm:w-64" value={f.at} min={toInput(new Date(Date.now() + minAt))} onChange={e => setF({ ...f, at: e.target.value })} />
<p className="mt-1 text-xs text-slate-500">At least {f.emergency ? "15 minutes" : "4 hours"} away, so the church gets notice.</p>
</div>}
<label className="flex items-start gap-2 text-sm"><input type="checkbox" className="mt-1" checked={f.emergency} onChange={e => setF({ ...f, emergency: e.target.checked })} /> <span>Emergency (security fix or broken release): a reason and your two-factor code</span></label>
{f.emergency && (
<div className="space-y-3 rounded-lg border border-red-200 bg-red-50/40 p-3">
<fieldset className="flex flex-wrap gap-4 text-sm">
<legend className="sr-only">When the emergency update runs</legend>
<label className="flex items-center gap-2"><input type="radio" name="cu-when" checked={f.asap} onChange={() => setF({ ...f, asap: true })} /> As soon as possible (within a minute)</label>
<label className="flex items-center gap-2"><input type="radio" name="cu-when" checked={!f.asap} onChange={() => setF({ ...f, asap: false })} /> At a time, at least 15 minutes away</label>
</fieldset>
<div className="grid gap-3 sm:grid-cols-2">
<div><label className="label" htmlFor="cu-r">Reason (shown to the church)</label><input id="cu-r" className="input" required value={f.reason} onChange={e => setF({ ...f, reason: e.target.value })} /></div>
<div><label className="label" htmlFor="cu-t">Two-factor code</label><input id="cu-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={f.totp} onChange={e => setF({ ...f, totp: e.target.value })} /></div>
</div>
</div>
)}
</>
)}
<FormError error={error} />
<ModalButtons busy={busy} busyLabel="Working…" onCancel={onClose} danger={f.emergency} disabled={todo.length === 0 || blocked.length > 0}
label={asap ? `Update ${todo.length === 1 ? "it" : `all ${todo.length}`} now` : `Schedule ${todo.length === 1 ? "the update" : `${todo.length} updates`}`} />
</form>
)}
</Modal>
);
}
@@ -1,15 +1,20 @@
import React from "react";
import Link from "next/link";
import { RefreshCw } from "lucide-react";
import { ago } from "@/lib/format";
import { PRODUCT_NAMES, byProduct } from "@/lib/products";
import type { Customer } from "@/lib/types";
import { ReadCard } from "@/components/ui";
/** The church's sites: where each product runs and when it last checked in. */
export function SitesCard({ c }: { c: Customer }) {
/**
* The church's sites: where each product runs and when it last checked in. Hub 2.24.0: "Update
* everything to latest" plans each product's latest release (ChurchUpdateModal).
*/
export function SitesCard({ c, onUpdateAll }: { c: Customer; onUpdateAll?: () => void }) {
const sites = [...c.installs].sort((a, b) => (a.releasedAt ? 1 : 0) - (b.releasedAt ? 1 : 0) || byProduct(a, b));
const live = sites.some(s => !s.releasedAt);
return (
<ReadCard title="Sites">
<ReadCard title="Sites" actions={live && onUpdateAll ? <button type="button" className="btn-secondary px-2.5 py-1.5" onClick={onUpdateAll}><RefreshCw className="h-3.5 w-3.5" /> Update everything to latest</button> : null}>
{sites.length === 0 ? <p className="text-sm text-slate-500">No site has registered yet: enter a product&apos;s licence key in its setup.</p> : (
<ul className="divide-y divide-slate-100 text-sm">
{sites.map(s => (