@bevel-software/platform-core-frontend 0.27.0 → 0.28.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 (42) hide show
  1. package/package.json +2 -2
  2. package/src/core/ProductName.tsx +4 -4
  3. package/src/core/__tests__/ProductName.test.tsx +46 -0
  4. package/src/core/maker-url.ts +30 -0
  5. package/src/core/registry.ts +27 -0
  6. package/src/lib/__tests__/latest-request.test.ts +48 -0
  7. package/src/lib/latest-request.ts +45 -0
  8. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  9. package/src/modules/access/api.ts +19 -3
  10. package/src/modules/access/components/ManageAccessDialog.tsx +60 -7
  11. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  12. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  13. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  14. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  15. package/src/modules/admin/services/roles.api.ts +14 -1
  16. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  17. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  18. package/src/modules/auth/components/LoginScreen.tsx +100 -75
  19. package/src/modules/auth/services/account.api.ts +31 -2
  20. package/src/modules/auth/services/sso.ts +29 -8
  21. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  22. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  23. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +56 -1
  24. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +538 -81
  25. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +543 -124
  26. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  27. package/src/modules/onboarding/components/GetStartedColumn.tsx +30 -11
  28. package/src/modules/onboarding/components/InviteButton.tsx +119 -15
  29. package/src/modules/onboarding/components/InviteDialog.tsx +392 -75
  30. package/src/modules/onboarding/first-page-prompt.ts +34 -0
  31. package/src/modules/onboarding/invite-emails.ts +171 -33
  32. package/src/modules/onboarding/state/invite-dialog.context.ts +7 -4
  33. package/src/modules/onboarding/state/invite-dialog.tsx +12 -4
  34. package/src/modules/toolbar/commands/actions.tsx +10 -4
  35. package/src/modules/toolbar/commands/useCommandActions.ts +5 -3
  36. package/src/modules/toolbar/components/AppSwitcher.tsx +19 -0
  37. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +46 -1
  38. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +34 -2
  39. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  40. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  41. package/src/modules/workspace/hooks/useCreatePage.ts +118 -28
  42. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
@@ -1,60 +1,105 @@
1
1
  import { useEffect, useId, useRef, useState, type ReactNode } from 'react';
2
- import { Badge, Button, Dialog, type BadgeTone } from '../../../shared/components';
2
+ import { ChevronDown, Eye, EyeOff, KeyRound, RotateCw } from 'lucide-react';
3
+ import { MIN_PASSWORD_LENGTH } from '@bevel-software/platform-shared';
4
+ import { Badge, Banner, Button, Dialog, TextField, type BadgeTone } from '../../../shared/components';
3
5
  import { SlotBoundary } from '../../../shared/components/SlotBoundary';
4
6
  import { useAppRegistry } from '../../../core/registry';
5
7
  import { useAuth } from '../../auth/state/auth.context';
8
+ import { useSignInMethods } from '../../auth/state/use-sign-in-methods';
9
+ import type { LoginProviders } from '../../auth/services/sso';
6
10
  import { createAccount, listAccounts } from '../../auth/services/account.api';
7
11
  import { addMember, fetchRoles } from '../../admin/services/roles.api';
8
12
  import { copyToClipboard } from '../../library/utils/clipboard';
9
13
  import { initials } from '../../../lib/email';
10
14
  import { EmailChipsInput } from './EmailChipsInput';
11
15
  import {
16
+ gotPassword,
12
17
  isInvited,
13
18
  isValidEmail,
14
19
  sendInvites,
20
+ wasEmailed,
15
21
  splitEmails,
16
22
  type InviteOutcome,
17
23
  type InviteRole,
18
24
  } from '../invite-emails';
19
25
 
20
- const ROLE_HINT: Record<InviteRole, string> = {
21
- member: 'Sees everything shared with the whole workspace.',
22
- admin: 'Can also change settings and who has access.',
23
- };
24
-
25
26
  /** "1 person" / "3 people" — the one plural this dialog needs. */
26
27
  function people(n: number): string {
27
28
  return `${n} ${n === 1 ? 'person' : 'people'}`;
28
29
  }
29
30
 
