"use client"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import { Megaphone } from "lucide-react"; import { useAuth } from "@/hooks/useAuth"; import { apiFetch } from "@/lib/api"; import { errorMessage } from "@/lib/utils"; type News = { email: boolean; whatsapp: boolean }; /** * POPIA: asks once, after login, whether the person wants News & announcements — for * accounts that never answered (existing accounts, ones made at the door). Their current * setting is pre-filled; saving records the answer so it isn't asked again. */ export function NewsPrompt() { const { user, token } = useAuth(); const [news, setNews] = useState(null); const [canWhatsApp, setCanWhatsApp] = useState(false); const [done, setDone] = useState(false); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); const pending = !!user?.newsPromptPending && !done; useEffect(() => { if (!pending || !token || news) return; apiFetch<{ news: News; canWhatsApp: boolean }>("/api/privacy/me", { authToken: token }) .then(res => { setNews(res.news); setCanWhatsApp(res.canWhatsApp); }) .catch(() => setDone(true)); // never block the dashboard over this }, [pending, token, news]); if (!pending || !news) return null; const save = async (choice: News) => { if (!token) return; setSaving(true); setError(null); try { await apiFetch("/api/privacy/me/news", { method: "PUT", authToken: token, body: { ...choice, source: "prompt" } }); setDone(true); } catch (e) { setError(errorMessage(e) || "Could not save your choice."); } finally { setSaving(false); } }; return (

Hear about upcoming events?

We'd like to send you occasional news and announcements. Messages about events you register for are sent either way. You can change this any time under Privacy.

{canWhatsApp && ( )}
{error &&

{error}

}
); }