"use client"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import { ShieldAlert, KeyRound, ArrowUpCircle } 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. */ export function LicenceBanner() { const { user, token } = useAuth(); const [status, setStatus] = useState(null); 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. if (status.updateAvailable && !status.updateRequest) { return (
Cross Events {status.latestVersion} is available (this site runs {status.version}). Request the update in {link}
); } return null; }