@rapidmx/web-client 0.20.0 → 0.21.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 (118) 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/layout/AdminShell.tsx +384 -384
  16. package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -238
  17. package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
  18. package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -194
  19. package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
  20. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
  21. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
  22. package/apps/shared/components/admin/settings/PluginsManager.tsx +2093 -2093
  23. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
  24. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
  25. package/apps/shared/components/admin/setup/SetupWizard.tsx +446 -446
  26. package/apps/shared/components/admin/usePagedList.tsx +129 -129
  27. package/apps/shared/components/calendar/EventModal.tsx +206 -206
  28. package/apps/shared/components/calendar/MonthView.tsx +185 -185
  29. package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
  30. package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
  31. package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
  32. package/apps/shared/components/calendar/allDay.ts +124 -124
  33. package/apps/shared/components/contacts/ContactForm.tsx +383 -383
  34. package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -103
  35. package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
  36. package/apps/shared/components/layout/AppShell.tsx +463 -461
  37. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
  38. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
  39. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
  40. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
  41. package/apps/shared/components/layout/UserMenu.tsx +439 -439
  42. package/apps/shared/components/mail/ConversationList.tsx +332 -332
  43. package/apps/shared/components/mail/ConversationThreadPane.tsx +613 -613
  44. package/apps/shared/components/mail/MailSelectionBar.tsx +240 -240
  45. package/apps/shared/components/mail/MenuButton.tsx +404 -404
  46. package/apps/shared/components/mail/MessageDetailPane.tsx +1757 -1757
  47. package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
  48. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
  49. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1705 -1681
  50. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
  51. package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
  52. package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
  53. package/apps/shared/components/mail/reading/MessageMoreMenu.tsx +258 -258
  54. package/apps/shared/components/mail/reading/MessageSourceDialog.tsx +79 -79
  55. package/apps/shared/components/mail/reading/messageExport.ts +59 -59
  56. package/apps/shared/components/mail/reading/printMessage.ts +99 -99
  57. package/apps/shared/components/mail/reading/useMessageActions.ts +443 -443
  58. package/apps/shared/components/mail/verificationSeals.ts +125 -125
  59. package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
  60. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
  61. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
  62. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
  63. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
  64. package/apps/shared/keyboard/dispatch.ts +124 -124
  65. package/apps/shared/keyboard/format.ts +89 -89
  66. package/apps/shared/keyboard/keymap.ts +114 -114
  67. package/apps/shared/keyboard/registry.ts +65 -65
  68. package/apps/shared/keyboard/targets.ts +79 -79
  69. package/apps/shared/mail/folderOfType.ts +49 -49
  70. package/apps/shared/mail/folderTree.ts +143 -143
  71. package/apps/shared/mail/listAllPages.ts +39 -39
  72. package/apps/shared/mail/newMailNotifications.ts +171 -171
  73. package/apps/shared/mail/outbox/sendJob.ts +445 -445
  74. package/apps/shared/mail/outbox/sendOutcomes.ts +155 -155
  75. package/apps/shared/mail/reportNotices.ts +66 -66
  76. package/apps/shared/mail/senderBlocking.ts +141 -141
  77. package/apps/shared/mail/useMailConnection.ts +205 -205
  78. package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
  79. package/apps/shared/mail/useMailboxUpdateAccess.ts +60 -60
  80. package/apps/shared/mail/useMarkMessageRead.ts +47 -47
  81. package/apps/shared/mail/useNewMailNotifications.ts +178 -178
  82. package/apps/shared/notifications/store.ts +560 -560
  83. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
  84. package/apps/shared/search/localIndexBuilder.ts +481 -481
  85. package/apps/shared/signing/enrollmentStorage.ts +33 -33
  86. package/apps/shared/signing/enrollmentTracker.ts +385 -385
  87. package/apps/shared/signing/enrollmentView.ts +251 -251
  88. package/apps/shared/signing/useNow.ts +19 -19
  89. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
  90. package/apps/shared/styles/app.css +396 -396
  91. package/apps/www/calendar/index.tsx +581 -581
  92. package/apps/www/contacts/[uid].tsx +112 -112
  93. package/apps/www/index.tsx +3012 -3012
  94. package/apps/www/messages/[uid].tsx +139 -139
  95. package/apps/www/settings/auto-reply/index.tsx +136 -136
  96. package/apps/www/settings/blocked-senders/index.tsx +303 -303
  97. package/apps/www/settings/encryption/index.tsx +1290 -1290
  98. package/apps/www/settings/filters/[uid].tsx +179 -179
  99. package/apps/www/settings/filters/index.tsx +105 -105
  100. package/apps/www/settings/filters/new/index.tsx +165 -165
  101. package/apps/www/settings/labels/index.tsx +207 -207
  102. package/apps/www/settings/privacy/index.tsx +495 -495
  103. package/apps/www/settings/profile/index.tsx +251 -251
  104. package/apps/www/settings/read-receipts/index.tsx +150 -150
  105. package/apps/www/settings/sharing/index.tsx +259 -259
  106. package/apps/www/settings/signatures/[uid].tsx +175 -175
  107. package/apps/www/settings/signatures/index.tsx +91 -91
  108. package/apps/www/settings/signatures/new/index.tsx +138 -138
  109. package/apps/www/tasks/index.tsx +654 -654
  110. package/dist/apps/shared/components/admin/layout/AdminShell.js +2 -2
  111. package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
  112. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +2 -2
  113. package/dist/apps/shared/components/layout/AppShell.js +4 -2
  114. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +7 -1
  115. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +20 -1
  116. package/dist/apps/shared/components/mail/reading/printMessage.js +11 -11
  117. package/dist/apps/shared/styles/app.css +396 -396
  118. package/package.json +2 -2
