POPIA toolkit part 1: privacy page, unsubscribe, WhatsApp STOP, data requests
- Privacy page: news opt-in per channel with history, download my data (JSON + PDF), correction and deletion requests - Bulk messages are an Event update or News & announcements; news only reaches people who opted in, with unsubscribe links, one-click List-Unsubscribe headers and "Reply STOP" on WhatsApp - WhatsApp STOP via WAWP's message webhook, checked against a secret in the webhook URL - Sign-up opt-in box; existing accounts kept opted in and asked once - Admin -> Data requests with 30-day due dates and a daily reminder job - Deleting an account is a request; anonymising now covers attendees, form answers, consent details, payer details in provider payloads, etc. - Unit tests (privacy.test.js) and e2e (privacy.spec.ts); docs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
"use client";
|
||||
import React, { Suspense, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { Navbar } from "@/components/layout/Navbar";
|
||||
import { Footer } from "@/components/layout/Footer";
|
||||
import { apiFetch, ApiError } from "@/lib/api";
|
||||
import { MailX } from "lucide-react";
|
||||
|
||||
type Info =
|
||||
| { kind: "account"; email: string; hasPhone: boolean; news: { email: boolean; whatsapp: boolean } }
|
||||
| { kind: "address"; channel: "email" | "whatsapp"; address: string; optedOut: boolean };
|
||||
|
||||
/** Landing page for the unsubscribe link in News & announcements emails and WhatsApps. */
|
||||
function Unsubscribe() {
|
||||
const token = useSearchParams().get("t") || "";
|
||||
const [info, setInfo] = useState<Info | null>(null);
|
||||
const [error, setError] = useState<string | null>(token ? null : "This unsubscribe link is incomplete.");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [done, setDone] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return;
|
||||
apiFetch<Info>(`/api/privacy/unsubscribe/${encodeURIComponent(token)}`)
|
||||
.then(setInfo)
|
||||
.catch(e => setError(e instanceof ApiError ? e.message : "Couldn't load this link."));
|
||||
}, [token]);
|
||||
|
||||
const unsubscribe = async (channels?: ("email" | "whatsapp")[]) => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await apiFetch(`/api/privacy/unsubscribe/${encodeURIComponent(token)}`, { method: "POST", body: channels ? { channels } : {} });
|
||||
setDone(true);
|
||||
} catch (e) {
|
||||
setError(e instanceof ApiError ? e.message : "Couldn't unsubscribe. Please try again.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const alreadyOff = info && (info.kind === "account" ? !info.news.email && !info.news.whatsapp : info.optedOut);
|
||||
const btn = "px-4 py-2 rounded-lg text-sm font-medium disabled:opacity-50";
|
||||
|
||||
return (
|
||||
<>
|
||||
{error && <div className="border rounded-xl p-4 bg-red-50 text-red-800 text-sm">{error}</div>}
|
||||
{!info && !error && <div className="text-sm text-gray-600">Loading…</div>}
|
||||
{info && (
|
||||
<div className="border rounded-xl p-5 bg-white shadow-sm space-y-4">
|
||||
{done || alreadyOff ? (
|
||||
<p className="text-sm text-gray-700">
|
||||
You're unsubscribed from news and announcements{info.kind === "address" ? ` for ${info.address}` : ""}.
|
||||
You'll still get messages about events you register for.
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<p className="text-sm text-gray-700">
|
||||
Stop news and announcements to <strong>{info.kind === "account" ? info.email : info.address}</strong>?
|
||||
Messages about events you register for — tickets, reminders, changes — still come through.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{info.kind === "account" && info.news.email && info.news.whatsapp ? (
|
||||
<>
|
||||
<button onClick={() => unsubscribe()} disabled={busy} className={`${btn} bg-brand-600 text-white hover:bg-brand-700`}>Unsubscribe from all news</button>
|
||||
<button onClick={() => unsubscribe(["email"])} disabled={busy} className={`${btn} border border-gray-300 text-gray-700 hover:bg-gray-50`}>Email only</button>
|
||||
<button onClick={() => unsubscribe(["whatsapp"])} disabled={busy} className={`${btn} border border-gray-300 text-gray-700 hover:bg-gray-50`}>WhatsApp only</button>
|
||||
</>
|
||||
) : (
|
||||
<button onClick={() => unsubscribe()} disabled={busy} className={`${btn} bg-brand-600 text-white hover:bg-brand-700`}>{busy ? "Unsubscribing…" : "Unsubscribe"}</button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{info.kind === "account" && (
|
||||
<p className="text-xs text-gray-500">
|
||||
<Link href="/dashboard/user/privacy" className="text-brand-600 hover:underline">Log in to manage all your preferences</Link>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default function UnsubscribePage() {
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col">
|
||||
<Navbar />
|
||||
<main className="flex-1 px-4 py-10 max-w-xl mx-auto w-full">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="w-10 h-10 rounded-xl bg-brand-50 flex items-center justify-center shrink-0">
|
||||
<MailX className="w-5 h-5 text-brand-600" />
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold text-gray-900">Unsubscribe</h1>
|
||||
</div>
|
||||
<Suspense fallback={<div className="text-sm text-gray-600">Loading…</div>}>
|
||||
<Unsubscribe />
|
||||
</Suspense>
|
||||
</main>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user