Licence page: what's new, withdraw request, Not now, provider notices
- Site settings -> Licence shows the release notes for every newer version from the Hub; urgent (security/serious) updates are marked and can't be put off. - Withdraw an update request (the provider is told through the Hub). - "Not now" on the banner or Licence page hides update reminders until the next version. - Notices from the provider show as a dashboard banner for site admins and supervisors, in their time window, and on the Licence page. - New audit actions (migration), API docs, help, protocol doc, tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { KeyRound, RefreshCw, ShieldCheck, ShieldAlert, ArrowUpCircle } from "lucide-react";
|
||||
import { KeyRound, RefreshCw, ShieldCheck, ShieldAlert, ArrowUpCircle, Undo2, BellOff, BellRing, Megaphone } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
@@ -21,9 +21,39 @@ export type HubStatus = {
|
||||
version: string;
|
||||
latestVersion: string | null;
|
||||
updateAvailable: boolean;
|
||||
urgentUpdate: boolean;
|
||||
updateSnoozed: boolean;
|
||||
releases: HubRelease[];
|
||||
updateRequest: { requestedAt: string; version: string } | null;
|
||||
notices: HubNotice[];
|
||||
};
|
||||
|
||||
export type HubRelease = { version: string; releasedAt: string | null; urgent: boolean; notes: string };
|
||||
export type HubNotice = { id: string; level: "info" | "maintenance" | "warning"; title: string; message: string; startsAt: string | null; endsAt: string | null; updatedAt: string | null };
|
||||
|
||||
/** Release notes from the provider: lines starting with "- " are a list, the rest paragraphs. */
|
||||
export function ReleaseNotes({ notes }: { notes: string }) {
|
||||
const blocks: ({ list: false; text: string } | { list: true; items: string[] })[] = [];
|
||||
for (const raw of notes.split(/\r?\n/)) {
|
||||
const line = raw.trim();
|
||||
if (!line) continue;
|
||||
const item = /^[-*•]\s+(.*)$/.exec(line);
|
||||
const last = blocks[blocks.length - 1];
|
||||
if (item) {
|
||||
if (last?.list) last.items.push(item[1]);
|
||||
else blocks.push({ list: true, items: [item[1]] });
|
||||
} else blocks.push({ list: false, text: line });
|
||||
}
|
||||
if (!blocks.length) return <p className="text-gray-400 italic">No details given.</p>;
|
||||
return (
|
||||
<div className="space-y-1.5 text-gray-700">
|
||||
{blocks.map((b, i) => (b.list
|
||||
? <ul key={i} className="list-disc pl-5 space-y-0.5">{b.items.map((t, j) => <li key={j}>{t}</li>)}</ul>
|
||||
: <p key={i}>{b.text}</p>))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const STATE: Record<HubStatus["state"], { label: string; tone: string; text: string }> = {
|
||||
active: { label: "Active", tone: "bg-green-50 text-green-800 border-green-200", text: "Everything works." },
|
||||
grace: { label: "Needs renewing", tone: "bg-amber-50 text-amber-900 border-amber-200", text: "Everything still works for now — renew before the grace period ends." },
|
||||
@@ -94,18 +124,25 @@ export function LicenceTab({ active }: { active: boolean }) {
|
||||
}
|
||||
};
|
||||
|
||||
const requestUpdate = async () => {
|
||||
// Request, withdraw, "Not now" and "remind me again" all return the new status.
|
||||
const updateAction = async (path: string, body: unknown, ok: string) => {
|
||||
setBusy(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
setStatus(await apiFetch<HubStatus>("/api/hub/update-request", { method: "POST", authToken: token }));
|
||||
setMsg({ type: "ok", text: "Update requested. Your provider has been told and will update the site." });
|
||||
setStatus(await apiFetch<HubStatus>(path, { method: "POST", authToken: token, body }));
|
||||
setMsg({ type: "ok", text: ok });
|
||||
} catch (e) {
|
||||
setMsg({ type: "err", text: errorMessage(e) || "The Hub could not be reached." });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const requestUpdate = () => updateAction("/api/hub/update-request", undefined, "Update requested. Your provider has been told and will update the site.");
|
||||
const withdrawRequest = () => {
|
||||
if (!confirm("Withdraw the update request? Your provider is told not to update the site for now.")) return;
|
||||
updateAction("/api/hub/update-request/cancel", undefined, "Update request withdrawn. Your provider has been told.");
|
||||
};
|
||||
const snooze = (on: boolean) => updateAction("/api/hub/update-snooze", { snooze: on }, on ? "Got it — no more reminders until the next version comes out." : "Update reminders are back on.");
|
||||
|
||||
if (!status) return msg ? <p className="text-sm text-red-700">{msg.text}</p> : <p className="text-sm text-gray-400">Loading…</p>;
|
||||
const st = STATE[status.state];
|
||||
@@ -162,22 +199,78 @@ export function LicenceTab({ active }: { active: boolean }) {
|
||||
<div className="border rounded-xl p-4 text-sm">
|
||||
<div className="flex items-center gap-2 font-medium text-gray-900 mb-1"><ArrowUpCircle className="w-4 h-4" /> Version</div>
|
||||
<p>This site runs Cross Events <strong>{status.version}</strong>.{status.latestVersion && !status.updateAvailable && " It's up to date."}</p>
|
||||
{status.updateAvailable && (status.updateRequest ? (
|
||||
<p className="mt-1 text-gray-600">
|
||||
Version {status.latestVersion} is available. Update requested on {fmt(status.updateRequest.requestedAt)} — your provider will install it.
|
||||
</p>
|
||||
) : (
|
||||
<div className="mt-2 flex flex-wrap items-center gap-3">
|
||||
<p className="text-brand-700">Version {status.latestVersion} is available.</p>
|
||||
{status.connected && (
|
||||
<button onClick={requestUpdate} disabled={busy} className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">
|
||||
<ArrowUpCircle className="w-4 h-4" /> {busy ? "Requesting…" : "Request update"}
|
||||
</button>
|
||||
{status.updateAvailable && (
|
||||
<div className="mt-2 space-y-3">
|
||||
{status.urgentUpdate && (
|
||||
<p className="flex items-start gap-2 rounded-lg border border-red-200 bg-red-50 p-3 text-red-800">
|
||||
<ShieldAlert className="w-4 h-4 mt-0.5 shrink-0" />
|
||||
<span>This update fixes a security problem or a serious bug. Please ask for it soon.</span>
|
||||
</p>
|
||||
)}
|
||||
{status.updateRequest ? (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<p className="text-gray-600">Version {status.latestVersion} is available. Update requested on {fmt(status.updateRequest.requestedAt)} — your provider will install it.</p>
|
||||
{status.connected && (
|
||||
<button onClick={withdrawRequest} disabled={busy} className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border text-sm hover:bg-gray-50 disabled:opacity-50">
|
||||
<Undo2 className="w-4 h-4" /> Withdraw request
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<p className="text-brand-700">Version {status.latestVersion} is available.{status.updateSnoozed && <span className="text-gray-500"> You chose "Not now", so there are no reminders until the next version.</span>}</p>
|
||||
{status.connected && (
|
||||
<button onClick={requestUpdate} disabled={busy} className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">
|
||||
<ArrowUpCircle className="w-4 h-4" /> {busy ? "Working…" : "Request update"}
|
||||
</button>
|
||||
)}
|
||||
{!status.urgentUpdate && (status.updateSnoozed ? (
|
||||
<button onClick={() => snooze(false)} disabled={busy} className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border text-sm hover:bg-gray-50 disabled:opacity-50">
|
||||
<BellRing className="w-4 h-4" /> Remind me again
|
||||
</button>
|
||||
) : (
|
||||
<button onClick={() => snooze(true)} disabled={busy} className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border text-sm hover:bg-gray-50 disabled:opacity-50">
|
||||
<BellOff className="w-4 h-4" /> Not now
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{status.releases.length > 0 && (
|
||||
<div className="border-t pt-3">
|
||||
<h3 className="font-medium text-gray-900 mb-2">What's new</h3>
|
||||
<div className="space-y-4">
|
||||
{status.releases.map(r => (
|
||||
<div key={r.version}>
|
||||
<div className="flex flex-wrap items-center gap-2 mb-1">
|
||||
<span className="font-semibold">{r.version}</span>
|
||||
{r.urgent && <span className="inline-flex items-center gap-1 rounded-full bg-red-50 border border-red-200 px-2 py-0.5 text-xs font-medium text-red-700"><ShieldAlert className="w-3 h-3" /> Security or urgent fix</span>}
|
||||
{r.releasedAt && <span className="text-xs text-gray-500">{new Date(r.releasedAt).toLocaleDateString(undefined, { day: "numeric", month: "short", year: "numeric" })}</span>}
|
||||
</div>
|
||||
<ReleaseNotes notes={r.notes} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
)}
|
||||
</div>
|
||||
|
||||
{status.notices.length > 0 && (
|
||||
<div className="border rounded-xl p-4 text-sm">
|
||||
<div className="flex items-center gap-2 font-medium text-gray-900 mb-2"><Megaphone className="w-4 h-4" /> From your provider</div>
|
||||
<div className="space-y-3">
|
||||
{status.notices.map(n => (
|
||||
<div key={n.id}>
|
||||
<p className="font-medium">{n.title}</p>
|
||||
<p className="text-gray-700 whitespace-pre-line">{n.message}</p>
|
||||
{n.endsAt && <p className="text-xs text-gray-500 mt-0.5">Until {fmt(n.endsAt)}</p>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{msg && <div className={`p-3 rounded-lg text-sm ${msg.type === "ok" ? "bg-green-50 text-green-800 border border-green-200" : "bg-red-50 text-red-800 border border-red-200"}`}>{msg.text}</div>}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { ShieldAlert, KeyRound, ArrowUpCircle } from "lucide-react";
|
||||
import { ShieldAlert, KeyRound, ArrowUpCircle, BellOff } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import type { HubStatus } from "@/components/admin/LicenceTab";
|
||||
|
||||
/**
|
||||
* Licence and update notices for **site admins only** (never supervisors, staff, users or the
|
||||
* public site): grace period, suspended/revoked, not connected, update available.
|
||||
* public site): grace period, suspended/revoked, not connected, update available (with "Not now").
|
||||
* The provider's own notices are ProviderNotices.
|
||||
*/
|
||||
export function LicenceBanner() {
|
||||
const { user, token } = useAuth();
|
||||
const [status, setStatus] = useState<HubStatus | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const isAdmin = user?.role === "admin";
|
||||
|
||||
useEffect(() => {
|
||||
@@ -50,12 +52,31 @@ export function LicenceBanner() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
// Once an update has been requested there's nothing more for the admin to do.
|
||||
if (status.updateAvailable && !status.updateRequest) {
|
||||
// Once an update has been requested there's nothing more for the admin to do. "Not now" hides it
|
||||
// until the next version, except for urgent (security or serious bug) updates.
|
||||
if (status.urgentUpdate && !status.updateRequest) {
|
||||
return (
|
||||
<div role="status" className="bg-brand-50 border-b border-brand-100 text-brand-800 text-sm px-4 py-2 flex items-center gap-2">
|
||||
<ArrowUpCircle className="w-4 h-4 shrink-0" />
|
||||
<span>Cross Events {status.latestVersion} is available (this site runs {status.version}). Request the update in {link}</span>
|
||||
<div role="alert" className="bg-red-50 border-b border-red-200 text-red-800 text-sm px-4 py-2 flex items-center gap-2">
|
||||
<ShieldAlert className="w-4 h-4 shrink-0" />
|
||||
<span>Cross Events {status.latestVersion} fixes a security problem or a serious bug (this site runs {status.version}). Please request the update in {link}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (status.updateAvailable && !status.updateRequest && !status.updateSnoozed) {
|
||||
const notNow = async () => {
|
||||
setBusy(true);
|
||||
try { setStatus(await apiFetch<HubStatus>("/api/hub/update-snooze", { method: "POST", authToken: token, body: { snooze: true } })); } catch { /* the Licence page shows why */ }
|
||||
setBusy(false);
|
||||
};
|
||||
return (
|
||||
<div role="status" className="bg-brand-50 border-b border-brand-100 text-brand-800 text-sm px-4 py-2 flex flex-wrap items-center gap-x-3 gap-y-1">
|
||||
<span className="flex items-center gap-2">
|
||||
<ArrowUpCircle className="w-4 h-4 shrink-0" />
|
||||
<span>Cross Events {status.latestVersion} is available (this site runs {status.version}). See what's new and request it in {link}</span>
|
||||
</span>
|
||||
<button onClick={notNow} disabled={busy} className="ml-auto inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-brand-700 hover:bg-brand-100 disabled:opacity-50" title="Hide this until the next version comes out">
|
||||
<BellOff className="w-3.5 h-3.5" /> Not now
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Info, Wrench, AlertTriangle, X } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import type { HubNotice } from "@/components/admin/LicenceTab";
|
||||
|
||||
const DISMISSED_KEY = "cross_events_dismissed_notices";
|
||||
|
||||
const LEVEL = {
|
||||
info: { icon: Info, tone: "bg-sky-50 border-sky-200 text-sky-900" },
|
||||
maintenance: { icon: Wrench, tone: "bg-amber-50 border-amber-200 text-amber-900" },
|
||||
warning: { icon: AlertTriangle, tone: "bg-red-50 border-red-200 text-red-800" },
|
||||
} as const;
|
||||
|
||||
// A notice the provider edits shows again, so it's remembered by id and last change.
|
||||
const noticeKey = (n: HubNotice) => `${n.id}:${n.updatedAt || ""}`;
|
||||
|
||||
function readDismissed(): string[] {
|
||||
try { return JSON.parse(localStorage.getItem(DISMISSED_KEY) || "[]"); } catch { return []; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Notices from the provider (sent by the Cross Events Hub): maintenance, news and so on. Shown to
|
||||
* site admins and supervisors only. Each can be closed on this browser; it's still listed on Site
|
||||
* settings → Licence.
|
||||
*/
|
||||
export function ProviderNotices() {
|
||||
const { user, token } = useAuth();
|
||||
const [notices, setNotices] = useState<HubNotice[]>([]);
|
||||
const [dismissed, setDismissed] = useState<string[]>([]);
|
||||
const canSee = user?.role === "admin" || user?.role === "supervisor";
|
||||
|
||||
useEffect(() => {
|
||||
if (!canSee || !token) return;
|
||||
setDismissed(readDismissed());
|
||||
apiFetch<HubNotice[]>("/api/hub/notices", { authToken: token }).then(setNotices).catch(() => {});
|
||||
}, [canSee, token]);
|
||||
|
||||
if (!canSee) return null;
|
||||
const shown = notices.filter(n => !dismissed.includes(noticeKey(n)));
|
||||
if (!shown.length) return null;
|
||||
|
||||
const dismiss = (n: HubNotice) => {
|
||||
// Keep only notices that still exist, so the list doesn't grow forever.
|
||||
const next = [...dismissed.filter(k => notices.some(x => noticeKey(x) === k)), noticeKey(n)];
|
||||
setDismissed(next);
|
||||
try { localStorage.setItem(DISMISSED_KEY, JSON.stringify(next)); } catch { /* private window: closed until reload */ }
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{shown.map(n => {
|
||||
const { icon: Icon, tone } = LEVEL[n.level] || LEVEL.info;
|
||||
return (
|
||||
<div key={n.id} role={n.level === "warning" ? "alert" : "status"} className={`border-b text-sm px-4 py-2 flex items-start gap-2 ${tone}`}>
|
||||
<Icon className="w-4 h-4 shrink-0 mt-0.5" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<span className="font-medium">{n.title}</span>
|
||||
<span className="whitespace-pre-line"> — {n.message}</span>
|
||||
</div>
|
||||
<button onClick={() => dismiss(n)} className="shrink-0 rounded p-0.5 hover:bg-black/5" aria-label={`Close "${n.title}"`}>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user