Archived
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:
@@ -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