@rapidmx/web-client 0.4.0 → 0.5.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 (169) hide show
  1. package/apps/admin/audit-log/index.tsx +35 -8
  2. package/apps/admin/data-requests/index.tsx +480 -485
  3. package/apps/admin/distribution-lists/[uid].tsx +19 -1
  4. package/apps/admin/escrow-scopes/[uid].tsx +348 -237
  5. package/apps/admin/escrow-scopes/new/index.tsx +8 -2
  6. package/apps/admin/index.tsx +19 -1
  7. package/apps/admin/ingest-queue/index.tsx +44 -5
  8. package/apps/admin/mailboxes/[uid].tsx +211 -184
  9. package/apps/admin/quarantine/index.tsx +46 -14
  10. package/apps/admin/transport-rules/[uid].tsx +30 -1
  11. package/apps/admin/transport-rules/_transportRuleConfig.tsx +38 -2
  12. package/apps/admin/transport-rules/index.tsx +24 -6
  13. package/apps/admin/transport-rules/new/index.tsx +30 -1
  14. package/apps/escrow/_layout.tsx +2 -3
  15. package/apps/escrow/audit-log/index.tsx +196 -168
  16. package/apps/escrow/matters/[uid].tsx +621 -521
  17. package/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.tsx +22 -1
  18. package/apps/shared/components/admin/layout/AdminShell.tsx +3 -1
  19. package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -0
  20. package/apps/shared/components/admin/mailboxes/ResourceSettingsCard.tsx +3 -3
  21. package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +55 -11
  22. package/apps/shared/components/admin/settings/BrandingForm.tsx +15 -4
  23. package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +18 -7
  24. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +10 -2
  25. package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +6 -0
  26. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +45 -12
  27. package/apps/shared/components/admin/settings/PluginsManager.tsx +1235 -595
  28. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +174 -98
  29. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +49 -13
  30. package/apps/shared/components/admin/setup/SetupWizard.tsx +150 -34
  31. package/apps/shared/components/admin/signOut.ts +79 -0
  32. package/apps/shared/components/admin/usePagedList.tsx +129 -0
  33. package/apps/shared/components/calendar/EventModal.tsx +717 -549
  34. package/apps/shared/components/calendar/MonthView.tsx +173 -139
  35. package/apps/shared/components/calendar/RecurrenceEditor.tsx +222 -180
  36. package/apps/shared/components/calendar/SplitDayView.tsx +143 -137
  37. package/apps/shared/components/calendar/TimeGridView.tsx +244 -198
  38. package/apps/shared/components/calendar/allDay.ts +124 -0
  39. package/apps/shared/components/calendar/layout/CalendarShell.tsx +1 -1
  40. package/apps/shared/components/contacts/ContactDetailPane.tsx +100 -21
  41. package/apps/shared/components/contacts/ContactForm.tsx +377 -348
  42. package/apps/shared/components/contacts/ContactsSidebar.tsx +6 -2
  43. package/apps/shared/components/contacts/KeyChangeReview.tsx +192 -0
  44. package/apps/shared/components/contacts/contactKeys.ts +78 -0
  45. package/apps/shared/components/escrow/layout/EscrowShell.tsx +148 -134
  46. package/apps/shared/components/layout/AppShell.tsx +87 -15
  47. package/apps/shared/components/layout/BrandingChrome.tsx +48 -10
  48. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +389 -298
  49. package/apps/shared/components/layout/MailboxProvisioning.tsx +19 -3
  50. package/apps/shared/components/layout/RecoveryCodeUnlock.tsx +350 -0
  51. package/apps/shared/components/layout/UnlockPromptProvider.tsx +257 -128
  52. package/apps/shared/components/mail/ConversationThreadPane.tsx +216 -181
  53. package/apps/shared/components/mail/MessageDetailPane.tsx +1318 -630
  54. package/apps/shared/components/mail/compose/ComposeContext.tsx +20 -15
  55. package/apps/shared/components/mail/compose/ComposeWindow.tsx +854 -132
  56. package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -0
  57. package/apps/shared/components/mail/layout/MailShell.tsx +12 -2
  58. package/apps/shared/components/mail/pinnedSigners.ts +124 -0
  59. package/apps/shared/components/mail/verificationSeals.ts +125 -0
  60. package/apps/shared/components/mail/writableMailboxes.ts +101 -0
  61. package/apps/shared/components/rules/RuleBuilder.tsx +311 -276
  62. package/apps/shared/mail/listAllPages.ts +39 -0
  63. package/apps/shared/search/LocalIndexLifecycle.tsx +64 -55
  64. package/apps/shared/search/localIndexBuilder.ts +481 -179
  65. package/apps/shared/search/localIndexRpcClient.ts +228 -28
  66. package/apps/shared/search/localIndexSchema.ts +15 -6
  67. package/apps/shared/search/localIndexStorage.ts +98 -0
  68. package/apps/shared/search/localIndexVFS.ts +32 -1
  69. package/apps/shared/search/localIndexWorker.ts +648 -186
  70. package/apps/www/calendar/index.tsx +438 -417
  71. package/apps/www/contacts/[uid].tsx +21 -2
  72. package/apps/www/contacts/index.tsx +116 -12
  73. package/apps/www/index.tsx +1314 -1041
  74. package/apps/www/messages/[uid].tsx +18 -6
  75. package/apps/www/settings/auto-reply/index.tsx +134 -129
  76. package/apps/www/settings/booking-types/[uid].tsx +306 -300
  77. package/apps/www/settings/encryption/index.tsx +739 -216
  78. package/apps/www/settings/filters/[uid].tsx +171 -155
  79. package/apps/www/settings/filters/new/index.tsx +8 -1
  80. package/apps/www/settings/focused-inbox/index.tsx +150 -148
  81. package/apps/www/settings/privacy/index.tsx +494 -436
  82. package/apps/www/settings/read-receipts/index.tsx +148 -125
  83. package/apps/www/settings/sharing/index.tsx +17 -14
  84. package/apps/www/tasks/index.tsx +638 -579
  85. package/dist/apps/admin/audit-log/index.js +38 -8
  86. package/dist/apps/admin/data-requests/index.js +52 -72
  87. package/dist/apps/admin/distribution-lists/[uid].js +1 -1
  88. package/dist/apps/admin/escrow-scopes/[uid].js +91 -12
  89. package/dist/apps/admin/escrow-scopes/new/index.js +8 -3
  90. package/dist/apps/admin/index.js +4 -1
  91. package/dist/apps/admin/ingest-queue/index.js +24 -6
  92. package/dist/apps/admin/mailboxes/[uid].js +20 -4
  93. package/dist/apps/admin/quarantine/index.js +20 -11
  94. package/dist/apps/admin/transport-rules/[uid].js +18 -2
  95. package/dist/apps/admin/transport-rules/_transportRuleConfig.js +19 -0
  96. package/dist/apps/admin/transport-rules/index.js +22 -6
  97. package/dist/apps/admin/transport-rules/new/index.js +18 -2
  98. package/dist/apps/escrow/_layout.js +3 -3
  99. package/dist/apps/escrow/audit-log/index.js +26 -1
  100. package/dist/apps/escrow/matters/[uid].js +77 -42
  101. package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.js +11 -2
  102. package/dist/apps/shared/components/admin/layout/AdminShell.js +3 -1
  103. package/dist/apps/shared/components/admin/mailboxes/EscrowScopeCard.js +72 -0
  104. package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.js +3 -3
  105. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +22 -4
  106. package/dist/apps/shared/components/admin/settings/BrandingForm.js +15 -4
  107. package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +13 -7
  108. package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +7 -2
  109. package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +6 -0
  110. package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +34 -12
  111. package/dist/apps/shared/components/admin/settings/PluginsManager.js +390 -78
  112. package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +40 -11
  113. package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +29 -13
  114. package/dist/apps/shared/components/admin/setup/SetupWizard.js +87 -21
  115. package/dist/apps/shared/components/admin/signOut.js +75 -0
  116. package/dist/apps/shared/components/admin/usePagedList.js +99 -0
  117. package/dist/apps/shared/components/calendar/EventModal.js +142 -21
  118. package/dist/apps/shared/components/calendar/MonthView.js +12 -5
  119. package/dist/apps/shared/components/calendar/RecurrenceEditor.js +40 -5
  120. package/dist/apps/shared/components/calendar/SplitDayView.js +10 -4
  121. package/dist/apps/shared/components/calendar/TimeGridView.js +23 -7
  122. package/dist/apps/shared/components/calendar/allDay.js +111 -0
  123. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +1 -1
  124. package/dist/apps/shared/components/contacts/ContactDetailPane.js +43 -5
  125. package/dist/apps/shared/components/contacts/ContactForm.js +32 -10
  126. package/dist/apps/shared/components/contacts/ContactsSidebar.js +2 -2
  127. package/dist/apps/shared/components/contacts/KeyChangeReview.js +63 -0
  128. package/dist/apps/shared/components/contacts/contactKeys.js +64 -0
  129. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +24 -5
  130. package/dist/apps/shared/components/layout/AppShell.js +83 -14
  131. package/dist/apps/shared/components/layout/BrandingChrome.js +45 -10
  132. package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +49 -12
  133. package/dist/apps/shared/components/layout/MailboxProvisioning.js +10 -2
  134. package/dist/apps/shared/components/layout/RecoveryCodeUnlock.js +174 -0
  135. package/dist/apps/shared/components/layout/UnlockPromptProvider.js +73 -14
  136. package/dist/apps/shared/components/mail/ConversationThreadPane.js +50 -12
  137. package/dist/apps/shared/components/mail/MessageDetailPane.js +441 -36
  138. package/dist/apps/shared/components/mail/compose/ComposeContext.js +9 -6
  139. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +699 -128
  140. package/dist/apps/shared/components/mail/compose/composeFlushRegistry.js +50 -0
  141. package/dist/apps/shared/components/mail/layout/MailShell.js +12 -3
  142. package/dist/apps/shared/components/mail/pinnedSigners.js +98 -0
  143. package/dist/apps/shared/components/mail/verificationSeals.js +112 -0
  144. package/dist/apps/shared/components/mail/writableMailboxes.js +87 -0
  145. package/dist/apps/shared/components/rules/RuleBuilder.js +34 -6
  146. package/dist/apps/shared/mail/listAllPages.js +25 -0
  147. package/dist/apps/shared/search/LocalIndexLifecycle.js +58 -54
  148. package/dist/apps/shared/search/localIndexBuilder.js +292 -37
  149. package/dist/apps/shared/search/localIndexRpcClient.js +188 -25
  150. package/dist/apps/shared/search/localIndexSchema.js +12 -6
  151. package/dist/apps/shared/search/localIndexStorage.js +86 -0
  152. package/dist/apps/shared/search/localIndexVFS.js +68 -40
  153. package/dist/apps/shared/search/localIndexWorker.js +519 -173
  154. package/dist/apps/www/calendar/index.js +28 -10
  155. package/dist/apps/www/contacts/[uid].js +13 -2
  156. package/dist/apps/www/contacts/index.js +80 -10
  157. package/dist/apps/www/index.js +339 -108
  158. package/dist/apps/www/messages/[uid].js +18 -6
  159. package/dist/apps/www/settings/auto-reply/index.js +9 -4
  160. package/dist/apps/www/settings/booking-types/[uid].js +17 -12
  161. package/dist/apps/www/settings/encryption/index.js +514 -97
  162. package/dist/apps/www/settings/filters/[uid].js +22 -7
  163. package/dist/apps/www/settings/filters/new/index.js +8 -2
  164. package/dist/apps/www/settings/focused-inbox/index.js +3 -1
  165. package/dist/apps/www/settings/privacy/index.js +57 -22
  166. package/dist/apps/www/settings/read-receipts/index.js +10 -3
  167. package/dist/apps/www/settings/sharing/index.js +7 -11
  168. package/dist/apps/www/tasks/index.js +50 -10
  169. package/package.json +2 -2