31
+ /** "A", "A or B", "A, B or C": the single sign-on providers, by their labels. */
32
+ function either(labels: string[]): string {
33
+ if (labels.length <= 1) return labels[0] ?? '';
34
+ return `${labels.slice(0, -1).join(', ')} or ${labels[labels.length - 1]}`;
35
+ }
36
+
37
+ /**
38
+ * What the form asks for, from how the deployment signs people in:
39
+ * - `password`: password sign-in and no single sign-on — a starting password
40
+ * is required, or nobody invited could sign in;
41
+ * - `sso`: single sign-on and password sign-in — a password is an option;
42
+ * - `sso-only`: password sign-in is off — no password at all;
43
+ * - `none`: password sign-in is off and no single sign-on is on either —
44
+ * nobody invited could sign in, so nothing can be sent;
45
+ * - `unknown`: not known yet, or the check failed — nothing can be sent.
46
+ */
47
+ type FormMode = 'password' | 'sso' | 'sso-only' | 'none' | 'unknown';
48
+
49
+ function formMode(methods: LoginProviders | null): FormMode {
50
+ if (!methods) return 'unknown';
51
+ if (!methods.password) return methods.sso.length > 0 ? 'sso-only' : 'none';
52
+ return methods.sso.length > 0 ? 'sso' : 'password';
53
+ }
54
+
30
55
  interface InviteDialogProps {
31
56
  open: boolean;
32
57
  onClose(): void;
33
- /** Called after a send that created at least one account. */
58
+ /** Called after a send that created or changed at least one account. */
34
59
  onInvited?(): void;
60
+ /** Addresses already in the field when it opens (Manage access's Invite). */
61
+ initialEmails?: string[];
35
62
  }
36
63
 
37
64
  /**
38
- * Invite your team: addresses in, accounts out — each one waiting for that
39
- * person's first single sign-on, under the same access rules as everything
40
- * else (Share → Manage access decides what they then see).
65
+ * Invite your team: addresses in, accounts out, under the same access rules
66
+ * as everything else (Share → Manage access decides what they then see).
41
67
  *
42
- * Two views in one dialog. The form; then, after sending, who is invited and
43
- * how to tell them. The second view exists because creating an account sends
44
- * nobody anything — core has no mail — so the admin leaves with the sign-in
45
- * address and a message to forward, not with an assumption that people were
46
- * notified.
68
+ * How the invited people get in depends on the deployment, so the dialog
69
+ * asks it first (`GET /api/auth/providers`) and lets nothing be sent until it
70
+ * knows. Without single sign-on it requires a starting password, given to
71
+ * every account the send creates or that has none yet; with single sign-on
72
+ * the password is an option. An account that has its own password keeps it.
73
+ *
74
+ * Two views in one dialog. The form; then, after sending, who is invited,
75
+ * how each of them signs in, and how to tell them. The second view exists
76
+ * because creating an account sends nobody anything — core has no mail — so
77
+ * the admin leaves with the sign-in address and a message to forward, not
78
+ * with an assumption that people were notified.
79
+ *
80
+ * The starting password lives in this component's state only. It is never in
81
+ * the message or anything else a copy button copies, never shown again after
82
+ * the send, and gone with the dialog.
47
83
  *
48
84
  * Feedback stays INSIDE the dialog: the Library's toasts only exist under its
49
85
  * own routes, and this opens from Knowledge too.
50
86
  */
