@rapidmx/web-client 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/apps/admin/data-requests/index.tsx +485 -0
  2. package/apps/admin/escrow-scopes/[uid].tsx +237 -0
  3. package/apps/admin/escrow-scopes/index.tsx +124 -0
  4. package/apps/admin/escrow-scopes/new/index.tsx +128 -0
  5. package/apps/admin/mailboxes/[uid].tsx +66 -8
  6. package/apps/admin/retention-policy/index.tsx +132 -0
  7. package/apps/escrow/_layout.tsx +41 -0
  8. package/apps/escrow/audit-log/index.tsx +168 -0
  9. package/apps/escrow/index.tsx +139 -0
  10. package/apps/escrow/matters/[uid].tsx +521 -0
  11. package/apps/escrow/matters/new/index.tsx +173 -0
  12. package/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.tsx +171 -0
  13. package/apps/shared/components/admin/layout/AdminShell.tsx +24 -0
  14. package/apps/shared/components/contacts/ContactDetailPane.tsx +44 -0
  15. package/apps/shared/components/escrow/layout/EscrowShell.tsx +134 -0
  16. package/apps/shared/components/forms/StringListField.tsx +104 -0
  17. package/apps/shared/components/layout/AppShell.tsx +4 -0
  18. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +265 -0
  19. package/apps/shared/components/mail/ConversationThreadPane.tsx +8 -1
  20. package/apps/shared/components/mail/MessageDetailPane.tsx +214 -9
  21. package/apps/shared/components/mail/compose/ComposeContext.tsx +10 -1
  22. package/apps/shared/components/mail/compose/ComposeWindow.tsx +271 -24
  23. package/apps/shared/components/mail/layout/MailShell.tsx +302 -287
  24. package/apps/shared/components/settings/layout/SettingsShell.tsx +3 -0
  25. package/apps/www/index.tsx +122 -11
  26. package/apps/www/messages/[uid].tsx +15 -1
  27. package/apps/www/settings/encryption/index.tsx +664 -0
  28. package/apps/www/settings/labels/index.tsx +201 -0
  29. package/apps/www/settings/privacy/index.tsx +436 -0
  30. package/dist/apps/admin/data-requests/index.js +197 -0
  31. package/dist/apps/admin/escrow-scopes/[uid].js +141 -0
  32. package/dist/apps/admin/escrow-scopes/index.js +31 -0
  33. package/dist/apps/admin/escrow-scopes/new/index.js +69 -0
  34. package/dist/apps/admin/mailboxes/[uid].js +26 -2
  35. package/dist/apps/admin/retention-policy/index.js +65 -0
  36. package/dist/apps/escrow/_layout.js +10 -0
  37. package/dist/apps/escrow/audit-log/index.js +66 -0
  38. package/dist/apps/escrow/index.js +31 -0
  39. package/dist/apps/escrow/matters/[uid].js +234 -0
  40. package/dist/apps/escrow/matters/new/index.js +75 -0
  41. package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.js +26 -0
  42. package/dist/apps/shared/components/admin/layout/AdminShell.js +19 -1
  43. package/dist/apps/shared/components/contacts/ContactDetailPane.js +10 -1
  44. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +75 -0
  45. package/dist/apps/shared/components/forms/StringListField.js +39 -0
  46. package/dist/apps/shared/components/layout/AppShell.js +4 -0
  47. package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +142 -0
  48. package/dist/apps/shared/components/mail/ConversationThreadPane.js +2 -2
  49. package/dist/apps/shared/components/mail/MessageDetailPane.js +105 -6
  50. package/dist/apps/shared/components/mail/compose/ComposeContext.js +2 -1
  51. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +184 -21
  52. package/dist/apps/shared/components/mail/layout/MailShell.js +11 -2
  53. package/dist/apps/shared/components/settings/layout/SettingsShell.js +3 -0
  54. package/dist/apps/www/index.js +110 -10
  55. package/dist/apps/www/messages/[uid].js +12 -2
  56. package/dist/apps/www/settings/encryption/index.js +330 -0
  57. package/dist/apps/www/settings/labels/index.js +95 -0
  58. package/dist/apps/www/settings/privacy/index.js +167 -0
  59. package/package.json +9 -3
