@rapidmx/web-client 0.11.0 → 0.12.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.
@@ -0,0 +1,164 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { KeyboardEvent, ReactNode, useEffect, useState } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import { ResolvedPrincipal } from "@rapidmx/react-shared/mail/mailboxAccessApi.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
+ export interface PrincipalResolverProps {
12
+ /** Resolves what was typed - a mailbox address, an auth-server username or e-mail alias, or a user uid - to
13
+ * the one person it names, exact match only. Rejects (typically with an `ApiRequestError`) for nobody. */
14
+ resolve: (principal: string) => Promise<ResolvedPrincipal>;
15
+ /** Called once the caller confirms the resolved person is the right one. The box is cleared once this
16
+ * resolves - throw (or reject) to keep the person on screen and show an error instead. */
17
+ onResolved: (person: ResolvedPrincipal) => void | Promise<void>;
18
+ /** Text put in the box to start with - a stored entry being replaced, say - looked up automatically on mount. */
19
+ initialPrincipal?: string;
20
+ /** What the box asks for. */
21
+ placeholder: string;
22
+ /** The box's accessible name. */
23
+ ariaLabel: string;
24
+ /** Extra controls rendered between the text box and the Find button (e.g. a role selector). */
25
+ children?: ReactNode;
26
+ /** The confirm button's label (e.g. "Grant", "Use this owner"). */
27
+ confirmLabel: string;
28
+ /** What the confirmation row says once a person is found - e.g. "Share with X as Y?". */
29
+ describeConfirm: (person: ResolvedPrincipal) => ReactNode;
30
+ /** Shown if `onResolved` rejects, unless it was an `ApiRequestError` (then its own message is shown). */
31
+ confirmErrorMessage: string;
32
+ /** Shown as a Cancel button next to the box when set (replacing an entry). */
33
+ onCancel?: () => void;
34
+ }
35
+
36
+ /** Who a resolved person is, for a person to check before confirming: their name and address, else their uid. */
37
+ export function describePerson(person: ResolvedPrincipal): string {
38
+ if (person.displayName && person.address) return `${person.displayName} <${person.address}>`;
39
+ return person.displayName ?? person.address ?? `user ${person.userUid}`;
40
+ }
41
+
42
+ /**
43
+ * "Who?" - anywhere a person is assigned by typed identifier rather than picked from an already-loaded list. What
44
+ * is typed is RESOLVED by the server (`resolve`) to the person it names before anything is saved, and the person is
45
+ * shown (name and address) for the caller to confirm; only `onResolved` ever sees the resolved, verified person -
46
+ * never the free text. This is deliberately exact-match, type-then-confirm - never a live/fuzzy search-as-you-type
47
+ * autocomplete, which would let anyone with access to the field enumerate the user directory by partial name.
48
+ *
49
+ * Parameterized entirely by `resolve`/`onResolved` (and the wording props) so every caller - mailbox sharing
50
+ * (`PrincipalPicker`, a thin wrapper around this component), mailbox ownership, escrow-scope holders, ... - reuses
51
+ * the same resolve-then-confirm UX and privacy posture rather than each reimplementing it.
52
+ *
53
+ * Deliberately renders no `<form>` of its own (Enter-to-find is wired up by hand instead, see `handleKeyDown()`) -
54
+ * some callers (`MailboxCreateForm`) use this as one field of their own, larger `<form>`, and a nested `<form>` is
55
+ * invalid HTML that real browsers mis-handle (an inner Enter keypress can submit the wrong one).
56
+ */
57
+ export default function PrincipalResolver({
58
+ resolve,
59
+ onResolved,
60
+ initialPrincipal,
61
+ placeholder,
62
+ ariaLabel,
63
+ children,
64
+ confirmLabel,
65
+ describeConfirm,
66
+ confirmErrorMessage,
67
+ onCancel,
68
+ }: PrincipalResolverProps) {
69
+ const [typed, setTyped] = useState(initialPrincipal ?? "");
70
+ const [person, setPerson] = useState<ResolvedPrincipal | null>(null);
71
+ const [busy, setBusy] = useState(false);
72
+ const [error, setError] = useState<string | null>(null);
73
+
74
+ // A stored entry being replaced is looked up straight away, so its person is shown without a click.
75
+ useEffect(() => {
76
+ if (initialPrincipal) {
77
+ void find(initialPrincipal);
78
+ }
79
+ }, [initialPrincipal]);
80
+
81
+ async function find(principal: string) {
82
+ setBusy(true);
83
+ setError(null);
84
+ setPerson(null);
85
+ try {
86
+ setPerson(await resolve(principal));
87
+ } catch (err) {
88
+ setError(err instanceof ApiRequestError ? err.message : "Could not look that person up.");
89
+ } finally {
90
+ setBusy(false);
91
+ }
92
+ }
93
+
94
+ function submitFind() {
95
+ const principal = typed.trim();
96
+ if (principal) {
97
+ void find(principal);
98
+ }
99
+ }
100
+
101
+ /** Enter in the text box finds, same as clicking the button - handled here (not a native `<form>` submit,
102
+ * see this component's own doc comment on why) so it works whether or not a caller nests this inside one of
103
+ * their own forms (`MailboxCreateForm` does). */
104
+ function handleKeyDown(e: KeyboardEvent<HTMLInputElement>) {
105
+ if (e.key === "Enter") {
106
+ // Stops the keystroke from also submitting an ANCESTOR `<form>` this component happens to be nested in.
107
+ e.preventDefault();
108
+ submitFind();
109
+ }
110
+ }
111
+
112
+ // Only reachable from the confirm button, which only renders once `person` is set.
113
+ async function handleConfirm() {
114
+ setBusy(true);
115
+ setError(null);
116
+ try {
117
+ await onResolved(person!);
118
+ setTyped("");
119
+ setPerson(null);
120
+ } catch (err) {
121
+ setError(err instanceof ApiRequestError ? err.message : confirmErrorMessage);
122
+ } finally {
123
+ setBusy(false);
124
+ }
125
+ }
126
+
127
+ return (
128
+ <div className="flex flex-col gap-2">
129
+ {error && <Alert>{error}</Alert>}
130
+ <div className="flex gap-2">
131
+ <input
132
+ type="text"
133
+ aria-label={ariaLabel}
134
+ placeholder={placeholder}
135
+ className="flex-1 text-sm border border-border rounded-sm py-1.5 px-2 bg-surface text-text"
136
+ value={typed}
137
+ onChange={(e) => {
138
+ setTyped(e.target.value);
139
+ setPerson(null);
140
+ }}
141
+ onKeyDown={handleKeyDown}
142
+ disabled={busy}
143
+ />
144
+ {children}
145
+ <Button type="button" variant="secondary" loading={busy && !person} disabled={busy} className="!w-auto" onClick={submitFind}>
146
+ Find
147
+ </Button>
148
+ {onCancel && (
149
+ <Button type="button" variant="text" className="!w-auto" onClick={onCancel}>
150
+ Cancel
151
+ </Button>
152
+ )}
153
+ </div>
154
+ {person && (
155
+ <div className="flex items-center justify-between gap-3 text-sm py-2 px-3 border border-border rounded-sm">
156
+ <span>{describeConfirm(person)}</span>
157
+ <Button type="button" loading={busy} disabled={busy} className="!w-auto" onClick={() => void handleConfirm()}>
158
+ {confirmLabel}
159
+ </Button>
160
+ </div>
161
+ )}
162
+ </div>
163
+ );
164
+ }
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import AdminShell from "../../../shared/components/admin/layout/AdminShell.js";
3
3
  import MailboxCreateForm from "../../../shared/components/admin/settings/MailboxCreateForm.js";
