Hub 2.15.0: install page as a header and tabs, popups for every action
- Install page (/servers/installs/[id]): header with status, Schedule update and a ⋯ menu (move onto the monorepo, demo site, uninstall, remove from the Hub, remove the record); tiles for site/registration, version, server, ports and last heartbeat. - Tabs: Jobs, Settings (.env), Exports; the tab in the URL (?tab=settings). - Every action is a popup (Update, Adopt, Demo, Uninstall, Remove) using the 2.14.0 Modal: asks before discarding, error by its button. Confirmations unchanged. - EnvPanel: read view in the tab, each file edited in a popup. - Banners for not registered, stale (no heartbeat for a day) and a planned uninstall. - Shared PageMessage (also on the customer page); ModalButtons gets danger/disabled. - Logic split into components/install/ (useSubmit, post with LIVE_EVENT re-confirm, uninstallPlan). Frontend only: no migration, no API changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import type { Release } from "@/lib/types";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { fromInput, toInput } from "@/components/servers";
|
||||
import { ModalButtons } from "@/components/customer/ReadCard";
|
||||
import { H, changed, post, productName, useSubmit, withWarnings, type Done, type Install } from "./shared";
|
||||
|
||||
/**
|
||||
* Schedule an update of one install: at a time at least 4 hours away (the church gets notice), or
|
||||
* an emergency with a reason and a two-factor code, at least 15 minutes away or as soon as possible.
|
||||
*/
|
||||
export function UpdateModal({ x, releases, onClose, onDone }: { x: Install; releases: Release[]; onClose: () => void; onDone: Done }) {
|
||||
const [form0] = useState(() => ({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" }));
|
||||
const [upd, setUpd] = useState(form0);
|
||||
const { busy, error, run } = useSubmit();
|
||||
const asap = upd.emergency && upd.asap;
|
||||
const minAt = upd.emergency ? 15 * 60 * 1000 : 4 * H;
|
||||
const mine = releases.filter(r => r.product === x.product);
|
||||
|
||||
const save = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
run(async () => {
|
||||
const r = await post("/api/admin/updates", { deploymentIds: [x.id], product: x.product, version: upd.version || undefined, at: asap ? undefined : fromInput(upd.at), asap, emergency: upd.emergency, reason: upd.reason || null, totp: upd.totp || null });
|
||||
onDone({ type: "ok", text: withWarnings(asap ? "Started: the agent picks it up within a minute. The site admin was emailed and sees a banner." : "Planned. The site admin was emailed and sees a banner.", r) });
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal title={`Update ${productName(x.product)} of ${x.shortName}`} onClose={onClose} dirty={changed(upd, form0)}>
|
||||
<form onSubmit={save} className="space-y-4">
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<label className="label" htmlFor="u-v">Release</label>
|
||||
<select id="u-v" className="input" value={upd.version} onChange={e => setUpd({ ...upd, version: e.target.value })}>
|
||||
<option value="">Latest</option>
|
||||
{mine.map(r => <option key={r.id} value={r.version}>{r.version}{r.latest ? " (latest)" : ""}{r.requires?.length ? ` · needs ${r.requires.map(q => `${PRODUCT_NAMES[q.product]} ${q.version}`).join(", ")}` : ""}</option>)}
|
||||
</select>
|
||||
<p className="mt-1 text-xs text-slate-500">Now on {x.install?.version || x.version || "an unknown version"}.</p>
|
||||
</div>
|
||||
{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="u-at">When</label>
|
||||
<input id="u-at" type="datetime-local" className="input" value={upd.at} min={toInput(new Date(Date.now() + minAt))} onChange={e => setUpd({ ...upd, at: e.target.value })} />
|
||||
<p className="mt-1 text-xs text-slate-500">At least {upd.emergency ? "15 minutes" : "4 hours"} away, so the church gets notice.</p>
|
||||
</div>}
|
||||
</div>
|
||||
|
||||
<label className="flex items-start gap-2 text-sm"><input type="checkbox" className="mt-1" checked={upd.emergency} onChange={e => setUpd({ ...upd, emergency: e.target.checked })} /> <span>Emergency (security fix or broken release): a reason and your two-factor code</span></label>
|
||||
|
||||
{upd.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="u-when" checked={upd.asap} onChange={() => setUpd({ ...upd, asap: true })} /> As soon as possible (within a minute)</label>
|
||||
<label className="flex items-center gap-2"><input type="radio" name="u-when" checked={!upd.asap} onChange={() => setUpd({ ...upd, 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="u-r">Reason (shown to the church)</label><input id="u-r" className="input" required value={upd.reason} onChange={e => setUpd({ ...upd, reason: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="u-t">Two-factor code</label><input id="u-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={upd.totp} onChange={e => setUpd({ ...upd, totp: e.target.value })} /></div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<FormError error={error} />
|
||||
<ModalButtons busy={busy} busyLabel="Working…" onCancel={onClose} danger={upd.emergency} label={asap ? "Update now" : "Schedule"} />
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user