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:
@@ -3,11 +3,11 @@
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useParams } from "next/navigation";
|
||||
import { KeyRound, X } from "lucide-react";
|
||||
import { KeyRound } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { PRODUCTS, byProduct } from "@/lib/products";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { Loading, Message, Tabs } from "@/components/ui";
|
||||
import { Loading, Message, PageMessage, Tabs } from "@/components/ui";
|
||||
import { RecordPayment } from "@/components/billing/RecordPayment";
|
||||
import { OneOffInvoice } from "@/components/billing/OneOffInvoice";
|
||||
import { CustomerHeader, type HeaderAction } from "@/components/customer/CustomerHeader";
|
||||
@@ -70,13 +70,6 @@ export default function CustomerPage() {
|
||||
window.history.replaceState(null, "", t === "overview" ? window.location.pathname : `?tab=${t}`);
|
||||
};
|
||||
|
||||
// An "ok" message fades after a while; an error stays until it's closed or replaced.
|
||||
useEffect(() => {
|
||||
if (msg?.type !== "ok") return;
|
||||
const t = setTimeout(() => setMsg(m => (m === msg ? null : m)), 12000);
|
||||
return () => clearTimeout(t);
|
||||
}, [msg]);
|
||||
|
||||
/** Every card and popup reports here: close the popup, show the message, reload. */
|
||||
const done: Done = m => { setPopup(null); setMsg(m); load(); };
|
||||
const close = () => setPopup(null);
|
||||
@@ -101,12 +94,7 @@ export default function CustomerPage() {
|
||||
<>
|
||||
<CustomerHeader c={c} b={b} preview={preview} canAdd={available.length > 0} onAction={onAction} onArchive={setArchivedState} />
|
||||
|
||||
{msg && (
|
||||
<div className="sticky top-2 z-30 mb-4 flex items-start gap-2 [&>div]:flex-1 [&>div]:shadow-sm" role="status">
|
||||
<Message msg={msg} />
|
||||
<button type="button" aria-label="Dismiss" onClick={() => setMsg(null)} className="mt-2.5 rounded p-1 text-slate-400 hover:bg-slate-100 hover:text-slate-700"><X className="h-4 w-4" /></button>
|
||||
</div>
|
||||
)}
|
||||
<PageMessage msg={msg} onClose={() => setMsg(null)} />
|
||||
|
||||
<Tabs tabs={TABS} active={tab} onChange={openTab} />
|
||||
|
||||
|
||||
@@ -3,37 +3,29 @@
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import { api, ApiError, errorText } from "@/lib/api";
|
||||
import { ago, bytes, fmtDate } from "@/lib/format";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { useServerPaged } from "@/lib/paging";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import type { Release } from "@/lib/types";
|
||||
import { Loading, Message, PageTitle, Pager } from "@/components/ui";
|
||||
import { ServersNav, StatusPill, toInput, fromInput, type Deployment, type Job, type ServerSummary } from "@/components/servers";
|
||||
import { Loading, Message, PageMessage, Tabs } from "@/components/ui";
|
||||
import { ServersNav, type Job } from "@/components/servers";
|
||||
import { EnvPanel } from "@/components/EnvPanel";
|
||||
import { InstallHeader, type InstallAction } from "@/components/install/InstallHeader";
|
||||
import { ExportsCard, JobsCard } from "@/components/install/JobsCard";
|
||||
import { UpdateModal } from "@/components/install/UpdateModal";
|
||||
import { AdoptModal } from "@/components/install/AdoptModal";
|
||||
import { DemoModal } from "@/components/install/DemoModal";
|
||||
import { UninstallModal } from "@/components/install/UninstallModal";
|
||||
import { RemoveModal } from "@/components/install/RemoveModal";
|
||||
import { post, productName, running, uninstallPlan, withWarnings, type Detail, type Done, type Msg } from "@/components/install/shared";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
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;
|
||||
};
|
||||
};
|
||||
type Tab = "jobs" | "settings" | "exports";
|
||||
type Popup = Exclude<InstallAction, "undemo"> | null;
|
||||
|
||||
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). */
|
||||
/**
|
||||
* One install on a server (§7–9). Hub 2.15.0: a header with the status and tiles, then Jobs,
|
||||
* Settings (.env) and Exports as tabs; every update, move, demo, uninstall and removal is a popup.
|
||||
*/
|
||||
export default function DeploymentPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const router = useRouter();
|
||||
@@ -41,16 +33,11 @@ export default function DeploymentPage() {
|
||||
const [d, setD] = useState<Detail | null>(null);
|
||||
const [msg, setMsg] = useState<Msg>(warn ? { type: "err", text: warn } : null);
|
||||
const [problems, setProblems] = useState<string[]>([]);
|
||||
const [upd, setUpd] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" });
|
||||
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).
|
||||
const [tab, setTab] = useState<Tab>("jobs");
|
||||
const [popup, setPopup] = useState<Popup>(null);
|
||||
|
||||
// Hub 2.6.0: every job of this install, a page at a time.
|
||||
const jobsPaged = useServerPaged<Job>("/api/admin/jobs", { deploymentId: String(id) }, r => r.jobs as Job[], 20);
|
||||
const load = useCallback(() => {
|
||||
jobsPaged.reload();
|
||||
@@ -60,256 +47,108 @@ export default function DeploymentPage() {
|
||||
useEffect(() => { load(); }, [load]);
|
||||
useEffect(() => { api<Release[]>("/api/admin/releases").then(setReleases).catch(() => {}); }, []);
|
||||
|
||||
// 2.7.1: every button here is off from a click until the Hub answers, so one click is one job.
|
||||
// The tab is in the address (?tab=settings), so a reload or a shared link opens it.
|
||||
useEffect(() => {
|
||||
const q = new URLSearchParams(window.location.search).get("tab");
|
||||
if (q === "settings" || q === "exports") setTab(q);
|
||||
}, []);
|
||||
const openTab = (t: Tab) => {
|
||||
setTab(t);
|
||||
const q = new URLSearchParams(window.location.search);
|
||||
if (t === "jobs") q.delete("tab"); else q.set("tab", t);
|
||||
const s = q.toString();
|
||||
window.history.replaceState(null, "", s ? `?${s}` : window.location.pathname);
|
||||
};
|
||||
|
||||
/** Every popup and card reports here: close the popup, show the message, reload. */
|
||||
const done: Done = m => { setPopup(null); setMsg(m); load(); };
|
||||
const close = () => setPopup(null);
|
||||
|
||||
// 2.7.1: the page's own buttons (proxy done, cancel a job, not a demo) are off from a click until the Hub answers.
|
||||
const [busy, setBusy] = useState(false);
|
||||
const withBusy = async (fn: () => Promise<void>) => {
|
||||
const act = async (fn: () => Promise<Msg>) => {
|
||||
if (busy) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await fn();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const act = async (path: string, body: Record<string, unknown>, ok: string): Promise<void> => {
|
||||
if (busy && !body.confirmLive) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await doAct(path, body, ok);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const doAct = async (path: string, body: Record<string, unknown>, ok: string): Promise<void> => {
|
||||
setMsg(null);
|
||||
try {
|
||||
const r = await api<{ warnings?: string[] }>(path, { method: "POST", body });
|
||||
setMsg({ type: "ok", text: `${ok}${r?.warnings?.length ? ` Note: ${r.warnings.join(" ")}` : ""}` });
|
||||
load();
|
||||
} catch (e) {
|
||||
// Hub 2.7.0: an event is on there now: ask once more, then go ahead.
|
||||
if (e instanceof ApiError && e.code === "LIVE_EVENT" && !body.confirmLive && window.confirm(e.message)) return doAct(path, { ...body, confirmLive: true }, ok);
|
||||
setMsg({ type: "err", text: errorText(e) });
|
||||
}
|
||||
};
|
||||
const proxyDone = () => withBusy(proxyDoneNow);
|
||||
const proxyDoneNow = async () => {
|
||||
setMsg(null);
|
||||
try {
|
||||
const r = await api<{ live: boolean; problems: string[] }>(`/api/admin/deployments/${id}/proxy-done`, { method: "POST" });
|
||||
setProblems(r.problems);
|
||||
setMsg(r.live ? { type: "ok", text: "Live. The site admin got the welcome email." } : { type: "err", text: "The site isn't answering as expected yet:" });
|
||||
load();
|
||||
} catch (e) { setMsg({ type: "err", text: errorText(e) }); }
|
||||
};
|
||||
|
||||
const removeRecord = () => withBusy(removeRecordNow);
|
||||
const removeRecordNow = async () => {
|
||||
if (!d || !window.confirm(`Remove the record of ${d.deployment.shortName}? Its install failed, so nothing of it is on the server.`)) return;
|
||||
setMsg(null);
|
||||
try {
|
||||
await api(`/api/admin/deployments/${id}`, { method: "DELETE" });
|
||||
router.push("/servers/installs");
|
||||
} 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) }); }
|
||||
try { done(await fn()); } catch (e) { setMsg({ type: "err", text: errorText(e) }); } finally { setBusy(false); }
|
||||
};
|
||||
|
||||
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;
|
||||
const plan = uninstallPlan(d);
|
||||
const hasEnv = ["events", "accounts"].includes(x.product) && running(x);
|
||||
const tabs: { key: Tab; label: string }[] = [
|
||||
{ key: "jobs", label: "Jobs" },
|
||||
...(hasEnv ? [{ key: "settings" as const, label: "Settings (.env)" }] : []),
|
||||
...(x.exports.length ? [{ key: "exports" as const, label: `Exports (${x.exports.length})` }] : []),
|
||||
];
|
||||
const shown = tabs.some(t => t.key === tab) ? tab : "jobs";
|
||||
|
||||
const proxyDone = () => act(async () => {
|
||||
const r = await api<{ live: boolean; problems: string[] }>(`/api/admin/deployments/${id}/proxy-done`, { method: "POST" });
|
||||
setProblems(r.problems);
|
||||
return r.live ? { type: "ok", text: "Live. The site admin got the welcome email." } : { type: "err", text: "The site isn't answering as expected yet:" };
|
||||
});
|
||||
const cancelJob = (j: Job) => act(async () => {
|
||||
const r = await post(`/api/admin/jobs/${j.id}/cancel`);
|
||||
return { type: "ok", text: withWarnings("Cancelled; the church was told.", r) };
|
||||
});
|
||||
const onAction = (a: InstallAction) => {
|
||||
if (a === "undemo") {
|
||||
if (!window.confirm(`${x.shortName} won't be a demo site any more: its data can't be replaced from the Hub then.`)) return;
|
||||
act(async () => { await post(`/api/admin/deployments/${x.id}/demo`, { isDemo: false }); return { type: "ok", text: "No longer a demo site." }; });
|
||||
} else setPopup(a);
|
||||
};
|
||||
|
||||
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={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). */}
|
||||
<p className="mt-2 text-sm text-slate-600">
|
||||
{x.install
|
||||
? <>Registered site: <a className="text-indigo-700 hover:underline" href={x.install.url} target="_blank" rel="noreferrer">{x.install.url}</a>, last heartbeat {x.install.lastHeartbeatAt ? ago(x.install.lastHeartbeatAt) : "never"}.</>
|
||||
: <span className="text-amber-800">The site hasn't registered with the Hub yet. It registers by itself with its licence key when it starts, and is tied to this record at its first heartbeat; if that doesn't happen, check its HUB_URL and HUB_LICENCE_KEY.</span>}
|
||||
</p>
|
||||
{!!problems.length && <ul className="mt-2 list-disc pl-6 text-sm text-red-800">{problems.map(p => <li key={p}>{p}</li>)}</ul>}
|
||||
<>
|
||||
<InstallHeader d={d} onAction={onAction} />
|
||||
<ServersNav active="/servers/installs" />
|
||||
|
||||
<PageMessage msg={msg} onClose={() => { setMsg(null); setProblems([]); }} />
|
||||
{!!problems.length && <ul className="-mt-2 mb-4 list-disc pl-6 text-sm text-red-800">{problems.map(p => <li key={p}>{p}</li>)}</ul>}
|
||||
|
||||
<div className="mb-6 space-y-3 empty:hidden">
|
||||
{/* Hub 2.6.0: the site registers with the Hub itself; its banners, licence and heartbeats need it. */}
|
||||
{!x.install && running(x) && (
|
||||
<p className="rounded-lg border border-amber-200 bg-amber-50 p-3 text-sm text-amber-900">The site hasn't registered with the Hub yet. It registers by itself with its licence key when it starts, and is tied to this record at its first heartbeat; if that doesn't happen, check its HUB_URL and HUB_LICENCE_KEY.</p>
|
||||
)}
|
||||
{/* Hub 2.12.0: gone from its server without the Hub (uninstalled by hand, server rebuilt …)? */}
|
||||
{d.stale.stale && (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-900">
|
||||
<span>No heartbeat since {d.stale.since ? fmtDate(d.stale.since) : "it was made"}. If the site is gone from {x.server.name}, remove it from the Hub; if it's still there, uninstall it.</span>
|
||||
<button type="button" className="btn-secondary px-2.5 py-1.5" onClick={() => setPopup("forget")}>Remove from the Hub…</button>
|
||||
</div>
|
||||
)}
|
||||
{plan.planned && (
|
||||
<p className="rounded-lg border border-amber-200 bg-amber-50 p-3 text-sm text-amber-900">
|
||||
Uninstall planned for {fmtDate(plan.planned.notBefore)}{plan.planned.products ? (plan.planned.products.length > 1 ? `, with ${plan.planned.products.filter(p => p !== x.product).map(productName).join(" and ")}` : "") : ": the whole church"}.{" "}
|
||||
<Link className="underline" href={`/jobs/${plan.planned.jobId}`}>See the job</Link> to cancel it.
|
||||
</p>
|
||||
)}
|
||||
{(x.status === "waiting_for_proxy" || x.status === "installing") && (
|
||||
<section className="card space-y-3">
|
||||
<h2 className="font-semibold">Set up the site in FastPanel</h2>
|
||||
<pre className="overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-50 p-3 text-xs">{d.fastPanel}</pre>
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button type="button" className="btn-primary" disabled={x.status !== "waiting_for_proxy" || busy} aria-busy={busy} onClick={proxyDone}>{busy ? "Checking…" : "Proxy done"}</button>
|
||||
{x.status === "installing" && <p className="text-xs text-slate-500">Waiting for the install to finish (see its job under Jobs).</p>}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{(x.status === "waiting_for_proxy" || x.status === "installing") && (
|
||||
<div className="card">
|
||||
<h2 className="font-medium">Set up the site in FastPanel</h2>
|
||||
<pre className="mt-3 overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-50 p-3 text-xs">{d.fastPanel}</pre>
|
||||
<button className="btn-primary mt-3" disabled={x.status !== "waiting_for_proxy" || busy} onClick={proxyDone}>Proxy done</button>
|
||||
{x.status === "installing" && <p className="mt-2 text-xs text-slate-500">Waiting for the install to finish (see its job below).</p>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{x.status === "live" && (
|
||||
<form className="card grid gap-3 md:grid-cols-2" onSubmit={e => { e.preventDefault(); const asap = upd.emergency && upd.asap; act("/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 }, 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."); }}>
|
||||
<h2 className="font-medium md:col-span-2">Schedule an update</h2>
|
||||
<div>
|
||||
<label className="label" htmlFor="u-v">{PRODUCT_NAMES[x.product as keyof typeof PRODUCT_NAMES] || x.product} release</label>
|
||||
<select id="u-v" className="input" value={upd.version} onChange={e => setUpd({ ...upd, version: e.target.value })}>
|
||||
<option value="">Latest</option>
|
||||
{releases.filter(r => r.product === x.product).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>
|
||||
</div>
|
||||
{upd.emergency && upd.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>}
|
||||
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={upd.emergency} onChange={e => setUpd({ ...upd, emergency: e.target.checked })} /> Emergency (security fix or broken release): a reason and your two-factor code</label>
|
||||
{upd.emergency && <>
|
||||
<fieldset className="md:col-span-2 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><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 className="md:col-span-2"><button className="btn-primary" disabled={busy} aria-busy={busy}>{busy ? "Working…" : upd.emergency && upd.asap ? "Update now" : "Schedule"}</button></div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{x.status === "live" && x.install?.version?.startsWith("2.1.") && (
|
||||
<form className="card grid gap-3 md:grid-cols-3" onSubmit={e => { e.preventDefault(); act(`/api/admin/deployments/${x.id}/adopt`, { eventsDir: adopt.eventsDir, version: adopt.version || undefined, address: adopt.address || undefined, at: fromInput(adopt.at) }, "Adopt planned. The site admin was emailed."); }}>
|
||||
<h2 className="font-medium md:col-span-3">Move onto the monorepo (crosscode adopt)</h2>
|
||||
<p className="text-sm text-slate-500 md:col-span-3">Moves the site from its old folder to /var/www/sites/{x.shortName}/events. Same database, uploads, .env and ports; the old folder is kept 14 days for <code>crosscode adopt {x.shortName} --undo</code>.</p>
|
||||
<div><label className="label" htmlFor="a-d">The old install's folder</label><input id="a-d" className="input font-mono" required placeholder="/var/www/hope-events" value={adopt.eventsDir} onChange={e => setAdopt({ ...adopt, eventsDir: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="a-a">The church's address</label><input id="a-a" className="input" required={!x.domain.startsWith("events.")} placeholder={x.domain.startsWith("events.") ? x.domain.slice("events.".length) : "hope.co.za"} value={adopt.address} onChange={e => setAdopt({ ...adopt, address: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="a-v">Release</label><input id="a-v" className="input" placeholder="latest" value={adopt.version} onChange={e => setAdopt({ ...adopt, version: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="a-at">When</label><input id="a-at" type="datetime-local" className="input" value={adopt.at} onChange={e => setAdopt({ ...adopt, at: e.target.value })} /></div>
|
||||
<div className="md:col-span-3"><button className="btn-primary" disabled={busy}>Plan the move</button></div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{/* Hub 2.8.0: the install's .env, and changing it with a restart. */}
|
||||
{["events", "accounts"].includes(x.product) && ["live", "waiting_for_proxy"].includes(x.status) && <EnvPanel deploymentId={x.id} product={x.product} />}
|
||||
|
||||
{x.product === "events" && ["live", "waiting_for_proxy"].includes(x.status) && (
|
||||
<div className="card space-y-3">
|
||||
<h2 className="font-medium">Demo site</h2>
|
||||
{!x.isDemo ? (
|
||||
<form className="grid gap-3 md:grid-cols-[1fr_auto] md:items-end" onSubmit={e => { e.preventDefault(); act(`/api/admin/deployments/${x.id}/demo`, { isDemo: true, confirm: demo.markConfirm }, "Marked as a demo site."); }}>
|
||||
<p className="text-sm text-slate-500 md:col-span-2">A demo site's data can be replaced with demo data from here. Only mark sites used for showing Cross Events, never a church's real site.</p>
|
||||
<div><label className="label" htmlFor="d-m">Type {x.shortName}</label><input id="d-m" className="input" value={demo.markConfirm} onChange={e => setDemo({ ...demo, markConfirm: e.target.value })} /></div>
|
||||
<button className="btn-secondary" disabled={demo.markConfirm !== x.shortName || busy}>Mark as a demo site</button>
|
||||
</form>
|
||||
) : (
|
||||
<>
|
||||
<form className="grid gap-3 md:grid-cols-3 md:items-end" onSubmit={e => { e.preventDefault(); if (window.confirm(`Replace ALL of ${x.shortName}'s data with the "${demo.profile}" demo? A backup is taken first; one admin account is kept.`)) act(`/api/admin/deployments/${x.id}/seed-demo`, { profile: demo.profile, confirm: demo.confirm }, "Queued: the agent loads the demo data on its next poll (see Jobs below). You get an email when it's done."); }}>
|
||||
<p className="text-sm text-slate-500 md:col-span-3">Replaces everything (events, people, payments) with a demo set, keeping the site settings and {x.adminEmail || "the site's first admin"}. Demo logins use the password Demo@1234.</p>
|
||||
<div><label className="label" htmlFor="d-p">Demo</label>
|
||||
<select id="d-p" className="input" value={demo.profile} onChange={e => setDemo({ ...demo, profile: e.target.value })}>
|
||||
<option value="small">Small church: the essentials</option>
|
||||
<option value="events">Events and conferences</option>
|
||||
<option value="ministry">Weekly ministry: courses, kids, volunteers</option>
|
||||
<option value="multicampus">Three campuses</option>
|
||||
</select>
|
||||
</div>
|
||||
<div><label className="label" htmlFor="d-c">Type {x.shortName}</label><input id="d-c" className="input" value={demo.confirm} onChange={e => setDemo({ ...demo, confirm: e.target.value })} /></div>
|
||||
<button className="btn-danger" disabled={demo.confirm !== x.shortName || busy}>Load demo data</button>
|
||||
</form>
|
||||
<button type="button" className="text-sm text-slate-500 underline" onClick={() => act(`/api/admin/deployments/${x.id}/demo`, { isDemo: false }, "No longer a demo site.")}>It isn't a demo site any more</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<h2 className="px-5 pt-5 font-medium">Jobs</h2>
|
||||
<table className="mt-3 w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-5 py-1">Job</th><th>When</th><th>Status</th><th>Result</th><th /></tr></thead>
|
||||
<tbody>{(jobsPaged.rows ?? x.jobs).map(j => (
|
||||
<tr key={j.id} className="border-t">
|
||||
<td className="px-5 py-1.5"><Link className="text-indigo-700 hover:underline" href={`/jobs/${j.id}`}>{j.type}</Link>{j.emergency && <span className="ml-1 text-xs text-red-700">emergency</span>}</td>
|
||||
<td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td><td className="max-w-md truncate text-xs text-slate-500">{j.message}</td>
|
||||
<td className="pr-5">{["queued", "scheduled"].includes(j.status) && <button className="btn-secondary px-2 py-1 text-xs" disabled={busy} onClick={() => act(`/api/admin/jobs/${j.id}/cancel`, {}, "Cancelled; the church was told.")}>Cancel</button>}</td>
|
||||
</tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
<Pager page={jobsPaged.page} pages={jobsPaged.pages} setPage={jobsPaged.setPage} total={jobsPaged.total} pageSize={jobsPaged.pageSize} />
|
||||
<Tabs tabs={tabs} active={shown} onChange={openTab} />
|
||||
<div role="tabpanel" id={`panel-${shown}`} aria-labelledby={`tab-${shown}`}>
|
||||
{shown === "jobs" && <JobsCard paged={jobsPaged} fallback={x.jobs} busy={busy} onCancel={cancelJob} />}
|
||||
{shown === "settings" && <EnvPanel deploymentId={x.id} product={x.product} onMessage={setMsg} />}
|
||||
{shown === "exports" && <ExportsCard exports={x.exports} />}
|
||||
</div>
|
||||
|
||||
{!!x.exports.length && (
|
||||
<div className="card text-sm">
|
||||
<h2 className="font-medium">Exports</h2>
|
||||
{x.exports.map(e => <p key={e.id} className="mt-2">{e.id}: {bytes(e.bytes)}, {e.deletedAt ? `deleted ${fmtDate(e.deletedAt)}` : `until ${fmtDate(e.expiresAt)}`}{e.downloadedAt ? `, downloaded ${fmtDate(e.downloadedAt)}` : ", not downloaded yet"}</p>)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{d.canRemoveRecord && (
|
||||
<div className="card border-red-200">
|
||||
<h2 className="font-medium text-red-800">Remove the record</h2>
|
||||
<p className="mt-1 text-sm text-slate-500">This install failed and the server already removed what it made, so there's nothing to export or uninstall. Removing the record frees the short name.</p>
|
||||
<button className="btn-danger mt-3" disabled={busy} onClick={removeRecord}>Remove the record</button>
|
||||
</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();
|
||||
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 || wholeChurch || accountsInUse}>Plan the uninstall</button></div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
{popup === "update" && <UpdateModal x={x} releases={releases} onClose={close} onDone={done} />}
|
||||
{popup === "adopt" && <AdoptModal x={x} onClose={close} onDone={done} />}
|
||||
{popup === "demo" && <DemoModal x={x} onClose={close} onDone={done} />}
|
||||
{popup === "uninstall" && <UninstallModal x={x} plan={plan} onClose={close} onDone={done} />}
|
||||
{(popup === "record" || popup === "forget") && <RemoveModal kind={popup} x={x} stale={d.stale} onClose={close} onRemoved={() => router.push("/servers/installs")} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user