@bevel-software/platform-core-frontend 0.26.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.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ProductName.test.tsx +46 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/maker-url.ts +30 -0
- package/src/core/registry.ts +78 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/lib/__tests__/latest-request.test.ts +48 -0
- package/src/lib/latest-request.ts +45 -0
- package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/api.ts +19 -3
- package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
- package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
- package/src/modules/admin/services/roles.api.ts +14 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
- package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
- package/src/modules/auth/components/LoginScreen.tsx +101 -73
- package/src/modules/auth/services/account.api.ts +59 -3
- package/src/modules/auth/services/sso.ts +30 -10
- package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
- package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
- package/src/modules/onboarding/components/InviteButton.tsx +139 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +123 -0
- package/src/modules/onboarding/invite-emails.ts +313 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +330 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
- package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
import { useEffect, useId, useRef, useState, type ReactNode } from 'react';
|
|
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';
|
|
5
|
+
import { SlotBoundary } from '../../../shared/components/SlotBoundary';
|
|
6
|
+
import { useAppRegistry } from '../../../core/registry';
|
|
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';
|
|
10
|
+
import { createAccount, listAccounts } from '../../auth/services/account.api';
|
|
11
|
+
import { addMember, fetchRoles } from '../../admin/services/roles.api';
|
|
12
|
+
import { copyToClipboard } from '../../library/utils/clipboard';
|
|
13
|
+
import { initials } from '../../../lib/email';
|
|
14
|
+
import { EmailChipsInput } from './EmailChipsInput';
|
|
15
|
+
import {
|
|
16
|
+
gotPassword,
|
|
17
|
+
isInvited,
|
|
18
|
+
isValidEmail,
|
|
19
|
+
sendInvites,
|
|
20
|
+
wasEmailed,
|
|
21
|
+
splitEmails,
|
|
22
|
+
type InviteOutcome,
|
|
23
|
+
type InviteRole,
|
|
24
|
+
} from '../invite-emails';
|
|
25
|
+
|
|
26
|
+
/** "1 person" / "3 people" — the one plural this dialog needs. */
|
|
27
|
+
function people(n: number): string {
|
|
28
|
+
return `${n} ${n === 1 ? 'person' : 'people'}`;
|
|
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
|
+
|
|
55
|
+
interface InviteDialogProps {
|
|
56
|
+
open: boolean;
|
|
57
|
+
onClose(): void;
|
|
58
|
+
/** Called after a send that created or changed at least one account. */
|
|
59
|
+
onInvited?(): void;
|
|
60
|
+
/** Addresses already in the field when it opens (Manage access's Invite). */
|
|
61
|
+
initialEmails?: string[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
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).
|
|
67
|
+
*
|
|
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.
|
|
83
|
+
*
|
|
84
|
+
* Feedback stays INSIDE the dialog: the Library's toasts only exist under its
|
|
85
|
+
* own routes, and this opens from Knowledge too.
|
|
86
|
+
*/
|
|
87
|
+
export function InviteDialog({ open, onClose, onInvited, initialEmails }: InviteDialogProps) {
|
|
88
|
+
const { user } = useAuth();
|
|
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 ?? []);
|
|
93
|
+
const [draft, setDraft] = useState('');
|
|
94
|
+
const [role, setRole] = useState<InviteRole>('member');
|
|
95
|
+
const [password, setPassword] = useState('');
|
|
96
|
+
const [alsoPassword, setAlsoPassword] = useState(false);
|
|
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);
|
|
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);
|
|
103
|
+
const emailsId = useId();
|
|
104
|
+
const doneRef = useRef<HTMLButtonElement>(null);
|
|
105
|
+
|
|
106
|
+
// The address field, not the header's close button, is where an invite
|
|
107
|
+
// starts: on open and again after "Invite more people". A frame late on
|
|
108
|
+
// purpose — the dialog moves focus to its first control as it opens, and
|
|
109
|
+
// that runs after this component's own effects.
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!open || outcomes) return;
|
|
112
|
+
const frame = requestAnimationFrame(() => document.getElementById(emailsId)?.focus());
|
|
113
|
+
return () => cancelAnimationFrame(frame);
|
|
114
|
+
}, [open, outcomes, emailsId]);
|
|
115
|
+
|
|
116
|
+
// The button that sent is gone once the result shows; focus goes to the
|
|
117
|
+
// way out rather than falling to the page behind the dialog.
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (outcomes) doneRef.current?.focus();
|
|
120
|
+
}, [outcomes]);
|
|
121
|
+
|
|
122
|
+
// What a send would include: the chips plus anything still in the field,
|
|
123
|
+
// so typing one address and clicking Invite does what it says.
|
|
124
|
+
const pending = [...emails];
|
|
125
|
+
for (const email of splitEmails(draft)) if (!pending.includes(email)) pending.push(email);
|
|
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;
|
|
130
|
+
|
|
131
|
+
async function send() {
|
|
132
|
+
if (!canSend) return;
|
|
133
|
+
setSending(true);
|
|
134
|
+
setAccountsUnreadable(false);
|
|
135
|
+
try {
|
|
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
|
+
}
|
|
147
|
+
setEmails([]);
|
|
148
|
+
setDraft('');
|
|
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
|
+
}
|
|
155
|
+
} finally {
|
|
156
|
+
setSending(false);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function inviteMore() {
|
|
161
|
+
setEmails([]);
|
|
162
|
+
setDraft('');
|
|
163
|
+
setRole('member');
|
|
164
|
+
setPassword('');
|
|
165
|
+
setAlsoPassword(false);
|
|
166
|
+
setSentWithPassword(false);
|
|
167
|
+
setOutcomes(null);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (outcomes) {
|
|
171
|
+
const sso = (methods?.sso.length ?? 0) > 0;
|
|
172
|
+
const invited = outcomes.filter((o) => isInvited(o, sso)).length;
|
|
173
|
+
return (
|
|
174
|
+
<Dialog
|
|
175
|
+
open={open}
|
|
176
|
+
onClose={onClose}
|
|
177
|
+
size="lg"
|
|
178
|
+
title={
|
|
179
|
+
invited === 0
|
|
180
|
+
? 'Nobody was invited'
|
|
181
|
+
: `${people(invited)} ${invited === 1 ? 'is' : 'are'} invited`
|
|
182
|
+
}
|
|
183
|
+
footer={
|
|
184
|
+
<>
|
|
185
|
+
<Button variant="quiet" size="sm" className="mr-auto" onClick={inviteMore}>
|
|
186
|
+
Invite more people
|
|
187
|
+
</Button>
|
|
188
|
+
<Button ref={doneRef} variant="primary" size="sm" onClick={onClose}>
|
|
189
|
+
Done
|
|
190
|
+
</Button>
|
|
191
|
+
</>
|
|
192
|
+
}
|
|
193
|
+
>
|
|
194
|
+
<InvitedBody outcomes={outcomes} invited={invited} methods={methods} passwordGiven={sentWithPassword} />
|
|
195
|
+
</Dialog>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const domain = user?.email.split('@')[1];
|
|
200
|
+
return (
|
|
201
|
+
<Dialog
|
|
202
|
+
open={open}
|
|
203
|
+
onClose={onClose}
|
|
204
|
+
busy={sending}
|
|
205
|
+
size="lg"
|
|
206
|
+
title="Invite your team"
|
|
207
|
+
footer={
|
|
208
|
+
<>
|
|
209
|
+
<Button size="sm" onClick={onClose} disabled={sending}>
|
|
210
|
+
Cancel
|
|
211
|
+
</Button>
|
|
212
|
+
<Button size="sm" variant="primary" onClick={() => void send()} disabled={!canSend}>
|
|
213
|
+
{sending
|
|
214
|
+
? 'Inviting…'
|
|
215
|
+
: valid.length > 0
|
|
216
|
+
? `Invite ${people(valid.length)}`
|
|
217
|
+
: 'Invite people'}
|
|
218
|
+
</Button>
|
|
219
|
+
</>
|
|
220
|
+
}
|
|
221
|
+
>
|
|
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) ?? []}
|
|
240
|
+
emailsId={emailsId}
|
|
241
|
+
emails={emails}
|
|
242
|
+
onEmailsChange={setEmails}
|
|
243
|
+
draft={draft}
|
|
244
|
+
onDraftChange={setDraft}
|
|
245
|
+
role={role}
|
|
246
|
+
onRoleChange={setRole}
|
|
247
|
+
password={password}
|
|
248
|
+
onPasswordChange={setPassword}
|
|
249
|
+
alsoPassword={alsoPassword}
|
|
250
|
+
onAlsoPasswordChange={setAlsoPassword}
|
|
251
|
+
validCount={valid.length}
|
|
252
|
+
invalidCount={pending.length - valid.length}
|
|
253
|
+
sending={sending}
|
|
254
|
+
placeholder={domain ? `name@${domain}` : 'name@company.com'}
|
|
255
|
+
/>
|
|
256
|
+
</Dialog>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
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
|
+
|
|
282
|
+
function InviteFormBody({
|
|
283
|
+
mode,
|
|
284
|
+
alert,
|
|
285
|
+
ssoLabels,
|
|
286
|
+
emailsId,
|
|
287
|
+
emails,
|
|
288
|
+
onEmailsChange,
|
|
289
|
+
draft,
|
|
290
|
+
onDraftChange,
|
|
291
|
+
role,
|
|
292
|
+
onRoleChange,
|
|
293
|
+
password,
|
|
294
|
+
onPasswordChange,
|
|
295
|
+
alsoPassword,
|
|
296
|
+
onAlsoPasswordChange,
|
|
297
|
+
validCount,
|
|
298
|
+
invalidCount,
|
|
299
|
+
sending,
|
|
300
|
+
placeholder,
|
|
301
|
+
}: {
|
|
302
|
+
mode: FormMode;
|
|
303
|
+
alert: ReactNode;
|
|
304
|
+
ssoLabels: string[];
|
|
305
|
+
emailsId: string;
|
|
306
|
+
emails: string[];
|
|
307
|
+
onEmailsChange(next: string[]): void;
|
|
308
|
+
draft: string;
|
|
309
|
+
onDraftChange(next: string): void;
|
|
310
|
+
role: InviteRole;
|
|
311
|
+
onRoleChange(next: InviteRole): void;
|
|
312
|
+
password: string;
|
|
313
|
+
onPasswordChange(next: string): void;
|
|
314
|
+
alsoPassword: boolean;
|
|
315
|
+
onAlsoPasswordChange(next: boolean): void;
|
|
316
|
+
validCount: number;
|
|
317
|
+
/**
|
|
318
|
+
* Addresses a send would leave out — chips and text still in the field
|
|
319
|
+
* alike, since a send clears both and the field's would otherwise go
|
|
320
|
+
* without a word.
|
|
321
|
+
*/
|
|
322
|
+
invalidCount: number;
|
|
323
|
+
sending: boolean;
|
|
324
|
+
placeholder: string;
|
|
325
|
+
}) {
|
|
326
|
+
const Extras = useAppRegistry().inviteExtras;
|
|
327
|
+
const invalidId = useId();
|
|
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
|
+
);
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
<div className="flex flex-col gap-5 py-2">
|
|
357
|
+
{alert}
|
|
358
|
+
<div className="flex flex-col gap-1.5">
|
|
359
|
+
<FieldLabel htmlFor={emailsId}>Emails</FieldLabel>
|
|
360
|
+
<EmailChipsInput
|
|
361
|
+
id={emailsId}
|
|
362
|
+
emails={emails}
|
|
363
|
+
onEmailsChange={onEmailsChange}
|
|
364
|
+
draft={draft}
|
|
365
|
+
onDraftChange={onDraftChange}
|
|
366
|
+
placeholder={placeholder}
|
|
367
|
+
aria-describedby={invalidCount > 0 ? invalidId : undefined}
|
|
368
|
+
disabled={sending}
|
|
369
|
+
/>
|
|
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
|
+
)}
|
|
376
|
+
</div>
|
|
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
|
+
)}
|
|
425
|
+
</div>
|
|
426
|
+
{Extras && (
|
|
427
|
+
<SlotBoundary label="invite panel">
|
|
428
|
+
<Extras inviting={validCount} />
|
|
429
|
+
</SlotBoundary>
|
|
430
|
+
)}
|
|
431
|
+
</div>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
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
|
+
|
|
486
|
+
/** How each outcome reads on its row. */
|
|
487
|
+
const OUTCOME_BADGE: Record<InviteOutcome['status'], { tone: BadgeTone; label: string }> = {
|
|
488
|
+
created: { tone: 'neutral', label: 'Hasn’t signed in yet' },
|
|
489
|
+
existing: { tone: 'outline', label: 'Already had an account' },
|
|
490
|
+
'no-seat': { tone: 'wait', label: 'Not invited: no seat left' },
|
|
491
|
+
error: { tone: 'danger', label: 'Not invited' },
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* A switched-off account is on the list but cannot sign in: its row says so,
|
|
496
|
+
* in the waiting tone, rather than "Already had an account" beside a claim
|
|
497
|
+
* that it is ready. One whose password could not be set says that.
|
|
498
|
+
*/
|
|
499
|
+
function outcomeBadge(outcome: InviteOutcome): { tone: BadgeTone; label: string } {
|
|
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' };
|
|
502
|
+
return OUTCOME_BADGE[outcome.status];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** How the person on one row signs in — or why they can't. */
|
|
506
|
+
function outcomeDetail(outcome: InviteOutcome, idp: string, passwordGiven: boolean): string {
|
|
507
|
+
switch (outcome.status) {
|
|
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
|
+
}
|
|
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
|
+
}
|
|
530
|
+
const access = outcome.deactivated
|
|
531
|
+
? 'Can’t sign in until it’s switched on in User accounts'
|
|
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';
|
|
543
|
+
if (outcome.roleError) return `${access}: couldn’t make them an admin (${outcome.roleError})`;
|
|
544
|
+
if (outcome.promoted) return `${access}, now an admin`;
|
|
545
|
+
if (outcome.alreadyAdmin) return `${access}, already an admin`;
|
|
546
|
+
return access;
|
|
547
|
+
}
|
|
548
|
+
case 'no-seat':
|
|
549
|
+
case 'error':
|
|
550
|
+
return outcome.message;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
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
|
+
}) {
|
|
587
|
+
const { user } = useAuth();
|
|
588
|
+
const origin = window.location.origin;
|
|
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) });
|
|
605
|
+
|
|
606
|
+
return (
|
|
607
|
+
<div className="flex flex-col gap-4 py-1">
|
|
608
|
+
<p className="text-detail text-ink-muted">
|
|
609
|
+
{invited === 0
|
|
610
|
+
? 'No accounts were created. The reason is on each row.'
|
|
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.'}
|
|
620
|
+
</p>
|
|
621
|
+
<ul aria-label="People" className="flex flex-col divide-y divide-line">
|
|
622
|
+
{user && (
|
|
623
|
+
<PersonRow
|
|
624
|
+
label={`${user.name} (you)`}
|
|
625
|
+
detail={user.email}
|
|
626
|
+
badge={<Badge>Admin</Badge>}
|
|
627
|
+
strong
|
|
628
|
+
/>
|
|
629
|
+
)}
|
|
630
|
+
{outcomes.map((outcome) => {
|
|
631
|
+
const badge = outcomeBadge(outcome);
|
|
632
|
+
return (
|
|
633
|
+
<PersonRow
|
|
634
|
+
key={outcome.email}
|
|
635
|
+
label={outcome.email}
|
|
636
|
+
detail={outcomeDetail(outcome, idp, passwordGiven)}
|
|
637
|
+
badge={<Badge tone={badge.tone}>{badge.label}</Badge>}
|
|
638
|
+
/>
|
|
639
|
+
);
|
|
640
|
+
})}
|
|
641
|
+
</ul>
|
|
642
|
+
{invited > 0 && (
|
|
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
|
+
)}
|
|
656
|
+
<CopyRow label="Where they sign in" text={origin} copyLabel="Copy link" mono />
|
|
657
|
+
{!allEmailed && <CopyRow label="Or send this message" text={message} copyLabel="Copy message" />}
|
|
658
|
+
</>
|
|
659
|
+
)}
|
|
660
|
+
</div>
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function PersonRow({
|
|
665
|
+
label,
|
|
666
|
+
detail,
|
|
667
|
+
badge,
|
|
668
|
+
strong = false,
|
|
669
|
+
}: {
|
|
670
|
+
label: string;
|
|
671
|
+
detail: string;
|
|
672
|
+
badge: ReactNode;
|
|
673
|
+
strong?: boolean;
|
|
674
|
+
}) {
|
|
675
|
+
return (
|
|
676
|
+
<li className="flex items-center gap-2.5 py-2">
|
|
677
|
+
<span
|
|
678
|
+
aria-hidden
|
|
679
|
+
className="flex size-[26px] flex-none items-center justify-center rounded-full border border-line bg-sunken text-micro font-bold text-ink-muted"
|
|
680
|
+
>
|
|
681
|
+
{initials(label)}
|
|
682
|
+
</span>
|
|
683
|
+
<span className="min-w-0 flex-1">
|
|
684
|
+
<span className={`block truncate text-ui text-ink ${strong ? 'font-semibold' : ''}`}>
|
|
685
|
+
{label}
|
|
686
|
+
</span>
|
|
687
|
+
<span className="block truncate text-meta text-ink-faint" title={detail}>
|
|
688
|
+
{detail}
|
|
689
|
+
</span>
|
|
690
|
+
</span>
|
|
691
|
+
{badge}
|
|
692
|
+
</li>
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Text to hand on, with its own copy button. The result is said on the
|
|
698
|
+
* button, and a failed copy says what to do instead — the text is on screen
|
|
699
|
+
* to select by hand.
|
|
700
|
+
*/
|
|
701
|
+
function CopyRow({
|
|
702
|
+
label,
|
|
703
|
+
text,
|
|
704
|
+
copyLabel,
|
|
705
|
+
mono = false,
|
|
706
|
+
}: {
|
|
707
|
+
label: string;
|
|
708
|
+
text: string;
|
|
709
|
+
copyLabel: string;
|
|
710
|
+
mono?: boolean;
|
|
711
|
+
}) {
|
|
712
|
+
const [state, setState] = useState<'idle' | 'copied' | 'failed'>('idle');
|
|
713
|
+
const labelId = useId();
|
|
714
|
+
return (
|
|
715
|
+
<div className="flex flex-col gap-1.5">
|
|
716
|
+
<span id={labelId} className="text-detail font-medium text-ink">
|
|
717
|
+
{label}
|
|
718
|
+
</span>
|
|
719
|
+
<div className="flex items-stretch overflow-hidden rounded-md border border-line bg-sunken">
|
|
720
|
+
<p
|
|
721
|
+
aria-labelledby={labelId}
|
|
722
|
+
className={`min-w-0 flex-1 px-3 py-2 text-detail text-ink ${mono ? 'truncate font-mono' : 'whitespace-pre-wrap'}`}
|
|
723
|
+
>
|
|
724
|
+
{text}
|
|
725
|
+
</p>
|
|
726
|
+
<button
|
|
727
|
+
type="button"
|
|
728
|
+
onClick={() => {
|
|
729
|
+
void copyToClipboard(text).then((ok) => setState(ok ? 'copied' : 'failed'));
|
|
730
|
+
}}
|
|
731
|
+
className="flex-none border-l border-line bg-surface px-3 text-detail font-medium text-ink hover:bg-hover"
|
|
732
|
+
>
|
|
733
|
+
{state === 'copied' ? 'Copied' : copyLabel}
|
|
734
|
+
</button>
|
|
735
|
+
</div>
|
|
736
|
+
<span role="status" aria-live="polite" className="text-meta text-ink-faint empty:hidden">
|
|
737
|
+
{state === 'failed' ? 'Couldn’t copy: select the text and copy it yourself.' : ''}
|
|
738
|
+
</span>
|
|
739
|
+
</div>
|
|
740
|
+
);
|
|
741
|
+
}
|