@@ -1,119 +1,119 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import React, { FormEvent, useEffect, useState } from "react";
6
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
- import { EncryptionPolicy, PolicyState, updateEncryptionPolicy } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
8
- import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
9
- import Button from "@rapidmx/react-shared/components/buttons/Button.js";
10
-
11
- const SELECT_CLASS =
12
- "w-full text-sm py-2 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
13
-
14
- const TIERS: { key: keyof EncryptionPolicy; label: string; help: string }[] = [
15
- { key: "encryptSameOrg", label: "Mail within this server", help: "Messages between mailboxes hosted on this server." },
16
- {
17
- key: "encryptFederated",
18
- label: "Mail to other RapidMX servers",
19
- help: "Messages to people on another RapidMX server that publishes its encryption keys.",
20
- },
21
- { key: "encryptExternal", label: "Mail to everyone else", help: "Messages to any other email provider, using S/MIME." },
22
- ];
23
-
24
- const STATES: { value: PolicyState; label: string }[] = [
25
- { value: "automatic", label: "Always encrypt when possible" },
26
- { value: "optional", label: "Let people choose" },
27
- { value: "prohibited", label: "Never encrypt" },
28
- ];
29
-
30
- /** Whether end-to-end encryption can be used at all under `policy` - i.e. any tier allows it. */
31
- export function isEncryptionEnabled(policy: EncryptionPolicy): boolean {
32
- return TIERS.some((tier) => policy[tier.key] !== "prohibited");
33
- }
34
-
35
- export interface EncryptionPolicyFormProps {
36
- policy: EncryptionPolicy;
37
- onChange: (policy: EncryptionPolicy) => void;
38
- /** Told whether the form has edits that haven't been saved. */
39
- onDirtyChange?: (dirty: boolean) => void;
40
- /** Set when shown as one section of a page with its own heading (the setup wizard), so the title is a smaller,
41
- * lower-level heading. */
42
- embedded?: boolean;
43
- }
44
-
45
- /** The end-to-end encryption policy editor, shared by the Encryption Policy page and the setup wizard. */
46
- export default function EncryptionPolicyForm({ policy, onChange, onDirtyChange, embedded = false }: EncryptionPolicyFormProps) {
47
- const [values, setValues] = useState<EncryptionPolicy>(policy);
48
- const [error, setError] = useState<string | null>(null);
49
- const [saving, setSaving] = useState(false);
50
- const [saved, setSaved] = useState(false);
51
-
52
- // Edits are unsaved until they match what was loaded or last saved.
53
- const [savedValues, setSavedValues] = useState<EncryptionPolicy>(policy);
54
- const dirty: boolean = TIERS.some((tier) => values[tier.key] !== savedValues[tier.key]);
55
- useEffect(() => onDirtyChange?.(dirty), [dirty]);
56
-
57
- async function handleSubmit(e: FormEvent) {
58
- e.preventDefault();
59
- setError(null);
60
- setSaved(false);
61
- setSaving(true);
62
- try {
63
- const updated = await updateEncryptionPolicy(values);
64
- onChange(updated);
65
- setSavedValues(values);
66
- setSaved(true);
67
- } catch (err) {
68
- setError(err instanceof ApiRequestError ? err.message : "Could not save the encryption policy.");
69
- } finally {
70
- setSaving(false);
71
- }
72
- }
73
-
74
- return (
75
- <div className="max-w-xl">
76
- {embedded ? (
77
- <h3 className="text-base font-bold uppercase tracking-wide mb-1">End-to-end encryption</h3>
78
- ) : (
79
- <h2 className="text-lg font-bold uppercase tracking-wide mb-1">End-to-end encryption</h2>
80
- )}
81
- <p className="text-sm text-text-muted mb-5">
82
- Encrypted messages can only be read by their senders and recipients - not by this server or its
83
- administrators. Choose how encryption applies to each kind of mail.
84
- </p>
85
-
86
- {error && <Alert>{error}</Alert>}
87
- {saved && !error && <div className="mb-4 text-sm text-success font-medium">Saved.</div>}
88
-
89
- <form onSubmit={handleSubmit} className="flex flex-col gap-4">
90
- {TIERS.map((tier) => (
91
- <label key={tier.key} className="flex flex-col gap-1.5 text-sm">
92
- <span className="font-semibold">{tier.label}</span>
93
- <select
94
- aria-label={tier.label}
95
- className={SELECT_CLASS}
96
- value={values[tier.key]}
97
- onChange={(e) => {
98
- setSaved(false);
99
- setValues({ ...values, [tier.key]: e.target.value as PolicyState });
100
- }}
101
- >
102
- {STATES.map((state) => (
103
- <option key={state.value} value={state.value}>
104
- {state.label}
105
- </option>
106
- ))}
107
- </select>
108
- <span className="text-xs text-text-muted">{tier.help}</span>
109
- </label>
110
- ))}
111
- <div>
112
- <Button type="submit" loading={saving} disabled={saving} className="!w-auto">
113
- Save
114
- </Button>
115
- </div>
116
- </form>
117
- </div>
118
- );
119
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { FormEvent, useEffect, useState } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import { EncryptionPolicy, PolicyState, updateEncryptionPolicy } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
8
+ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
9
+ import Button from "@rapidmx/react-shared/components/buttons/Button.js";
10
+
11
+ const SELECT_CLASS =
12
+ "w-full text-sm py-2 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
13
+
14
+ const TIERS: { key: keyof EncryptionPolicy; label: string; help: string }[] = [
15
+ { key: "encryptSameOrg", label: "Mail within this server", help: "Messages between mailboxes hosted on this server." },
16
+ {
17
+ key: "encryptFederated",
18
+ label: "Mail to other RapidMX servers",
19
+ help: "Messages to people on another RapidMX server that publishes its encryption keys.",
20
+ },
21
+ { key: "encryptExternal", label: "Mail to everyone else", help: "Messages to any other email provider, using S/MIME." },
22
+ ];
23
+
24
+ const STATES: { value: PolicyState; label: string }[] = [
25
+ { value: "automatic", label: "Always encrypt when possible" },
26
+ { value: "optional", label: "Let people choose" },
27
+ { value: "prohibited", label: "Never encrypt" },
28
+ ];
29
+
30
+ /** Whether end-to-end encryption can be used at all under `policy` - i.e. any tier allows it. */
31
+ export function isEncryptionEnabled(policy: EncryptionPolicy): boolean {
32
+ return TIERS.some((tier) => policy[tier.key] !== "prohibited");
33
+ }
34
+
35
+ export interface EncryptionPolicyFormProps {
36
+ policy: EncryptionPolicy;
37
+ onChange: (policy: EncryptionPolicy) => void;
38
+ /** Told whether the form has edits that haven't been saved. */
39
+ onDirtyChange?: (dirty: boolean) => void;
40
+ /** Set when shown as one section of a page with its own heading (the setup wizard), so the title is a smaller,
41
+ * lower-level heading. */
42
+ embedded?: boolean;
43
+ }
44
+
45
+ /** The end-to-end encryption policy editor, shared by the Encryption Policy page and the setup wizard. */
46
+ export default function EncryptionPolicyForm({ policy, onChange, onDirtyChange, embedded = false }: EncryptionPolicyFormProps) {
47
+ const [values, setValues] = useState<EncryptionPolicy>(policy);
48
+ const [error, setError] = useState<string | null>(null);
49
+ const [saving, setSaving] = useState(false);
50
+ const [saved, setSaved] = useState(false);
51
+
52
+ // Edits are unsaved until they match what was loaded or last saved.
53
+ const [savedValues, setSavedValues] = useState<EncryptionPolicy>(policy);
54
+ const dirty: boolean = TIERS.some((tier) => values[tier.key] !== savedValues[tier.key]);
55
+ useEffect(() => onDirtyChange?.(dirty), [dirty]);
56
+
57
+ async function handleSubmit(e: FormEvent) {
58
+ e.preventDefault();
59
+ setError(null);
60
+ setSaved(false);
61
+ setSaving(true);
62
+ try {
63
+ const updated = await updateEncryptionPolicy(values);
64
+ onChange(updated);
65
+ setSavedValues(values);
66
+ setSaved(true);
67
+ } catch (err) {
68
+ setError(err instanceof ApiRequestError ? err.message : "Could not save the encryption policy.");
69
+ } finally {
70
+ setSaving(false);
71
+ }
72
+ }
73
+
74
+ return (
75
+ <div className="max-w-xl">
76
+ {embedded ? (
77
+ <h3 className="text-base font-bold uppercase tracking-wide mb-1">End-to-end encryption</h3>
78
+ ) : (
79
+ <h2 className="text-lg font-bold uppercase tracking-wide mb-1">End-to-end encryption</h2>
80
+ )}
81
+ <p className="text-sm text-text-muted mb-5">
82
+ Encrypted messages can only be read by their senders and recipients - not by this server or its
83
+ administrators. Choose how encryption applies to each kind of mail.
84
+ </p>
85
+
86
+ {error && <Alert>{error}</Alert>}
87
+ {saved && !error && <div className="mb-4 text-sm text-success font-medium">Saved.</div>}
88
+
89
+ <form onSubmit={handleSubmit} className="flex flex-col gap-4">
90
+ {TIERS.map((tier) => (
91
+ <label key={tier.key} className="flex flex-col gap-1.5 text-sm">
92
+ <span className="font-semibold">{tier.label}</span>
93
+ <select
94
+ aria-label={tier.label}
95
+ className={SELECT_CLASS}
96
+ value={values[tier.key]}
97
+ onChange={(e) => {
98
+ setSaved(false);
99
+ setValues({ ...values, [tier.key]: e.target.value as PolicyState });
100
+ }}
101
+ >
102
+ {STATES.map((state) => (
103
+ <option key={state.value} value={state.value}>
104
+ {state.label}
105
+ </option>
106
+ ))}
107
+ </select>
108
+ <span className="text-xs text-text-muted">{tier.help}</span>
109
+ </label>
110
+ ))}
111
+ <div>
112
+ <Button type="submit" loading={saving} disabled={saving} className="!w-auto">
113
+ Save
114
+ </Button>
115
+ </div>
116
+ </form>
117
+ </div>
118
+ );
119
+ }
@@ -1,198 +1,198 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import React, { FormEvent, useEffect, useState } from "react";
6
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
- import { MailboxPolicy, updateMailboxPolicy } from "@rapidmx/react-shared/admin/mailboxPolicyApi.js";
8
- import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
9
- import Button from "@rapidmx/react-shared/components/buttons/Button.js";
10
-
11
- const INPUT_CLASS =
12
- "w-full text-sm py-2 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
13
-
14
- const GB = 1_000_000_000;
15
-
16
- /** Unrounded, so a quota that isn't a whole number of hundredths of a GB (say 4 MB) is shown as it is. */
17
- function toGb(bytes: number): string {
18
- return String(bytes / GB);
19
- }
20
-
21
- /** Whether a quota field's text is not the given number of bytes. */
22
- function differsFromBytes(text: string, bytes: number): boolean {
23
- return Math.round(Number(text) * GB) !== bytes;
24
- }
25
-
26
- /** Puts a field back to the server's config value; nothing is saved until the form is. */
27
- function ResetToDefault({ label, shown, onClick }: { label: string; shown: boolean; onClick: () => void }) {
28
- if (!shown) {
29
- return null;
30
- }
31
- return (
32
- <Button type="button" variant="text" className="!w-auto self-start text-xs -mt-2" onClick={onClick}>
33
- Reset to server default ({label})
34
- </Button>
35
- );
36
- }
37
-
38
- /** The form's values as they were loaded or last saved. */
39
- interface Baseline {
40
- defaultQuotaGb: string;
41
- autoProvisionEnabled: boolean;
42
- autoProvisionQuotaGb: string;
43
- }
44
-
45
- export interface MailboxPolicyFormProps {
46
- policy: MailboxPolicy;
47
- onChange: (policy: MailboxPolicy) => void;
48
- /** Told whether the form has edits that haven't been saved. */
49
- onDirtyChange?: (dirty: boolean) => void;
50
- /** Set when shown as one section of a page with its own heading (the setup wizard), so the title is a smaller,
51
- * lower-level heading. */
52
- embedded?: boolean;
53
- }
54
-
55
- /**
56
- * The mailbox defaults editor, shared by the Mailbox Policy page and the setup wizard. Each field can be reset to what
57
- * the server's config currently says (`policy.defaults`), which lets an administrator take a newly deployed value
58
- * without typing it in; the reset fills the field in and is saved with the rest of the form.
59
- */
60
- export default function MailboxPolicyForm({ policy, onChange, onDirtyChange, embedded = false }: MailboxPolicyFormProps) {
61
- const defaults = policy.defaults;
62
- const [defaultQuotaGb, setDefaultQuotaGb] = useState(toGb(policy.defaultQuotaBytes));
63
- const [autoProvisionEnabled, setAutoProvisionEnabled] = useState(policy.autoProvisionEnabled);
64
- const [autoProvisionQuotaGb, setAutoProvisionQuotaGb] = useState(toGb(policy.autoProvisionQuotaBytes));
65
- const [error, setError] = useState<string | null>(null);
66
- const [saving, setSaving] = useState(false);
67
- const [saved, setSaved] = useState(false);
68
-
69
- // Edits are unsaved until they match what was loaded or last saved.
70
- const [baseline, setBaseline] = useState<Baseline>({ defaultQuotaGb, autoProvisionEnabled, autoProvisionQuotaGb });
71
- const dirty: boolean =
72
- defaultQuotaGb !== baseline.defaultQuotaGb ||
73
- autoProvisionEnabled !== baseline.autoProvisionEnabled ||
74
- autoProvisionQuotaGb !== baseline.autoProvisionQuotaGb;
75
- useEffect(() => onDirtyChange?.(dirty), [dirty]);
76
-
77
- async function handleSubmit(e: FormEvent) {
78
- e.preventDefault();
79
- setError(null);
80
- setSaved(false);
81
- // Only fields the administrator changed are sent, so a quota left alone keeps its exact stored bytes.
82
- const patch: Partial<MailboxPolicy> = {};
83
- for (const [field, text, base] of [
84
- ["defaultQuotaBytes", defaultQuotaGb, baseline.defaultQuotaGb],
85
- ["autoProvisionQuotaBytes", autoProvisionQuotaGb, baseline.autoProvisionQuotaGb],
86
- ] as const) {
87
- if (text === base) {
88
- continue;
89
- }
90
- const bytes: number = Math.round(Number(text) * GB);
91
- if (!(bytes >= 1)) {
92
- setError("Quotas must be more than 0 GB.");
93
- return;
94
- }
95
- patch[field] = bytes;
96
- }
97
- if (autoProvisionEnabled !== baseline.autoProvisionEnabled) {
98
- patch.autoProvisionEnabled = autoProvisionEnabled;
99
- }
100
- const current: Baseline = { defaultQuotaGb, autoProvisionEnabled, autoProvisionQuotaGb };
101
- if (Object.keys(patch).length === 0) {
102
- setSaved(true);
103
- return;
104
- }
105
- setSaving(true);
106
- try {
107
- const updated = await updateMailboxPolicy(patch);
108
- onChange(updated);
109
- setBaseline(current);
110
- setSaved(true);
111
- } catch (err) {
112
- setError(err instanceof ApiRequestError ? err.message : "Could not save the mailbox policy.");
113
- } finally {
114
- setSaving(false);
115
- }
116
- }
117
-
118
- return (
119
- <div className="max-w-xl">
120
- {embedded ? (
121
- <h3 className="text-base font-bold uppercase tracking-wide mb-1">Mailboxes</h3>
122
- ) : (
123
- <h2 className="text-lg font-bold uppercase tracking-wide mb-1">Mailboxes</h2>
124
- )}
125
- <p className="text-sm text-text-muted mb-5">Defaults for new mailboxes on this server.</p>
126
-
127
- {error && <Alert>{error}</Alert>}
128
- {saved && !error && <div className="mb-4 text-sm text-success font-medium">Saved.</div>}
129
-
130
- <form onSubmit={handleSubmit} className="flex flex-col gap-4">
131
- <label className="flex flex-col gap-1.5 text-sm">
132
- <span className="font-semibold">Default quota (GB)</span>
133
- <input
134
- aria-label="Default quota (GB)"
135
- type="number"
136
- min={0}
137
- step="any"
138
- className={INPUT_CLASS}
139
- value={defaultQuotaGb}
140
- onChange={(e) => setDefaultQuotaGb(e.target.value)}
141
- />
142
- <span className="text-xs text-text-muted">The storage a mailbox starts with when an administrator creates it.</span>
143
- </label>
144
- <ResetToDefault
145
- label={defaults ? `${toGb(defaults.defaultQuotaBytes)} GB` : ""}
146
- shown={!!defaults && differsFromBytes(defaultQuotaGb, defaults.defaultQuotaBytes)}
147
- onClick={() => setDefaultQuotaGb(toGb(defaults!.defaultQuotaBytes))}
148
- />
149
- <label className="flex items-start gap-2 text-sm">
150
- <input
151
- type="checkbox"
152
- className="mt-1"
153
- checked={autoProvisionEnabled}
154
- onChange={(e) => setAutoProvisionEnabled(e.target.checked)}
155
- />
156
- <span>
157
- <span className="font-semibold block">Let people create their own mailbox</span>
158
- <span className="text-xs text-text-muted">
159
- Someone who signs in without a mailbox can create one, using their username on one of this
160
- server&rsquo;s verified domains.
161
- </span>
162
- </span>
163
- </label>
164
- <ResetToDefault
165
- label={defaults?.autoProvisionEnabled ? "on" : "off"}
166
- shown={!!defaults && autoProvisionEnabled !== defaults.autoProvisionEnabled}
167
- onClick={() => setAutoProvisionEnabled(defaults!.autoProvisionEnabled)}
168
- />
169
- {autoProvisionEnabled && (
170
- <>
171
- <label className="flex flex-col gap-1.5 text-sm">
172
- <span className="font-semibold">Quota for self-created mailboxes (GB)</span>
173
- <input
174
- aria-label="Quota for self-created mailboxes (GB)"
175
- type="number"
176
- min={0}
177
- step="any"
178
- className={INPUT_CLASS}
179
- value={autoProvisionQuotaGb}
180
- onChange={(e) => setAutoProvisionQuotaGb(e.target.value)}
181
- />
182
- </label>
183
- <ResetToDefault
184
- label={defaults ? `${toGb(defaults.autoProvisionQuotaBytes)} GB` : ""}
185
- shown={!!defaults && differsFromBytes(autoProvisionQuotaGb, defaults.autoProvisionQuotaBytes)}
186
- onClick={() => setAutoProvisionQuotaGb(toGb(defaults!.autoProvisionQuotaBytes))}
187
- />
188
- </>
189
- )}
190
- <div>
191
- <Button type="submit" loading={saving} disabled={saving} className="!w-auto">
192
- Save
193
- </Button>
194
- </div>
195
- </form>
196
- </div>
197
- );
198
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { FormEvent, useEffect, useState } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import { MailboxPolicy, updateMailboxPolicy } from "@rapidmx/react-shared/admin/mailboxPolicyApi.js";
8
+ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
9
+ import Button from "@rapidmx/react-shared/components/buttons/Button.js";
10
+
11
+ const INPUT_CLASS =
12
+ "w-full text-sm py-2 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
13
+
14
+ const GB = 1_000_000_000;
15
+
16
+ /** Unrounded, so a quota that isn't a whole number of hundredths of a GB (say 4 MB) is shown as it is. */
17
+ function toGb(bytes: number): string {
18
+ return String(bytes / GB);
19
+ }
20
+
21
+ /** Whether a quota field's text is not the given number of bytes. */
22
+ function differsFromBytes(text: string, bytes: number): boolean {
23
+ return Math.round(Number(text) * GB) !== bytes;
24
+ }
25
+
26
+ /** Puts a field back to the server's config value; nothing is saved until the form is. */
27
+ function ResetToDefault({ label, shown, onClick }: { label: string; shown: boolean; onClick: () => void }) {
28
+ if (!shown) {
29
+ return null;
30
+ }
31
+ return (
32
+ <Button type="button" variant="text" className="!w-auto self-start text-xs -mt-2" onClick={onClick}>
33
+ Reset to server default ({label})
34
+ </Button>
35
+ );
36
+ }
37
+
38
+ /** The form's values as they were loaded or last saved. */
39
+ interface Baseline {
40
+ defaultQuotaGb: string;
41
+ autoProvisionEnabled: boolean;
42
+ autoProvisionQuotaGb: string;
43
+ }
44
+
45
+ export interface MailboxPolicyFormProps {
46
+ policy: MailboxPolicy;
47
+ onChange: (policy: MailboxPolicy) => void;
48
+ /** Told whether the form has edits that haven't been saved. */
49
+ onDirtyChange?: (dirty: boolean) => void;
50
+ /** Set when shown as one section of a page with its own heading (the setup wizard), so the title is a smaller,
51
+ * lower-level heading. */
52
+ embedded?: boolean;
53
+ }
54
+
55
+ /**
56
+ * The mailbox defaults editor, shared by the Mailbox Policy page and the setup wizard. Each field can be reset to what
57
+ * the server's config currently says (`policy.defaults`), which lets an administrator take a newly deployed value
58
+ * without typing it in; the reset fills the field in and is saved with the rest of the form.
59
+ */
60
+ export default function MailboxPolicyForm({ policy, onChange, onDirtyChange, embedded = false }: MailboxPolicyFormProps) {
61
+ const defaults = policy.defaults;
62
+ const [defaultQuotaGb, setDefaultQuotaGb] = useState(toGb(policy.defaultQuotaBytes));
63
+ const [autoProvisionEnabled, setAutoProvisionEnabled] = useState(policy.autoProvisionEnabled);
64
+ const [autoProvisionQuotaGb, setAutoProvisionQuotaGb] = useState(toGb(policy.autoProvisionQuotaBytes));
65
+ const [error, setError] = useState<string | null>(null);
66
+ const [saving, setSaving] = useState(false);
67
+ const [saved, setSaved] = useState(false);
68
+
69
+ // Edits are unsaved until they match what was loaded or last saved.
70
+ const [baseline, setBaseline] = useState<Baseline>({ defaultQuotaGb, autoProvisionEnabled, autoProvisionQuotaGb });
71
+ const dirty: boolean =
72
+ defaultQuotaGb !== baseline.defaultQuotaGb ||
73
+ autoProvisionEnabled !== baseline.autoProvisionEnabled ||
74
+ autoProvisionQuotaGb !== baseline.autoProvisionQuotaGb;
75
+ useEffect(() => onDirtyChange?.(dirty), [dirty]);
76
+
77
+ async function handleSubmit(e: FormEvent) {
78
+ e.preventDefault();
79
+ setError(null);
80
+ setSaved(false);
81
+ // Only fields the administrator changed are sent, so a quota left alone keeps its exact stored bytes.
82
+ const patch: Partial<MailboxPolicy> = {};
83
+ for (const [field, text, base] of [
84
+ ["defaultQuotaBytes", defaultQuotaGb, baseline.defaultQuotaGb],
85
+ ["autoProvisionQuotaBytes", autoProvisionQuotaGb, baseline.autoProvisionQuotaGb],
86
+ ] as const) {
87
+ if (text === base) {
88
+ continue;
89
+ }
90
+ const bytes: number = Math.round(Number(text) * GB);
91
+ if (!(bytes >= 1)) {
92
+ setError("Quotas must be more than 0 GB.");
93
+ return;
94
+ }
95
+ patch[field] = bytes;
96
+ }
97
+ if (autoProvisionEnabled !== baseline.autoProvisionEnabled) {
98
+ patch.autoProvisionEnabled = autoProvisionEnabled;
99
+ }
100
+ const current: Baseline = { defaultQuotaGb, autoProvisionEnabled, autoProvisionQuotaGb };
101
+ if (Object.keys(patch).length === 0) {
102
+ setSaved(true);
103
+ return;
104
+ }
105
+ setSaving(true);
106
+ try {
107
+ const updated = await updateMailboxPolicy(patch);
108
+ onChange(updated);
109
+ setBaseline(current);
110
+ setSaved(true);
111
+ } catch (err) {
112
+ setError(err instanceof ApiRequestError ? err.message : "Could not save the mailbox policy.");
113
+ } finally {
114
+ setSaving(false);
115
+ }
116
+ }
117
+
118
+ return (
119
+ <div className="max-w-xl">
120
+ {embedded ? (
121
+ <h3 className="text-base font-bold uppercase tracking-wide mb-1">Mailboxes</h3>
122
+ ) : (
123
+ <h2 className="text-lg font-bold uppercase tracking-wide mb-1">Mailboxes</h2>
124
+ )}
125
+ <p className="text-sm text-text-muted mb-5">Defaults for new mailboxes on this server.</p>
126
+
127
+ {error && <Alert>{error}</Alert>}
128
+ {saved && !error && <div className="mb-4 text-sm text-success font-medium">Saved.</div>}
129
+
130
+ <form onSubmit={handleSubmit} className="flex flex-col gap-4">
131
+ <label className="flex flex-col gap-1.5 text-sm">
132
+ <span className="font-semibold">Default quota (GB)</span>
133
+ <input
134
+ aria-label="Default quota (GB)"
135
+ type="number"
136
+ min={0}
137
+ step="any"
138
+ className={INPUT_CLASS}
139
+ value={defaultQuotaGb}
140
+ onChange={(e) => setDefaultQuotaGb(e.target.value)}
141
+ />
142
+ <span className="text-xs text-text-muted">The storage a mailbox starts with when an administrator creates it.</span>
143
+ </label>
144
+ <ResetToDefault
145
+ label={defaults ? `${toGb(defaults.defaultQuotaBytes)} GB` : ""}
146
+ shown={!!defaults && differsFromBytes(defaultQuotaGb, defaults.defaultQuotaBytes)}
147
+ onClick={() => setDefaultQuotaGb(toGb(defaults!.defaultQuotaBytes))}
148
+ />
149
+ <label className="flex items-start gap-2 text-sm">
150
+ <input
151
+ type="checkbox"
152
+ className="mt-1"
153
+ checked={autoProvisionEnabled}
154
+ onChange={(e) => setAutoProvisionEnabled(e.target.checked)}
155
+ />
156
+ <span>
157
+ <span className="font-semibold block">Let people create their own mailbox</span>
158
+ <span className="text-xs text-text-muted">
159
+ Someone who signs in without a mailbox can create one, using their username on one of this
160
+ server&rsquo;s verified domains.
161
+ </span>
162
+ </span>
163
+ </label>
164
+ <ResetToDefault
165
+ label={defaults?.autoProvisionEnabled ? "on" : "off"}
166
+ shown={!!defaults && autoProvisionEnabled !== defaults.autoProvisionEnabled}
167
+ onClick={() => setAutoProvisionEnabled(defaults!.autoProvisionEnabled)}
168
+ />
169
+ {autoProvisionEnabled && (
170
+ <>
171
+ <label className="flex flex-col gap-1.5 text-sm">
172
+ <span className="font-semibold">Quota for self-created mailboxes (GB)</span>
173
+ <input
174
+ aria-label="Quota for self-created mailboxes (GB)"
175
+ type="number"
176
+ min={0}
177
+ step="any"
178
+ className={INPUT_CLASS}
179
+ value={autoProvisionQuotaGb}
180
+ onChange={(e) => setAutoProvisionQuotaGb(e.target.value)}
181
+ />
182
+ </label>
183
+ <ResetToDefault
184
+ label={defaults ? `${toGb(defaults.autoProvisionQuotaBytes)} GB` : ""}
185
+ shown={!!defaults && differsFromBytes(autoProvisionQuotaGb, defaults.autoProvisionQuotaBytes)}
186
+ onClick={() => setAutoProvisionQuotaGb(toGb(defaults!.autoProvisionQuotaBytes))}
187
+ />
188
+ </>
189
+ )}
190
+ <div>
191
+ <Button type="submit" loading={saving} disabled={saving} className="!w-auto">
192
+ Save
193
+ </Button>
194
+ </div>
195
+ </form>
196
+ </div>
197
+ );
198
+ }