Archived
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:
@@ -10,6 +10,7 @@ import { AllocationGroupFilter } from "@/components/shared/AllocationGroupFilter
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import type { Event, MessageSendResult, Registration, User } from "@/types";
|
||||
import { BackLink } from "@/components/shared/BackLink";
|
||||
import { MessageKindPicker, matchedText, type MessageKind } from "@/components/shared/MessageKindPicker";
|
||||
|
||||
type Attendee = { id: string; name: string; email: string; pref: string };
|
||||
type TemplateKey = 'custom'|'payment_reminder'|'event_reminder'|'tickets';
|
||||
@@ -243,6 +244,7 @@ function EmailAttendeesPageInner() {
|
||||
}, [preselectEventId]);
|
||||
|
||||
const [templateKey, setTemplateKey] = useState<TemplateKey>('custom');
|
||||
const [messageKind, setMessageKind] = useState<MessageKind>('update');
|
||||
const [showInfo, setShowInfo] = useState(false);
|
||||
|
||||
// Broadcasts state
|
||||
@@ -256,7 +258,9 @@ function EmailAttendeesPageInner() {
|
||||
const [broadcastPreviewCount, setBroadcastPreviewCount] = useState<number|null>(null);
|
||||
const [broadcastPreviewSample, setBroadcastPreviewSample] = useState<{email:string;name?:string}[]|null>(null);
|
||||
const [broadcastScheduledAtLocal, setBroadcastScheduledAtLocal] = useState<string>("");
|
||||
const [broadcastKind, setBroadcastKind] = useState<MessageKind>('news');
|
||||
const resetBroadcastForm = () => {
|
||||
setBroadcastKind('news');
|
||||
setSelectedUserIds([]);
|
||||
setBroadcastEventId("");
|
||||
setBroadcastSubject("");
|
||||
@@ -423,11 +427,12 @@ function EmailAttendeesPageInner() {
|
||||
if (!subject.trim()) { setError("Subject is required"); return; }
|
||||
if (!body.trim()) { setError("Message is required"); return; }
|
||||
}
|
||||
const payload: { subject: string; filter: MessageFilter; dryRun: boolean; template: TemplateKey } & EmailContent = {
|
||||
const payload: { subject: string; filter: MessageFilter; dryRun: boolean; template: TemplateKey; kind: MessageKind } & EmailContent = {
|
||||
subject: subject || "(no subject)",
|
||||
filter: { status: status !== 'any' ? status : undefined, attendeeIds: selectedAttendeeIds && selectedAttendeeIds.length ? selectedAttendeeIds : undefined, allocationGroupId: groupId || undefined },
|
||||
dryRun: true,
|
||||
template: templateKey,
|
||||
kind: messageKind,
|
||||
};
|
||||
if (templateKey !== 'tickets') {
|
||||
if (body.trim().startsWith('<')) payload.html = body; else payload.text = body;
|
||||
@@ -435,7 +440,7 @@ function EmailAttendeesPageInner() {
|
||||
const res = await apiFetch<EmailSendResult>(`/api/events/${encodeURIComponent(eventId)}/email-attendees`, { method: 'POST', authToken: token, body: payload });
|
||||
setPreviewCount(res?.matched ?? 0);
|
||||
setPreviewSample(Array.isArray(res?.recipients) ? res.recipients : null);
|
||||
setInfo(`Matched ${res?.matched ?? 0} recipient(s).`);
|
||||
setInfo(matchedText(res));
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || 'Failed to preview recipients');
|
||||
}
|
||||
@@ -443,6 +448,7 @@ function EmailAttendeesPageInner() {
|
||||
|
||||
const resetAttendeesForm = () => {
|
||||
setTemplateKey('custom');
|
||||
setMessageKind('update');
|
||||
setSubject(''); setBody('');
|
||||
setSubjectDirty(false); setBodyDirty(false);
|
||||
setStatus('any');
|
||||
@@ -463,10 +469,11 @@ function EmailAttendeesPageInner() {
|
||||
if (!body.trim()) { setError("Message is required"); return; }
|
||||
}
|
||||
setSending(true);
|
||||
const payload: { subject: string; filter: MessageFilter; template: TemplateKey } & EmailContent = {
|
||||
const payload: { subject: string; filter: MessageFilter; template: TemplateKey; kind: MessageKind } & EmailContent = {
|
||||
subject,
|
||||
filter: { status: status !== 'any' ? status : undefined, attendeeIds: selectedAttendeeIds && selectedAttendeeIds.length ? selectedAttendeeIds : undefined, allocationGroupId: groupId || undefined },
|
||||
template: templateKey,
|
||||
kind: messageKind,
|
||||
};
|
||||
if (templateKey !== 'tickets') {
|
||||
if (body.trim().startsWith('<')) payload.html = body; else payload.text = body.replace(/\n/g, '\n');
|
||||
@@ -571,6 +578,10 @@ function EmailAttendeesPageInner() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{templateKey !== 'tickets' && (
|
||||
<MessageKindPicker name="attendeesKind" value={messageKind} onChange={setMessageKind} />
|
||||
)}
|
||||
|
||||
{showInfo && (
|
||||
<div className="fixed inset-0 z-20">
|
||||
<div className="absolute inset-0 bg-black/30" onClick={() => setShowInfo(false)} />
|
||||
@@ -663,10 +674,11 @@ function EmailAttendeesPageInner() {
|
||||
if (!body.trim()) { setError('Message is required'); return; }
|
||||
}
|
||||
const whenIso = new Date(scheduledAtLocal).toISOString();
|
||||
const payload: { subject: string; filter: MessageFilter; template: TemplateKey; scheduledAt: string } & EmailContent = {
|
||||
const payload: { subject: string; filter: MessageFilter; template: TemplateKey; kind: MessageKind; scheduledAt: string } & EmailContent = {
|
||||
subject,
|
||||
filter: { status: status !== 'any' ? status : undefined, attendeeIds: selectedAttendeeIds && selectedAttendeeIds.length ? selectedAttendeeIds : undefined, allocationGroupId: groupId || undefined },
|
||||
template: templateKey,
|
||||
kind: messageKind,
|
||||
scheduledAt: whenIso,
|
||||
};
|
||||
if (templateKey !== 'tickets') {
|
||||
@@ -739,6 +751,8 @@ function EmailAttendeesPageInner() {
|
||||
<PrefWarning attendees={users} selectedIds={selectedUserIds} channel="email" />
|
||||
)}
|
||||
|
||||
<MessageKindPicker name="broadcastKind" value={broadcastKind} onChange={setBroadcastKind} />
|
||||
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="block text-xs text-gray-600 mb-1">Subject</label>
|
||||
@@ -782,11 +796,11 @@ Jane Doe <jane@example.com>
|
||||
if (!token) { setError('Not authenticated'); return; }
|
||||
if (!broadcastSubject.trim()) { setError('Subject is required'); return; }
|
||||
if (!broadcastBody.trim()) { setError('Message is required'); return; }
|
||||
const body = { userIds: selectedUserIds, emails: broadcastEmails, eventId: broadcastEventId || undefined };
|
||||
const body = { userIds: selectedUserIds, emails: broadcastEmails, eventId: broadcastEventId || undefined, kind: broadcastKind };
|
||||
const res = await apiFetch<EmailSendResult>(`/api/broadcasts/preview`, { method: 'POST', authToken: token, body });
|
||||
setBroadcastPreviewCount(res?.matched ?? 0);
|
||||
setBroadcastPreviewSample(Array.isArray(res?.recipients) ? res.recipients : null);
|
||||
setInfo(`Matched ${res?.matched ?? 0} recipient(s).`);
|
||||
setInfo(matchedText(res));
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || 'Failed to preview recipients');
|
||||
}
|
||||
@@ -798,10 +812,10 @@ Jane Doe <jane@example.com>
|
||||
if (!token) { setError('Not authenticated'); return; }
|
||||
if (!broadcastSubject.trim()) { setError('Subject is required'); return; }
|
||||
if (!broadcastBody.trim()) { setError('Message is required'); return; }
|
||||
const payload: { subject: string; eventId?: string; userIds: string[]; emails: string } & EmailContent = { subject: broadcastSubject, eventId: broadcastEventId || undefined, userIds: selectedUserIds, emails: broadcastEmails };
|
||||
const payload: { subject: string; eventId?: string; userIds: string[]; emails: string; kind: MessageKind } & EmailContent = { subject: broadcastSubject, eventId: broadcastEventId || undefined, userIds: selectedUserIds, emails: broadcastEmails, kind: broadcastKind };
|
||||
if (broadcastBody.trim().startsWith('<')) payload.html = broadcastBody; else payload.text = broadcastBody;
|
||||
const res = await apiFetch<EmailSendResult>(`/api/broadcasts/send`, { method: 'POST', authToken: token, body: payload });
|
||||
setInfo(`Sent ${res?.sent ?? 0} out of ${res?.matched ?? 0} recipient(s).`);
|
||||
setInfo(`Sent ${res?.sent ?? 0} out of ${res?.matched ?? 0} recipient(s).${res?.skipped ? ` ${res.skipped} skipped — not opted in to news or unsubscribed.` : ''}`);
|
||||
// Reset broadcast form
|
||||
resetBroadcastForm();
|
||||
} catch (e) {
|
||||
@@ -816,7 +830,7 @@ Jane Doe <jane@example.com>
|
||||
if (!broadcastSubject.trim()) { setError('Subject is required'); return; }
|
||||
if (!broadcastBody.trim()) { setError('Message is required'); return; }
|
||||
const whenIso = new Date(broadcastScheduledAtLocal).toISOString();
|
||||
const payload: { scheduledAt: string; subject: string; eventId?: string; userIds: string[]; emails: string } & EmailContent = { scheduledAt: whenIso, subject: broadcastSubject, eventId: broadcastEventId || undefined, userIds: selectedUserIds, emails: broadcastEmails };
|
||||
const payload: { scheduledAt: string; subject: string; eventId?: string; userIds: string[]; emails: string; kind: MessageKind } & EmailContent = { scheduledAt: whenIso, subject: broadcastSubject, eventId: broadcastEventId || undefined, userIds: selectedUserIds, emails: broadcastEmails, kind: broadcastKind };
|
||||
if (broadcastBody.trim().startsWith('<')) payload.html = broadcastBody; else payload.text = broadcastBody;
|
||||
const res = await apiFetch<EmailSendResult>(`/api/broadcasts/schedule`, { method: 'POST', authToken: token, body: payload });
|
||||
if (res?.job?.id) setInfo('Broadcast scheduled. It will be sent around the specified time.'); else setInfo('Scheduled.');
|
||||
|
||||
Reference in New Issue
Block a user