"use client"; import React, { useCallback, useEffect, useState } from "react"; import Link from "next/link"; import { CheckCircle2, Circle, ArrowRight } from "lucide-react"; import { apiFetch } from "@/lib/api"; import { errorMessage } from "@/lib/utils"; type Check = { key: string; label: string; ok: boolean; detail: string; href: string | null; applies: boolean }; type Readiness = { score: number; passed: number; total: number; checks: Check[] }; /** Admin → Privacy → Readiness: a checklist of what's set up for POPIA, with a score. */ export function ReadinessPanel({ token }: { token: string }) { const [data, setData] = useState(null); const [error, setError] = useState(null); const load = useCallback(async () => { try { setData(await apiFetch("/api/privacy/readiness", { authToken: token })); } catch (e) { setError(errorMessage(e) || "Could not load the checklist."); } }, [token]); useEffect(() => { load(); }, [load]); if (error) return

{error}

; if (!data) return

Loading…

; const tone = data.score >= 90 ? "text-green-700 bg-green-50 border-green-200" : data.score >= 60 ? "text-amber-800 bg-amber-50 border-amber-200" : "text-red-700 bg-red-50 border-red-200"; const todo = data.checks.filter(c => c.applies && !c.ok); const done = data.checks.filter(c => c.applies && c.ok); const na = data.checks.filter(c => !c.applies); const Row = ({ c }: { c: Check }) => (
  • {c.ok ? : }
    {c.label}
    {c.detail}
    {!c.ok && c.href && ( Fix )}
  • ); return (
    {data.score}%
    POPIA readiness
    {data.passed} of {data.total} checks done. This helps you comply; it isn't legal advice — your Information Officer stays responsible.
    {todo.length > 0 && (

    To do

      {todo.map(c => )}
    )} {done.length > 0 && (

    Done

      {done.map(c => )}
    )} {na.length > 0 &&

    Not counted (doesn't apply here): {na.map(c => c.label).join(", ")}.

    }
    ); }