@@ -1,436 +1,494 @@
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
- }
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
+ /** Request statuses still waiting or running - shown as a neutral in-progress badge, never as success. Includes
38
+ * restapi's `processing` (exports/imports) and `in_progress` (an erasure that is running). */
39
+ const IN_PROGRESS_STATUSES = new Set(["pending", "processing", "in_progress"]);
40
+
41
+ function statusBadgeClass(status: string): string {
42
+ if (status === "failed" || status === "denied") return "bg-danger-bg text-danger";
43
+ if (IN_PROGRESS_STATUSES.has(status)) return "bg-surface-alt text-text-muted";
44
+ return "bg-success text-white";
45
+ }
46
+
47
+ /** A status as shown on its badge (`in_progress` -> `in progress`). */
48
+ function statusLabel(status: string): string {
49
+ return status.replace(/_/g, " ");
50
+ }
51
+
52
+ export type SettingsPrivacyPageProps = Omit<SettingsShellProps, "active">;
53
+
54
+ export default function SettingsPrivacyPage(props: SettingsPrivacyPageProps) {
55
+ return (
56
+ <SettingsShell {...props} active="privacy">
57
+ <PrivacyContent userUid={props.userUid} />
58
+ </SettingsShell>
59
+ );
60
+ }
61
+
62
+ function PrivacyContent({ userUid }: { userUid?: string }) {
63
+ const { mailboxUid, mailboxes } = useSettingsShell();
64
+ // Data export, account erasure, and (for a non-admin) mail import all act on the *caller's own*
65
+ // mailbox server-side - none of these requests carries a mailbox a regular user may choose, so
66
+ // restapi resolves "own mailbox" itself with an unordered lookup by owner. That is only unambiguous
67
+ // when the caller owns exactly one mailbox, so all three are only offered while the switcher is on
68
+ // that single owned mailbox, and name it explicitly. (Import on any other mailbox would always be
69
+ // rejected: its destination folder wouldn't belong to the mailbox the server resolved.)
70
+ const selected = mailboxes.find((mb) => mb.uid === mailboxUid)!;
71
+ const ownedMailboxes = mailboxes.filter((mb) => mb.ownerUserUid !== undefined && mb.ownerUserUid === userUid);
72
+ const ownMailbox = ownedMailboxes.length === 1 ? ownedMailboxes[0] : undefined;
73
+ const selectedIsOwn = selected.uid === ownMailbox?.uid;
74
+
75
+ return (
76
+ <div className="flex-1 min-w-0 overflow-y-auto p-6">
77
+ <div className="max-w-xl flex flex-col gap-8">
78
+ <div>
79
+ <h1 className="text-lg font-bold tracking-tight mb-1">Privacy &amp; Data</h1>
80
+ <p className="text-sm text-text-muted">Export or manage the data associated with this mailbox.</p>
81
+ </div>
82
+
83
+ {selectedIsOwn ? (
84
+ <>
85
+ <ExportSection mailboxUid={mailboxUid} mailboxLabel={`${selected.displayName} (${selected.primarySmtpAddress})`} />
86
+ <ImportSection mailboxUid={mailboxUid} />
87
+ <ErasureSection mailboxLabel={`${selected.displayName} (${selected.primarySmtpAddress})`} />
88
+ </>
89
+ ) : (
90
+ <OwnMailboxOnlyNotice
91
+ ownedMailboxCount={ownedMailboxes.length}
92
+ ownMailboxLabel={ownMailbox && `${ownMailbox.displayName} (${ownMailbox.primarySmtpAddress})`}
93
+ />
94
+ )}
95
+ </div>
96
+ </div>
97
+ );
98
+ }
99
+
100
+ function OwnMailboxOnlyNotice({ ownedMailboxCount, ownMailboxLabel }: { ownedMailboxCount: number; ownMailboxLabel?: string }) {
101
+ let detail: string;
102
+ if (ownMailboxLabel) {
103
+ detail = `Switch to ${ownMailboxLabel} to manage them.`;
104
+ } else if (ownedMailboxCount > 1) {
105
+ detail =
106
+ "You own more than one mailbox, so which one these would apply to can't be determined here. Ask an administrator to export, import, or erase data for a specific mailbox.";
107
+ } else {
108
+ detail = "You don't have a mailbox of your own to manage here.";
109
+ }
110
+ return (
111
+ <div>
112
+ <h2 className="text-sm font-semibold mb-2">Export, import, or delete my data</h2>
113
+ <p className="text-xs text-text-muted">
114
+ Exporting your data, importing mail, and deleting your account only apply to your own mailbox, not
115
+ one shared with you. {detail}
116
+ </p>
117
+ </div>
118
+ );
119
+ }
120
+
121
+ function ExportSection({ mailboxUid, mailboxLabel }: { mailboxUid?: string; mailboxLabel: string }) {
122
+ const [requests, setRequests] = useState<DataExportRequest[]>([]);
123
+ const [loading, setLoading] = useState(true);
124
+ const [loadError, setLoadError] = useState<string | null>(null);
125
+ const [format, setFormat] = useState<DataExportFormat>("json");
126
+ const [creating, setCreating] = useState(false);
127
+ const [createError, setCreateError] = useState<string | null>(null);
128
+
129
+ // The create form below isn't gated behind `loading`, so a fast create-then-reload can resolve before
130
+ // the initial mount fetch does; without this guard the mount fetch's now-stale response would land
131
+ // last and silently revert the list. Only the most-recently-issued load's response is ever applied.
132
+ const loadSeq = useRef(0);
133
+ function loadRequests() {
134
+ const seq = ++loadSeq.current;
135
+ return listExportRequests()
136
+ .then((data) => {
137
+ if (seq === loadSeq.current) {
138
+ setRequests(data);
139
+ }
140
+ })
141
+ .catch((err) => {
142
+ if (seq === loadSeq.current) {
143
+ setLoadError(err instanceof ApiRequestError ? err.message : "Could not load your export requests.");
144
+ }
145
+ });
146
+ }
147
+
148
+ useEffect(() => {
149
+ void loadRequests().finally(() => setLoading(false));
150
+ }, [mailboxUid]);
151
+
152
+ async function handleCreate(e: FormEvent) {
153
+ e.preventDefault();
154
+ setCreateError(null);
155
+ setCreating(true);
156
+ try {
157
+ await createExportRequest({ format });
158
+ await loadRequests();
159
+ } catch (err) {
160
+ setCreateError(err instanceof ApiRequestError ? err.message : "Could not start this export.");
161
+ } finally {
162
+ setCreating(false);
163
+ }
164
+ }
165
+
166
+ return (
167
+ <div>
168
+ <h2 className="text-sm font-semibold mb-2">Export my data</h2>
169
+ <p className="text-xs text-text-muted mb-3">
170
+ Requests a copy of <strong>{mailboxLabel}</strong>&rsquo;s messages, contacts, calendar, tasks, and notes. This runs
171
+ in the background and can take a few minutes — check back here for a download link once it&rsquo;s
172
+ ready.
173
+ </p>
174
+
175
+ <form onSubmit={handleCreate} className="flex items-end gap-3 mb-5">
176
+ <label className="flex flex-col gap-1.5 text-sm">
177
+ <span className="font-semibold">Format</span>
178
+ <select
179
+ aria-label="Export format"
180
+ className="text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
181
+ value={format}
182
+ onChange={(e) => setFormat(e.target.value as DataExportFormat)}
183
+ >
184
+ <option value="json">JSON</option>
185
+ <option value="mbox">Mbox</option>
186
+ </select>
187
+ </label>
188
+ <Button type="submit" variant="secondary" className="!w-auto" loading={creating} disabled={creating}>
189
+ Request export
190
+ </Button>
191
+ </form>
192
+
193
+ {createError && <Alert>{createError}</Alert>}
194
+ {loadError && <Alert>{loadError}</Alert>}
195
+
196
+ {loading ? (
197
+ <p className="text-sm text-text-muted">Loading&hellip;</p>
198
+ ) : requests.length === 0 ? (
199
+ <p className="text-sm text-text-muted">No export requests yet.</p>
200
+ ) : (
201
+ <ul className="flex flex-col gap-2">
202
+ {requests.map((request) => (
203
+ <li
204
+ key={request.uid}
205
+ className="flex items-center justify-between gap-3 text-sm py-1.5 px-3 bg-surface-alt rounded-sm"
206
+ >
207
+ <span>
208
+ {request.format.toUpperCase()} &middot; {new Date(request.dateCreated).toLocaleString()}
209
+ {request.status === "failed" && request.errorMessage && (
210
+ <span className="text-danger"> — {request.errorMessage}</span>
211
+ )}
212
+ </span>
213
+ <span className="flex items-center gap-3">
214
+ <span
215
+ className={`text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill ${statusBadgeClass(request.status)}`}
216
+ >
217
+ {statusLabel(request.status)}
218
+ </span>
219
+ {request.status === "ready" && (
220
+ <a
221
+ href={exportRequestDownloadUrl(request.uid)}
222
+ className="text-primary-dark hover:underline font-medium"
223
+ >
224
+ Download
225
+ </a>
226
+ )}
227
+ </span>
228
+ </li>
229
+ ))}
230
+ </ul>
231
+ )}
232
+ </div>
233
+ );
234
+ }
235
+
236
+ function ImportSection({ mailboxUid }: { mailboxUid?: string }) {
237
+ const [folders, setFolders] = useState<Folder[]>([]);
238
+ const [targetFolderUid, setTargetFolderUid] = useState("");
239
+ const [foldersError, setFoldersError] = useState<string | null>(null);
240
+ const [requests, setRequests] = useState<MailboxImportRequest[]>([]);
241
+ const [loading, setLoading] = useState(true);
242
+ const [loadError, setLoadError] = useState<string | null>(null);
243
+ const [uploading, setUploading] = useState(false);
244
+ const [uploadError, setUploadError] = useState<string | null>(null);
245
+ const fileInputRef = useRef<HTMLInputElement>(null);
246
+
247
+ // Same stale-response guard as ExportSection's loadRequests() - the Upload button is enabled
248
+ // independently of this section's own `loading`, so a fast upload-then-reload can resolve before the
249
+ // initial mount fetch does.
250
+ const loadSeq = useRef(0);
251
+ function loadRequests() {
252
+ const seq = ++loadSeq.current;
253
+ return listImportRequests()
254
+ .then((data) => {
255
+ if (seq === loadSeq.current) {
256
+ setRequests(data);
257
+ }
258
+ })
259
+ .catch((err) => {
260
+ if (seq === loadSeq.current) {
261
+ setLoadError(err instanceof ApiRequestError ? err.message : "Could not load your import requests.");
262
+ }
263
+ });
264
+ }
265
+
266
+ useEffect(() => {
267
+ // Only reachable once mailboxUid is resolved - SettingsShell never renders this page's children
268
+ // until then, the same invariant every other settings page in this codebase already relies on.
269
+ void Promise.all([
270
+ listFolders(mailboxUid!)
271
+ .then((all) => {
272
+ const mailFolders = all.filter((f) => !NON_MAIL_FOLDER_TYPES.has(f.type));
273
+ setFolders(mailFolders);
274
+ setTargetFolderUid(mailFolders[0]?.uid ?? "");
275
+ })
276
+ .catch((err) =>
277
+ setFoldersError(err instanceof ApiRequestError ? err.message : "Could not load this mailbox's folders."),
278
+ ),
279
+ loadRequests(),
280
+ ]).finally(() => setLoading(false));
281
+ }, [mailboxUid]);
282
+
283
+ function handleFileChange(e: ChangeEvent<HTMLInputElement>) {
284
+ const file = e.target.files?.[0];
285
+ e.target.value = "";
286
+ if (!file || !targetFolderUid) {
287
+ return;
288
+ }
289
+ setUploadError(null);
290
+ setUploading(true);
291
+ uploadMailboxImport(file, { format: importFormatFromFilename(file.name), targetFolderUid })
292
+ .then(() => loadRequests())
293
+ .catch((err) => setUploadError(err instanceof ApiRequestError ? err.message : "Could not upload this file."))
294
+ .finally(() => setUploading(false));
295
+ }
296
+
297
+ return (
298
+ <div>
299
+ <h2 className="text-sm font-semibold mb-2">Import mail</h2>
300
+ <p className="text-xs text-text-muted mb-3">
301
+ Uploads an Mbox or PST archive and imports every message it contains into the folder you
302
+ choose below. This runs in the background — check back here for its progress.
303
+ </p>
304
+
305
+ {folders.length > 0 && (
306
+ <label className="flex flex-col gap-1.5 text-sm mb-3 max-w-xs">
307
+ <span className="font-semibold">Destination folder</span>
308
+ <select
309
+ aria-label="Destination folder"
310
+ className="text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
311
+ value={targetFolderUid}
312
+ onChange={(e) => setTargetFolderUid(e.target.value)}
313
+ >
314
+ {folders.map((folder) => (
315
+ <option key={folder.uid} value={folder.uid}>
316
+ {folder.name}
317
+ </option>
318
+ ))}
319
+ </select>
320
+ </label>
321
+ )}
322
+
323
+ <Button
324
+ type="button"
325
+ variant="secondary"
326
+ className="!w-auto mb-3"
327
+ loading={uploading}
328
+ disabled={uploading || !targetFolderUid}
329
+ onClick={() => fileInputRef.current?.click()}
330
+ >
331
+ Upload Mbox or PST file
332
+ </Button>
333
+ <input
334
+ ref={fileInputRef}
335
+ type="file"
336
+ accept=".mbox,.pst"
337
+ aria-label="Upload mail archive"
338
+ className="hidden"
339
+ onChange={handleFileChange}
340
+ />
341
+
342
+ {foldersError && <Alert>{foldersError}</Alert>}
343
+ {uploadError && <Alert>{uploadError}</Alert>}
344
+ {loadError && <Alert>{loadError}</Alert>}
345
+
346
+ {loading ? (
347
+ <p className="text-sm text-text-muted">Loading&hellip;</p>
348
+ ) : requests.length === 0 ? (
349
+ <p className="text-sm text-text-muted">No import requests yet.</p>
350
+ ) : (
351
+ <ul className="flex flex-col gap-2">
352
+ {requests.map((request) => (
353
+ <li
354
+ key={request.uid}
355
+ className="flex items-center justify-between gap-3 text-sm py-1.5 px-3 bg-surface-alt rounded-sm"
356
+ >
357
+ <span>
358
+ {request.format.toUpperCase()} &middot; {new Date(request.dateCreated).toLocaleString()}
359
+ {request.status === "completed" && (
360
+ <span className="text-text-muted">
361
+ {" "}
362
+ — {request.importedCount ?? 0} imported
363
+ {request.failedCount ? `, ${request.failedCount} failed` : ""}
364
+ </span>
365
+ )}
366
+ {request.status === "failed" && request.errorMessage && (
367
+ <span className="text-danger"> — {request.errorMessage}</span>
368
+ )}
369
+ </span>
370
+ <span
371
+ className={`text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill ${statusBadgeClass(request.status)}`}
372
+ >
373
+ {statusLabel(request.status)}
374
+ </span>
375
+ </li>
376
+ ))}
377
+ </ul>
378
+ )}
379
+ </div>
380
+ );
381
+ }
382
+
383
+ function ErasureSection({ mailboxLabel }: { mailboxLabel: string }) {
384
+ const [requests, setRequests] = useState<DataSubjectErasureRequest[]>([]);
385
+ const [loading, setLoading] = useState(true);
386
+ const [loadError, setLoadError] = useState<string | null>(null);
387
+ const [confirming, setConfirming] = useState(false);
388
+ const [creating, setCreating] = useState(false);
389
+ const [createError, setCreateError] = useState<string | null>(null);
390
+
391
+ function loadRequests() {
392
+ return listErasureRequests()
393
+ .then(setRequests)
394
+ .catch((err) => setLoadError(err instanceof ApiRequestError ? err.message : "Could not load your erasure requests."));
395
+ }
396
+
397
+ useEffect(() => {
398
+ void loadRequests().finally(() => setLoading(false));
399
+ }, []);
400
+
401
+ const hasPending = requests.some((request) => request.status === "pending");
402
+
403
+ function closeConfirm() {
404
+ setConfirming(false);
405
+ }
406
+
407
+ async function handleConfirm() {
408
+ setCreateError(null);
409
+ setCreating(true);
410
+ try {
411
+ await createErasureRequest();
412
+ setConfirming(false);
413
+ await loadRequests();
414
+ } catch (err) {
415
+ setCreateError(err instanceof ApiRequestError ? err.message : "Could not submit this request.");
416
+ } finally {
417
+ setCreating(false);
418
+ }
419
+ }
420
+
421
+ return (
422
+ <div>
423
+ <h2 className="text-sm font-semibold mb-2">Delete my account</h2>
424
+ <p className="text-xs text-text-muted mb-3">
425
+ Permanently and irreversibly deletes <strong>{mailboxLabel}</strong> and everything in it, once a compliance
426
+ administrator reviews and approves the request. There is no way to cancel a request or undo
427
+ the deletion once it runs.
428
+ </p>
429
+
430
+ {loadError && <Alert>{loadError}</Alert>}
431
+
432
+ {loading ? (
433
+ <p className="text-sm text-text-muted">Loading&hellip;</p>
434
+ ) : (
435
+ <>
436
+ {requests.length > 0 && (
437
+ <ul className="flex flex-col gap-2 mb-3">
438
+ {requests.map((request) => (
439
+ <li
440
+ key={request.uid}
441
+ className="flex items-center justify-between gap-3 text-sm py-1.5 px-3 bg-surface-alt rounded-sm"
442
+ >
443
+ <span>
444
+ {new Date(request.dateCreated).toLocaleString()}
445
+ {request.status === "denied" && request.reason && (
446
+ <span className="text-danger"> — {request.reason}</span>
447
+ )}
448
+ </span>
449
+ <span
450
+ className={`text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill ${statusBadgeClass(request.status)}`}
451
+ >
452
+ {statusLabel(request.status)}
453
+ </span>
454
+ </li>
455
+ ))}
456
+ </ul>
457
+ )}
458
+ <Button
459
+ type="button"
460
+ variant="secondary"
461
+ className="!w-auto !border-danger !text-danger hover:!border-danger hover:!text-danger"
462
+ disabled={hasPending}
463
+ onClick={() => setConfirming(true)}
464
+ >
465
+ Request account erasure
466
+ </Button>
467
+ </>
468
+ )}
469
+
470
+ <Modal open={confirming} onClose={closeConfirm} title="Delete my account">
471
+ <p className="text-sm mb-5">
472
+ This permanently deletes {mailboxLabel} and everything in it — messages, contacts,
473
+ calendar, tasks, and notes — once approved. This cannot be undone and cannot be
474
+ cancelled once submitted.
475
+ </p>
476
+ {createError && <Alert>{createError}</Alert>}
477
+ <div className="flex gap-3 justify-end mt-5">
478
+ <Button type="button" variant="secondary" className="!w-auto" disabled={creating} onClick={closeConfirm}>
479
+ Cancel
480
+ </Button>
481
+ <Button
482
+ type="button"
483
+ className="!w-auto !bg-none !bg-danger !border-danger hover:!bg-danger"
484
+ loading={creating}
485
+ disabled={creating}
486
+ onClick={handleConfirm}
487
+ >
488
+ Request erasure
489
+ </Button>
490
+ </div>
491
+ </Modal>
492
+ </div>
493
+ );
494
+ }