4
4
  export default function NewMailboxPage(props) {
5
- return (_jsx(AdminShell, { ...props, active: "mailboxes", children: _jsxs("div", { className: "max-w-xl", children: [_jsx("h1", { className: "text-xl font-bold uppercase tracking-wide mb-1", children: "New mailbox" }), _jsx("p", { className: "text-sm text-text-muted mb-5", children: "Leave \"Owner user uid\" blank to create a true ownerless shared mailbox (the Exchange \"shared mailbox\" concept) \u2014 access is then granted entirely to delegates afterward, not to a single owner. Set an owner to create a mailbox for a specific user instead." }), _jsx(MailboxCreateForm, { cancelHref: "/admin", onCreated: (mailbox) => {
5
+ return (_jsx(AdminShell, { ...props, active: "mailboxes", children: _jsxs("div", { className: "max-w-xl", children: [_jsx("h1", { className: "text-xl font-bold uppercase tracking-wide mb-1", children: "New mailbox" }), _jsx("p", { className: "text-sm text-text-muted mb-5", children: "Choose \"Shared mailbox\" to create a true ownerless mailbox (the Exchange \"shared mailbox\" concept) \u2014 access is then granted entirely to delegates afterward, not to a single owner. Choose \"Owned by a specific person\" and look them up to create a mailbox for a specific user instead." }), _jsx(MailboxCreateForm, { cancelHref: "/admin", onCreated: (mailbox) => {
6
6
  window.location.href = `/admin/mailboxes/${encodeURIComponent(mailbox.uid)}`;
7
7
  } })] }) }));
8
8
  }
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { toDatetimeLocal } from "@rapidmx/react-shared/util/dateInput.js";
3
+ import { resolveEscrowScopeHolder } from "@rapidmx/react-shared/admin/escrowScopesApi.js";
3
4
  import FormField from "@rapidmx/react-shared/components/forms/FormField.js";
4
- import StringListField from "../../forms/StringListField.js";
5
+ import PrincipalListField from "../../sharing/PrincipalListField.js";
5
6
  const INPUT_CLASS = "w-full text-sm py-2.5 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
6
7
  /** Builds an all-zeroes starting point for the "new" page — `notBefore`/`notAfter` default to "now" so an
7
8
  * admin pasting in a cert's own dates only has to touch what actually differs. */
@@ -31,5 +32,5 @@ export default function EscrowScopeKeyAndHoldersFields({ value, onChange, disabl
31
32
  function set(key, next) {
32
33
  onChange({ ...value, [key]: next });
33
34
  }
34
- return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsx("h2", { className: "text-base font-bold uppercase tracking-wide mb-1", children: "Public key" }), _jsx("p", { className: "text-sm text-text-muted mb-4", children: "The fields of an already-issued certificate \u2014 this server never generates or holds the corresponding private key." }), _jsx(FormField, { label: "Public key (base64)", htmlFor: "publicKey", children: _jsx("textarea", { id: "publicKey", className: `${INPUT_CLASS} font-mono text-xs`, rows: 4, value: value.publicKey, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("publicKey", e.target.value) }) }), _jsx(FormField, { label: "Key type", htmlFor: "keyType", children: _jsx("input", { id: "keyType", type: "text", className: INPUT_CLASS, value: value.keyType, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("keyType", e.target.value), placeholder: "x509" }) }), _jsx(FormField, { label: "Fingerprint (hex SHA-256)", htmlFor: "fingerprint", children: _jsx("input", { id: "fingerprint", type: "text", className: `${INPUT_CLASS} font-mono`, value: value.fingerprint, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("fingerprint", e.target.value) }) }), _jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-x-4", children: [_jsx(FormField, { label: "Not before", htmlFor: "notBefore", children: _jsx("input", { id: "notBefore", type: "datetime-local", className: INPUT_CLASS, value: value.notBefore, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("notBefore", e.target.value) }) }), _jsx(FormField, { label: "Not after", htmlFor: "notAfter", children: _jsx("input", { id: "notAfter", type: "datetime-local", className: INPUT_CLASS, value: value.notAfter, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("notAfter", e.target.value) }) })] })] }), _jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsx("h2", { className: "text-base font-bold uppercase tracking-wide mb-1", children: "Holders & dual control" }), _jsx("p", { className: "text-sm text-text-muted mb-4", children: "Every uid below is granted the eDiscovery/compliance holder role for this scope \u2014 a deliberately separate role from server administration. At least one holder is required." }), _jsx(StringListField, { label: "Holder user uids", id: "holderUserUids", values: value.holderUserUids, onChange: (holderUserUids) => set("holderUserUids", holderUserUids), placeholder: "User uid to add", emptyMessage: "No holders added yet.", disabled: disabled }), _jsx(FormField, { label: "Required holders (M-of-N dual control)", htmlFor: "requiredHolders", children: _jsx("input", { id: "requiredHolders", type: "number", className: INPUT_CLASS, value: value.requiredHolders, disabled: disabled, onChange: (e) => set("requiredHolders", Number(e.target.value) || 1) }) }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: value.notifySubjectOnAccess, disabled: disabled, onChange: (e) => set("notifySubjectOnAccess", e.target.checked) }), "Notify subject on access"] })] })] }));
35
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsx("h2", { className: "text-base font-bold uppercase tracking-wide mb-1", children: "Public key" }), _jsx("p", { className: "text-sm text-text-muted mb-4", children: "The fields of an already-issued certificate \u2014 this server never generates or holds the corresponding private key." }), _jsx(FormField, { label: "Public key (base64)", htmlFor: "publicKey", children: _jsx("textarea", { id: "publicKey", className: `${INPUT_CLASS} font-mono text-xs`, rows: 4, value: value.publicKey, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("publicKey", e.target.value) }) }), _jsx(FormField, { label: "Key type", htmlFor: "keyType", children: _jsx("input", { id: "keyType", type: "text", className: INPUT_CLASS, value: value.keyType, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("keyType", e.target.value), placeholder: "x509" }) }), _jsx(FormField, { label: "Fingerprint (hex SHA-256)", htmlFor: "fingerprint", children: _jsx("input", { id: "fingerprint", type: "text", className: `${INPUT_CLASS} font-mono`, value: value.fingerprint, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("fingerprint", e.target.value) }) }), _jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-x-4", children: [_jsx(FormField, { label: "Not before", htmlFor: "notBefore", children: _jsx("input", { id: "notBefore", type: "datetime-local", className: INPUT_CLASS, value: value.notBefore, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("notBefore", e.target.value) }) }), _jsx(FormField, { label: "Not after", htmlFor: "notAfter", children: _jsx("input", { id: "notAfter", type: "datetime-local", className: INPUT_CLASS, value: value.notAfter, disabled: disabled, readOnly: keyReadOnly, onChange: (e) => set("notAfter", e.target.value) }) })] })] }), _jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsx("h2", { className: "text-base font-bold uppercase tracking-wide mb-1", children: "Holders & dual control" }), _jsx("p", { className: "text-sm text-text-muted mb-4", children: "Every uid below is granted the eDiscovery/compliance holder role for this scope \u2014 a deliberately separate role from server administration. At least one holder is required." }), _jsx(PrincipalListField, { label: "Holder user uids", values: value.holderUserUids, onChange: (holderUserUids) => set("holderUserUids", holderUserUids), resolve: resolveEscrowScopeHolder, emptyMessage: "No holders added yet.", disabled: disabled }), _jsx(FormField, { label: "Required holders (M-of-N dual control)", htmlFor: "requiredHolders", children: _jsx("input", { id: "requiredHolders", type: "number", className: INPUT_CLASS, value: value.requiredHolders, disabled: disabled, onChange: (e) => set("requiredHolders", Number(e.target.value) || 1) }) }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: value.notifySubjectOnAccess, disabled: disabled, onChange: (e) => set("notifySubjectOnAccess", e.target.checked) }), "Notify subject on access"] })] })] }));
35
36
  }
@@ -15,6 +15,8 @@ const RECORD_TYPE_LABELS = {
15
15
  spf: "SPF",
16
16
  dkim: "DKIM",
17
17
  dmarc: "DMARC",
18
+ autodiscover_cname: "Autodiscover (CNAME)",
19
+ autodiscover_srv: "Autodiscover (SRV)",
18
20
  };
19
21
  /** How each record is named in a Copy button's accessible name ("Copy value for the SPF record"). */
20
22
  const RECORD_TYPE_NAMES = {
@@ -23,12 +25,25 @@ const RECORD_TYPE_NAMES = {
23
25
  spf: "SPF",
24
26
  dkim: "DKIM",
25
27
  dmarc: "DMARC",
28
+ autodiscover_cname: "Autodiscover CNAME",
29
+ autodiscover_srv: "Autodiscover SRV",
30
+ };
31
+ /** A one-line "why this matters", shown under a checklist row's label - only for record types unfamiliar
32
+ * enough to need one; the well-known mail records (ownership/MX/SPF/DKIM/DMARC) don't. */
33
+ const RECORD_TYPE_HELP = {
34
+ autodiscover_cname: "So EAS and Outlook clients can find this server automatically from just an email address. This hostname also needs to be covered by this server's TLS certificate.",
35
+ autodiscover_srv: "Same purpose as the CNAME above, for clients that check DNS SRV instead - and, unlike the CNAME, needs no extra TLS certificate, since it points at a hostname already covered. Prefer this one when a second certificate is hard to obtain.",
26
36
  };
27
37
  /** An MX record's recommended value is `"<priority> <mail server>"` - two separate fields in a DNS provider's form. */
28
38
  function splitMxValue(value) {
29
39
  const match = /^(\d+)\s+(\S+)$/.exec(value.trim());
30
40
  return match ? { priority: match[1], server: match[2] } : null;
31
41
  }
42
+ /** A SRV record's recommended value is `"<priority> <weight> <port> <target>"` - four separate fields in a DNS provider's form. */
43
+ function splitSrvValue(value) {
44
+ const match = /^(\d+)\s+(\d+)\s+(\d+)\s+(\S+)$/.exec(value.trim());
45
+ return match ? { priority: match[1], weight: match[2], port: match[3], target: match[4] } : null;
46
+ }
32
47
  /** A value to type into a DNS provider's form, shown in full (long DKIM keys wrap) with a Copy button beside it. */
33
48
  function CopyableValue({ value, copyLabel }) {
34
49
  return (_jsxs("div", { className: "flex items-start gap-2", children: [_jsx("code", { className: "flex-1 min-w-0 text-xs break-all", children: value }), _jsx(CopyButton, { value: value, label: copyLabel })] }));
@@ -88,14 +103,19 @@ export default function DomainDnsSetup({ uid, onLoaded }) {
88
103
  const ownership = dnsSetup.find((c) => c.type === "ownership");
89
104
  const ownershipValue = ownership?.recommendedValue ?? `rapidmx-domain-verification=${domain.verificationToken}`;
90
105
  const ownershipName = ownership?.recordName || domain.name;
91
- return (_jsxs("div", { className: "flex flex-col gap-5", children: [_jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsxs("dl", { className: "grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3 text-sm", children: [_jsx("dt", { className: "text-text-muted", children: "Enabled" }), _jsx("dd", { children: domain.enabled ? "Yes" : "No" }), _jsx("dt", { className: "text-text-muted", children: "Verification" }), _jsx("dd", { children: domain.verified ? (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-success text-white", children: "Verified" })) : (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-surface-alt text-text-muted", children: "Unverified" })) }), _jsx("dt", { className: "text-text-muted", children: "Last checked" }), _jsx("dd", { children: domain.lastCheckedAt ? new Date(domain.lastCheckedAt).toLocaleString() : "Never" })] }), !domain.verified && (_jsxs("div", { className: "mt-5 pt-5 border-t border-border", children: [_jsxs("p", { className: "text-sm mb-2", children: ["Add the following TXT record to ", _jsx("strong", { children: domain.name }), " to prove ownership, then verify:"] }), _jsxs("dl", { className: "grid grid-cols-[auto_1fr] items-start gap-x-4 gap-y-2 text-sm", children: [_jsx("dt", { className: "text-text-muted py-2", children: "Type" }), _jsx("dd", { className: "py-2", children: "TXT" }), _jsx("dt", { className: "text-text-muted py-2", children: "Name / host" }), _jsx("dd", { className: "bg-surface-alt border border-border rounded-sm py-1.5 px-3", children: _jsx(CopyableValue, { value: ownershipName, copyLabel: "Copy name for the ownership TXT record" }) }), _jsx("dt", { className: "text-text-muted py-2", children: "Value" }), _jsx("dd", { className: "bg-surface-alt border border-border rounded-sm py-1.5 px-3", children: _jsx(CopyableValue, { value: ownershipValue, copyLabel: "Copy value for the ownership TXT record" }) })] }), verifyError && (_jsx("div", { className: "mt-3", children: _jsx(Alert, { children: verifyError }) })), _jsx(Button, { type: "button", className: "!w-auto mt-3", loading: verifying, disabled: verifying, onClick: handleVerify, children: verifyError ? "Try again" : "Verify now" })] }))] }), dnsSetup.length > 0 && (_jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsx("h2", { className: "text-sm font-bold uppercase tracking-wide mb-3", children: "DNS setup checklist" }), _jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full text-sm border-collapse", children: [_jsx("thead", { children: _jsx("tr", { children: ["Record", "Status", "Name / host", "Recommended value"].map((h) => (_jsx("th", { className: "text-left text-xs uppercase tracking-wide text-text-muted py-2 px-2.5 border-b border-border", children: h }, h))) }) }), _jsx("tbody", { children: dnsSetup.map((check) => (_jsxs("tr", { children: [_jsxs("td", { className: "py-2.5 px-2.5 border-b border-border", children: [RECORD_TYPE_LABELS[check.type], _jsxs("div", { className: "text-xs text-text-muted", children: ["Type: ", check.recordKind] })] }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border", children: !check.configured ? (_jsx("span", { className: "text-xs text-text-muted", children: "Not configured" })) : check.matches ? (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-success text-white", children: "Live" })) : (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-surface-alt text-text-muted", children: "Not found" })) }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border text-text-muted min-w-[10rem]", children: check.recordName ? (_jsx(CopyableValue, { value: check.recordName, copyLabel: `Copy name for the ${RECORD_TYPE_NAMES[check.type]} record` })) : (_jsx("code", { className: "text-xs", children: "\u2014" })) }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border text-text-muted", children: check.recommendedValue ? (_jsx(DnsRecordValue, { check: check, value: check.recommendedValue })) : (_jsx("code", { className: "text-xs", children: "\u2014" })) })] }, check.type))) })] }) }), _jsxs("p", { className: "text-xs text-text-muted mt-3", children: ["Some DNS providers want the name relative to the domain (for example ", _jsx("code", { children: "@" }), " for the domain itself) rather than the full name."] })] }))] }));
106
+ return (_jsxs("div", { className: "flex flex-col gap-5", children: [_jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsxs("dl", { className: "grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3 text-sm", children: [_jsx("dt", { className: "text-text-muted", children: "Enabled" }), _jsx("dd", { children: domain.enabled ? "Yes" : "No" }), _jsx("dt", { className: "text-text-muted", children: "Verification" }), _jsx("dd", { children: domain.verified ? (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-success text-white", children: "Verified" })) : (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-surface-alt text-text-muted", children: "Unverified" })) }), _jsx("dt", { className: "text-text-muted", children: "Last checked" }), _jsx("dd", { children: domain.lastCheckedAt ? new Date(domain.lastCheckedAt).toLocaleString() : "Never" })] }), !domain.verified && (_jsxs("div", { className: "mt-5 pt-5 border-t border-border", children: [_jsxs("p", { className: "text-sm mb-2", children: ["Add the following TXT record to ", _jsx("strong", { children: domain.name }), " to prove ownership, then verify:"] }), _jsxs("dl", { className: "grid grid-cols-[auto_1fr] items-start gap-x-4 gap-y-2 text-sm", children: [_jsx("dt", { className: "text-text-muted py-2", children: "Type" }), _jsx("dd", { className: "py-2", children: "TXT" }), _jsx("dt", { className: "text-text-muted py-2", children: "Name / host" }), _jsx("dd", { className: "bg-surface-alt border border-border rounded-sm py-1.5 px-3", children: _jsx(CopyableValue, { value: ownershipName, copyLabel: "Copy name for the ownership TXT record" }) }), _jsx("dt", { className: "text-text-muted py-2", children: "Value" }), _jsx("dd", { className: "bg-surface-alt border border-border rounded-sm py-1.5 px-3", children: _jsx(CopyableValue, { value: ownershipValue, copyLabel: "Copy value for the ownership TXT record" }) })] }), verifyError && (_jsx("div", { className: "mt-3", children: _jsx(Alert, { children: verifyError }) })), _jsx(Button, { type: "button", className: "!w-auto mt-3", loading: verifying, disabled: verifying, onClick: handleVerify, children: verifyError ? "Try again" : "Verify now" })] }))] }), dnsSetup.length > 0 && (_jsxs("div", { className: "bg-surface border border-border rounded-md p-6", children: [_jsx("h2", { className: "text-sm font-bold uppercase tracking-wide mb-3", children: "DNS setup checklist" }), _jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full text-sm border-collapse", children: [_jsx("thead", { children: _jsx("tr", { children: ["Record", "Status", "Name / host", "Recommended value"].map((h) => (_jsx("th", { className: "text-left text-xs uppercase tracking-wide text-text-muted py-2 px-2.5 border-b border-border", children: h }, h))) }) }), _jsx("tbody", { children: dnsSetup.map((check) => (_jsxs("tr", { children: [_jsxs("td", { className: "py-2.5 px-2.5 border-b border-border", children: [RECORD_TYPE_LABELS[check.type], _jsxs("div", { className: "text-xs text-text-muted", children: ["Type: ", check.recordKind] }), RECORD_TYPE_HELP[check.type] && (_jsx("div", { className: "text-xs text-text-muted mt-1 max-w-xs", children: RECORD_TYPE_HELP[check.type] }))] }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border", children: !check.configured ? (_jsx("span", { className: "text-xs text-text-muted", children: "Not configured" })) : check.matches ? (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-success text-white", children: "Live" })) : (_jsx("span", { className: "text-xs font-bold uppercase tracking-wide py-0.5 px-2 rounded-pill bg-surface-alt text-text-muted", children: "Not found" })) }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border text-text-muted min-w-[10rem]", children: check.recordName ? (_jsx(CopyableValue, { value: check.recordName, copyLabel: `Copy name for the ${RECORD_TYPE_NAMES[check.type]} record` })) : (_jsx("code", { className: "text-xs", children: "\u2014" })) }), _jsx("td", { className: "py-2.5 px-2.5 border-b border-border text-text-muted", children: check.recommendedValue ? (_jsx(DnsRecordValue, { check: check, value: check.recommendedValue })) : (_jsx("code", { className: "text-xs", children: "\u2014" })) })] }, check.type))) })] }) }), _jsxs("p", { className: "text-xs text-text-muted mt-3", children: ["Some DNS providers want the name relative to the domain (for example ", _jsx("code", { children: "@" }), " for the domain itself) rather than the full name."] })] }))] }));
92
107
  }
