"use client"; import React, { useEffect, useState } from "react"; import Link from "next/link"; 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 (with "Not now"). * The provider's own notices are ProviderNotices. */ export function LicenceBanner() { const { user, token } = useAuth(); const [status, setStatus] = useState(null); const [busy, setBusy] = useState(false); const isAdmin = user?.role === "admin"; useEffect(() => { if (!isAdmin || !token) return; apiFetch("/api/hub/status", { authToken: token }).then(setStatus).catch(() => {}); }, [isAdmin, token]); if (!isAdmin || !status) return null; const link = Licence settings; if (status.state === "grace") { return (
Licence needs renewing — {status.daysLeft} day{status.daysLeft === 1 ? "" : "s"} left. {link}
); } if (status.state === "suspended" || status.state === "revoked") { return (
The licence is {status.state === "revoked" ? "revoked" : "suspended"}: the site is read-only — events can't be created or edited, and no new registrations or payments. Tickets still scan and all data can be exported. {link}
); } if (status.state === "unlicensed" && status.readOnly) { return (
This site has no licence, so it's read-only — events can't be created or edited. Connect your licence key in {link}
); } // 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 (
Cross Events {status.latestVersion} fixes a security problem or a serious bug (this site runs {status.version}). Please request the update in {link}
); } if (status.updateAvailable && !status.updateRequest && !status.updateSnoozed) { const notNow = async () => { setBusy(true); try { setStatus(await apiFetch("/api/hub/update-snooze", { method: "POST", authToken: token, body: { snooze: true } })); } catch { /* the Licence page shows why */ } setBusy(false); }; return (
Cross Events {status.latestVersion} is available (this site runs {status.version}). See what's new and request it in {link}
); } return null; }