@@ -0,0 +1,201 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { useEffect, useState } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import { Label, createLabel, deleteLabel, listLabels, updateLabel } from "@rapidmx/react-shared/mail/labelsApi.js";
8
+ import SettingsShell, { SettingsShellProps, useSettingsShell } from "../../../shared/components/settings/layout/SettingsShell.js";
9
+ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
10
+ import Button from "@rapidmx/react-shared/components/buttons/Button.js";
11
+ import FormField from "@rapidmx/react-shared/components/forms/FormField.js";
12
+ import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
13
+
14
+ export type SettingsLabelsPageProps = Omit<SettingsShellProps, "active">;
15
+
16
+ export default function SettingsLabelsPage(props: SettingsLabelsPageProps) {
17
+ return (
18
+ <SettingsShell {...props} active="labels">
19
+ <LabelsContent />
20
+ </SettingsShell>
21
+ );
22
+ }
23
+
24
+ const DEFAULT_COLOR = "#6366f1";
25
+
26
+ function LabelsContent() {
27
+ const { mailboxUid } = useSettingsShell();
28
+ const [labels, setLabels] = useState<Label[]>([]);
29
+ const [loading, setLoading] = useState(true);
30
+ const [error, setError] = useState<string | null>(null);
31
+
32
+ // `editing === null` means the create form; otherwise the label currently being renamed/recolored.
33
+ const [editing, setEditing] = useState<Label | null>(null);
34
+ const [formOpen, setFormOpen] = useState(false);
35
+ const [formName, setFormName] = useState("");
36
+ const [formColor, setFormColor] = useState(DEFAULT_COLOR);
37
+ const [formError, setFormError] = useState<string | null>(null);
38
+ const [saving, setSaving] = useState(false);
39
+
40
+ const [deleting, setDeleting] = useState<Label | null>(null);
41
+ const [deleteError, setDeleteError] = useState<string | null>(null);
42
+ const [deleteBusy, setDeleteBusy] = useState(false);
43
+
44
+ // `SettingsShell` only ever renders its children once `mailboxUid` has resolved — same established
45
+ // non-null pattern as `apps/www/settings/auto-reply/index.tsx`.
46
+ useEffect(() => {
47
+ listLabels(mailboxUid!)
48
+ .then(setLabels)
49
+ .catch((err) => setError(err instanceof ApiRequestError ? err.message : "Could not load labels."))
50
+ .finally(() => setLoading(false));
51
+ }, [mailboxUid]);
52
+
53
+ function openCreateForm() {
54
+ setEditing(null);
55
+ setFormName("");
56
+ setFormColor(DEFAULT_COLOR);
57
+ setFormError(null);
58
+ setFormOpen(true);
59
+ }
60
+
61
+ function openEditForm(label: Label) {
62
+ setEditing(label);
63
+ setFormName(label.name);
64
+ setFormColor(label.color ?? DEFAULT_COLOR);
65
+ setFormError(null);
66
+ setFormOpen(true);
67
+ }
68
+
69
+ async function handleSave() {
70
+ setSaving(true);
71
+ setFormError(null);
72
+ try {
73
+ if (editing) {
74
+ const updated = await updateLabel({ uid: editing.uid, version: editing.version, name: formName, color: formColor });
75
+ setLabels((prev) => prev.map((l) => (l.uid === updated.uid ? updated : l)));
76
+ } else {
77
+ const created = await createLabel({ mailboxUid: mailboxUid!, name: formName, color: formColor });
78
+ setLabels((prev) => [...prev, created]);
79
+ }
80
+ setFormOpen(false);
81
+ } catch (err) {
82
+ setFormError(err instanceof ApiRequestError ? err.message : "Could not save this label.");
83
+ } finally {
84
+ setSaving(false);
85
+ }
86
+ }
87
+
88
+ async function handleDelete() {
89
+ setDeleteBusy(true);
90
+ setDeleteError(null);
91
+ try {
92
+ await deleteLabel(deleting!.uid, deleting!.version);
93
+ setLabels((prev) => prev.filter((l) => l.uid !== deleting!.uid));
94
+ setDeleting(null);
95
+ } catch (err) {
96
+ setDeleteError(err instanceof ApiRequestError ? err.message : "Could not delete this label.");
97
+ } finally {
98
+ setDeleteBusy(false);
99
+ }
100
+ }
101
+
102
+ return (
103
+ <div className="flex-1 min-w-0 overflow-y-auto p-6">
104
+ <div className="max-w-3xl">
105
+ <div className="flex items-center justify-between mb-5">
106
+ <h1 className="text-lg font-bold tracking-tight">Labels</h1>
107
+ <Button type="button" className="!w-auto" onClick={openCreateForm}>
108
+ + New label
109
+ </Button>
110
+ </div>
111
+
112
+ {error && <Alert>{error}</Alert>}
113
+
114
+ {loading ? (
115
+ <p className="text-sm text-text-muted">Loading&hellip;</p>
116
+ ) : labels.length === 0 ? (
117
+ <p className="text-sm text-text-muted">No labels yet.</p>
118
+ ) : (
119
+ <ul className="flex flex-col gap-2">
120
+ {labels.map((label) => (
121
+ <li key={label.uid} className="flex items-center justify-between border border-border rounded-md p-3">
122
+ <div className="flex items-center gap-2">
123
+ <span
124
+ className="w-3 h-3 rounded-full shrink-0"
125
+ style={{ backgroundColor: label.color ?? DEFAULT_COLOR }}
126
+ aria-hidden="true"
127
+ />
128
+ <span className="text-sm font-semibold">{label.name}</span>
129
+ </div>
130
+ <div className="flex items-center gap-3">
131
+ <button
132
+ type="button"
133
+ className="text-primary-dark hover:underline font-medium text-sm"
134
+ onClick={() => openEditForm(label)}
135
+ >
136
+ Edit
137
+ </button>
138
+ <button
139
+ type="button"
140
+ className="text-danger hover:underline font-medium text-sm"
141
+ onClick={() => {
142
+ setDeleting(label);
143
+ setDeleteError(null);
144
+ }}
145
+ >
146
+ Delete
147
+ </button>
148
+ </div>
149
+ </li>
150
+ ))}
151
+ </ul>
152
+ )}
153
+ </div>
154
+
155
+ <Modal open={formOpen} onClose={() => setFormOpen(false)} title={editing ? "Edit label" : "New label"}>
156
+ {formError && <Alert>{formError}</Alert>}
157
+ <FormField label="Name" htmlFor="label-name">
158
+ <input
159
+ id="label-name"
160
+ type="text"
161
+ value={formName}
162
+ onChange={(e) => setFormName(e.target.value)}
163
+ className="w-full text-sm px-3 py-1.5 rounded-md border border-border bg-surface"
164
+ />
165
+ </FormField>
166
+ <FormField label="Color" htmlFor="label-color">
167
+ <input
168
+ id="label-color"
169
+ type="color"
170
+ value={formColor}
171
+ onChange={(e) => setFormColor(e.target.value)}
172
+ className="h-9 w-16 rounded-md border border-border bg-surface"
173
+ />
174
+ </FormField>
175
+ <div className="flex justify-end gap-2 mt-2">
176
+ <Button type="button" variant="secondary" className="!w-auto" onClick={() => setFormOpen(false)}>
177
+ Cancel
178
+ </Button>
179
+ <Button type="button" className="!w-auto" loading={saving} disabled={saving || !formName.trim()} onClick={handleSave}>
180
+ Save
181
+ </Button>
182
+ </div>
183
+ </Modal>
184
+
185
+ <Modal open={!!deleting} onClose={() => setDeleting(null)} title="Delete this label?">
186
+ {deleteError && <Alert>{deleteError}</Alert>}
187
+ <p className="text-sm text-text-muted mb-4">
188
+ This removes &ldquo;{deleting?.name}&rdquo; from every message it's applied to. This can't be undone.
189
+ </p>
190
+ <div className="flex justify-end gap-2">
191
+ <Button type="button" variant="secondary" className="!w-auto" onClick={() => setDeleting(null)}>
192
+ Cancel
193
+ </Button>
194
+ <Button type="button" className="!w-auto" loading={deleteBusy} disabled={deleteBusy} onClick={handleDelete}>
195
+ Delete label
196
+ </Button>
197
+ </div>
198
+ </Modal>
199
+ </div>
200
+ );
201
+ }
@@ -0,0 +1,436 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { ChangeEvent, FormEvent, useEffect, useRef, useState } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import {
8
+ DataExportFormat,
9
+ DataExportRequest,
10
+ createExportRequest,
11
+ exportRequestDownloadUrl,
12
+ listExportRequests,
13
+ } from "@rapidmx/react-shared/mail/dataExportApi.js";
14
+ import {
15
+ MailboxImportFormat,
16
+ MailboxImportRequest,
17
+ listImportRequests,
18
+ uploadMailboxImport,
19
+ } from "@rapidmx/react-shared/mail/mailboxImportApi.js";
20
+ import {
21
+ DataSubjectErasureRequest,
22
+ createErasureRequest,
23
+ listErasureRequests,
24
+ } from "@rapidmx/react-shared/mail/erasureRequestApi.js";
25
+ import { Folder, listFolders } from "@rapidmx/react-shared/mail/mailApi.js";
26
+ import SettingsShell, { SettingsShellProps, useSettingsShell } from "../../../shared/components/settings/layout/SettingsShell.js";
27
+ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
28
+ import Button from "@rapidmx/react-shared/components/buttons/Button.js";
29
+ import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
30
+
31
+ const NON_MAIL_FOLDER_TYPES = new Set(["calendar", "contacts", "tasks", "notes"]);
32
+
33
+ function importFormatFromFilename(filename: string): MailboxImportFormat {
34
+ return filename.toLowerCase().endsWith(".pst") ? "pst" : "mbox";
35
+ }
36
+
37
+ function statusBadgeClass(status: string): string {
38
+ if (status === "failed" || status === "denied") return "bg-danger-bg text-danger";
39
+ if (status === "pending" || status === "processing") return "bg-surface-alt text-text-muted";
40
+ return "bg-success text-white";
41
+ }
42
+
43
+ export type SettingsPrivacyPageProps = Omit<SettingsShellProps, "active">;
44
+
45
+ export default function SettingsPrivacyPage(props: SettingsPrivacyPageProps) {
46
+ return (
47
+ <SettingsShell {...props} active="privacy">
48
+ <PrivacyContent />
49
+ </SettingsShell>
50
+ );
51
+ }
52
+
53
+ function PrivacyContent() {
54
+ const { mailboxUid } = useSettingsShell();
55
+
56
+ return (
57
+ <div className="flex-1 min-w-0 overflow-y-auto p-6">
58
+ <div className="max-w-xl flex flex-col gap-8">
59
+ <div>
60
+ <h1 className="text-lg font-bold tracking-tight mb-1">Privacy &amp; Data</h1>
61
+ <p className="text-sm text-text-muted">Export or manage the data associated with this mailbox.</p>
62
+ </div>
63
+
64
+ <ExportSection mailboxUid={mailboxUid} />
65
+ <ImportSection mailboxUid={mailboxUid} />
66
+ <ErasureSection />
67
+ </div>
68
+ </div>
69
+ );
70
+ }
71
+
72
+ function ExportSection({ mailboxUid }: { mailboxUid?: string }) {
73
+ const [requests, setRequests] = useState<DataExportRequest[]>([]);
74
+ const [loading, setLoading] = useState(true);
75
+ const [loadError, setLoadError] = useState<string | null>(null);
76
+ const [format, setFormat] = useState<DataExportFormat>("json");
77
+ const [creating, setCreating] = useState(false);
78
+ const [createError, setCreateError] = useState<string | null>(null);
79
+
80
+ // The create form below isn't gated behind `loading`, so a fast create-then-reload can resolve before
81
+ // the initial mount fetch does; without this guard the mount fetch's now-stale response would land
82
+ // last and silently revert the list. Only the most-recently-issued load's response is ever applied.
83
+ const loadSeq = useRef(0);
84
+ function loadRequests() {
85
+ const seq = ++loadSeq.current;
86
+ return listExportRequests()
87
+ .then((data) => {
88
+ if (seq === loadSeq.current) setRequests(data);
89
+ })
90
+ .catch((err) => {
91
+ if (seq === loadSeq.current)
92
+ setLoadError(err instanceof ApiRequestError ? err.message : "Could not load your export requests.");
93
+ });
94
+ }
95
+
96
+ useEffect(() => {
97
+ loadRequests().finally(() => setLoading(false));
98
+ // eslint-disable-next-line react-hooks/exhaustive-deps
99
+ }, [mailboxUid]);
100
+
101
+ async function handleCreate(e: FormEvent) {
102
+ e.preventDefault();
103
+ setCreateError(null);
104
+ setCreating(true);
105
+ try {
106
+ await createExportRequest({ format });
107
+ await loadRequests();
108
+ } catch (err) {
109
+ setCreateError(err instanceof ApiRequestError ? err.message : "Could not start this export.");
110
+ } finally {
111
+ setCreating(false);
112
+ }
113
+ }
114
+
115
+ return (
116
+ <div>
117
+ <h2 className="text-sm font-semibold mb-2">Export my data</h2>
118
+ <p className="text-xs text-text-muted mb-3">
119
+ Requests a copy of this mailbox&rsquo;s messages, contacts, calendar, tasks, and notes. This runs
120
+ in the background and can take a few minutes — check back here for a download link once it&rsquo;s
121
+ ready.
122
+ </p>
123
+
124
+ <form onSubmit={handleCreate} className="flex items-end gap-3 mb-5">
125
+ <label className="flex flex-col gap-1.5 text-sm">
126
+ <span className="font-semibold">Format</span>
127
+ <select
128
+ aria-label="Export format"
129
+ className="text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
130
+ value={format}
131
+ onChange={(e) => setFormat(e.target.value as DataExportFormat)}
132
+ >
133
+ <option value="json">JSON</option>
134
+ <option value="mbox">Mbox</option>
135
+ </select>
136
+ </label>
137
+ <Button type="submit" variant="secondary" className="!w-auto" loading={creating} disabled={creating}>
138
+ Request export
139
+ </Button>
140
+ </form>
141
+
142
+ {createError && <Alert>{createError}</Alert>}
143
+ {loadError && <Alert>{loadError}</Alert>}
144
+
145
+ {loading ? (
146
+ <p className="text-sm text-text-muted">Loading&hellip;</p>
147
+ ) : requests.length === 0 ? (
148
+ <p className="text-sm text-text-muted">No export requests yet.</p>
149
+ ) : (
150
+ <ul className="flex flex-col gap-2">
151
+ {requests.map((request) => (
152
+ <li
153
+ key={request.uid}
154
+ className="flex items-center justify-between gap-3 text-sm py-1.5 px-3 bg-surface-alt rounded-sm"
155
+ >
156
+ <span>
157
+ {request.format.toUpperCase()} &middot; {new Date(request.dateCreated).toLocaleString()}
158
+ {request.status === "failed" && request.errorMessage && (
159
+ <span className="text-danger"> — {request.errorMessage}</span>
160
+ )}
161
+ </span>
162
+ <span className="flex items-center gap-3">
163
+ <span
164
+ className={`text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill ${statusBadgeClass(request.status)}`}
165
+ >
166
+ {request.status}
167
+ </span>
168
+ {request.status === "ready" && (
169
+ <a
170
+ href={exportRequestDownloadUrl(request.uid)}
171
+ className="text-primary-dark hover:underline font-medium"
172
+ >
173
+ Download
174
+ </a>
175
+ )}
176
+ </span>
177
+ </li>
178
+ ))}
179
+ </ul>
180
+ )}
181
+ </div>
182
+ );
183
+ }
184
+
185
+ function ImportSection({ mailboxUid }: { mailboxUid?: string }) {
186
+ const [folders, setFolders] = useState<Folder[]>([]);
187
+ const [targetFolderUid, setTargetFolderUid] = useState("");
188
+ const [requests, setRequests] = useState<MailboxImportRequest[]>([]);
189
+ const [loading, setLoading] = useState(true);
190
+ const [loadError, setLoadError] = useState<string | null>(null);
191
+ const [uploading, setUploading] = useState(false);
192
+ const [uploadError, setUploadError] = useState<string | null>(null);
193
+ const fileInputRef = useRef<HTMLInputElement>(null);
194
+
195
+ // Same stale-response guard as ExportSection's loadRequests() - the Upload button is enabled
196
+ // independently of this section's own `loading`, so a fast upload-then-reload can resolve before the
197
+ // initial mount fetch does.
198
+ const loadSeq = useRef(0);
199
+ function loadRequests() {
200
+ const seq = ++loadSeq.current;
201
+ return listImportRequests()
202
+ .then((data) => {
203
+ if (seq === loadSeq.current) setRequests(data);
204
+ })
205
+ .catch((err) => {
206
+ if (seq === loadSeq.current)
207
+ setLoadError(err instanceof ApiRequestError ? err.message : "Could not load your import requests.");
208
+ });
209
+ }
210
+
211
+ useEffect(() => {
212
+ // Only reachable once mailboxUid is resolved - SettingsShell never renders this page's children
213
+ // until then, the same invariant every other settings page in this codebase already relies on.
214
+ Promise.all([
215
+ listFolders(mailboxUid!).then((all) => {
216
+ const mailFolders = all.filter((f) => !NON_MAIL_FOLDER_TYPES.has(f.type));
217
+ setFolders(mailFolders);
218
+ setTargetFolderUid(mailFolders[0]?.uid ?? "");
219
+ }),
220
+ loadRequests(),
221
+ ]).finally(() => setLoading(false));
222
+ // eslint-disable-next-line react-hooks/exhaustive-deps
223
+ }, [mailboxUid]);
224
+
225
+ function handleFileChange(e: ChangeEvent<HTMLInputElement>) {
226
+ const file = e.target.files?.[0];
227
+ e.target.value = "";
228
+ if (!file || !targetFolderUid) {
229
+ return;
230
+ }
231
+ setUploadError(null);
232
+ setUploading(true);
233
+ uploadMailboxImport(file, { format: importFormatFromFilename(file.name), targetFolderUid })
234
+ .then(() => loadRequests())
235
+ .catch((err) => setUploadError(err instanceof ApiRequestError ? err.message : "Could not upload this file."))
236
+ .finally(() => setUploading(false));
237
+ }
238
+
239
+ return (
240
+ <div>
241
+ <h2 className="text-sm font-semibold mb-2">Import mail</h2>
242
+ <p className="text-xs text-text-muted mb-3">
243
+ Uploads an Mbox or PST archive and imports every message it contains into the folder you
244
+ choose below. This runs in the background — check back here for its progress.
245
+ </p>
246
+
247
+ {folders.length > 0 && (
248
+ <label className="flex flex-col gap-1.5 text-sm mb-3 max-w-xs">
249
+ <span className="font-semibold">Destination folder</span>
250
+ <select
251
+ aria-label="Destination folder"
252
+ className="text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
253
+ value={targetFolderUid}
254
+ onChange={(e) => setTargetFolderUid(e.target.value)}
255
+ >
256
+ {folders.map((folder) => (
257
+ <option key={folder.uid} value={folder.uid}>
258
+ {folder.name}
259
+ </option>
260
+ ))}
261
+ </select>
262
+ </label>
263
+ )}
264
+
265
+ <Button
266
+ type="button"
267
+ variant="secondary"
268
+ className="!w-auto mb-3"
269
+ loading={uploading}
270
+ disabled={uploading || !targetFolderUid}
271
+ onClick={() => fileInputRef.current?.click()}
272
+ >
273
+ Upload Mbox or PST file
274
+ </Button>
275
+ <input
276
+ ref={fileInputRef}
277
+ type="file"
278
+ accept=".mbox,.pst"
279
+ aria-label="Upload mail archive"
280
+ className="hidden"
281
+ onChange={handleFileChange}
282
+ />
283
+
284
+ {uploadError && <Alert>{uploadError}</Alert>}
285
+ {loadError && <Alert>{loadError}</Alert>}
286
+
287
+ {loading ? (
288
+ <p className="text-sm text-text-muted">Loading&hellip;</p>
289
+ ) : requests.length === 0 ? (
290
+ <p className="text-sm text-text-muted">No import requests yet.</p>
291
+ ) : (
292
+ <ul className="flex flex-col gap-2">
293
+ {requests.map((request) => (
294
+ <li
295
+ key={request.uid}
296
+ className="flex items-center justify-between gap-3 text-sm py-1.5 px-3 bg-surface-alt rounded-sm"
297
+ >
298
+ <span>
299
+ {request.format.toUpperCase()} &middot; {new Date(request.dateCreated).toLocaleString()}
300
+ {request.status === "completed" && (
301
+ <span className="text-text-muted">
302
+ {" "}
303
+ — {request.importedCount ?? 0} imported
304
+ {request.failedCount ? `, ${request.failedCount} failed` : ""}
305
+ </span>
306
+ )}
307
+ {request.status === "failed" && request.errorMessage && (
308
+ <span className="text-danger"> — {request.errorMessage}</span>
309
+ )}
310
+ </span>
311
+ <span
312
+ className={`text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill ${statusBadgeClass(request.status)}`}
313
+ >
314
+ {request.status}
315
+ </span>
316
+ </li>
317
+ ))}
318
+ </ul>
319
+ )}
320
+ </div>
321
+ );
322
+ }
323
+
324
+ function ErasureSection() {
325
+ const [requests, setRequests] = useState<DataSubjectErasureRequest[]>([]);
326
+ const [loading, setLoading] = useState(true);
327
+ const [loadError, setLoadError] = useState<string | null>(null);
328
+ const [confirming, setConfirming] = useState(false);
329
+ const [creating, setCreating] = useState(false);
330
+ const [createError, setCreateError] = useState<string | null>(null);
331
+
332
+ function loadRequests() {
333
+ return listErasureRequests()
334
+ .then(setRequests)
335
+ .catch((err) => setLoadError(err instanceof ApiRequestError ? err.message : "Could not load your erasure requests."));
336
+ }
337
+
338
+ useEffect(() => {
339
+ loadRequests().finally(() => setLoading(false));
340
+ // eslint-disable-next-line react-hooks/exhaustive-deps
341
+ }, []);
342
+
343
+ const hasPending = requests.some((request) => request.status === "pending");
344
+
345
+ function closeConfirm() {
346
+ setConfirming(false);
347
+ }
348
+
349
+ async function handleConfirm() {
350
+ setCreateError(null);
351
+ setCreating(true);
352
+ try {
353
+ await createErasureRequest();
354
+ setConfirming(false);
355
+ await loadRequests();
356
+ } catch (err) {
357
+ setCreateError(err instanceof ApiRequestError ? err.message : "Could not submit this request.");
358
+ } finally {
359
+ setCreating(false);
360
+ }
361
+ }
362
+
363
+ return (
364
+ <div>
365
+ <h2 className="text-sm font-semibold mb-2">Delete my account</h2>
366
+ <p className="text-xs text-text-muted mb-3">
367
+ Permanently and irreversibly deletes this mailbox and everything in it, once a compliance
368
+ administrator reviews and approves the request. There is no way to cancel a request or undo
369
+ the deletion once it runs.
370
+ </p>
371
+
372
+ {loadError && <Alert>{loadError}</Alert>}
373
+
374
+ {loading ? (
375
+ <p className="text-sm text-text-muted">Loading&hellip;</p>
376
+ ) : (
377
+ <>
378
+ {requests.length > 0 && (
379
+ <ul className="flex flex-col gap-2 mb-3">
380
+ {requests.map((request) => (
381
+ <li
382
+ key={request.uid}
383
+ className="flex items-center justify-between gap-3 text-sm py-1.5 px-3 bg-surface-alt rounded-sm"
384
+ >
385
+ <span>
386
+ {new Date(request.dateCreated).toLocaleString()}
387
+ {request.status === "denied" && request.reason && (
388
+ <span className="text-danger"> — {request.reason}</span>
389
+ )}
390
+ </span>
391
+ <span
392
+ className={`text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill ${statusBadgeClass(request.status)}`}
393
+ >
394
+ {request.status}
395
+ </span>
396
+ </li>
397
+ ))}
398
+ </ul>
399
+ )}
400
+ <Button
401
+ type="button"
402
+ variant="secondary"
403
+ className="!w-auto !border-danger !text-danger hover:!border-danger hover:!text-danger"
404
+ disabled={hasPending}
405
+ onClick={() => setConfirming(true)}
406
+ >
407
+ Request account erasure
408
+ </Button>
409
+ </>
410
+ )}
411
+
412
+ <Modal open={confirming} onClose={closeConfirm} title="Delete my account">
413
+ <p className="text-sm mb-5">
414
+ This permanently deletes this mailbox and everything in it — messages, contacts,
415
+ calendar, tasks, and notes — once approved. This cannot be undone and cannot be
416
+ cancelled once submitted.
417
+ </p>
418
+ {createError && <Alert>{createError}</Alert>}
419
+ <div className="flex gap-3 justify-end mt-5">
420
+ <Button type="button" variant="secondary" className="!w-auto" disabled={creating} onClick={closeConfirm}>
421
+ Cancel
422
+ </Button>
423
+ <Button
424
+ type="button"
425
+ className="!w-auto !bg-none !bg-danger !border-danger hover:!bg-danger"
426
+ loading={creating}
427
+ disabled={creating}
428
+ onClick={handleConfirm}
429
+ >
430
+ Request erasure
431
+ </Button>
432
+ </div>
433
+ </Modal>
434
+ </div>
435
+ );
436
+ }