93
- /** The value cell of a checklist row: an MX value as its two form fields (priority and mail server), anything else whole. */
108
+ /** The value cell of a checklist row: an MX value as its two form fields (priority and mail server), a SRV value as
109
+ * its four form fields (priority, weight, port and target), anything else whole. */
94
110
  function DnsRecordValue({ check, value }) {
95
111
  const recordName = RECORD_TYPE_NAMES[check.type];
96
112
  const mx = check.type === "mx" ? splitMxValue(value) : null;
97
- if (!mx) {
98
- return _jsx(CopyableValue, { value: value, copyLabel: `Copy value for the ${recordName} record` });
113
+ if (mx) {
114
+ return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Priority" }), _jsx(CopyableValue, { value: mx.priority, copyLabel: `Copy priority for the ${recordName} record` })] }), _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Mail server" }), _jsx(CopyableValue, { value: mx.server, copyLabel: `Copy mail server for the ${recordName} record` })] })] }));
115
+ }
116
+ const srv = check.type === "autodiscover_srv" ? splitSrvValue(value) : null;
117
+ if (srv) {
118
+ return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Priority" }), _jsx(CopyableValue, { value: srv.priority, copyLabel: `Copy priority for the ${recordName} record` })] }), _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Weight" }), _jsx(CopyableValue, { value: srv.weight, copyLabel: `Copy weight for the ${recordName} record` })] }), _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Port" }), _jsx(CopyableValue, { value: srv.port, copyLabel: `Copy port for the ${recordName} record` })] }), _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Target" }), _jsx(CopyableValue, { value: srv.target, copyLabel: `Copy target for the ${recordName} record` })] })] }));
99
119
  }
