@rapidmx/web-client 0.19.0 → 0.20.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 (131) hide show
  1. package/README.md +381 -381
  2. package/apps/admin/branding/index.tsx +39 -39
  3. package/apps/admin/data-requests/index.tsx +482 -482
  4. package/apps/admin/domains/[uid].tsx +166 -166
  5. package/apps/admin/escrow-scopes/[uid].tsx +350 -350
  6. package/apps/admin/index.tsx +129 -129
  7. package/apps/admin/mailboxes/[uid].tsx +271 -271
  8. package/apps/admin/mailboxes/new/index.tsx +30 -30
  9. package/apps/admin/plugins/index.tsx +15 -15
  10. package/apps/admin/retention-policy/index.tsx +39 -39
  11. package/apps/admin/signing-certificates/index.tsx +343 -343
  12. package/apps/escrow/audit-log/index.tsx +196 -196
  13. package/apps/escrow/matters/[uid].tsx +621 -621
  14. package/apps/shared/auth/adminAccess.ts +99 -99
  15. package/apps/shared/components/admin/diagnostics/HostCard.tsx +2 -0
  16. package/apps/shared/components/admin/diagnostics/PressureTiles.tsx +108 -0
  17. package/apps/shared/components/admin/diagnostics/PvcTable.tsx +20 -6
  18. package/apps/shared/components/admin/diagnostics/diagnosticsApi.ts +21 -2
  19. package/apps/shared/components/admin/layout/AdminShell.tsx +384 -384
  20. package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -238
  21. package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
  22. package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -194
  23. package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
  24. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
  25. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
  26. package/apps/shared/components/admin/settings/PluginsManager.tsx +2093 -1620
  27. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
  28. package/apps/shared/components/admin/settings/pluginPreferences.ts +34 -0
  29. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
  30. package/apps/shared/components/admin/setup/SetupWizard.tsx +446 -446
  31. package/apps/shared/components/admin/usePagedList.tsx +129 -129
  32. package/apps/shared/components/calendar/EventModal.tsx +206 -206
  33. package/apps/shared/components/calendar/MonthView.tsx +185 -185
  34. package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
  35. package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
  36. package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
  37. package/apps/shared/components/calendar/allDay.ts +124 -124
  38. package/apps/shared/components/contacts/ContactForm.tsx +383 -383
  39. package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -103
  40. package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
  41. package/apps/shared/components/layout/AppShell.tsx +461 -461
  42. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
  43. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
  44. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
  45. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
  46. package/apps/shared/components/layout/UserMenu.tsx +439 -439
  47. package/apps/shared/components/mail/ConversationList.tsx +332 -323
  48. package/apps/shared/components/mail/ConversationThreadPane.tsx +613 -613
  49. package/apps/shared/components/mail/MailSelectionBar.tsx +240 -240
  50. package/apps/shared/components/mail/MenuButton.tsx +404 -404
  51. package/apps/shared/components/mail/MessageDetailPane.tsx +1757 -1757
  52. package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
  53. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
  54. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1681 -1681
  55. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
  56. package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
  57. package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
  58. package/apps/shared/components/mail/listPreferences.ts +3 -3
  59. package/apps/shared/components/mail/reading/MessageMoreMenu.tsx +258 -258
  60. package/apps/shared/components/mail/reading/MessageSourceDialog.tsx +79 -79
  61. package/apps/shared/components/mail/reading/messageExport.ts +59 -59
  62. package/apps/shared/components/mail/reading/printMessage.ts +99 -99
  63. package/apps/shared/components/mail/reading/useMessageActions.ts +443 -443
  64. package/apps/shared/components/mail/verificationSeals.ts +125 -125
  65. package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
  66. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
  67. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
  68. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
  69. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
  70. package/apps/shared/keyboard/dispatch.ts +124 -124
  71. package/apps/shared/keyboard/format.ts +89 -89
  72. package/apps/shared/keyboard/keymap.ts +114 -114
  73. package/apps/shared/keyboard/registry.ts +65 -65
  74. package/apps/shared/keyboard/targets.ts +79 -79
  75. package/apps/shared/mail/folderOfType.ts +49 -49
  76. package/apps/shared/mail/folderTree.ts +143 -143
  77. package/apps/shared/mail/listAllPages.ts +39 -39
  78. package/apps/shared/mail/newMailNotifications.ts +171 -171
  79. package/apps/shared/mail/outbox/sendJob.ts +445 -445
  80. package/apps/shared/mail/outbox/sendOutcomes.ts +155 -155
  81. package/apps/shared/mail/reportNotices.ts +66 -66
  82. package/apps/shared/mail/senderBlocking.ts +141 -141
  83. package/apps/shared/mail/useMailConnection.ts +205 -205
  84. package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
  85. package/apps/shared/mail/useMailboxUpdateAccess.ts +60 -60
  86. package/apps/shared/mail/useMarkMessageRead.ts +47 -47
  87. package/apps/shared/mail/useNewMailNotifications.ts +178 -178
  88. package/apps/shared/notifications/store.ts +560 -560
  89. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
  90. package/apps/shared/search/localIndexBuilder.ts +481 -481
  91. package/apps/shared/signing/enrollmentStorage.ts +33 -33
  92. package/apps/shared/signing/enrollmentTracker.ts +385 -385
  93. package/apps/shared/signing/enrollmentView.ts +251 -251
  94. package/apps/shared/signing/useNow.ts +19 -19
  95. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
  96. package/apps/shared/styles/app.css +396 -396
  97. package/apps/www/calendar/index.tsx +581 -581
  98. package/apps/www/contacts/[uid].tsx +112 -112
  99. package/apps/www/index.tsx +3012 -2962
  100. package/apps/www/messages/[uid].tsx +139 -139
  101. package/apps/www/settings/auto-reply/index.tsx +136 -136
  102. package/apps/www/settings/blocked-senders/index.tsx +303 -303
  103. package/apps/www/settings/encryption/index.tsx +1290 -1290
  104. package/apps/www/settings/filters/[uid].tsx +179 -179
  105. package/apps/www/settings/filters/index.tsx +105 -105
  106. package/apps/www/settings/filters/new/index.tsx +165 -165
  107. package/apps/www/settings/labels/index.tsx +207 -207
  108. package/apps/www/settings/privacy/index.tsx +495 -495
  109. package/apps/www/settings/profile/index.tsx +251 -251
  110. package/apps/www/settings/read-receipts/index.tsx +150 -150
  111. package/apps/www/settings/sharing/index.tsx +259 -259
  112. package/apps/www/settings/signatures/[uid].tsx +175 -175
  113. package/apps/www/settings/signatures/index.tsx +91 -91
  114. package/apps/www/settings/signatures/new/index.tsx +138 -138
  115. package/apps/www/tasks/index.tsx +654 -654
  116. package/dist/apps/shared/components/admin/diagnostics/HostCard.js +2 -1
  117. package/dist/apps/shared/components/admin/diagnostics/PressureTiles.d.ts +22 -0
  118. package/dist/apps/shared/components/admin/diagnostics/PressureTiles.js +52 -0
  119. package/dist/apps/shared/components/admin/diagnostics/PvcTable.js +9 -4
  120. package/dist/apps/shared/components/admin/diagnostics/diagnosticsApi.d.ts +35 -2
  121. package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
  122. package/dist/apps/shared/components/admin/settings/PluginsManager.js +267 -35
  123. package/dist/apps/shared/components/admin/settings/pluginPreferences.d.ts +2 -0
  124. package/dist/apps/shared/components/admin/settings/pluginPreferences.js +35 -0
  125. package/dist/apps/shared/components/mail/ConversationList.d.ts +10 -3
  126. package/dist/apps/shared/components/mail/ConversationList.js +9 -5
  127. package/dist/apps/shared/components/mail/listPreferences.d.ts +1 -1
  128. package/dist/apps/shared/components/mail/reading/printMessage.js +11 -11
  129. package/dist/apps/shared/styles/app.css +396 -396
  130. package/dist/apps/www/index.js +51 -10
  131. package/package.json +2 -2
