@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.
Files changed (206) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ProductName.test.tsx +46 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  6. package/src/core/__tests__/core-contributions.test.ts +16 -0
  7. package/src/core/core-contributions.ts +17 -0
  8. package/src/core/maker-url.ts +30 -0
  9. package/src/core/registry.ts +78 -1
  10. package/src/index.css +23 -5
  11. package/src/index.ts +5 -0
  12. package/src/lib/__tests__/latest-request.test.ts +48 -0
  13. package/src/lib/latest-request.ts +45 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  16. package/src/modules/access/api.ts +19 -3
  17. package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
  18. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  19. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  20. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  21. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  23. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  24. package/src/modules/admin/services/roles.api.ts +14 -1
  25. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  26. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  27. package/src/modules/auth/components/LoginScreen.tsx +101 -73
  28. package/src/modules/auth/services/account.api.ts +59 -3
  29. package/src/modules/auth/services/sso.ts +30 -10
  30. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  31. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  32. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  33. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  34. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  35. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  36. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  37. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  38. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  39. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  40. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  41. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  42. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  43. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  44. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  45. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  46. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  47. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  48. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  49. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  50. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  51. package/src/modules/embed/components/EmbedView.tsx +545 -0
  52. package/src/modules/embed/embed-config.ts +132 -0
  53. package/src/modules/embed/embed-host.ts +120 -0
  54. package/src/modules/embed/mount.tsx +80 -0
  55. package/src/modules/embed/services/embed-token.ts +22 -0
  56. package/src/modules/embed/services/embed.api.ts +158 -0
  57. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  58. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  59. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  60. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  61. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  62. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  63. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  64. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  65. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  66. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  67. package/src/modules/git/index.ts +15 -0
  68. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  69. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  70. package/src/modules/git/services/error-messages.ts +58 -1
  71. package/src/modules/git/services/pull-failure.ts +68 -0
  72. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  73. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  74. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  75. package/src/modules/layout/breakpoints.ts +8 -0
  76. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  77. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  78. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  79. package/src/modules/library/components/LibraryPage.tsx +22 -0
  80. package/src/modules/library/components/PluginExtras.tsx +23 -6
  81. package/src/modules/library/components/PluginPage.tsx +6 -1
  82. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  83. package/src/modules/library/services/plugins.api.ts +4 -1
  84. package/src/modules/library/state/plugins-revision.ts +28 -0
  85. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  86. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  87. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  88. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
  89. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
  90. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
  91. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  92. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  93. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  94. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  95. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  96. package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
  97. package/src/modules/onboarding/components/InviteButton.tsx +139 -0
  98. package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
  99. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  100. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  101. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  102. package/src/modules/onboarding/first-page-prompt.ts +123 -0
  103. package/src/modules/onboarding/invite-emails.ts +313 -0
  104. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  105. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  106. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  107. package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
  108. package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
  109. package/src/modules/onboarding/state/onboarding.ts +133 -59
  110. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  111. package/src/modules/settings/settings-nav-items.tsx +8 -3
  112. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  113. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  114. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  115. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  116. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  117. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  118. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  119. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  120. package/src/modules/setup/components/SetupGate.tsx +46 -1
  121. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  122. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  123. package/src/modules/setup/services/setup.api.ts +3 -3
  124. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  125. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  126. package/src/modules/toolbar/commands/actions.tsx +330 -0
  127. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  128. package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
  129. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  130. package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
  131. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  132. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  133. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  134. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  135. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
  136. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  137. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
  138. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  139. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  140. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  141. package/src/modules/toolbar/search/rank.ts +111 -0
  142. package/src/modules/toolbar/search/sources.ts +169 -0
  143. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  144. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  145. package/src/modules/workflow/services/lock.api.ts +17 -2
  146. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  147. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  148. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  149. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  150. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  151. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  152. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  153. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  154. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  155. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  156. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  157. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  158. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  159. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  160. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  161. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  162. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  163. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  164. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  165. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  166. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  167. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  168. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  169. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  170. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  171. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  172. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  173. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  174. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  175. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  176. package/src/modules/workspace/components/renderers/index.ts +26 -0
  177. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  178. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  179. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  180. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  181. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  182. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  183. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  184. package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
  185. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
  186. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  189. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  190. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  191. package/src/modules/workspace/state/editable-page.ts +42 -0
  192. package/src/modules/workspace/state/workspace.context.ts +13 -4
  193. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  194. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  195. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  196. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  197. package/src/modules/workspace/utils/fileTree.ts +49 -14
  198. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  199. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  200. package/src/shared/components/ConfirmProvider.tsx +156 -0
  201. package/src/shared/components/Dialog.tsx +7 -0
  202. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  203. package/src/shared/components/confirm-context.ts +94 -0
  204. package/src/shared/components/index.ts +3 -0
  205. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  206. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -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
- }