51
- export function InviteDialog({ open, onClose, onInvited }: InviteDialogProps) {
87
+ export function InviteDialog({ open, onClose, onInvited, initialEmails }: InviteDialogProps) {
52
88
  const { user } = useAuth();
53
- const [emails, setEmails] = useState<string[]>([]);
89
+ const signIn = useSignInMethods();
90
+ const methods = signIn.status === 'ready' ? signIn.methods : null;
91
+ const mode = formMode(methods);
92
+ const [emails, setEmails] = useState<string[]>(() => initialEmails ?? []);
54
93
  const [draft, setDraft] = useState('');
55
94
  const [role, setRole] = useState<InviteRole>('member');
95
+ const [password, setPassword] = useState('');
96
+ const [alsoPassword, setAlsoPassword] = useState(false);
56
97
  const [sending, setSending] = useState(false);
98
+ // A send with a password stopped before any write: the account list could not be read.
99
+ const [accountsUnreadable, setAccountsUnreadable] = useState(false);
57
100
  const [outcomes, setOutcomes] = useState<InviteOutcome[] | null>(null);
101
+ // Whether the send that produced `outcomes` carried a starting password (never the password itself).
102
+ const [sentWithPassword, setSentWithPassword] = useState(false);
58
103
  const emailsId = useId();
59
104
  const doneRef = useRef<HTMLButtonElement>(null);
60
105
 
@@ -79,16 +124,34 @@ export function InviteDialog({ open, onClose, onInvited }: InviteDialogProps) {
79
124
  const pending = [...emails];
80
125
  for (const email of splitEmails(draft)) if (!pending.includes(email)) pending.push(email);
81
126
  const valid = pending.filter(isValidEmail);
127
+ const wantsPassword = mode === 'password' || (mode === 'sso' && alsoPassword);
128
+ const passwordOk = !wantsPassword || password.length >= MIN_PASSWORD_LENGTH;
129
+ const canSend = mode !== 'unknown' && mode !== 'none' && valid.length > 0 && passwordOk && !sending;
82
130
 
83
131
  async function send() {
84
- if (valid.length === 0 || sending) return;
132
+ if (!canSend) return;
85
133
  setSending(true);
134
+ setAccountsUnreadable(false);
86
135
  try {
87
- const result = await sendInvites(valid, role, { listAccounts, createAccount, addMember, fetchRoles });
136
+ const result = await sendInvites(
137
+ valid,
138
+ role,
139
+ { listAccounts, createAccount, addMember, fetchRoles },
140
+ { password: wantsPassword ? password : undefined },
141
+ );
142
+ if (result.status === 'accounts-unreadable') {
143
+ // Nothing was written; the form keeps what the admin typed.
144
+ setAccountsUnreadable(true);
145
+ return;
146
+ }
88
147
  setEmails([]);
89
148
  setDraft('');
90
- setOutcomes(result);
91
- if (result.some((o) => o.status === 'created')) onInvited?.();
149
+ setPassword('');
150
+ setSentWithPassword(wantsPassword);
151
+ setOutcomes(result.outcomes);
152
+ if (result.outcomes.some((o) => o.status === 'created' || gotPassword(o) || (o.status === 'existing' && o.promoted))) {
153
+ onInvited?.();
154
+ }
92
155
  } finally {
93
156
  setSending(false);
94
157
  }
@@ -98,11 +161,15 @@ export function InviteDialog({ open, onClose, onInvited }: InviteDialogProps) {
98
161
  setEmails([]);
99
162
  setDraft('');
100
163
  setRole('member');
164
+ setPassword('');
165
+ setAlsoPassword(false);
166
+ setSentWithPassword(false);
101
167
  setOutcomes(null);
102
168
  }
103
169
 
104
170
  if (outcomes) {
105
- const invited = outcomes.filter(isInvited).length;
171
+ const sso = (methods?.sso.length ?? 0) > 0;
172
+ const invited = outcomes.filter((o) => isInvited(o, sso)).length;
106
173
  return (
107
174
  <Dialog
108
175
  open={open}
@@ -124,7 +191,7 @@ export function InviteDialog({ open, onClose, onInvited }: InviteDialogProps) {
124
191
  </>
125
192
  }
126
193
  >
127
- <InvitedBody outcomes={outcomes} invited={invited} />
194
+ <InvitedBody outcomes={outcomes} invited={invited} methods={methods} passwordGiven={sentWithPassword} />
128
195
  </Dialog>
129
196
  );
130
197
  }
@@ -139,18 +206,10 @@ export function InviteDialog({ open, onClose, onInvited }: InviteDialogProps) {
139
206
  title="Invite your team"
140
207
  footer={
141
208
  <>
142
- <span className="mr-auto self-center text-meta text-ink-faint">
143
- Uses the same access rules as Share → Manage access.
144
- </span>
145
209
  <Button size="sm" onClick={onClose} disabled={sending}>
146
210
  Cancel
147
211
  </Button>
148
- <Button
149
- size="sm"
150
- variant="primary"
151
- onClick={() => void send()}
152
- disabled={valid.length === 0 || sending}
153
- >
212
+ <Button size="sm" variant="primary" onClick={() => void send()} disabled={!canSend}>
154
213
  {sending
155
214
  ? 'Inviting…'
156
215
  : valid.length > 0
@@ -161,6 +220,23 @@ export function InviteDialog({ open, onClose, onInvited }: InviteDialogProps) {
161
220
  }
162
221
  >
163
222
  <InviteFormBody
223
+ mode={mode}
224
+ alert={
225
+ signIn.status === 'failed' ? (
226
+ <RetryAlert text="Couldn’t check how people sign in here." onRetry={signIn.retry} />
227
+ ) : mode === 'none' ? (
228
+ <Banner tone="danger" role="alert">
229
+ Nobody could sign in: password sign-in is off here and no single sign-on is set up.
230
+ </Banner>
231
+ ) : accountsUnreadable ? (
232
+ <RetryAlert
233
+ text="Nothing was sent: couldn’t check who already has an account."
234
+ onRetry={() => void send()}
235
+ disabled={!canSend}
236
+ />
237
+ ) : null
238
+ }
239
+ ssoLabels={methods?.sso.map((p) => p.label) ?? []}
164
240
  emailsId={emailsId}
165
241
  emails={emails}
166
242
  onEmailsChange={setEmails}
@@ -168,16 +244,45 @@ export function InviteDialog({ open, onClose, onInvited }: InviteDialogProps) {
168
244
  onDraftChange={setDraft}
169
245
  role={role}
170
246
  onRoleChange={setRole}
247
+ password={password}
248
+ onPasswordChange={setPassword}
249
+ alsoPassword={alsoPassword}
250
+ onAlsoPasswordChange={setAlsoPassword}
171
251
  validCount={valid.length}
172
252
  invalidCount={pending.length - valid.length}
173
253
  sending={sending}
174
- placeholder={domain ? `name@${domain}, name@${domain}` : 'name@company.com'}
254
+ placeholder={domain ? `name@${domain}` : 'name@company.com'}
175
255
  />
176
256
  </Dialog>
177
257
  );
178
258
  }
179
259
 
260
+ /** A red bar saying what went wrong, with a Retry beside it. */
261
+ function RetryAlert({ text, onRetry, disabled = false }: { text: string; onRetry(): void; disabled?: boolean }) {
262
+ return (
263
+ <Banner tone="danger" role="alert">
264
+ <div className="flex items-center gap-3">
265
+ <span className="flex-1">{text}</span>
266
+ <Button size="sm" leadingIcon={<RotateCw size={14} aria-hidden />} onClick={onRetry} disabled={disabled}>
267
+ Retry
268
+ </Button>
269
+ </div>
270
+ </Banner>
271
+ );
272
+ }
273
+
274
+ function FieldLabel({ htmlFor, children }: { htmlFor: string; children: ReactNode }) {
275
+ return (
276
+ <label htmlFor={htmlFor} className="text-detail font-medium text-ink">
277
+ {children}
278
+ </label>
279
+ );
280
+ }
281
+
180
282
  function InviteFormBody({
283
+ mode,
284
+ alert,
285
+ ssoLabels,
181
286
  emailsId,
182
287
  emails,
183
288
  onEmailsChange,
@@ -185,11 +290,18 @@ function InviteFormBody({
185
290
  onDraftChange,
186
291
  role,
187
292
  onRoleChange,
293
+ password,
294
+ onPasswordChange,
295
+ alsoPassword,
296
+ onAlsoPasswordChange,
188
297
  validCount,
189
298
  invalidCount,
190
299
  sending,
191
300
  placeholder,
192
301
  }: {
302
+ mode: FormMode;
303
+ alert: ReactNode;
304
+ ssoLabels: string[];
193
305
  emailsId: string;
194
306
  emails: string[];
195
307
  onEmailsChange(next: string[]): void;
@@ -197,6 +309,10 @@ function InviteFormBody({
197
309
  onDraftChange(next: string): void;
198
310
  role: InviteRole;
199
311
  onRoleChange(next: InviteRole): void;
312
+ password: string;
313
+ onPasswordChange(next: string): void;
314
+ alsoPassword: boolean;
315
+ onAlsoPasswordChange(next: boolean): void;
200
316
  validCount: number;
201
317
  /**
202
318
  * Addresses a send would leave out — chips and text still in the field
@@ -208,18 +324,39 @@ function InviteFormBody({
208
324
  placeholder: string;
209
325
  }) {
210
326
  const Extras = useAppRegistry().inviteExtras;
211
- const hintId = useId();
327
+ const invalidId = useId();
212
328
  const roleId = useId();
329
+ const passwordId = useId();
330
+ const helpId = useId();
331
+
332
+ const showPassword = mode === 'password' || (mode === 'sso' && alsoPassword);
333
+ const tooShort = showPassword && password.length > 0 && password.length < MIN_PASSWORD_LENGTH;
334
+ const idp = either(ssoLabels);
335
+ const help =
336
+ mode === 'password'
337
+ ? 'They sign in with their email and the password you set.'
338
+ : (mode === 'sso' || mode === 'sso-only') && idp
339
+ ? showPassword
340
+ ? `They sign in with ${idp}, or with their email and the password you set.`
341
+ : `They sign in with ${idp}.`
342
+ : null;
343
+
344
+ const passwordField = (
345
+ <PasswordField
346
+ id={passwordId}
347
+ value={password}
348
+ onChange={onPasswordChange}
349
+ invalid={tooShort}
350
+ disabled={sending}
351
+ describedBy={helpId}
352
+ />
353
+ );
213
354
 
214
355
  return (
215
- <div className="flex flex-col gap-4 py-1">
216
- <p className="text-detail text-ink-muted">
217
- They sign in with the account for the address you add.
218
- </p>
356
+ <div className="flex flex-col gap-5 py-2">
357
+ {alert}
219
358
  <div className="flex flex-col gap-1.5">
220
- <label htmlFor={emailsId} className="text-detail font-medium text-ink">
221
- Work emails
222
- </label>
359
+ <FieldLabel htmlFor={emailsId}>Emails</FieldLabel>
223
360
  <EmailChipsInput
224
361
  id={emailsId}
225
362
  emails={emails}
@@ -227,30 +364,64 @@ function InviteFormBody({
227
364
  draft={draft}
228
365
  onDraftChange={onDraftChange}
229
366
  placeholder={placeholder}
230
- aria-describedby={hintId}
367
+ aria-describedby={invalidCount > 0 ? invalidId : undefined}
231
368
  disabled={sending}
232
369
  />
233
- <span id={hintId} className="text-meta text-ink-faint">
234
- {invalidCount > 0
235
- ? `${invalidCount === 1 ? 'One address isn’t' : `${invalidCount} addresses aren’t`} valid and won’t be invited.`
236
- : 'Paste a list, or press Enter or comma after each address.'}
237
- </span>
370
+ {invalidCount > 0 && (
371
+ <span id={invalidId} className="text-meta text-danger">
372
+ {invalidCount === 1 ? 'One address isn’t' : `${invalidCount} addresses aren’t`} valid and won’t be
373
+ invited.
374
+ </span>
375
+ )}
238
376
  </div>
239
- <div className="flex flex-wrap items-center gap-2.5">
240
- <label htmlFor={roleId} className="text-detail text-ink-muted">
241
- Invite as
242
- </label>
243
- <select
244
- id={roleId}
245
- value={role}
246
- disabled={sending}
247
- onChange={(e) => onRoleChange(e.target.value as InviteRole)}
248
- className="rounded-md border border-line-strong bg-surface px-2 py-1 text-detail text-ink"
249
- >
250
- <option value="member">Member</option>
251
- <option value="admin">Admin</option>
252
- </select>
253
- <span className="text-meta text-ink-faint">{ROLE_HINT[role]}</span>
377
+ <div className="flex flex-col gap-2">
378
+ <div className={`grid grid-cols-[9rem_1fr] gap-3 ${mode === 'password' ? '' : 'items-end'}`}>
379
+ <div className="flex flex-col gap-1.5">
380
+ <FieldLabel htmlFor={roleId}>Role</FieldLabel>
381
+ <div className="relative">
382
+ <select
383
+ id={roleId}
384
+ value={role}
385
+ disabled={sending}
386
+ onChange={(e) => onRoleChange(e.target.value as InviteRole)}
387
+ className="w-full appearance-none rounded-md border border-line-strong bg-surface py-2 pl-2.5 pr-8 text-ui text-ink"
388
+ >
389
+ <option value="member">Member</option>
390
+ <option value="admin">Admin</option>
391
+ </select>
392
+ <ChevronDown
393
+ size={14}
394
+ aria-hidden
395
+ className="pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 text-ink-muted"
396
+ />
397
+ </div>
398
+ </div>
399
+ {mode === 'password' && passwordField}
400
+ {mode === 'sso' && (
401
+ <label className="flex h-[38px] items-center gap-2 text-ui text-ink">
402
+ <input
403
+ type="checkbox"
404
+ checked={alsoPassword}
405
+ disabled={sending}
406
+ onChange={(e) => onAlsoPasswordChange(e.target.checked)}
407
+ className="size-4 accent-[var(--color-accent)]"
408
+ />
409
+ Also give them a password
410
+ </label>
411
+ )}
412
+ </div>
413
+ {mode === 'sso' && alsoPassword && <div className="mt-3">{passwordField}</div>}
414
+ {tooShort ? (
415
+ <p id={helpId} className="text-meta text-danger">
416
+ The password needs at least {MIN_PASSWORD_LENGTH} characters.
417
+ </p>
418
+ ) : (
419
+ help && (
420
+ <p id={helpId} className="text-meta text-ink-faint">
421
+ {help}
422
+ </p>
423
+ )
424
+ )}
254
425
  </div>
255
426
  {Extras && (
256
427
  <SlotBoundary label="invite panel">
@@ -261,6 +432,57 @@ function InviteFormBody({
261
432
  );
262
433
  }
263
434
 
435
+ /**
436
+ * The starting password: masked, with an eye button to check what was typed.
437
+ * `new-password` so the browser offers to generate one rather than filling
438
+ * in the admin's own.
439
+ */
440
+ function PasswordField({
441
+ id,
442
+ value,
443
+ onChange,
444
+ invalid,
445
+ disabled,
446
+ describedBy,
447
+ }: {
448
+ id: string;
449
+ value: string;
450
+ onChange(next: string): void;
451
+ invalid: boolean;
452
+ disabled: boolean;
453
+ describedBy: string;
454
+ }) {
455
+ const [shown, setShown] = useState(false);
456
+ return (
457
+ <div className="flex flex-col gap-1.5">
458
+ <FieldLabel htmlFor={id}>Starting password</FieldLabel>
459
+ <div className="relative">
460
+ <TextField
461
+ id={id}
462
+ type={shown ? 'text' : 'password'}
463
+ autoComplete="new-password"
464
+ required
465
+ value={value}
466
+ disabled={disabled}
467
+ onChange={(e) => onChange(e.target.value)}
468
+ aria-invalid={invalid || undefined}
469
+ aria-describedby={describedBy}
470
+ className={`pr-10 ${invalid ? 'border-danger' : ''}`}
471
+ />
472
+ <button
473
+ type="button"
474
+ aria-label={shown ? 'Hide password' : 'Show password'}
475
+ aria-pressed={shown}
476
+ onClick={() => setShown((s) => !s)}
477
+ className="absolute inset-y-0 right-0 flex items-center px-3 text-ink-faint hover:text-ink"
478
+ >
479
+ {shown ? <EyeOff size={16} aria-hidden /> : <Eye size={16} aria-hidden />}
480
+ </button>
481
+ </div>
482
+ </div>
483
+ );
484
+ }
485
+
264
486
  /** How each outcome reads on its row. */
265
487
  const OUTCOME_BADGE: Record<InviteOutcome['status'], { tone: BadgeTone; label: string }> = {
266
488
  created: { tone: 'neutral', label: 'Hasn’t signed in yet' },
@@ -272,22 +494,52 @@ const OUTCOME_BADGE: Record<InviteOutcome['status'], { tone: BadgeTone; label: s
272
494
  /**
273
495
  * A switched-off account is on the list but cannot sign in: its row says so,
274
496
  * in the waiting tone, rather than "Already had an account" beside a claim
275
- * that it is ready.
497
+ * that it is ready. One whose password could not be set says that.
276
498
  */
277
499
  function outcomeBadge(outcome: InviteOutcome): { tone: BadgeTone; label: string } {
278
500
  if (outcome.status === 'existing' && outcome.deactivated) return { tone: 'wait', label: 'Account switched off' };
501
+ if (outcome.status === 'existing' && outcome.passwordError) return { tone: 'danger', label: 'Password not set' };
279
502
  return OUTCOME_BADGE[outcome.status];
280
503
  }
281
504
 
282
- function outcomeDetail(outcome: InviteOutcome): string {
505
+ /** How the person on one row signs in — or why they can't. */
506
+ function outcomeDetail(outcome: InviteOutcome, idp: string, passwordGiven: boolean): string {
283
507
  switch (outcome.status) {
284
- case 'created':
285
- if (outcome.roleError) return `Member: couldn’t make them an admin (${outcome.roleError})`;
286
- return outcome.role === 'admin' ? 'Admin' : 'Member';
508
+ case 'created': {
509
+ const as = outcome.roleError
510
+ ? `Member: couldn’t make them an admin (${outcome.roleError})`
511
+ : outcome.role === 'admin'
512
+ ? 'Admin'
513
+ : 'Member';
514
+ const how = outcome.passwordSet
515
+ ? idp
516
+ ? `signs in with ${idp} or password`
517
+ : 'signs in with the password you set'
518
+ : idp
519
+ ? `signs in with ${idp}`
520
+ : null;
521
+ // The deployment emailed them the invite itself (see `wasEmailed`): the
522
+ // row says so first, since it is what the admin no longer has to do.
523
+ return [wasEmailed(outcome) ? 'Emailed' : null, as, how].filter(Boolean).join(' · ');
524
+ }
287
525
  case 'existing': {
526
+ if (outcome.passwordError) {
527
+ const failed = `Couldn’t set the password: ${outcome.passwordError}`;
528
+ return idp ? `${failed} · signs in with ${idp}` : failed;
529
+ }
288
530
  const access = outcome.deactivated
289
531
  ? 'Can’t sign in until it’s switched on in User accounts'
290
- : 'Can sign in already';
532
+ : outcome.passwordSet
533
+ ? idp
534
+ ? `Had no password: now signs in with ${idp} or the one you set`
535
+ : 'Had no password: now uses the one you set'
536
+ : outcome.hasOwnPassword
537
+ ? passwordGiven
538
+ ? 'Signs in with their own password (unchanged)'
539
+ : 'Signs in with their own password'
540
+ : idp
541
+ ? `Signs in with ${idp}`
542
+ : 'Can sign in already';
291
543
  if (outcome.roleError) return `${access}: couldn’t make them an admin (${outcome.roleError})`;
292
544
  if (outcome.promoted) return `${access}, now an admin`;
293
545
  if (outcome.alreadyAdmin) return `${access}, already an admin`;
@@ -299,19 +551,72 @@ function outcomeDetail(outcome: InviteOutcome): string {
299
551
  }
300
552
  }
301
553
 
302
- function InvitedBody({ outcomes, invited }: { outcomes: InviteOutcome[]; invited: number }) {
554
+ const INTRO = 'I’ve added you to our workspace, where we keep what our AI agents should know about the company.';
555
+
556
+ /**
557
+ * The message to forward, saying how to sign in on this deployment. Never
558
+ * the password: when one was set, it tells them it comes separately.
559
+ */
560
+ function inviteMessage(origin: string, how: { idp: string; passwordSet: boolean; passwordSignIn: boolean }): string {
561
+ const { idp, passwordSet, passwordSignIn } = how;
562
+ if (passwordSet && idp) {
563
+ return `${INTRO} Sign in at ${origin} with ${idp}, or with your work email and the password I’ll send you separately (change it on your Account page). Then connect your agent from the welcome page.`;
564
+ }
565
+ if (passwordSet) {
566
+ return `${INTRO} Sign in at ${origin} with your work email and the password I’ll send you separately. Then change it on your Account page and connect your agent from the welcome page.`;
567
+ }
568
+ if (idp) return `${INTRO} Sign in at ${origin} with ${idp}, then connect your agent from the welcome page.`;
569
+ if (passwordSignIn) {
570
+ return `${INTRO} Sign in at ${origin} with your work email and your password, then connect your agent from the welcome page.`;
571
+ }
572
+ return `${INTRO} Sign in with your work account at ${origin}, then connect your agent from the welcome page.`;
573
+ }
574
+
575
+ function InvitedBody({
576
+ outcomes,
577
+ invited,
578
+ methods,
579
+ passwordGiven,
580
+ }: {
581
+ outcomes: InviteOutcome[];
582
+ invited: number;
583
+ methods: LoginProviders | null;
584
+ /** The send carried a starting password, whoever ended up with it. */
585
+ passwordGiven: boolean;
586
+ }) {
303
587
  const { user } = useAuth();
304
588
  const origin = window.location.origin;
305
- const message =
306
- 'I’ve added you to our workspace, where we keep what our AI agents should know about the company. ' +
307
- `Sign in with your work account at ${origin}, then connect your agent from the welcome page.`;
589
+ const idp = either(methods?.sso.map((p) => p.label) ?? []);
590
+ // Who was given the starting password in this send: the reminder names
591
+ // them when it was not everyone invited, since a person who kept their own
592
+ // password cannot use it.
593
+ const gotIt = outcomes.filter(gotPassword).length;
594
+ const passwordSet = gotIt > 0;
595
+ // The deployment emailed EVERY invited person the invite itself (the
596
+ // cloud's mail, say): the admin has nothing to send but a password. One
597
+ // person it did not reach — an existing account that only got a
598
+ // password, a deployment with no mail — and the message is offered as
599
+ // before, for them.
600
+ // The same single-sign-on test `invited` was counted with (a provider is
601
+ // one whatever its label says), so the two agree on who was invited.
602
+ const sso = (methods?.sso.length ?? 0) > 0;
603
+ const allEmailed = invited > 0 && outcomes.filter((o) => isInvited(o, sso)).every(wasEmailed);
604
+ const message = inviteMessage(origin, { idp, passwordSet, passwordSignIn: Boolean(methods?.password) });
308
605
 
309
606
  return (
310
607
  <div className="flex flex-col gap-4 py-1">
311
608
  <p className="text-detail text-ink-muted">
312
609
  {invited === 0
313
610
  ? 'No accounts were created. The reason is on each row.'
314
- : 'Their accounts are ready. Send them the link so they know to sign in.'}
611
+ : allEmailed
612
+ ? passwordSet
613
+ ? 'They have been emailed the link. Send them the password separately.'
614
+ : 'They have been emailed the link and how to sign in.'
615
+ : passwordSet
616
+ ? 'They can sign in now. Send them the link and the password.'
617
+ : idp
618
+ ? `They can sign in now with ${idp}. Send them the link.`
619
+ : 'Their accounts are ready. Send them the link so they know to sign in.'}
315
620
  </p>
316
621
  <ul aria-label="People" className="flex flex-col divide-y divide-line">
317
622
  {user && (
@@ -328,7 +633,7 @@ function InvitedBody({ outcomes, invited }: { outcomes: InviteOutcome[]; invited
328
633
  <PersonRow
329
634
  key={outcome.email}
330
635
  label={outcome.email}
331
- detail={outcomeDetail(outcome)}
636
+ detail={outcomeDetail(outcome, idp, passwordGiven)}
332
637
  badge={<Badge tone={badge.tone}>{badge.label}</Badge>}
333
638
  />
334
639
  );
@@ -336,8 +641,20 @@ function InvitedBody({ outcomes, invited }: { outcomes: InviteOutcome[]; invited
336
641
  </ul>
337
642
  {invited > 0 && (
338
643
  <>
644
+ {passwordSet && (
645
+ <Banner tone="wait" role="status" icon={<KeyRound size={16} aria-hidden />}>
646
+ <span className="font-semibold">
647
+ {gotIt === invited
648
+ ? 'Send them the password you set, separately.'
649
+ : `Send the password you set, separately, to the ${gotIt === 1 ? 'person' : `${gotIt} people`} whose row says they use it.`}
650
+ </span>{' '}
651
+ {allEmailed
652
+ ? 'It isn’t in the email they were sent.'
653
+ : 'It isn’t in the message below, so the message is safe to post in a shared channel.'}
654
+ </Banner>
655
+ )}
339
656
  <CopyRow label="Where they sign in" text={origin} copyLabel="Copy link" mono />
340
- <CopyRow label="Or send this message" text={message} copyLabel="Copy message" />
657
+ {!allEmailed && <CopyRow label="Or send this message" text={message} copyLabel="Copy message" />}
341
658
  </>
342
659
  )}
343
660
  </div>