- components/ReleaseSelect.tsx: Latest (with its version) first, then the newest 10 releases, Show older versions for the rest; marked latest, running now and what each needs. - New install and Move onto the monorepo use it (they were free text); the install's Update popup and the Updates page use it too. Move onto the monorepo lists Events from 2.2.0 (the first monorepo tag). - docs/VERSION-PICKERS-PLAN.md: this and 2.19.0 (agent releases). Frontend only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
4.6 KiB
TypeScript
70 lines
4.6 KiB
TypeScript
"use client";
|
|
|
|
import React, { useState } from "react";
|
|
import type { Release } from "@/lib/types";
|
|
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
|
import { fromInput, toInput } from "@/components/servers";
|
|
import { ReleaseSelect } from "@/components/ReleaseSelect";
|
|
import { H, changed, post, productName, 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>
|
|
<ReleaseSelect id="u-v" releases={mine} value={upd.version} onChange={version => setUpd({ ...upd, version })} current={x.install?.version || x.version} />
|
|
<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>
|
|
);
|
|
}
|