"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: asked once after login when this person never accepted the privacy notice (an account * made for them, or from before acceptances were recorded) — reason "first" — or a version marked * as a significant change came out after the one they accepted ("updated"). It can't be waved * away, but the notice and the Privacy page (to delete the account instead) stay reachable. */ export function NoticePrompt({ reason = "updated", onDone }: { reason?: "first" | "updated"; 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 = reason === "updated" ? notice.versions.find(v => v.requiresAcceptance)?.changeSummary || notice.changeSummary : null; return (

{reason === "first" ? "Our privacy notice" : <>We've updated our privacy notice}

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

{reason === "first" && <>It explains what we keep about you and why, and your rights. } 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}

}
); }