@bevel-software/platform-core-frontend 0.26.0 → 0.27.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__/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/registry.ts +51 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/auth/components/LoginScreen.tsx +4 -1
- package/src/modules/auth/services/account.api.ts +28 -1
- package/src/modules/auth/services/sso.ts +1 -2
- 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__/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 +109 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -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 +651 -0
- package/src/modules/onboarding/components/InviteButton.tsx +35 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +424 -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 +89 -0
- package/src/modules/onboarding/invite-emails.ts +175 -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 +32 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +31 -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 +324 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +106 -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 +187 -54
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -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__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +116 -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,156 @@
|
|
|
1
|
+
import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
import { Dialog } from './Dialog';
|
|
5
|
+
import { useLatestRef } from './useLatestRef';
|
|
6
|
+
import {
|
|
7
|
+
ConfirmContext,
|
|
8
|
+
type AskFn,
|
|
9
|
+
type ConfirmAnswer,
|
|
10
|
+
type ConfirmRequest,
|
|
11
|
+
} from './confirm-context';
|
|
12
|
+
|
|
13
|
+
interface Pending {
|
|
14
|
+
id: number;
|
|
15
|
+
request: ConfirmRequest;
|
|
16
|
+
resolve(answer: ConfirmAnswer): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const CANCELLED: ConfirmAnswer = { confirmed: false, dontAskAgain: false };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Hosts the app's confirmation dialog; mount it once, near the root. Anything
|
|
23
|
+
* below asks through `useConfirm()`.
|
|
24
|
+
*
|
|
25
|
+
* One question shows at a time. A second request waits behind the first
|
|
26
|
+
* rather than stacking two dialogs, so two closes in quick succession are
|
|
27
|
+
* asked in turn.
|
|
28
|
+
*/
|
|
29
|
+
export function ConfirmProvider({ children }: { children: ReactNode }) {
|
|
30
|
+
const [queue, setQueue] = useState<Pending[]>([]);
|
|
31
|
+
const nextId = useRef(0);
|
|
32
|
+
// Mirrors `queue` for `answer` and the unmount sweep below, which must not
|
|
33
|
+
// depend on it. Written in a layout effect: a click on a dialog that has
|
|
34
|
+
// just come up from the queue must already see it at the head.
|
|
35
|
+
const queueRef = useLatestRef(queue);
|
|
36
|
+
|
|
37
|
+
const confirm = useCallback<AskFn>(
|
|
38
|
+
(request, signal) =>
|
|
39
|
+
new Promise<ConfirmAnswer>((resolve) => {
|
|
40
|
+
// The asker is already gone: nobody is there to confirm.
|
|
41
|
+
if (signal.aborted) {
|
|
42
|
+
resolve(CANCELLED);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
nextId.current += 1;
|
|
46
|
+
const id = nextId.current;
|
|
47
|
+
// The asker went away with the question open (or queued): take it
|
|
48
|
+
// down and answer Cancel, so the gone view's action never runs.
|
|
49
|
+
const withdraw = () => {
|
|
50
|
+
resolve(CANCELLED);
|
|
51
|
+
setQueue((q) => q.filter((p) => p.id !== id));
|
|
52
|
+
};
|
|
53
|
+
signal.addEventListener('abort', withdraw, { once: true });
|
|
54
|
+
const settle = (answer: ConfirmAnswer) => {
|
|
55
|
+
signal.removeEventListener('abort', withdraw);
|
|
56
|
+
resolve(answer);
|
|
57
|
+
};
|
|
58
|
+
setQueue((q) => [...q, { id, request, resolve: settle }]);
|
|
59
|
+
}),
|
|
60
|
+
[],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// A provider that goes away with questions still open answers them Cancel,
|
|
64
|
+
// so nothing awaiting one hangs forever.
|
|
65
|
+
useEffect(
|
|
66
|
+
() => () => {
|
|
67
|
+
for (const p of queueRef.current) p.resolve(CANCELLED);
|
|
68
|
+
},
|
|
69
|
+
// The ref is stable for the provider's life; listed for the linter.
|
|
70
|
+
[queueRef],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const current = queue[0];
|
|
74
|
+
const answer = useCallback((id: number, value: ConfirmAnswer) => {
|
|
75
|
+
const head = queueRef.current[0];
|
|
76
|
+
if (!head || head.id !== id) return;
|
|
77
|
+
head.resolve(value);
|
|
78
|
+
setQueue((q) => (q[0]?.id === id ? q.slice(1) : q));
|
|
79
|
+
}, [queueRef]);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<ConfirmContext.Provider value={confirm}>
|
|
83
|
+
{children}
|
|
84
|
+
{/* Portaled to <body> at the moment it opens, so it lands after any
|
|
85
|
+
portaled panel already there (the branch switcher's list is one)
|
|
86
|
+
and draws above it at the same z-index. */}
|
|
87
|
+
{current &&
|
|
88
|
+
createPortal(
|
|
89
|
+
<ConfirmDialog
|
|
90
|
+
key={current.id}
|
|
91
|
+
request={current.request}
|
|
92
|
+
onAnswer={(value) => answer(current.id, value)}
|
|
93
|
+
/>,
|
|
94
|
+
document.body,
|
|
95
|
+
)}
|
|
96
|
+
</ConfirmContext.Provider>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function ConfirmDialog({
|
|
101
|
+
request,
|
|
102
|
+
onAnswer,
|
|
103
|
+
}: {
|
|
104
|
+
request: ConfirmRequest;
|
|
105
|
+
onAnswer(answer: ConfirmAnswer): void;
|
|
106
|
+
}) {
|
|
107
|
+
const [dontAskAgain, setDontAskAgain] = useState(false);
|
|
108
|
+
const messageId = useId();
|
|
109
|
+
const cancel = () => onAnswer(CANCELLED);
|
|
110
|
+
return (
|
|
111
|
+
<Dialog
|
|
112
|
+
open
|
|
113
|
+
size="md"
|
|
114
|
+
title={request.title}
|
|
115
|
+
describedBy={messageId}
|
|
116
|
+
// Escape, the scrim and the header's X all count as Cancel.
|
|
117
|
+
onClose={cancel}
|
|
118
|
+
footer={
|
|
119
|
+
<div className="flex w-full flex-wrap items-center justify-end gap-2">
|
|
120
|
+
{request.offerDontAskAgain && (
|
|
121
|
+
<label className="mr-auto flex items-center gap-2 text-detail text-ink-muted">
|
|
122
|
+
<input
|
|
123
|
+
type="checkbox"
|
|
124
|
+
checked={dontAskAgain}
|
|
125
|
+
onChange={(e) => setDontAskAgain(e.target.checked)}
|
|
126
|
+
/>
|
|
127
|
+
Don't ask again
|
|
128
|
+
</label>
|
|
129
|
+
)}
|
|
130
|
+
<Button size="sm" onClick={cancel}>
|
|
131
|
+
{request.cancelLabel ?? 'Cancel'}
|
|
132
|
+
</Button>
|
|
133
|
+
<Button
|
|
134
|
+
size="sm"
|
|
135
|
+
variant={request.destructive ? 'danger' : 'primary'}
|
|
136
|
+
onClick={() =>
|
|
137
|
+
onAnswer({ confirmed: true, dontAskAgain: !!request.offerDontAskAgain && dontAskAgain })
|
|
138
|
+
}
|
|
139
|
+
>
|
|
140
|
+
{request.confirmLabel ?? 'OK'}
|
|
141
|
+
</Button>
|
|
142
|
+
</div>
|
|
143
|
+
}
|
|
144
|
+
>
|
|
145
|
+
{/* The question itself is the dialog's description, so a screen reader
|
|
146
|
+
announces it with the title, as it did the browser's confirm(). */}
|
|
147
|
+
<div id={messageId}>
|
|
148
|
+
{typeof request.message === 'string' ? (
|
|
149
|
+
<p className="text-detail text-ink whitespace-pre-line break-words">{request.message}</p>
|
|
150
|
+
) : (
|
|
151
|
+
request.message
|
|
152
|
+
)}
|
|
153
|
+
</div>
|
|
154
|
+
</Dialog>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
@@ -40,6 +40,11 @@ interface DialogProps {
|
|
|
40
40
|
onClose(): void;
|
|
41
41
|
/** Rendered in the header bar next to the close button. */
|
|
42
42
|
title: ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* Id of the element that describes the dialog (`aria-describedby`): the
|
|
45
|
+
* question a confirmation asks, so a screen reader reads it with the title.
|
|
46
|
+
*/
|
|
47
|
+
describedBy?: string;
|
|
43
48
|
children: ReactNode;
|
|
44
49
|
/** Pinned footer (e.g. action buttons). Omit for a bodyless dialog. */
|
|
45
50
|
footer?: ReactNode;
|
|
@@ -66,6 +71,7 @@ export function Dialog({
|
|
|
66
71
|
open,
|
|
67
72
|
onClose,
|
|
68
73
|
title,
|
|
74
|
+
describedBy,
|
|
69
75
|
children,
|
|
70
76
|
footer,
|
|
71
77
|
headerActions,
|
|
@@ -173,6 +179,7 @@ export function Dialog({
|
|
|
173
179
|
role="dialog"
|
|
174
180
|
aria-modal="true"
|
|
175
181
|
aria-labelledby={titleId}
|
|
182
|
+
aria-describedby={describedBy}
|
|
176
183
|
tabIndex={-1}
|
|
177
184
|
className={`bg-white border border-line rounded-lg shadow-xl w-full ${SIZE_CLASS[size]} max-h-[90vh] flex flex-col`}
|
|
178
185
|
onClick={(e) => e.stopPropagation()}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, fireEvent, render, renderHook, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import { useLayoutEffect, type ReactNode } from 'react';
|
|
4
|
+
import { ConfirmProvider, useConfirm, type ConfirmAnswer } from '..';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The app's own confirmation. It resolves only on the person's answer —
|
|
8
|
+
* Confirm, Cancel, Escape, the scrim or the X — never on anything the browser
|
|
9
|
+
* decides, and it asks one question at a time.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const wrapper = ({ children }: { children: ReactNode }) => <ConfirmProvider>{children}</ConfirmProvider>;
|
|
13
|
+
|
|
14
|
+
afterEach(() => vi.restoreAllMocks());
|
|
15
|
+
|
|
16
|
+
function ask(request: Parameters<ReturnType<typeof useConfirm>>[0] = { title: 'Delete', message: 'Delete it?' }) {
|
|
17
|
+
const { result } = renderHook(() => useConfirm(), { wrapper });
|
|
18
|
+
let answer!: Promise<ConfirmAnswer>;
|
|
19
|
+
act(() => {
|
|
20
|
+
answer = result.current(request);
|
|
21
|
+
});
|
|
22
|
+
return { answer, confirm: result.current };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('ConfirmProvider', () => {
|
|
26
|
+
it('confirms only on the confirm button', async () => {
|
|
27
|
+
const { answer } = ask({ title: 'Delete', message: 'Delete it?', confirmLabel: 'Delete', destructive: true });
|
|
28
|
+
const dialog = await screen.findByRole('dialog');
|
|
29
|
+
expect(within(dialog).getByText('Delete it?')).toBeInTheDocument();
|
|
30
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Delete' }));
|
|
31
|
+
await expect(answer).resolves.toEqual({ confirmed: true, dontAskAgain: false });
|
|
32
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it.each([
|
|
36
|
+
['Cancel', () => fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))],
|
|
37
|
+
['the X', () => fireEvent.click(screen.getByRole('button', { name: 'Close' }))],
|
|
38
|
+
['Escape', () => fireEvent.keyDown(document, { key: 'Escape' })],
|
|
39
|
+
[
|
|
40
|
+
'the scrim',
|
|
41
|
+
() => {
|
|
42
|
+
const scrim = screen.getByRole('dialog').parentElement!;
|
|
43
|
+
fireEvent.mouseDown(scrim);
|
|
44
|
+
fireEvent.click(scrim);
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
])('counts %s as Cancel', async (_name, dismiss) => {
|
|
48
|
+
const { answer } = ask();
|
|
49
|
+
await screen.findByRole('dialog');
|
|
50
|
+
dismiss();
|
|
51
|
+
await expect(answer).resolves.toEqual({ confirmed: false, dontAskAgain: false });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('offers "Don\'t ask again" only when asked to, and reports the tick on confirm', async () => {
|
|
55
|
+
const plain = ask();
|
|
56
|
+
expect(within(await screen.findByRole('dialog')).queryByRole('checkbox')).toBeNull();
|
|
57
|
+
fireEvent.click(screen.getByRole('button', { name: 'OK' }));
|
|
58
|
+
await plain.answer;
|
|
59
|
+
|
|
60
|
+
const { answer } = ask({ title: 'Delete', message: 'Delete it?', offerDontAskAgain: true });
|
|
61
|
+
const dialog = await screen.findByRole('dialog');
|
|
62
|
+
fireEvent.click(within(dialog).getByRole('checkbox', { name: "Don't ask again" }));
|
|
63
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'OK' }));
|
|
64
|
+
await expect(answer).resolves.toEqual({ confirmed: true, dontAskAgain: true });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('is not answered by the browser: a suppressed window.confirm is never consulted', async () => {
|
|
68
|
+
const spy = vi.spyOn(window, 'confirm').mockReturnValue(false);
|
|
69
|
+
const { answer } = ask();
|
|
70
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'OK' }));
|
|
71
|
+
await expect(answer).resolves.toMatchObject({ confirmed: true });
|
|
72
|
+
expect(spy).not.toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('withdraws the question as Cancel when the component that asked goes away', async () => {
|
|
76
|
+
// Two askers under one provider; only the first goes away.
|
|
77
|
+
let showAsker = true;
|
|
78
|
+
const asks: { current: ReturnType<typeof useConfirm> | null }[] = [{ current: null }, { current: null }];
|
|
79
|
+
function Asker({ slot }: { slot: number }) {
|
|
80
|
+
asks[slot].current = useConfirm();
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const tree = () => (
|
|
84
|
+
<ConfirmProvider>
|
|
85
|
+
{showAsker && <Asker slot={0} />}
|
|
86
|
+
<Asker slot={1} />
|
|
87
|
+
</ConfirmProvider>
|
|
88
|
+
);
|
|
89
|
+
const { rerender } = render(tree());
|
|
90
|
+
let gone!: Promise<ConfirmAnswer>;
|
|
91
|
+
let stays!: Promise<ConfirmAnswer>;
|
|
92
|
+
act(() => {
|
|
93
|
+
gone = asks[0].current!({ title: 'Gone', message: 'From the view that leaves?' });
|
|
94
|
+
stays = asks[1].current!({ title: 'Stays', message: 'From the view that stays?' });
|
|
95
|
+
});
|
|
96
|
+
expect(await screen.findByText('From the view that leaves?')).toBeInTheDocument();
|
|
97
|
+
|
|
98
|
+
showAsker = false;
|
|
99
|
+
rerender(tree());
|
|
100
|
+
await expect(gone).resolves.toEqual({ confirmed: false, dontAskAgain: false });
|
|
101
|
+
// The other view's question comes up next and still needs its own answer.
|
|
102
|
+
const dialog = await screen.findByRole('dialog');
|
|
103
|
+
expect(within(dialog).getByText('From the view that stays?')).toBeInTheDocument();
|
|
104
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'OK' }));
|
|
105
|
+
await expect(stays).resolves.toEqual({ confirmed: true, dontAskAgain: false });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("withdraws a question asked from the asker's own first layout effect when it goes away", async () => {
|
|
109
|
+
let answer!: Promise<ConfirmAnswer>;
|
|
110
|
+
function AsksOnMount() {
|
|
111
|
+
const confirm = useConfirm();
|
|
112
|
+
useLayoutEffect(() => {
|
|
113
|
+
answer = confirm({ title: 'Early', message: 'Asked on mount?' });
|
|
114
|
+
}, [confirm]);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const { rerender } = render(
|
|
118
|
+
<ConfirmProvider>
|
|
119
|
+
<AsksOnMount />
|
|
120
|
+
</ConfirmProvider>,
|
|
121
|
+
);
|
|
122
|
+
expect(await screen.findByText('Asked on mount?')).toBeInTheDocument();
|
|
123
|
+
rerender(<ConfirmProvider>{null}</ConfirmProvider>);
|
|
124
|
+
await expect(answer).resolves.toEqual({ confirmed: false, dontAskAgain: false });
|
|
125
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('asks one question at a time, in order', async () => {
|
|
129
|
+
const { result } = renderHook(() => useConfirm(), { wrapper });
|
|
130
|
+
let first!: Promise<ConfirmAnswer>;
|
|
131
|
+
let second!: Promise<ConfirmAnswer>;
|
|
132
|
+
act(() => {
|
|
133
|
+
first = result.current({ title: 'One', message: 'First?' });
|
|
134
|
+
second = result.current({ title: 'Two', message: 'Second?' });
|
|
135
|
+
});
|
|
136
|
+
await screen.findByRole('dialog');
|
|
137
|
+
expect(screen.getAllByRole('dialog')).toHaveLength(1);
|
|
138
|
+
expect(screen.getByText('First?')).toBeInTheDocument();
|
|
139
|
+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
|
140
|
+
await expect(first).resolves.toMatchObject({ confirmed: false });
|
|
141
|
+
expect(await screen.findByText('Second?')).toBeInTheDocument();
|
|
142
|
+
fireEvent.click(screen.getByRole('button', { name: 'OK' }));
|
|
143
|
+
await expect(second).resolves.toMatchObject({ confirmed: true });
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('answers a queued question on the first click once it comes up', async () => {
|
|
147
|
+
const { result } = renderHook(() => useConfirm(), { wrapper });
|
|
148
|
+
let first!: Promise<ConfirmAnswer>;
|
|
149
|
+
let second!: Promise<ConfirmAnswer>;
|
|
150
|
+
act(() => {
|
|
151
|
+
first = result.current({ title: 'One', message: 'First?' });
|
|
152
|
+
second = result.current({ title: 'Two', message: 'Second?' });
|
|
153
|
+
});
|
|
154
|
+
fireEvent.click(await screen.findByRole('button', { name: 'OK' }));
|
|
155
|
+
await expect(first).resolves.toMatchObject({ confirmed: true });
|
|
156
|
+
// Clicked in the same tick the second dialog commits: no second click
|
|
157
|
+
// needed, nothing dropped.
|
|
158
|
+
act(() => {
|
|
159
|
+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
|
160
|
+
});
|
|
161
|
+
await expect(second).resolves.toMatchObject({ confirmed: false });
|
|
162
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('gives the dialog its question as the accessible description', async () => {
|
|
166
|
+
ask({ title: 'Delete branch', message: 'Delete "alice/draft"?' });
|
|
167
|
+
const dialog = await screen.findByRole('dialog', { name: 'Delete branch' });
|
|
168
|
+
expect(dialog).toHaveAccessibleDescription('Delete "alice/draft"?');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('keeps line breaks in a string question', async () => {
|
|
172
|
+
ask({ title: 'Unsaved', message: 'You have unsaved changes in:\n - a.md\nClose anyway?' });
|
|
173
|
+
const dialog = await screen.findByRole('dialog');
|
|
174
|
+
expect(dialog.textContent).toContain('You have unsaved changes in:\n - a.md\nClose anyway?');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('answers open questions Cancel when it goes away', async () => {
|
|
178
|
+
const { result, unmount } = renderHook(() => useConfirm(), { wrapper });
|
|
179
|
+
let answer!: Promise<ConfirmAnswer>;
|
|
180
|
+
act(() => {
|
|
181
|
+
answer = result.current({ title: 'Delete', message: 'Delete it?' });
|
|
182
|
+
});
|
|
183
|
+
await screen.findByRole('dialog');
|
|
184
|
+
unmount();
|
|
185
|
+
await expect(answer).resolves.toEqual({ confirmed: false, dontAskAgain: false });
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('refuses loudly without a provider rather than inventing an answer', async () => {
|
|
189
|
+
const { result } = renderHook(() => useConfirm());
|
|
190
|
+
await expect(result.current({ title: 'x', message: 'y' })).rejects.toThrow(/ConfirmProvider/);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('renders inside the page normally', () => {
|
|
194
|
+
render(<ConfirmProvider><p>page</p></ConfirmProvider>);
|
|
195
|
+
expect(screen.getByText('page')).toBeInTheDocument();
|
|
196
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
} from 'react';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* What the app asks before an action, through its own dialog — never the
|
|
12
|
+
* browser's `window.confirm`.
|
|
13
|
+
*
|
|
14
|
+
* The built-in dialog can be switched off by the browser itself: after a few
|
|
15
|
+
* of them it offers "prevent this page from creating additional dialogs", and
|
|
16
|
+
* from then on every `confirm()` answers false without showing anything. The
|
|
17
|
+
* page cannot tell that apart from a real Cancel, so the action it guarded
|
|
18
|
+
* just stopped, without a word. The app's own dialog has no such switch:
|
|
19
|
+
* only the person's Confirm, Cancel, Escape or close answers it.
|
|
20
|
+
*/
|
|
21
|
+
export interface ConfirmRequest {
|
|
22
|
+
/** The dialog's header. */
|
|
23
|
+
title: ReactNode;
|
|
24
|
+
/** The question. A string keeps its line breaks. */
|
|
25
|
+
message: ReactNode;
|
|
26
|
+
/** The confirming button's label. Defaults to "OK". */
|
|
27
|
+
confirmLabel?: string;
|
|
28
|
+
/** Defaults to "Cancel". */
|
|
29
|
+
cancelLabel?: string;
|
|
30
|
+
/** Paint the confirming button in the danger tone. */
|
|
31
|
+
destructive?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Offer a "Don't ask again" box. The dialog only REPORTS the tick; the
|
|
34
|
+
* caller decides what remembering it means, and where it is stored.
|
|
35
|
+
*/
|
|
36
|
+
offerDontAskAgain?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ConfirmAnswer {
|
|
40
|
+
confirmed: boolean;
|
|
41
|
+
/** The "Don't ask again" box was ticked when the person confirmed. */
|
|
42
|
+
dontAskAgain: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type ConfirmFn = (request: ConfirmRequest) => Promise<ConfirmAnswer>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The provider's side: a question tied to the life of whoever asked it.
|
|
49
|
+
* Once `signal` aborts, the question is withdrawn and answers Cancel.
|
|
50
|
+
*/
|
|
51
|
+
export type AskFn = (request: ConfirmRequest, signal: AbortSignal) => Promise<ConfirmAnswer>;
|
|
52
|
+
|
|
53
|
+
export const ConfirmContext = createContext<AskFn | null>(null);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Without a `ConfirmProvider` there is nobody to ask, and an answer made up
|
|
57
|
+
* here would be exactly the silent "no" this replaces — so it fails loudly.
|
|
58
|
+
*/
|
|
59
|
+
const missingProvider: AskFn = () =>
|
|
60
|
+
Promise.reject(new Error('useConfirm() needs a <ConfirmProvider> above it'));
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Ask the person, and wait for the answer. The returned function is stable,
|
|
64
|
+
* so it can sit in a hook's dependency list.
|
|
65
|
+
*
|
|
66
|
+
* const confirm = useConfirm();
|
|
67
|
+
* const { confirmed } = await confirm({ title: 'Delete', message: '…' });
|
|
68
|
+
*
|
|
69
|
+
* A question belongs to the component that asked it. If that component goes
|
|
70
|
+
* away while the dialog is open (a route change, Back), the dialog closes and
|
|
71
|
+
* the question answers Cancel: the action it guarded was the gone view's, and
|
|
72
|
+
* nobody confirmed it.
|
|
73
|
+
*/
|
|
74
|
+
export function useConfirm(): ConfirmFn {
|
|
75
|
+
const ask = useContext(ConfirmContext) ?? missingProvider;
|
|
76
|
+
const lifeRef = useRef<AbortController | null>(null);
|
|
77
|
+
useLayoutEffect(() => {
|
|
78
|
+
// Made in an effect, not during render, so a StrictMode remount gets a
|
|
79
|
+
// fresh one rather than one already aborted. A LAYOUT effect, so it is in
|
|
80
|
+
// place before the asker's own layout effects, which may already ask.
|
|
81
|
+
const life = new AbortController();
|
|
82
|
+
lifeRef.current = life;
|
|
83
|
+
return () => life.abort();
|
|
84
|
+
}, []);
|
|
85
|
+
return useCallback<ConfirmFn>(
|
|
86
|
+
(request) => {
|
|
87
|
+
// Before the first effect (a question asked during render) there is no
|
|
88
|
+
// life yet; tie it to one that never ends rather than refuse to ask.
|
|
89
|
+
const signal = lifeRef.current?.signal ?? new AbortController().signal;
|
|
90
|
+
return ask(request, signal);
|
|
91
|
+
},
|
|
92
|
+
[ask],
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -41,6 +41,9 @@ export type { MenuPanelProps, MenuItemProps } from './Menu';
|
|
|
41
41
|
/* Pre-existing components that are part of the same surface. */
|
|
42
42
|
export { Dialog } from './Dialog';
|
|
43
43
|
export type { DialogSize } from './Dialog';
|
|
44
|
+
export { ConfirmProvider } from './ConfirmProvider';
|
|
45
|
+
export { useConfirm } from './confirm-context';
|
|
46
|
+
export type { ConfirmAnswer, ConfirmFn, ConfirmRequest } from './confirm-context';
|
|
44
47
|
export { PageShell } from './PageShell';
|
|
45
48
|
export type { PageShellWidth } from './PageShell';
|
|
46
49
|
export { useModalLayer } from './useModalLayer';
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect } from 'react';
|
|
2
|
-
import { useAdmin } from '../../admin/state/admin.context';
|
|
3
|
-
import { setSidebarCollapsed } from '../../layout/state/sidebar';
|
|
4
|
-
import { useLibrary } from '../../library/state/library-data';
|
|
5
|
-
import { useWelcomeRouteState } from '../welcome-state';
|
|
6
|
-
import { CreatorWelcomePage } from './CreatorWelcomePage';
|
|
7
|
-
import { WelcomePage } from './WelcomePage';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Chooses the first welcome without changing what the permanent reminder does.
|
|
11
|
-
*
|
|
12
|
-
* Only RootLanding sends `greeting: true`. A later visit from the Connect your
|
|
13
|
-
* agent reminder has no greeting state and must always reach its existing
|
|
14
|
-
* instructions, even when the admin has not created anything yet.
|
|
15
|
-
*/
|
|
16
|
-
export function WelcomeRoute() {
|
|
17
|
-
const { isAdmin, isAdminLoading = false } = useAdmin();
|
|
18
|
-
const data = useLibrary();
|
|
19
|
-
// The same reading `WelcomePage` gets — one parser, so the router and the
|
|
20
|
-
// page cannot disagree about whether a deep link was carried.
|
|
21
|
-
const { greeting, returnTo } = useWelcomeRouteState();
|
|
22
|
-
|
|
23
|
-
// Hold the sidebar out of the first painted frame while the admin and
|
|
24
|
-
// library checks settle. Both welcome pages use the full reading column.
|
|
25
|
-
useLayoutEffect(() => {
|
|
26
|
-
if (greeting) setSidebarCollapsed(true, true);
|
|
27
|
-
}, [greeting]);
|
|
28
|
-
|
|
29
|
-
// A carried deep link outranks the creator welcome, admin or not: only
|
|
30
|
-
// `WelcomePage` has the exit that honors `returnTo`, and a greeting that
|
|
31
|
-
// concluded by discarding the page someone was sent would cost them the
|
|
32
|
-
// reason they came. The library can be built after the link is kept.
|
|
33
|
-
if (!greeting || returnTo || (!isAdminLoading && !isAdmin)) return <WelcomePage />;
|
|
34
|
-
|
|
35
|
-
if (isAdminLoading || data.loading || data.pluginsLoading) {
|
|
36
|
-
// Two phases, two truths. While the ADMIN verdict is unknown the reader
|
|
37
|
-
// may be headed for the agent welcome, where their library is beside the
|
|
38
|
-
// point — so the hold says nothing about one. Once the verdict says
|
|
39
|
-
// admin, the remaining wait really is their library loading.
|
|
40
|
-
// A live region: the wait changes its own words as it advances from the
|
|
41
|
-
// admin check to the library load, and a silent swap is a change only
|
|
42
|
-
// sighted users are told about.
|
|
43
|
-
return (
|
|
44
|
-
<div role="status" className="py-16 text-center text-ui text-ink-faint">
|
|
45
|
-
{isAdminLoading ? 'One moment…' : 'Preparing your library…'}
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const libraryIsEmpty =
|
|
51
|
-
!data.error &&
|
|
52
|
-
!data.pluginsError &&
|
|
53
|
-
data.items.length === 0 &&
|
|
54
|
-
data.pluginSummaries.length === 0;
|
|
55
|
-
|
|
56
|
-
return libraryIsEmpty ? <CreatorWelcomePage /> : <WelcomePage />;
|
|
57
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useLocation } from 'react-router-dom';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* What an arrival at the welcome route carries — parsed in ONE place.
|
|
5
|
-
*
|
|
6
|
-
* Two components read this state: `WelcomeRoute`, which decides WHICH welcome
|
|
7
|
-
* you get, and `WelcomePage`, which decides where its exits go. They have to
|
|
8
|
-
* agree — a router that preserves a deep link in front of a page that
|
|
9
|
-
* discards it (or the reverse) loses the destination silently, and neither
|
|
10
|
-
* side's tests would notice. So the shape and the rules live here rather than
|
|
11
|
-
* being re-derived from `location.state` at each call site.
|
|
12
|
-
*/
|
|
13
|
-
export interface WelcomeRouteState {
|
|
14
|
-
/**
|
|
15
|
-
* How you got here. The automatic redirect at first sign-in is the ONE
|
|
16
|
-
* navigation that sets it (see `RootLanding`); the sidebar pill and a typed
|
|
17
|
-
* URL do not. Everything ceremonial on the welcome hangs off this flag.
|
|
18
|
-
*/
|
|
19
|
-
greeting: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Where the person was actually GOING when the sign-in interrupted them — a
|
|
22
|
-
* deep link that survived the SSO round-trip (see `RootLanding`).
|
|
23
|
-
*
|
|
24
|
-
* Null unless this is the greeting arrival, and that condition is the rule
|
|
25
|
-
* worth centralising: a `returnTo` on a later, non-greeting visit is not a
|
|
26
|
-
* carried intention, it is stale state on a page someone opened themselves.
|
|
27
|
-
*/
|
|
28
|
-
returnTo: string | null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Reads the welcome contract off the current location. */
|
|
32
|
-
export function useWelcomeRouteState(): WelcomeRouteState {
|
|
33
|
-
const state = useLocation().state as { greeting?: boolean; returnTo?: string | null } | null;
|
|
34
|
-
const greeting = state?.greeting === true;
|
|
35
|
-
return { greeting, returnTo: greeting ? (state?.returnTo ?? null) : null };
|
|
36
|
-
}
|