100
- return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Priority" }), _jsx(CopyableValue, { value: mx.priority, copyLabel: `Copy priority for the ${recordName} record` })] }), _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-xs w-20 shrink-0 pt-1", children: "Mail server" }), _jsx(CopyableValue, { value: mx.server, copyLabel: `Copy mail server for the ${recordName} record` })] })] }));
120
+ return _jsx(CopyableValue, { value: value, copyLabel: `Copy value for the ${recordName} record` });
101
121
  }
@@ -6,10 +6,11 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
6
6
  import { useEffect, useRef, useState } from "react";
7
7
  import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
8
8
  import { getMailboxPolicy } from "@rapidmx/react-shared/admin/mailboxPolicyApi.js";
9
- import { createMailbox, listMailboxDomains } from "@rapidmx/react-shared/mail/mailApi.js";
9
+ import { createMailbox, listMailboxDomains, resolveMailboxOwner } from "@rapidmx/react-shared/mail/mailApi.js";
10
10
  import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
11
11
  import Button from "@rapidmx/react-shared/components/buttons/Button.js";
12
12
  import FormField from "@rapidmx/react-shared/components/forms/FormField.js";
13
+ import PrincipalResolver, { describePerson } from "../../sharing/PrincipalResolver.js";
13
14
  const INPUT_CLASS = "w-full text-sm py-2.5 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
