create-ailk 0.37.0 → 0.38.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 (232) hide show
  1. package/README.md +149 -2
  2. package/component-catalog.json +44 -6
  3. package/component-catalog.md +6 -5
  4. package/dist/add-module.js +16 -1
  5. package/dist/add-route.d.ts +7 -2
  6. package/dist/add-route.js +28 -13
  7. package/dist/cli.js +52 -0
  8. package/dist/declined-routes.d.ts +13 -0
  9. package/dist/declined-routes.js +74 -0
  10. package/dist/derive-architecture.d.ts +0 -6
  11. package/dist/derive-architecture.js +9 -15
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +3 -0
  14. package/dist/language-import.d.ts +93 -0
  15. package/dist/language-import.js +270 -43
  16. package/dist/lib/import-mdx.js +1 -1
  17. package/dist/lib/scaffold-render-sweep.d.ts +6 -3
  18. package/dist/lib/scaffold-render-sweep.js +8 -4
  19. package/dist/migrate-content.d.ts +6 -2
  20. package/dist/migrate-content.js +62 -5
  21. package/dist/module-architecture.js +139 -103
  22. package/dist/paid-sections.d.ts +13 -0
  23. package/dist/paid-sections.js +35 -5
  24. package/dist/programmatic.js +6 -16
  25. package/dist/remove-module.js +67 -0
  26. package/dist/routes.d.ts +103 -0
  27. package/dist/routes.js +708 -0
  28. package/dist/site-manifest.js +1 -1
  29. package/dist/site-roster.d.ts +2 -1
  30. package/dist/site-roster.js +30 -8
  31. package/dist/spoke-checkout.d.ts +28 -27
  32. package/dist/spoke-checkout.js +71 -102
  33. package/dist/surfaces.d.ts +18 -0
  34. package/dist/surfaces.js +47 -282
  35. package/dist/sync-routes.d.ts +28 -1
  36. package/dist/sync-routes.js +144 -11
  37. package/dist/template-record.d.ts +11 -0
  38. package/dist/template-record.js +18 -0
  39. package/dist/topology.d.ts +15 -1
  40. package/dist/topology.js +20 -4
  41. package/dist/update.d.ts +31 -2
  42. package/dist/update.js +627 -99
  43. package/package.json +3 -3
  44. package/templates/README.md +1 -1
  45. package/templates/apps/mcp/CLAUDE.md +5 -3
  46. package/templates/apps/web/CLAUDE.md +62 -20
  47. package/templates/apps/web/account.config.tsx +101 -0
  48. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
  49. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
  50. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
  51. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
  52. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
  54. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
  57. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
  58. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
  59. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
  60. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
  61. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
  62. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
  63. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
  64. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
  65. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
  66. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
  67. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
  68. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
  69. package/templates/apps/web/app/[locale]/layout.tsx +45 -28
  70. package/templates/apps/web/app/apple-icon.tsx +72 -0
  71. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  72. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  73. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  74. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  75. package/templates/apps/web/app/og/route.tsx +155 -72
  76. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  77. package/templates/apps/web/i18n/request.ts +44 -1
  78. package/templates/apps/web/jest.config.cjs +13 -1
  79. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  80. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
  81. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  82. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  83. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  84. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  85. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  86. package/templates/apps/web/lib/listings.tsx +2 -2
  87. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  88. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  89. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  90. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  91. package/templates/apps/web/lib/served-pages.ts +95 -0
  92. package/templates/apps/web/lib/site-brand.tsx +3 -5
  93. package/templates/apps/web/messages/en.json +8 -684
  94. package/templates/apps/web/middleware.ts +3 -1
  95. package/templates/apps/web/next.config.mjs +27 -0
  96. package/templates/apps/web/package.json +1 -0
  97. package/templates/customizations.yaml +9 -0
  98. package/templates/package.json +3 -1
  99. package/templates/tools/lint-architecture.ts +164 -11
  100. package/versions.json +48 -47
  101. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  102. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  103. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  104. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  105. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  106. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  107. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  108. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  109. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  110. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  111. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  112. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  113. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  114. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  115. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  116. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  117. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  118. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  119. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  120. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  121. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  122. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  123. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  124. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  125. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  126. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  127. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  128. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  129. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  130. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  131. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  132. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  133. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  134. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  135. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  136. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  137. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  138. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  139. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  140. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  141. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  142. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  143. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  144. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  145. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  146. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  147. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  148. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  149. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  150. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  151. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  152. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  153. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  154. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  155. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  156. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  157. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  158. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  159. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  160. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  161. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  162. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  163. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  164. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  165. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  166. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  167. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  168. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  169. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  170. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  171. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  172. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  173. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  174. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  175. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  176. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  177. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  178. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  179. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  180. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  181. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  182. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  183. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  184. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  185. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  186. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  187. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  188. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  189. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  190. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  191. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  192. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  193. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  194. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  195. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  196. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  197. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  198. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  199. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  200. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  201. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  202. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  203. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  204. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  205. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  206. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  207. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  208. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  209. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  210. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  211. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  212. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  213. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  214. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  215. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  216. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  217. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  218. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  219. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  220. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  221. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  222. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  223. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  224. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  225. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  226. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  227. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  228. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  229. package/templates/apps/web/lib/account-config.ts +0 -678
  230. package/templates/apps/web/lib/checkout-config.ts +0 -16
  231. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  232. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