@@ -1,238 +1,238 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import React, { FormEvent, useEffect, useRef, useState } from "react";
6
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
- import { eraseLeftoverMailbox } from "@rapidmx/react-shared/admin/leftoverMailboxApi.js";
8
- import { DataSubjectErasureStatus, getErasureRequest } from "@rapidmx/react-shared/mail/erasureRequestApi.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 Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
12
- import { notify } from "../../../notifications/store.js";
13
-
14
- const INPUT_CLASS =
15
- "w-full text-sm py-2.5 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
16
- const DANGER_BUTTON_CLASS = "!w-auto !bg-none !bg-danger !border-danger hover:!bg-danger";
17
-
18
- /** How often the request is asked how far the erasure has got. */
19
- export const ERASE_POLL_INTERVAL_MS = 2000;
20
-
21
- export interface EraseLeftoverDataDialogProps {
22
- /** The deleted mailbox's address. */
23
- address: string;
24
- /** What is left, when the caller knows it (the list of deleted mailboxes does): named in the confirmation. */
25
- counts?: { folders: number; messages: number };
26
- /** An erasure already filed for the address (approved or running): the dialog then watches it instead of asking first. */
27
- resume?: { uid: string; status: DataSubjectErasureStatus };
28
- /** The button shown once the data is erased (`onDone` runs when it is pressed - the dialog closes itself first). Default "Done". */
29
- doneLabel?: string;
30
- onDone?: () => void;
31
- /** Called once when the data is erased - whether or not the dialog is still open by then. */
32
- onErased?: (address: string) => void;
33
- onClose: () => void;
34
- /** How often to ask how far the erasure has got. */
35
- pollIntervalMs?: number;
36
- }
37
-
38
- type Phase = "confirm" | "filing" | "watching" | "done" | "refused";
39
-
40
- /** Where an erasure is, in words. */
41
- function progressLabel(status: DataSubjectErasureStatus | undefined): string {
42
- return status === "in_progress" ? "Erasing the data…" : "Waiting for the erasure to start…";
43
- }
44
-
45
- /**
46
- * Erases the data a deleted mailbox left behind - permanently - after the administrator types its address to confirm, then shows
47
- * how far it has got: the erasure runs on the server in the background, so this asks about it every few seconds until it has
48
- * finished or been refused. Mount it (with the address as its `key`) only while it is wanted; it holds its own state.
49
- *
50
- * The request that files the erasure can't be interrupted (closing is ignored while it is under way); once it is filed, closing
51
- * only stops watching - the erasure carries on, and the deleted-mailbox list shows it.
52
- */
53
- export default function EraseLeftoverDataDialog({
54
- address,
55
- counts,
56
- resume,
57
- doneLabel = "Done",
58
- onDone,
59
- onErased,
60
- onClose,
61
- pollIntervalMs = ERASE_POLL_INTERVAL_MS,
62
- }: EraseLeftoverDataDialogProps) {
63
- const [phase, setPhase] = useState<Phase>(resume ? "watching" : "confirm");
64
- const [typed, setTyped] = useState("");
65
- const [requestUid, setRequestUid] = useState<string | undefined>(resume?.uid);
66
- const [status, setStatus] = useState<DataSubjectErasureStatus | undefined>(resume?.status);
67
- const [error, setError] = useState<string | null>(null);
68
- // A check on the erasure failed (offline, a dropped connection): it is tried again, and the admin is told meanwhile.
69
- const [checkFailed, setCheckFailed] = useState(false);
70
- const onErasedRef = useRef(onErased);
71
- onErasedRef.current = onErased;
72
-
73
- const confirmed = typed.trim().toLowerCase() === address.trim().toLowerCase();
74
-
75
- async function handleErase(e: FormEvent) {
76
- e.preventDefault();
77
- if (!confirmed) {
78
- return;
79
- }
80
- setError(null);
81
- setPhase("filing");
82
- try {
83
- const request = await eraseLeftoverMailbox(address);
84
- setRequestUid(request.uid);
85
- setStatus(request.status);
86
- setPhase("watching");
87
- } catch (err) {
88
- // The server's own words: a legal hold names its matter, a mailbox that exists again says so.
89
- setError(err instanceof ApiRequestError ? err.message : "Could not start the erasure.");
90
- setPhase("confirm");
91
- }
92
- }
93
-
94
- // Watches the request until it has finished or been refused.
95
- useEffect(() => {
96
- if (phase !== "watching" || !requestUid) {
97
- return;
98
- }
99
- let cancelled = false;
100
- let timer: ReturnType<typeof setTimeout> | undefined;
101
- const check = async () => {
102
- try {
103
- const request = await getErasureRequest(requestUid);
104
- if (cancelled) {
105
- return;
106
- }
107
- setCheckFailed(false);
108
- setStatus(request.status);
109
- if (request.status === "completed") {
110
- setPhase("done");
111
- notify({ kind: "success", title: "Leftover data erased", message: `Everything left over from ${address} was erased.` });
112
- onErasedRef.current?.(address);
113
- return;
114
- }
115
- if (request.status === "denied") {
116
- setError(request.reason || "The erasure was refused.");
117
- setPhase("refused");
118
- return;
119
- }
120
- } catch {
121
- if (cancelled) {
122
- return;
123
- }
124
- setCheckFailed(true);
125
- }
126
- timer = setTimeout(() => void check(), pollIntervalMs);
127
- };
128
- void check();
129
- return () => {
130
- cancelled = true;
131
- clearTimeout(timer);
132
- };
133
- }, [phase, requestUid, address, pollIntervalMs]);
134
-
135
- // Closing is ignored while the request that files the erasure is under way, so its answer can't land on a dialog that was dismissed.
136
- function dismiss() {
137
- if (phase !== "filing") {
138
- onClose();
139
- }
140
- }
141
-
142
- function handleDone() {
143
- onClose();
144
- onDone?.();
145
- }
146
-
147
- const summary = counts
148
- ? `It still has ${counts.folders} ${counts.folders === 1 ? "folder" : "folders"} and ${counts.messages} ${counts.messages === 1 ? "message" : "messages"}, and everything else stored with them.`
149
- : "It still has its folders and everything stored in them.";
150
-
151
- return (
152
- <Modal open onClose={dismiss} title="Erase leftover data">
153
- {(phase === "confirm" || phase === "filing") && (
154
- <form onSubmit={handleErase}>
155
- <p className="text-sm mb-3">
156
- <strong className="break-all">{address}</strong> was deleted, but its data was kept. {summary}
157
- </p>
158
- <p className="text-sm mb-3">
159
- Erasing permanently deletes all of it - the mail, drafts and attachments, contacts, calendar events, tasks,
160
- notes, labels, filter rules and signatures, encryption keys, share links and access lists - and frees the
161
- address for a new mailbox.
162
- </p>
163
- <p className="text-sm font-semibold text-danger mb-4">This is irreversible and cannot be undone.</p>
164
- <label className="flex flex-col gap-1.5 text-sm mb-4">
165
- <span className="font-semibold">
166
- Type <span className="break-all">{address}</span> to confirm
167
- </span>
168
- <input
169
- aria-label="Type the address to confirm"
170
- className={INPUT_CLASS}
171
- value={typed}
172
- disabled={phase === "filing"}
173
- autoComplete="off"
174
- spellCheck={false}
175
- onChange={(e) => setTyped(e.target.value)}
176
- />
177
- </label>
178
- {error && <Alert>{error}</Alert>}
179
- <div className="flex gap-3 justify-end">
180
- <Button type="button" variant="secondary" className="!w-auto" disabled={phase === "filing"} onClick={dismiss}>
181
- Cancel
182
- </Button>
183
- <Button type="submit" className={DANGER_BUTTON_CLASS} loading={phase === "filing"} disabled={phase === "filing" || !confirmed}>
184
- Erase data
185
- </Button>
186
- </div>
187
- </form>
188
- )}
189
-
190
- {phase === "watching" && (
191
- <div>
192
- <p className="text-sm mb-3">
193
- Erasing the data left over from <strong className="break-all">{address}</strong>.
194
- </p>
195
- <p role="status" className="flex items-center gap-2 text-sm font-semibold mb-3">
196
- <span className="w-4 h-4 rounded-full border-2 border-current/30 border-t-current animate-spin" aria-hidden="true" />
197
- {progressLabel(status)}
198
- </p>
199
- {checkFailed && (
200
- <p className="text-sm text-danger mb-3">Could not check how far the erasure has got. Trying again&hellip;</p>
201
- )}
202
- <p className="text-sm text-text-muted mb-4">
203
- You can close this window: the erasure carries on in the background, and the Mailboxes page shows how it is going.
204
- </p>
205
- <div className="flex justify-end">
206
- <Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
207
- Stop watching
208
- </Button>
209
- </div>
210
- </div>
211
- )}
212
-
213
- {phase === "done" && (
214
- <div>
215
- <p role="status" className="text-sm mb-4">
216
- Everything left over from <strong className="break-all">{address}</strong> was erased. The address is free to use again.
217
- </p>
218
- <div className="flex justify-end">
219
- <Button type="button" className="!w-auto" onClick={handleDone}>
220
- {doneLabel}
221
- </Button>
222
- </div>
223
- </div>
224
- )}
225
-
226
- {phase === "refused" && (
227
- <div>
228
- <Alert>{error}</Alert>
229
- <div className="flex justify-end">
230
- <Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
231
- OK
232
- </Button>
233
- </div>
234
- </div>
235
- )}
236
- </Modal>
237
- );
238
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { FormEvent, useEffect, useRef, useState } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import { eraseLeftoverMailbox } from "@rapidmx/react-shared/admin/leftoverMailboxApi.js";
8
+ import { DataSubjectErasureStatus, getErasureRequest } from "@rapidmx/react-shared/mail/erasureRequestApi.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 Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
12
+ import { notify } from "../../../notifications/store.js";
13
+
14
+ const INPUT_CLASS =
15
+ "w-full text-sm py-2.5 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
16
+ const DANGER_BUTTON_CLASS = "!w-auto !bg-none !bg-danger !border-danger hover:!bg-danger";
17
+
18
+ /** How often the request is asked how far the erasure has got. */
19
+ export const ERASE_POLL_INTERVAL_MS = 2000;
20
+
21
+ export interface EraseLeftoverDataDialogProps {
22
+ /** The deleted mailbox's address. */
23
+ address: string;
24
+ /** What is left, when the caller knows it (the list of deleted mailboxes does): named in the confirmation. */
25
+ counts?: { folders: number; messages: number };
26
+ /** An erasure already filed for the address (approved or running): the dialog then watches it instead of asking first. */
27
+ resume?: { uid: string; status: DataSubjectErasureStatus };
28
+ /** The button shown once the data is erased (`onDone` runs when it is pressed - the dialog closes itself first). Default "Done". */
29
+ doneLabel?: string;
30
+ onDone?: () => void;
31
+ /** Called once when the data is erased - whether or not the dialog is still open by then. */
32
+ onErased?: (address: string) => void;
33
+ onClose: () => void;
34
+ /** How often to ask how far the erasure has got. */
35
+ pollIntervalMs?: number;
36
+ }
37
+
38
+ type Phase = "confirm" | "filing" | "watching" | "done" | "refused";
39
+
40
+ /** Where an erasure is, in words. */
41
+ function progressLabel(status: DataSubjectErasureStatus | undefined): string {
42
+ return status === "in_progress" ? "Erasing the data…" : "Waiting for the erasure to start…";
43
+ }
44
+
45
+ /**
46
+ * Erases the data a deleted mailbox left behind - permanently - after the administrator types its address to confirm, then shows
47
+ * how far it has got: the erasure runs on the server in the background, so this asks about it every few seconds until it has
48
+ * finished or been refused. Mount it (with the address as its `key`) only while it is wanted; it holds its own state.
49
+ *
50
+ * The request that files the erasure can't be interrupted (closing is ignored while it is under way); once it is filed, closing
51
+ * only stops watching - the erasure carries on, and the deleted-mailbox list shows it.
52
+ */
53
+ export default function EraseLeftoverDataDialog({
54
+ address,
55
+ counts,
56
+ resume,
57
+ doneLabel = "Done",
58
+ onDone,
59
+ onErased,
60
+ onClose,
61
+ pollIntervalMs = ERASE_POLL_INTERVAL_MS,
62
+ }: EraseLeftoverDataDialogProps) {
63
+ const [phase, setPhase] = useState<Phase>(resume ? "watching" : "confirm");
64
+ const [typed, setTyped] = useState("");
65
+ const [requestUid, setRequestUid] = useState<string | undefined>(resume?.uid);
66
+ const [status, setStatus] = useState<DataSubjectErasureStatus | undefined>(resume?.status);
67
+ const [error, setError] = useState<string | null>(null);
68
+ // A check on the erasure failed (offline, a dropped connection): it is tried again, and the admin is told meanwhile.
69
+ const [checkFailed, setCheckFailed] = useState(false);
70
+ const onErasedRef = useRef(onErased);
71
+ onErasedRef.current = onErased;
72
+
73
+ const confirmed = typed.trim().toLowerCase() === address.trim().toLowerCase();
74
+
75
+ async function handleErase(e: FormEvent) {
76
+ e.preventDefault();
77
+ if (!confirmed) {
78
+ return;
79
+ }
80
+ setError(null);
81
+ setPhase("filing");
82
+ try {
83
+ const request = await eraseLeftoverMailbox(address);
84
+ setRequestUid(request.uid);
85
+ setStatus(request.status);
86
+ setPhase("watching");
87
+ } catch (err) {
88
+ // The server's own words: a legal hold names its matter, a mailbox that exists again says so.
89
+ setError(err instanceof ApiRequestError ? err.message : "Could not start the erasure.");
90
+ setPhase("confirm");
91
+ }
92
+ }
93
+
94
+ // Watches the request until it has finished or been refused.
95
+ useEffect(() => {
96
+ if (phase !== "watching" || !requestUid) {
97
+ return;
98
+ }
99
+ let cancelled = false;
100
+ let timer: ReturnType<typeof setTimeout> | undefined;
101
+ const check = async () => {
102
+ try {
103
+ const request = await getErasureRequest(requestUid);
104
+ if (cancelled) {
105
+ return;
106
+ }
107
+ setCheckFailed(false);
108
+ setStatus(request.status);
109
+ if (request.status === "completed") {
110
+ setPhase("done");
111
+ notify({ kind: "success", title: "Leftover data erased", message: `Everything left over from ${address} was erased.` });
112
+ onErasedRef.current?.(address);
113
+ return;
114
+ }
115
+ if (request.status === "denied") {
116
+ setError(request.reason || "The erasure was refused.");
117
+ setPhase("refused");
118
+ return;
119
+ }
120
+ } catch {
121
+ if (cancelled) {
122
+ return;
123
+ }
124
+ setCheckFailed(true);
125
+ }
126
+ timer = setTimeout(() => void check(), pollIntervalMs);
127
+ };
128
+ void check();
129
+ return () => {
130
+ cancelled = true;
131
+ clearTimeout(timer);
132
+ };
133
+ }, [phase, requestUid, address, pollIntervalMs]);
134
+
135
+ // Closing is ignored while the request that files the erasure is under way, so its answer can't land on a dialog that was dismissed.
136
+ function dismiss() {
137
+ if (phase !== "filing") {
138
+ onClose();
139
+ }
140
+ }
141
+
142
+ function handleDone() {
143
+ onClose();
144
+ onDone?.();
145
+ }
146
+
147
+ const summary = counts
148
+ ? `It still has ${counts.folders} ${counts.folders === 1 ? "folder" : "folders"} and ${counts.messages} ${counts.messages === 1 ? "message" : "messages"}, and everything else stored with them.`
149
+ : "It still has its folders and everything stored in them.";
150
+
151
+ return (
152
+ <Modal open onClose={dismiss} title="Erase leftover data">
153
+ {(phase === "confirm" || phase === "filing") && (
154
+ <form onSubmit={handleErase}>
155
+ <p className="text-sm mb-3">
156
+ <strong className="break-all">{address}</strong> was deleted, but its data was kept. {summary}
157
+ </p>
158
+ <p className="text-sm mb-3">
159
+ Erasing permanently deletes all of it - the mail, drafts and attachments, contacts, calendar events, tasks,
160
+ notes, labels, filter rules and signatures, encryption keys, share links and access lists - and frees the
161
+ address for a new mailbox.
162
+ </p>
163
+ <p className="text-sm font-semibold text-danger mb-4">This is irreversible and cannot be undone.</p>
164
+ <label className="flex flex-col gap-1.5 text-sm mb-4">
165
+ <span className="font-semibold">
166
+ Type <span className="break-all">{address}</span> to confirm
167
+ </span>
168
+ <input
169
+ aria-label="Type the address to confirm"
170
+ className={INPUT_CLASS}
171
+ value={typed}
172
+ disabled={phase === "filing"}
173
+ autoComplete="off"
174
+ spellCheck={false}
175
+ onChange={(e) => setTyped(e.target.value)}
176
+ />
177
+ </label>
178
+ {error && <Alert>{error}</Alert>}
179
+ <div className="flex gap-3 justify-end">
180
+ <Button type="button" variant="secondary" className="!w-auto" disabled={phase === "filing"} onClick={dismiss}>
181
+ Cancel
182
+ </Button>
183
+ <Button type="submit" className={DANGER_BUTTON_CLASS} loading={phase === "filing"} disabled={phase === "filing" || !confirmed}>
184
+ Erase data
185
+ </Button>
186
+ </div>
187
+ </form>
188
+ )}
189
+
190
+ {phase === "watching" && (
191
+ <div>
192
+ <p className="text-sm mb-3">
193
+ Erasing the data left over from <strong className="break-all">{address}</strong>.
194
+ </p>
195
+ <p role="status" className="flex items-center gap-2 text-sm font-semibold mb-3">
196
+ <span className="w-4 h-4 rounded-full border-2 border-current/30 border-t-current animate-spin" aria-hidden="true" />
197
+ {progressLabel(status)}
198
+ </p>
199
+ {checkFailed && (
200
+ <p className="text-sm text-danger mb-3">Could not check how far the erasure has got. Trying again&hellip;</p>
201
+ )}
202
+ <p className="text-sm text-text-muted mb-4">
203
+ You can close this window: the erasure carries on in the background, and the Mailboxes page shows how it is going.
204
+ </p>
205
+ <div className="flex justify-end">
206
+ <Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
207
+ Stop watching
208
+ </Button>
209
+ </div>
210
+ </div>
211
+ )}
212
+
213
+ {phase === "done" && (
214
+ <div>
215
+ <p role="status" className="text-sm mb-4">
216
+ Everything left over from <strong className="break-all">{address}</strong> was erased. The address is free to use again.
217
+ </p>
218
+ <div className="flex justify-end">
219
+ <Button type="button" className="!w-auto" onClick={handleDone}>
220
+ {doneLabel}
221
+ </Button>
222
+ </div>
223
+ </div>
224
+ )}
225
+
226
+ {phase === "refused" && (
227
+ <div>
228
+ <Alert>{error}</Alert>
229
+ <div className="flex justify-end">
230
+ <Button type="button" variant="secondary" className="!w-auto" onClick={onClose}>
231
+ OK
232
+ </Button>
233
+ </div>
234
+ </div>
235
+ )}
236
+ </Modal>
237
+ );
238
+ }