14
15
  const SELECT_CLASS = "text-sm py-2.5 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
15
16
  /**
@@ -22,7 +23,8 @@ export default function MailboxCreateForm({ onCreated, defaults, submitLabel = "
22
23
  const [domains, setDomains] = useState([]);
23
24
  const [domain, setDomain] = useState("");
24
25
  const [displayName, setDisplayName] = useState(defaults?.displayName ?? "");
25
- const [ownerUserUid, setOwnerUserUid] = useState(defaults?.ownerUserUid ?? "");
26
+ const [ownerMode, setOwnerMode] = useState(defaults?.ownerUserUid ? "owned" : "shared");
27
+ const [resolvedOwner, setResolvedOwner] = useState(null);
26
28
  const [timezone, setTimezone] = useState("UTC");
27
29
  const [quotaGb, setQuotaGb] = useState(5);
28
30
  // Only replaced by the mailbox policy's default if the admin hasn't typed a quota of their own yet.
@@ -75,15 +77,18 @@ export default function MailboxCreateForm({ onCreated, defaults, submitLabel = "
75
77
  setError("A display name can't contain \"@\" (or a look-alike) or line breaks.");
76
78
  return;
77
79
  }
80
+ if (ownerMode === "owned" && !resolvedOwner) {
81
+ setError("Look up and confirm the mailbox's owner, or choose a shared mailbox instead.");
82
+ return;
83
+ }
78
84
  setSaving(true);
79
85
  try {
80
- // ownerUserUid left blank creates a true ownerless shared mailbox (e.g. support@example.com);
81
- // delegates are then granted access from the mailbox's detail page. A resource mailbox is
82
- // ownerless the same way — leave "Owner user uid" blank for one too.
86
+ // "Shared mailbox" creates a true ownerless mailbox (e.g. support@example.com); delegates are then
87
+ // granted access from the mailbox's detail page. A resource mailbox is ownerless the same way.
83
88
  const mailbox = await createMailbox({
84
89
  primarySmtpAddress: address,
85
90
  displayName: displayName.trim(),
86
- ownerUserUid: ownerUserUid.trim() || undefined,
91
+ ownerUserUid: ownerMode === "owned" ? resolvedOwner.userUid : undefined,
87
92
  timezone,
88
93
  quotaBytes: Math.round(quotaGb * 1000000000),
89
94
  ...(isResource && {
@@ -105,7 +110,13 @@ export default function MailboxCreateForm({ onCreated, defaults, submitLabel = "
105
110
  setSaving(false);
106
111
  }
107
112
  }
108
- return (_jsxs(_Fragment, { children: [error && _jsx(Alert, { children: error }), _jsxs("form", { onSubmit: handleSubmit, className: "bg-surface border border-border rounded-md p-6", children: [constrained ? (_jsx(FormField, { label: "Local part", htmlFor: "localPart", children: _jsxs("div", { className: "flex gap-2 items-center", children: [_jsx("input", { id: "localPart", type: "text", className: INPUT_CLASS, value: localPart, onChange: (e) => setLocalPart(e.target.value), placeholder: "support" }), _jsx("span", { className: "text-text-muted shrink-0", children: "@" }), _jsx("select", { "aria-label": "Domain", className: SELECT_CLASS, value: domain, onChange: (e) => setDomain(e.target.value), children: domains.map((d) => (_jsx("option", { value: d, children: d }, d))) })] }) })) : (_jsx(FormField, { label: "Primary SMTP address", htmlFor: "primarySmtpAddress", children: _jsx("input", { id: "primarySmtpAddress", type: "email", className: INPUT_CLASS, value: primarySmtpAddress, onChange: (e) => setPrimarySmtpAddress(e.target.value), placeholder: "support@example.com" }) })), _jsx(FormField, { label: "Display name", htmlFor: "displayName", children: _jsx("input", { id: "displayName", type: "text", className: INPUT_CLASS, value: displayName, onChange: (e) => setDisplayName(e.target.value), placeholder: "Support" }) }), _jsx(FormField, { label: "Owner user uid (optional)", htmlFor: "ownerUserUid", children: _jsx("input", { id: "ownerUserUid", type: "text", className: INPUT_CLASS, value: ownerUserUid, onChange: (e) => setOwnerUserUid(e.target.value), placeholder: "Leave blank for a shared mailbox" }) }), _jsx(FormField, { label: "Timezone", htmlFor: "timezone", children: _jsx("input", { id: "timezone", type: "text", className: INPUT_CLASS, value: timezone, onChange: (e) => setTimezone(e.target.value), placeholder: "America/Los_Angeles" }) }), _jsx(FormField, { label: "Quota (GB)", htmlFor: "quotaGb", children: _jsx("input", { id: "quotaGb", type: "number", min: 1, step: 1, className: INPUT_CLASS, value: quotaGb, onChange: (e) => {
113
+ return (_jsxs(_Fragment, { children: [error && _jsx(Alert, { children: error }), _jsxs("form", { onSubmit: handleSubmit, className: "bg-surface border border-border rounded-md p-6", children: [constrained ? (_jsx(FormField, { label: "Local part", htmlFor: "localPart", children: _jsxs("div", { className: "flex gap-2 items-center", children: [_jsx("input", { id: "localPart", type: "text", className: INPUT_CLASS, value: localPart, onChange: (e) => setLocalPart(e.target.value), placeholder: "support" }), _jsx("span", { className: "text-text-muted shrink-0", children: "@" }), _jsx("select", { "aria-label": "Domain", className: SELECT_CLASS, value: domain, onChange: (e) => setDomain(e.target.value), children: domains.map((d) => (_jsx("option", { value: d, children: d }, d))) })] }) })) : (_jsx(FormField, { label: "Primary SMTP address", htmlFor: "primarySmtpAddress", children: _jsx("input", { id: "primarySmtpAddress", type: "email", className: INPUT_CLASS, value: primarySmtpAddress, onChange: (e) => setPrimarySmtpAddress(e.target.value), placeholder: "support@example.com" }) })), _jsx(FormField, { label: "Display name", htmlFor: "displayName", children: _jsx("input", { id: "displayName", type: "text", className: INPUT_CLASS, value: displayName, onChange: (e) => setDisplayName(e.target.value), placeholder: "Support" }) }), _jsxs("div", { className: "mb-4", children: [_jsx("span", { className: "block text-sm font-semibold mb-1.5 text-text", children: "Owner" }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "radio", name: "ownerMode", checked: ownerMode === "shared", onChange: () => {
114
+ setOwnerMode("shared");
115
+ setResolvedOwner(null);
116
+ } }), "Shared mailbox (no single owner)"] }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "radio", name: "ownerMode", checked: ownerMode === "owned", onChange: () => setOwnerMode("owned") }), "Owned by a specific person"] }), ownerMode === "owned" &&
117
+ (resolvedOwner ? (_jsxs("div", { className: "flex items-center justify-between gap-3 text-sm py-2 px-3 border border-border rounded-sm", children: [_jsxs("span", { children: ["Owner: ", _jsx("strong", { className: "break-all", children: describePerson(resolvedOwner) })] }), _jsx(Button, { type: "button", variant: "text", className: "!w-auto", onClick: () => setResolvedOwner(null), children: "Change" })] })) : (_jsx(PrincipalResolver, { resolve: resolveMailboxOwner, onResolved: (person) => {
118
+ setResolvedOwner(person);
119
+ }, initialPrincipal: defaults?.ownerUserUid, placeholder: "Email address, username or user id", ariaLabel: "Mailbox owner", confirmLabel: "Use this owner", confirmErrorMessage: "Could not confirm this person.", describeConfirm: (person) => (_jsxs(_Fragment, { children: ["Make ", _jsx("strong", { className: "break-all", children: describePerson(person) }), " the owner?"] })) })))] })] }), _jsx(FormField, { label: "Timezone", htmlFor: "timezone", children: _jsx("input", { id: "timezone", type: "text", className: INPUT_CLASS, value: timezone, onChange: (e) => setTimezone(e.target.value), placeholder: "America/Los_Angeles" }) }), _jsx(FormField, { label: "Quota (GB)", htmlFor: "quotaGb", children: _jsx("input", { id: "quotaGb", type: "number", min: 1, step: 1, className: INPUT_CLASS, value: quotaGb, onChange: (e) => {
109
120
  quotaTouched.current = true;
110
121
  setQuotaGb(Number(e.target.value));
111
122
  } }) }), _jsxs("label", { className: "flex items-center gap-2 text-sm mb-4", children: [_jsx("input", { type: "checkbox", checked: isResource, onChange: (e) => setIsResource(e.target.checked) }), "This is a resource mailbox (a bookable room or piece of equipment)"] }), isResource && (_jsxs("div", { className: "border border-border rounded-sm p-4 mb-4 flex flex-col gap-4", children: [_jsx(FormField, { label: "Resource type", htmlFor: "resourceType", children: _jsxs("select", { id: "resourceType", className: SELECT_CLASS, value: resourceType, onChange: (e) => setResourceType(e.target.value), children: [_jsx("option", { value: "room", children: "Room" }), _jsx("option", { value: "equipment", children: "Equipment" })] }) }), _jsx(FormField, { label: "Capacity (optional)", htmlFor: "resourceCapacity", children: _jsx("input", { id: "resourceCapacity", type: "number", min: 0, step: 1, className: INPUT_CLASS, value: resourceCapacity, onChange: (e) => setResourceCapacity(e.target.value), placeholder: "Informational only" }) }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: autoAcceptBookings, onChange: (e) => setAutoAcceptBookings(e.target.checked) }), "Automatically accept booking requests"] }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: allowConflicts, onChange: (e) => setAllowConflicts(e.target.checked) }), "Allow conflicting bookings (skip conflict checking entirely)"] }), _jsx(FormField, { label: "Booking window, in days (optional)", htmlFor: "bookingWindowDays", children: _jsx("input", { id: "bookingWindowDays", type: "number", min: 0, step: 1, className: INPUT_CLASS, value: bookingWindowDays, onChange: (e) => setBookingWindowDays(e.target.value), placeholder: "No limit" }) }), _jsx(FormField, { label: "Maximum duration, in minutes (optional)", htmlFor: "maxDurationMinutes", children: _jsx("input", { id: "maxDurationMinutes", type: "number", min: 0, step: 1, className: INPUT_CLASS, value: maxDurationMinutes, onChange: (e) => setMaxDurationMinutes(e.target.value), placeholder: "No limit" }) })] })), _jsxs("div", { className: "flex gap-3 mt-2", children: [_jsx(Button, { type: "submit", loading: saving, disabled: saving, className: "!w-auto", children: submitLabel }), cancelHref && (_jsx("a", { href: cancelHref, children: _jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", children: "Cancel" }) }))] })] })] }));
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { ResolvedPrincipal } from "@rapidmx/react-shared/mail/mailboxAccessApi.js";
3
+ export interface PrincipalListFieldProps {
4
+ label: string;
5
+ values: string[];
6
+ onChange: (values: string[]) => void;
7
+ /** Exact-match resolve call for what's typed - see `PrincipalResolver`. */
8
+ resolve: (principal: string) => Promise<ResolvedPrincipal>;
9
+ placeholder?: string;
10
+ emptyMessage?: string;
11
+ disabled?: boolean;
12
+ }
13
+ /**
14
+ * A list-of-user-uids editor - the same visual list/per-item-remove shape `StringListField` established, but a
15
+ * uid can only be ADDED by looking it up and confirming who it is first (`PrincipalResolver`), never typed
16
+ * directly. Unlike `StringListField`'s free-text values (a distribution list's member addresses, a legal hold's
17
+ * custodian MAILBOX uids - values nobody needs to be "looked up" as a person for), every value here is a PERSON's
18
+ * user uid, granted a real role purely by what gets typed here - the exact "raw uid text field with no way to see
19
+ * whose it is" gap this app closes everywhere else a person is assigned by identifier.
20
+ *
21
+ * An already-added uid is still shown as plain text (same as `StringListField`, and as `ShareAccessCard`'s own
22
+ * member list) - it was already resolved and confirmed when it was added, so there is nothing left to look up.
23
+ */
24
+ export default function PrincipalListField({ label, values, onChange, resolve, placeholder, emptyMessage, disabled }: PrincipalListFieldProps): React.JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import PrincipalResolver, { describePerson } from "./PrincipalResolver.js";
3
+ /**
4
+ * A list-of-user-uids editor - the same visual list/per-item-remove shape `StringListField` established, but a
5
+ * uid can only be ADDED by looking it up and confirming who it is first (`PrincipalResolver`), never typed
6
+ * directly. Unlike `StringListField`'s free-text values (a distribution list's member addresses, a legal hold's
7
+ * custodian MAILBOX uids - values nobody needs to be "looked up" as a person for), every value here is a PERSON's
8
+ * user uid, granted a real role purely by what gets typed here - the exact "raw uid text field with no way to see
9
+ * whose it is" gap this app closes everywhere else a person is assigned by identifier.
10
+ *
11
+ * An already-added uid is still shown as plain text (same as `StringListField`, and as `ShareAccessCard`'s own
12
+ * member list) - it was already resolved and confirmed when it was added, so there is nothing left to look up.
13
+ */
14
+ export default function PrincipalListField({ label, values, onChange, resolve, placeholder, emptyMessage = "None added yet.", disabled }) {
15
+ function handleRemove(uid) {
16
+ onChange(values.filter((v) => v !== uid));
17
+ }
18
+ return (_jsxs("div", { className: "mb-4", children: [_jsx("span", { className: "block text-sm font-semibold mb-1.5 text-text", children: label }), _jsxs("ul", { className: "flex flex-col gap-2 mb-2", children: [values.length === 0 && (_jsx("li", { className: "text-sm text-text-muted", children: emptyMessage }, "empty")), values.map((uid) => (_jsxs("li", { className: "flex items-center justify-between gap-3 py-2 px-3 border border-border rounded-sm", children: [_jsx("span", { className: "text-sm font-medium break-all", children: uid }), _jsx("button", { type: "button", onClick: () => handleRemove(uid), disabled: disabled, className: "text-sm text-danger hover:underline disabled:opacity-55 shrink-0", children: "Remove" })] }, uid)))] }), !disabled && (_jsx(PrincipalResolver, { resolve: resolve, onResolved: (person) => {
19
+ if (!values.includes(person.userUid)) {
20
+ onChange([...values, person.userUid]);
21
+ }
22
+ }, placeholder: placeholder ?? "Email address, username or user id", ariaLabel: label, confirmLabel: "Add", confirmErrorMessage: "Could not add this person.", describeConfirm: (person) => (_jsxs(_Fragment, { children: ["Add ", _jsx("strong", { className: "break-all", children: describePerson(person) }), "?"] })) }))] }));
23
+ }
@@ -1,5 +1,7 @@
1
1
  import React from "react";
