"use client"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import { ScrollText } from "lucide-react"; import { useAuth } from "@/hooks/useAuth"; import { apiFetch } from "@/lib/api"; import { errorMessage } from "@/lib/utils"; import type { PublicNotice } from "@/components/shared/PrivacyNoticeSection"; /** * POPIA: a privacy notice version marked as a significant change has been published, and * this person accepted an older one. Asked once after login; it can't be waved away, but the * notice and the Privacy page (to delete the account instead) stay reachable. */ export function NoticePrompt({ onDone }: { onDone: () => void }) { const { token } = useAuth(); const [notice, setNotice] = useState(null); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); useEffect(() => { apiFetch("/api/privacy/notice").then(setNotice).catch(() => onDone()); }, [onDone]); if (!notice) return null; const accept = async () => { if (!token) return; setSaving(true); setError(null); try { await apiFetch("/api/privacy/me/notice/accept", { method: "POST", authToken: token }); onDone(); } catch (e) { setError(errorMessage(e) || "Could not save. Please try again."); } finally { setSaving(false); } }; // The newest version that needed accepting, for "what changed". const changes = notice.versions.find(v => v.requiresAcceptance)?.changeSummary || notice.changeSummary; return (

We've updated our privacy notice

{changes && (
What changed: {changes}
)}

Please read the privacy notice and accept it to carry on using your account. If you don't agree, you can{" "} delete your account instead.

{error &&

{error}

}
); }