@@ -1,365 +0,0 @@
1
- "use client"; // the menu, the dialog and the top-bar portal hold client state
2
-
3
- /**
4
- * NewMenu — the member area's New button over the Inbox (#8233, spec
5
- * docs/specs/8233-member-new-menu-the-new-spec.md D3, D5, D10; brief Layout
6
- * item 3). Copied from the Admin's NewMenu idiom (apps do not import apps).
7
- *
8
- * Its rows are the contributed New actions the Inbox page found offered
9
- * (`accountNewActions`, each already gated by its own member read). A row is
10
- * a menu item: it opens that action's popup in one dialog over the Inbox, or
11
- * — an action with `href` (#11154: Schedule appointment; #11152: Send
12
- * message, to the member thread page) — navigates to that account page. With
13
- * no action offered there is no menu at all.
14
- *
15
- * Two triggers share the dialog: the desktop New in the page's header row
16
- * (`md` up), and a compact + the frame's phone top bar holds. The frame hands
17
- * the top-bar node down through `NewMenuSlotProvider` on the Inbox route
18
- * only; outside a frame (a test, a story) the node is null and only the
19
- * desktop trigger renders.
20
- *
21
- * A popup body talks back through `useNewMenuPopup()`: `close(true)` after a
22
- * successful write closes the dialog and refreshes the Inbox, `open(id)`
23
- * switches to another offered action. A popup that reads on open uses
24
- * `useOpenRead` and `NewPopupStatus`, so loading, a failed read and its retry
25
- * look the same in every popup (D5).
26
- */
27
-
28
- import {
29
- Button,
30
- Dialog,
31
- DialogContent,
32
- DialogHeader,
33
- DialogTitle,
34
- DropdownMenu,
35
- DropdownMenuContent,
36
- DropdownMenuItem,
37
- DropdownMenuTrigger,
38
- Icon,
39
- InlineMessage,
40
- Text,
41
- } from "@working-theory/ui/primitives";
42
- import { ChevronDown, Plus } from "lucide-react";
43
- import { useRouter } from "next/navigation";
44
- import {
45
- createContext,
46
- useCallback,
47
- useContext,
48
- useEffect,
49
- useMemo,
50
- useRef,
51
- useState,
52
- type ReactElement,
53
- type ReactNode,
54
- } from "react";
55
- import { createPortal } from "react-dom";
56
-
57
- import type { NewActionErrorCode } from "./new-actions";
58
-
59
- /** One offered action, its label already translated: a popup, or a page to navigate to (#11154). */
60
- export interface NewMenuAction {
61
- id: string;
62
- label: string;
63
- popup?: ReactNode;
64
- /** The localized path the row navigates to; such a row has no popup. */
65
- href?: string;
66
- }
67
-
68
- export interface NewMenuLabels {
69
- trigger: string;
70
- close: string;
71
- }
72
-
73
- /** The strings every popup shares (D10, D11). */
74
- export interface NewPopupLabels {
75
- loading: string;
76
- loadFailed: string;
77
- retry: string;
78
- submitting: string;
79
- optional: string;
80
- errors: Record<NewActionErrorCode, string>;
81
- }
82
-
83
- // ── The top-bar slot ─────────────────────────────────────────────────────────
84
-
85
- const NewMenuSlotContext = createContext<HTMLElement | null>(null);
86
-
87
- /** Hands the phone top bar's trailing node to the page; `null` where the bar has none. */
88
- export function NewMenuSlotProvider({
89
- node,
90
- children,
91
- }: {
92
- node: HTMLElement | null;
93
- children: ReactNode;
94
- }): ReactElement {
95
- return <NewMenuSlotContext.Provider value={node}>{children}</NewMenuSlotContext.Provider>;
96
- }
97
-
98
- export function useNewMenuSlot(): HTMLElement | null {
99
- return useContext(NewMenuSlotContext);
100
- }
101
-
102
- // ── The popup API ────────────────────────────────────────────────────────────
103
-
104
- export interface NewMenuPopupApi {
105
- /** Closes the dialog; after a successful write, also refreshes the Inbox. */
106
- close(submitted: boolean): void;
107
- /** Switches the dialog to another offered action. */
108
- open(id: string): void;
109
- /** Whether an action is offered. */
110
- has(id: string): boolean;
111
- }
112
-
113
- const INERT_POPUP_API: NewMenuPopupApi = {
114
- close: () => undefined,
115
- open: () => undefined,
116
- has: () => false,
117
- };
118
-
119
- const NewMenuPopupContext = createContext<NewMenuPopupApi>(INERT_POPUP_API);
120
-
121
- export function useNewMenuPopup(): NewMenuPopupApi {
122
- return useContext(NewMenuPopupContext);
123
- }
124
-
125
- // ── The menu ─────────────────────────────────────────────────────────────────
126
-
127
- function ActionMenu({
128
- compact,
129
- actions,
130
- label,
131
- onPick,
132
- onNavigate,
133
- }: {
134
- compact: boolean;
135
- actions: readonly NewMenuAction[];
136
- label: string;
137
- onPick: (id: string, trigger: HTMLElement | null) => void;
138
- onNavigate: (href: string) => void;
139
- }): ReactElement {
140
- const triggerRef = useRef<HTMLButtonElement>(null);
141
- // A pick hands focus to the dialog, so the closing menu must not take it back.
142
- const picked = useRef(false);
143
- return (
144
- <DropdownMenu>
145
- <DropdownMenuTrigger asChild>
146
- {compact ? (
147
- <Button
148
- ref={triggerRef}
149
- variant="ghost"
150
- size="big"
151
- iconOnly
152
- aria-label={label}
153
- className="size-11 rounded-full"
154
- data-testid="account-new-menu-trigger-compact"
155
- >
156
- <Icon icon={Plus} size="md" decorative />
157
- </Button>
158
- ) : (
159
- <Button
160
- ref={triggerRef}
161
- variant="default"
162
- className="hidden gap-1 md:inline-flex"
163
- data-testid="account-new-menu-trigger"
164
- >
165
- <Icon icon={Plus} size="sm" decorative />
166
- {label}
167
- <Icon icon={ChevronDown} size="sm" decorative />
168
- </Button>
169
- )}
170
- </DropdownMenuTrigger>
171
- <DropdownMenuContent
172
- align="end"
173
- className="min-w-56"
174
- onCloseAutoFocus={(event) => {
175
- if (picked.current) event.preventDefault();
176
- picked.current = false;
177
- }}
178
- data-testid="account-new-menu-content"
179
- >
180
- {actions.map((action) => (
181
- <DropdownMenuItem
182
- key={action.id}
183
- onSelect={() => {
184
- // A link row navigates and leaves focus to the next page (#11154).
185
- if (action.href !== undefined) {
186
- onNavigate(action.href);
187
- return;
188
- }
189
- picked.current = true;
190
- onPick(action.id, triggerRef.current);
191
- }}
192
- {...(action.href !== undefined ? { "data-href": action.href } : {})}
193
- data-testid={`account-new-menu-item-${action.id}`}
194
- >
195
- {action.label}
196
- </DropdownMenuItem>
197
- ))}
198
- </DropdownMenuContent>
199
- </DropdownMenu>
200
- );
201
- }
202
-
203
- export function NewMenu({
204
- actions,
205
- labels,
206
- }: {
207
- actions: readonly NewMenuAction[];
208
- labels: NewMenuLabels;
209
- }): ReactElement | null {
210
- const router = useRouter();
211
- const slot = useNewMenuSlot();
212
- const [openId, setOpenId] = useState<string | null>(null);
213
- // The trigger that opened the dialog gets focus back when it closes.
214
- const returnFocus = useRef<HTMLElement | null>(null);
215
-
216
- const api = useMemo<NewMenuPopupApi>(() => {
217
- const has = (id: string): boolean => actions.some((action) => action.id === id);
218
- return {
219
- close(submitted) {
220
- setOpenId(null);
221
- if (submitted) router.refresh();
222
- },
223
- open(id) {
224
- if (has(id)) setOpenId(id);
225
- },
226
- has,
227
- };
228
- }, [actions, router]);
229
-
230
- if (actions.length === 0) return null;
231
-
232
- const current = actions.find((action) => action.id === openId) ?? null;
233
- const onPick = (id: string, trigger: HTMLElement | null): void => {
234
- returnFocus.current = trigger;
235
- setOpenId(id);
236
- };
237
- const onNavigate = (href: string): void => router.push(href);
238
-
239
- return (
240
- <>
241
- <ActionMenu
242
- compact={false}
243
- actions={actions}
244
- label={labels.trigger}
245
- onPick={onPick}
246
- onNavigate={onNavigate}
247
- />
248
- {slot
249
- ? createPortal(
250
- <ActionMenu
251
- compact
252
- actions={actions}
253
- label={labels.trigger}
254
- onPick={onPick}
255
- onNavigate={onNavigate}
256
- />,
257
- slot,
258
- )
259
- : null}
260
- <Dialog
261
- open={current !== null}
262
- onOpenChange={(open) => {
263
- if (!open) setOpenId(null);
264
- }}
265
- >
266
- {current ? (
267
- <DialogContent
268
- closeLabel={labels.close}
269
- aria-describedby={undefined}
270
- onCloseAutoFocus={(event) => {
271
- const trigger = returnFocus.current;
272
- if (trigger?.isConnected) {
273
- event.preventDefault();
274
- trigger.focus();
275
- }
276
- }}
277
- data-testid="account-new-popup"
278
- >
279
- <DialogHeader>
280
- <DialogTitle>{current.label}</DialogTitle>
281
- </DialogHeader>
282
- <NewMenuPopupContext.Provider value={api}>
283
- {/* Keyed, so switching actions mounts a fresh popup that reads anew. */}
284
- <div key={current.id} className="mt-block-tight">
285
- {current.popup}
286
- </div>
287
- </NewMenuPopupContext.Provider>
288
- </DialogContent>
289
- ) : null}
290
- </Dialog>
291
- </>
292
- );
293
- }
294
-
295
- // ── Shared popup parts (D5, D10) ─────────────────────────────────────────────
296
-
297
- export type OpenRead<T> = "loading" | { kind: "error" } | ({ kind: "ok" } & T);
298
-
299
- /**
300
- * Reads a popup's data when it mounts — the dialog mounts a popup only while
301
- * it is open, so this is a read per open (D5) — and returns a retry.
302
- */
303
- export function useOpenRead<T>(
304
- read: () => Promise<{ kind: "error" } | ({ kind: "ok" } & T)>,
305
- ): [OpenRead<T>, () => void] {
306
- const [state, setState] = useState<OpenRead<T>>("loading");
307
- // Only the newest read lands: a retry never loses to the read it replaced.
308
- const latest = useRef(0);
309
- const load = useCallback(() => {
310
- const readId = ++latest.current;
311
- const land = (next: OpenRead<T>): void => {
312
- if (readId === latest.current) setState(next);
313
- };
314
- setState("loading");
315
- read().then(land, () => land({ kind: "error" }));
316
- }, [read]);
317
- useEffect(load, [load]);
318
- return [state, load];
319
- }
320
-
321
- /** A popup's loading line, or its failed-read line with Try again. */
322
- export function NewPopupStatus({
323
- failed,
324
- labels,
325
- onRetry,
326
- }: {
327
- failed: boolean;
328
- labels: NewPopupLabels;
329
- onRetry: () => void;
330
- }): ReactElement {
331
- if (!failed) {
332
- return (
333
- <div role="status" data-testid="new-popup-loading">
334
- <Text as="p" variant="body-sm" tone="muted">
335
- {labels.loading}
336
- </Text>
337
- </div>
338
- );
339
- }
340
- return (
341
- <div className="flex flex-wrap items-center gap-3" data-testid="new-popup-load-failed">
342
- <InlineMessage variant="error" className="text-body-sm">
343
- {labels.loadFailed}
344
- </InlineMessage>
345
- <Button variant="outline" onClick={onRetry} data-testid="new-popup-retry">
346
- {labels.retry}
347
- </Button>
348
- </div>
349
- );
350
- }
351
-
352
- /** A refused write's plain message; the popup stays open with every value kept. */
353
- export function NewPopupRefusal({
354
- code,
355
- labels,
356
- }: {
357
- code: NewActionErrorCode;
358
- labels: NewPopupLabels;
359
- }): ReactElement {
360
- return (
361
- <InlineMessage variant="error" data-testid="new-popup-error">
362
- {labels.errors[code]}
363
- </InlineMessage>
364
- );
365
- }
@@ -1,86 +0,0 @@
1
- /**
2
- * new-popups.tsx — the New menu's actions with their popups bound (#8233 D1,
3
- * D2, D6–D8).
4
- *
5
- * `lib/account-config.ts` carries each action's server half — its id, its
6
- * label and the member read that decides whether it is offered — and this
7
- * file adds the popup each one opens, composing the `AccountNewAction`
8
- * contract (`@working-theory/templates/account`) the Inbox page consumes.
9
- *
10
- * The split is create-ailk's spoke closure (`spokeExclusions`,
11
- * `packages/create-ailk/src/topology.ts`): a spoke without sign-in drops the
12
- * whole `(authed)` group, these popups included, and every file that imports
13
- * one of them goes too — but `account-config.ts` is a shared lib file every
14
- * spoke keeps, so it may import nothing under `(authed)` (the closure guard
15
- * refuses the scaffold, naming it). This file sits inside the group: it goes
16
- * with the popups on such a spoke, and stays with them on a hub-sign-in one
17
- * and on a single site, where the page still renders all three.
18
- *
19
- * A popup receives only its locale and strings built through `ctx.t` — never
20
- * `ctx`, its init, its user or `t` itself — so no credential or email reaches
21
- * the client payload (SEC-8233-1). `popups` is keyed on the config's own id
22
- * union, so a read added there without a popup here is a type error, never a
23
- * menu row that opens nothing. A read carrying `href` is a link row and
24
- * binds no popup: Schedule appointment (#11154) navigates to
25
- * `/account/appointments`, the retired schedule popup's one booking path;
26
- * Send message (#11152) navigates to `/account/inbox/thread`, the member's
27
- * thread page, whose composer took over from the retired message lightbox.
28
- */
29
-
30
- import type {
31
- AccountContext,
32
- AccountNewAction,
33
- AccountTranslate,
34
- } from "@working-theory/templates/account";
35
- import type { ReactNode } from "react";
36
-
37
- import { accountNewActions } from "../../../../lib/account-config";
38
-
39
- import { RequestQuote } from "./components/request-quote";
40
- import type { NewActionErrorCode } from "./new-actions";
41
- import type { NewPopupLabels } from "./new-menu";
42
-
43
- /** Each refusal code's plain line — the popups' and the thread composer's (#11152) one map. */
44
- export function newActionErrorLabels(t: AccountTranslate): Record<NewActionErrorCode, string> {
45
- return {
46
- link_not_https: t("new.errors.linkNotHttps"),
47
- answers_invalid: t("new.errors.answersInvalid"),
48
- request_form_off: t("new.errors.requestFormOff"),
49
- meeting_type_not_offered: t("new.errors.meetingTypeNotOffered"),
50
- slot_unavailable: t("new.errors.slotUnavailable"),
51
- too_many_requests: t("new.errors.tooManyRequests"),
52
- invalid_input: t("new.errors.invalidInput"),
53
- failed: t("new.errors.failed"),
54
- };
55
- }
56
-
57
- /** The strings every popup shares — plain strings, so nothing else crosses to the client. */
58
- function popupLabels(t: AccountTranslate): NewPopupLabels {
59
- return {
60
- loading: t("new.loading"),
61
- loadFailed: t("new.loadFailed"),
62
- retry: t("new.retry"),
63
- submitting: t("new.submitting"),
64
- optional: t("new.optional"),
65
- errors: newActionErrorLabels(t),
66
- };
67
- }
68
-
69
- /** The ids of the reads that open a popup — every read without an `href` (#11154). */
70
- type AccountNewPopupId = Exclude<(typeof accountNewActions)[number], { href: string }>["id"];
71
-
72
- /** The popup each action opens, keyed on the config's ids (D6–D8). */
73
- const popups = {
74
- "request-quote": ({ locale, t }) => (
75
- <RequestQuote
76
- locale={locale}
77
- labels={{ ...popupLabels(t), submit: t("new.quote.submit"), pickDate: t("new.quote.pickDate") }}
78
- />
79
- ),
80
- } satisfies Record<AccountNewPopupId, (ctx: AccountContext) => ReactNode>;
81
-
82
- /** The New actions in menu order (D2), each with its popup or its page — what the Inbox page offers. */
83
- export const newActions: readonly AccountNewAction[] = accountNewActions.map(
84
- (read): AccountNewAction =>
85
- "href" in read ? read : { ...read, renderPopup: popups[read.id] },
86
- );
@@ -1,120 +0,0 @@
1
- "use server";
2
-
3
- /**
4
- * account/onboarding/actions.ts — the onboarding page's read and write
5
- * (#8515, spec docs/specs/8515-standard-client-onboarding-diagnostic-and-spec.md
6
- * D12; the routes are D7's `GET` and D8's `POST /v1/member/onboarding`).
7
- *
8
- * - `readOnboardingForm` — `member.onboarding`, the standard onboarding
9
- * magnet's questions, or `form: null` while it is not open to the
10
- * caller. A 404 (no member area on this build, or a hub that does not
11
- * admit the route) is that same "not open" state; any other refusal is
12
- * `error`, so the page shows its error row with Retry.
13
- * - `submitOnboarding` — `member.submitOnboarding` with the answers.
14
- *
15
- * Both send `forwardedCookieInit()`'s init as built — the session cookie
16
- * plus the request's `Origin` on a single site, the hub credential on a
17
- * hub-mode spoke — so nothing here tests the topology, and no identity is
18
- * posted: the API takes the Person from the credential.
19
- *
20
- * The answers are the entries named `answer.<name>`; a repeated name becomes
21
- * an array, and so does a name the form lists under `multi` (a multi
22
- * question with one box checked still posts an array, which is what the API
23
- * asks of it). A value is sent as typed; one left empty or all-space is
24
- * omitted, because the API refuses `""`. The API checks every answer
25
- * against the form it serves — nothing here is trusted.
26
- *
27
- * Not a `*.actions.ts` file and no `*Action`-suffixed export: apps/mcp's
28
- * parity test reads that suffix, and the member routes have no MCP twin by
29
- * decision (8515 C4). Logs carry the function, the status and the code only
30
- * — never an answer or a credential.
31
- */
32
-
33
- import { member } from "@working-theory/api-client";
34
- import type { MemberOnboardingFormResponse } from "@working-theory/validation";
35
-
36
- import { forwardedCookieInit } from "../../../../../lib/server-api";
37
-
38
- /** The refusal codes the form has its own words for; anything else is `failed`. */
39
- const KNOWN_CODES = [
40
- "onboarding_off",
41
- "answers_invalid",
42
- "link_not_https",
43
- "too_many_requests",
44
- ] as const;
45
-
46
- export type OnboardingErrorCode = (typeof KNOWN_CODES)[number] | "failed";
47
-
48
- /** What the form shows after a submit. */
49
- export type OnboardingState =
50
- | { kind: "idle" }
51
- | { kind: "sent" }
52
- | { kind: "error"; code: OnboardingErrorCode };
53
-
54
- export type OnboardingForm = NonNullable<MemberOnboardingFormResponse["form"]>;
55
-
56
- export type OnboardingRead = { kind: "ok"; form: OnboardingForm | null } | { kind: "error" };
57
-
58
- /** PII-safe error identity for logs (`err.name` only). */
59
- function errorName(err: unknown): string {
60
- return err instanceof Error ? err.name : "unknown";
61
- }
62
-
63
- /** The `error.code` of a member refusal body, when it has one. */
64
- function errorCode(body: unknown): string | null {
65
- const code = (body as { error?: { code?: unknown } } | null)?.error?.code;
66
- return typeof code === "string" ? code : null;
67
- }
68
-
69
- function knownCode(status: number, code: string | null): OnboardingErrorCode {
70
- const known = KNOWN_CODES.find((candidate) => candidate === code);
71
- if (known) return known;
72
- // The hub's per-person budget and the per-IP limiter answer `429 rate_limited`.
73
- return status === 429 ? "too_many_requests" : "failed";
74
- }
75
-
76
- export async function readOnboardingForm(): Promise<OnboardingRead> {
77
- try {
78
- const res = await member.onboarding(await forwardedCookieInit());
79
- if (res.ok) return { kind: "ok", form: res.body.form };
80
- if (res.status === 404) return { kind: "ok", form: null };
81
- console.error(
82
- `[onboarding] readOnboardingForm status=${res.status} code=${errorCode(res.body) ?? "none"}`,
83
- );
84
- } catch (err) {
85
- console.error(`[onboarding] readOnboardingForm errName=${errorName(err)}`);
86
- }
87
- return { kind: "error" };
88
- }
89
-
90
- /** `(prev, formData)` for `useActionState`. */
91
- export async function submitOnboarding(
92
- _prev: OnboardingState,
93
- formData: FormData,
94
- ): Promise<OnboardingState> {
95
- // Action input is untrusted: a hand-built call may post anything.
96
- if (!(formData instanceof FormData)) return { kind: "error", code: "failed" };
97
-
98
- const multi = new Set(formData.getAll("multi").filter((v) => typeof v === "string"));
99
- const answers: Record<string, string | string[]> = {};
100
- for (const key of new Set(formData.keys())) {
101
- if (!key.startsWith("answer.")) continue;
102
- const name = key.slice("answer.".length);
103
- const values = formData
104
- .getAll(key)
105
- .filter((v): v is string => typeof v === "string" && v.trim() !== "");
106
- if (values.length === 0) continue;
107
- answers[name] = values.length > 1 || multi.has(name) ? values : values[0]!;
108
- }
109
-
110
- try {
111
- const res = await member.submitOnboarding({ answers }, await forwardedCookieInit());
112
- if (res.ok) return { kind: "sent" };
113
- const code = knownCode(res.status, errorCode(res.body));
114
- console.error(`[onboarding] submitOnboarding status=${res.status} code=${code}`);
115
- return { kind: "error", code };
116
- } catch (err) {
117
- console.error(`[onboarding] submitOnboarding errName=${errorName(err)}`);
118
- return { kind: "error", code: "failed" };
119
- }
120
- }