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:
@@ -19,6 +19,8 @@ export function RegisterForm() {
|
||||
const [phoneNumber, setPhoneNumber] = useState("");
|
||||
const [notificationPreference, setNotificationPreference] = useState<"email" | "whatsapp" | "both">("email");
|
||||
const [accepted, setAccepted] = useState(false);
|
||||
// POPIA: marketing needs an opt-in, so this starts unticked.
|
||||
const [newsOptIn, setNewsOptIn] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
@@ -53,6 +55,7 @@ export function RegisterForm() {
|
||||
password,
|
||||
phoneNumber: phoneNumber || undefined,
|
||||
notificationPreference: hasValidPhone ? notificationPreference : "email",
|
||||
newsOptIn,
|
||||
});
|
||||
window.location.href = redirectTo;
|
||||
} catch (err) {
|
||||
@@ -150,6 +153,19 @@ export function RegisterForm() {
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-2">
|
||||
<input
|
||||
id="news"
|
||||
type="checkbox"
|
||||
checked={newsOptIn}
|
||||
onChange={(e) => setNewsOptIn(e.target.checked)}
|
||||
className="mt-1 h-4 w-4 border-gray-300 rounded accent-brand-600"
|
||||
/>
|
||||
<label htmlFor="news" className="text-sm text-gray-700 leading-snug">
|
||||
Send me news and announcements about upcoming events (optional — you can unsubscribe at any time).
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="mt-1">
|
||||
<a
|
||||
href={loginHref}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { Calendar, User, LayoutDashboard, ShieldCheck, Globe, Menu, type LucideIcon } from "lucide-react";
|
||||
import { Calendar, User, LayoutDashboard, ShieldCheck, Globe, Menu, Lock, type LucideIcon } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { RoleBadge, type Role } from "@/components/shared/RoleBadge";
|
||||
import { UserAvatar } from "@/components/shared/UserAvatar";
|
||||
@@ -12,6 +12,7 @@ import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
|
||||
const navLinks: { href: string; label: string; icon: LucideIcon; roles?: string[] }[] = [
|
||||
{ href: "/dashboard/user", label: "My Events", icon: Calendar, roles: ["user", "staff", "supervisor", "admin"] },
|
||||
{ href: "/dashboard/user/profile", label: "Profile & Security", icon: User, roles: ["user", "staff", "supervisor", "admin"] },
|
||||
{ href: "/dashboard/user/privacy", label: "Privacy", icon: Lock, roles: ["user", "staff", "supervisor", "admin"] },
|
||||
{ href: "/dashboard/staff", label: "Staff", icon: LayoutDashboard, roles: ["staff"] },
|
||||
{ href: "/dashboard/supervisor", label: "Supervisor", icon: LayoutDashboard, roles: ["supervisor"] },
|
||||
{ href: "/dashboard/admin", label: "Admin", icon: ShieldCheck, roles: ["admin"] },
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
|
||||
export type MessageKind = "update" | "news";
|
||||
|
||||
const OPTIONS: { value: MessageKind; label: string; description: string }[] = [
|
||||
{
|
||||
value: "update",
|
||||
label: "Event update",
|
||||
description: "About an event the recipients registered for — a reminder, venue or time change, what to bring. Goes to everyone selected.",
|
||||
},
|
||||
{
|
||||
value: "news",
|
||||
label: "News & announcements",
|
||||
description: "Promoting events or sharing news. Only goes to people who opted in, and includes an unsubscribe link.",
|
||||
},
|
||||
];
|
||||
|
||||
/** POPIA: what kind of bulk message this is — decides who it may go to (see utils/privacy.js). */
|
||||
export function MessageKindPicker({ value, onChange, name }: { value: MessageKind; onChange: (kind: MessageKind) => void; name: string }) {
|
||||
return (
|
||||
<fieldset>
|
||||
<legend className="block text-xs text-gray-600 mb-1">Message type</legend>
|
||||
<div className="grid sm:grid-cols-2 gap-2">
|
||||
{OPTIONS.map(o => (
|
||||
<label key={o.value} className={`flex items-start gap-2 border rounded-lg p-2.5 cursor-pointer ${value === o.value ? "border-brand-500 bg-brand-50" : "border-gray-200 bg-white hover:bg-gray-50"}`}>
|
||||
<input type="radio" name={name} className="mt-0.5 accent-brand-600" checked={value === o.value} onChange={() => onChange(o.value)} />
|
||||
<span>
|
||||
<span className="block text-sm font-medium text-gray-800">{o.label}</span>
|
||||
<span className="block text-[11px] text-gray-500">{o.description}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
|
||||
/** "Matched 12 recipient(s)." plus how many news skipped. */
|
||||
export function matchedText(res: { matched?: number; skipped?: number } | null | undefined) {
|
||||
const skipped = res?.skipped ?? 0;
|
||||
return `Matched ${res?.matched ?? 0} recipient(s).${skipped ? ` ${skipped} skipped — not opted in to news or unsubscribed.` : ""}`;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
"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<News | null>(null);
|
||||
const [canWhatsApp, setCanWhatsApp] = useState(false);
|
||||
const [done, setDone] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(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 (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4" role="dialog" aria-modal="true" aria-labelledby="news-prompt-title">
|
||||
<div className="w-full max-w-md rounded-xl bg-white p-6 shadow-xl">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<div className="w-9 h-9 rounded-lg flex items-center justify-center bg-brand-50 text-brand-600 shrink-0">
|
||||
<Megaphone className="w-5 h-5" />
|
||||
</div>
|
||||
<h2 id="news-prompt-title" className="text-lg font-semibold text-gray-900">Hear about upcoming events?</h2>
|
||||
</div>
|
||||
<p className="text-sm text-gray-600 mb-4">
|
||||
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 <Link href="/dashboard/user/privacy" className="text-brand-600 hover:underline">Privacy</Link>.
|
||||
</p>
|
||||
<div className="space-y-3 mb-5">
|
||||
<label className="flex items-center gap-3 text-sm text-gray-700 cursor-pointer">
|
||||
<input type="checkbox" className="h-4 w-4 accent-brand-600" checked={news.email} onChange={e => setNews({ ...news, email: e.target.checked })} />
|
||||
By email
|
||||
</label>
|
||||
{canWhatsApp && (
|
||||
<label className="flex items-center gap-3 text-sm text-gray-700 cursor-pointer">
|
||||
<input type="checkbox" className="h-4 w-4 accent-brand-600" checked={news.whatsapp} onChange={e => setNews({ ...news, whatsapp: e.target.checked })} />
|
||||
By WhatsApp
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
{error && <p className="text-sm text-red-600 mb-3">{error}</p>}
|
||||
<div className="flex flex-wrap justify-end gap-3">
|
||||
<button onClick={() => save({ email: false, whatsapp: false })} disabled={saving} className="px-4 py-2 rounded-lg bg-gray-100 text-sm font-medium hover:bg-gray-200 disabled:opacity-50">
|
||||
No thanks
|
||||
</button>
|
||||
<button onClick={() => save({ email: news.email, whatsapp: canWhatsApp && news.whatsapp })} disabled={saving} className="px-4 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">
|
||||
{saving ? "Saving…" : "Save my choice"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user