2
2
  import { MailboxAccessRole, ResolvedPrincipal } from "@rapidmx/react-shared/mail/mailboxAccessApi.js";
3
+ import { describePerson } from "./PrincipalResolver.js";
4
+ export { describePerson };
3
5
  export interface PrincipalPickerProps {
4
6
  mailboxUid: string;
5
7
  /** What each access level is called on this page. */
@@ -15,12 +17,12 @@ export interface PrincipalPickerProps {
15
17
  /** Shown as a Cancel button next to the box when set (replacing an entry). */
16
18
  onCancel?: () => void;
17
19
  }
18
- /** Who a resolved person is, for a person to check before saving: their name and address, else their uid. */
19
- export declare function describePerson(person: ResolvedPrincipal): string;
20
20
  /**
21
- * "Who?" for a sharing screen. What is typed - a mailbox address, an auth-server username or e-mail alias, or a user id -
22
- * is RESOLVED by the server (`resolveMailboxPrincipal()`) to the person it names before anything is saved, and the person
23
- * is shown (name and address) for the caller to confirm; only then is the grant made, against that person's uid. Free text
24
- * is never stored: an ACL record matches a user uid and nothing else, so a grant to a typed username applies to nobody.
21
+ * "Who?" for a sharing screen - a thin wrapper around the general `PrincipalResolver`, supplying mailbox sharing's
22
+ * own resolve call (`resolveMailboxPrincipal()`), its role selector, and its grant action (`setMailboxAccess()`).
23
+ * What is typed - a mailbox address, an auth-server username or e-mail alias, or a user id - is RESOLVED by the
24
+ * server before anything is saved, and the person is shown (name and address) for the caller to confirm; only then
25
+ * is the grant made, against that person's uid. Free text is never stored: an ACL record matches a user uid and
26
+ * nothing else, so a grant to a typed username applies to nobody.
25
27
  */
26
28
  export default function PrincipalPicker({ mailboxUid, roleLabels, initialPrincipal, defaultRole, placeholder, onGranted, onCancel }: PrincipalPickerProps): React.JSX.Element;
@@ -1,77 +1,24 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  ///////////////////////////////////////////////////////////////////////////////
3
3
  // Copyright (C) 2026 Jean-Philippe Steinmetz
4
4
  // SPDX-License-Identifier: MPL-2.0
5
5
  ///////////////////////////////////////////////////////////////////////////////
6
- import { useEffect, useState } from "react";
7
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
6
+ import { useState } from "react";
8
7
  import { resolveMailboxPrincipal, setMailboxAccess, } from "@rapidmx/react-shared/mail/mailboxAccessApi.js";
9
- import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
10
- import Button from "@rapidmx/react-shared/components/buttons/Button.js";
11
- /** Who a resolved person is, for a person to check before saving: their name and address, else their uid. */
12
- export function describePerson(person) {
13
- if (person.displayName && person.address)
14
- return `${person.displayName} <${person.address}>`;
15
- return person.displayName ?? person.address ?? `user ${person.userUid}`;
16
- }
8
+ import PrincipalResolver, { describePerson } from "./PrincipalResolver.js";
9
+ export { describePerson };
17
10
  /**
18
- * "Who?" for a sharing screen. What is typed - a mailbox address, an auth-server username or e-mail alias, or a user id -
19
- * is RESOLVED by the server (`resolveMailboxPrincipal()`) to the person it names before anything is saved, and the person
20
- * is shown (name and address) for the caller to confirm; only then is the grant made, against that person's uid. Free text
21
- * is never stored: an ACL record matches a user uid and nothing else, so a grant to a typed username applies to nobody.
11
+ * "Who?" for a sharing screen - a thin wrapper around the general `PrincipalResolver`, supplying mailbox sharing's
12
+ * own resolve call (`resolveMailboxPrincipal()`), its role selector, and its grant action (`setMailboxAccess()`).
13
+ * What is typed - a mailbox address, an auth-server username or e-mail alias, or a user id - is RESOLVED by the
14
+ * server before anything is saved, and the person is shown (name and address) for the caller to confirm; only then
15
+ * is the grant made, against that person's uid. Free text is never stored: an ACL record matches a user uid and
16
+ * nothing else, so a grant to a typed username applies to nobody.
22
17
  */
23
18
  export default function PrincipalPicker({ mailboxUid, roleLabels, initialPrincipal, defaultRole = "viewer", placeholder, onGranted, onCancel }) {
24
- const [typed, setTyped] = useState(initialPrincipal ?? "");
25
19
  const [role, setRole] = useState(defaultRole);
26
- const [person, setPerson] = useState(null);
27
- const [busy, setBusy] = useState(false);
28
- const [error, setError] = useState(null);
29
- // A stored entry being replaced is looked up straight away, so its person is shown without a click.
30
- useEffect(() => {
31
- if (initialPrincipal) {
32
- void find(initialPrincipal);
33
- }
34
- }, [initialPrincipal]);
35
- async function find(principal) {
36
- setBusy(true);
37
- setError(null);
38
- setPerson(null);
39
- try {
40
- setPerson(await resolveMailboxPrincipal(mailboxUid, principal));
41
- }
42
- catch (err) {
43
- setError(err instanceof ApiRequestError ? err.message : "Could not look that person up.");
44
- }
45
- finally {
46
- setBusy(false);
47
- }
48
- }
49
- function handleFind(e) {
50
- e.preventDefault();
51
- const principal = typed.trim();
52
- if (principal) {
53
- void find(principal);
54
- }
55
- }
56
- // Only reachable from the confirm button, which only renders once `person` is set.
57
- async function handleGrant() {
58
- setBusy(true);
59
- setError(null);
60
- try {
20
+ return (_jsx(PrincipalResolver, { resolve: (principal) => resolveMailboxPrincipal(mailboxUid, principal), onResolved: async (person) => {
61
21
  await setMailboxAccess(mailboxUid, person.userUid, role);
62
22
  await onGranted(person, role);
63
- setTyped("");
64
- setPerson(null);
65
- }
66
- catch (err) {
67
- setError(err instanceof ApiRequestError ? err.message : "Could not grant access.");
68
- }
69
- finally {
70
- setBusy(false);
71
- }
72
- }
73
- return (_jsxs("div", { className: "flex flex-col gap-2", children: [error && _jsx(Alert, { children: error }), _jsxs("form", { onSubmit: handleFind, className: "flex gap-2", children: [_jsx("input", { type: "text", "aria-label": "Who to share with", placeholder: placeholder ?? "Email address, username or user id", className: "flex-1 text-sm border border-border rounded-sm py-1.5 px-2 bg-surface text-text", value: typed, onChange: (e) => {
74
- setTyped(e.target.value);
75
- setPerson(null);
76
- }, disabled: busy }), _jsx("select", { "aria-label": "Access level", className: "text-sm border border-border rounded-sm py-1.5 px-2 bg-surface text-text", value: role, onChange: (e) => setRole(e.target.value), disabled: busy, children: Object.keys(roleLabels).map((value) => (_jsx("option", { value: value, children: roleLabels[value] }, value))) }), _jsx(Button, { type: "submit", variant: "secondary", loading: busy && !person, disabled: busy, className: "!w-auto", children: "Find" }), onCancel && (_jsx(Button, { type: "button", variant: "text", className: "!w-auto", onClick: onCancel, children: "Cancel" }))] }), person && (_jsxs("div", { className: "flex items-center justify-between gap-3 text-sm py-2 px-3 border border-border rounded-sm", children: [_jsxs("span", { children: ["Share with ", _jsx("strong", { className: "break-all", children: describePerson(person) }), " as ", _jsx("em", { children: roleLabels[role] }), "?"] }), _jsx(Button, { type: "button", loading: busy, disabled: busy, className: "!w-auto", onClick: () => void handleGrant(), children: "Grant" })] }))] }));
23
+ }, initialPrincipal: initialPrincipal, placeholder: placeholder ?? "Email address, username or user id", ariaLabel: "Who to share with", confirmLabel: "Grant", confirmErrorMessage: "Could not grant access.", describeConfirm: (person) => (_jsxs(_Fragment, { children: ["Share with ", _jsx("strong", { className: "break-all", children: describePerson(person) }), " as ", _jsx("em", { children: roleLabels[role] }), "?"] })), onCancel: onCancel, children: _jsx("select", { "aria-label": "Access level", className: "text-sm border border-border rounded-sm py-1.5 px-2 bg-surface text-text", value: role, onChange: (e) => setRole(e.target.value), children: Object.keys(roleLabels).map((value) => (_jsx("option", { value: value, children: roleLabels[value] }, value))) }) }));
77
24
  }
@@ -0,0 +1,44 @@
1
+ import React, { ReactNode } from "react";
2
+ import { ResolvedPrincipal } from "@rapidmx/react-shared/mail/mailboxAccessApi.js";
3
+ export interface PrincipalResolverProps {
4
+ /** Resolves what was typed - a mailbox address, an auth-server username or e-mail alias, or a user uid - to
5
+ * the one person it names, exact match only. Rejects (typically with an `ApiRequestError`) for nobody. */
6
+ resolve: (principal: string) => Promise<ResolvedPrincipal>;
7
+ /** Called once the caller confirms the resolved person is the right one. The box is cleared once this
8
+ * resolves - throw (or reject) to keep the person on screen and show an error instead. */
9
+ onResolved: (person: ResolvedPrincipal) => void | Promise<void>;
10
+ /** Text put in the box to start with - a stored entry being replaced, say - looked up automatically on mount. */
11
+ initialPrincipal?: string;
12
+ /** What the box asks for. */
13
+ placeholder: string;
14
+ /** The box's accessible name. */
15
+ ariaLabel: string;
16
+ /** Extra controls rendered between the text box and the Find button (e.g. a role selector). */
17
+ children?: ReactNode;
18
+ /** The confirm button's label (e.g. "Grant", "Use this owner"). */
19
+ confirmLabel: string;
20
+ /** What the confirmation row says once a person is found - e.g. "Share with X as Y?". */
21
+ describeConfirm: (person: ResolvedPrincipal) => ReactNode;
22
+ /** Shown if `onResolved` rejects, unless it was an `ApiRequestError` (then its own message is shown). */
23
+ confirmErrorMessage: string;
24
+ /** Shown as a Cancel button next to the box when set (replacing an entry). */
25
+ onCancel?: () => void;
26
+ }
27
+ /** Who a resolved person is, for a person to check before confirming: their name and address, else their uid. */
28
+ export declare function describePerson(person: ResolvedPrincipal): string;
29
+ /**
30
+ * "Who?" - anywhere a person is assigned by typed identifier rather than picked from an already-loaded list. What
31
+ * is typed is RESOLVED by the server (`resolve`) to the person it names before anything is saved, and the person is
32
+ * shown (name and address) for the caller to confirm; only `onResolved` ever sees the resolved, verified person -
33
+ * never the free text. This is deliberately exact-match, type-then-confirm - never a live/fuzzy search-as-you-type
34
+ * autocomplete, which would let anyone with access to the field enumerate the user directory by partial name.
35
+ *
36
+ * Parameterized entirely by `resolve`/`onResolved` (and the wording props) so every caller - mailbox sharing
37
+ * (`PrincipalPicker`, a thin wrapper around this component), mailbox ownership, escrow-scope holders, ... - reuses
38
+ * the same resolve-then-confirm UX and privacy posture rather than each reimplementing it.
39
+ *
40
+ * Deliberately renders no `<form>` of its own (Enter-to-find is wired up by hand instead, see `handleKeyDown()`) -
41
+ * some callers (`MailboxCreateForm`) use this as one field of their own, larger `<form>`, and a nested `<form>` is
42
+ * invalid HTML that real browsers mis-handle (an inner Enter keypress can submit the wrong one).
43
+ */
44
+ export default function PrincipalResolver({ resolve, onResolved, initialPrincipal, placeholder, ariaLabel, children, confirmLabel, describeConfirm, confirmErrorMessage, onCancel, }: PrincipalResolverProps): React.JSX.Element;