create-ailk 0.36.0 → 0.37.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 (94) hide show
  1. package/component-catalog.json +40 -1
  2. package/component-catalog.md +7 -5
  3. package/dist/surfaces.js +60 -19
  4. package/dist/update.d.ts +19 -1
  5. package/dist/update.js +293 -35
  6. package/package.json +3 -3
  7. package/templates/.env.example +17 -0
  8. package/templates/apps/api/.env.example +38 -0
  9. package/templates/apps/api/CLAUDE.md +3 -0
  10. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  11. package/templates/apps/mcp/CLAUDE.md +1 -1
  12. package/templates/apps/web/CLAUDE.md +28 -1
  13. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  14. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  15. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  16. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  17. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  18. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  19. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  20. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  21. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  22. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  30. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  31. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  32. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  33. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  34. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  36. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  38. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  39. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  40. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  41. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  42. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  43. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  45. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  46. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  47. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  48. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  50. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  52. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  53. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  54. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  59. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  60. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  62. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  63. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  64. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  65. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  66. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  68. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  69. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  70. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  71. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  72. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  73. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  74. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  75. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  76. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  77. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  78. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  79. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  80. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  81. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  82. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  83. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  84. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  85. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  86. package/templates/apps/web/lib/account-config.ts +132 -8
  87. package/templates/apps/web/lib/auth-routes.ts +11 -6
  88. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  89. package/templates/apps/web/messages/en.json +156 -80
  90. package/versions.json +48 -48
  91. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  92. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  93. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  94. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -0,0 +1,426 @@
1
+ /**
2
+ * The Appointments pages (#11154).
3
+ *
4
+ * `/account/appointments` and `/account/appointments/[slug]`, rendered as the
5
+ * RSCs they are, with the api-client's `member.meetingTypes` (the offer) and
6
+ * `schedule.meetings` (the Cal.com link) as the two mocked reads. Covers:
7
+ * - the list renders `AccountListFrame`'s table Title · Duration · Price in
8
+ * the read's order, a chevron on every row, each row opening the type's
9
+ * booking page, the All count, and the phone rows' "<duration> · <price>"
10
+ * captions; a priced type reads its price, an unpriced one "Free";
11
+ * - an empty offer and a 404 (and a 401/403 while the email is unverified)
12
+ * are the empty line; any other failure is the error row with Retry and
13
+ * no frame (7423 D12);
14
+ * - the booking page is one H1 over the `scheduler-embed` section (provider
15
+ * cal, month view, the tight gap) built from the member read's Cal.com
16
+ * link with the member's name and verified email as the section's
17
+ * `prefill` (the booker opens with both filled), and "← All
18
+ * appointments" under it;
19
+ * - a slug the member read does not serve answers "This appointment type is
20
+ * no longer offered." with no embed and no public read; a type the member read
21
+ * gives no link is the error row; a dotted or malformed segment and
22
+ * no session are not-found.
23
+ */
24
+
25
+ import { render, screen, within } from "@testing-library/react";
26
+
27
+ jest.mock("next-intl/server", () => {
28
+ const msgs: unknown = require("../../../../../../messages/en.json");
29
+ const dig = (obj: unknown, path: string): unknown =>
30
+ path
31
+ .split(".")
32
+ .reduce<unknown>(
33
+ (acc, k) =>
34
+ acc !== null && typeof acc === "object"
35
+ ? (acc as Record<string, unknown>)[k]
36
+ : undefined,
37
+ obj,
38
+ );
39
+ return {
40
+ __esModule: true,
41
+ getTranslations: async (
42
+ arg: string | { namespace?: string; locale?: string },
43
+ ) => {
44
+ const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
45
+ const messages = dig(msgs, ns);
46
+ return (key: string, values?: Record<string, unknown>): string => {
47
+ const value = dig(messages, key);
48
+ if (typeof value !== "string") return `${ns}.${key}`;
49
+ return value.replace(/\{(\w+)\}/g, (m, name: string) =>
50
+ values && name in values ? String(values[name]) : m,
51
+ );
52
+ };
53
+ },
54
+ };
55
+ });
56
+
57
+ jest.mock("next/headers", () => ({
58
+ __esModule: true,
59
+ headers: jest.fn().mockResolvedValue(new Headers()),
60
+ cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
61
+ }));
62
+
63
+ const mockGetSession = jest.fn();
64
+ // eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test of the session fields can mock without standing up Prisma.
65
+ jest.mock("../../../../../../auth", () => ({
66
+ __esModule: true,
67
+ auth: {
68
+ api: { getSession: (...args: unknown[]) => mockGetSession(...args) },
69
+ },
70
+ }));
71
+
72
+ const mockMeetingTypes = jest.fn();
73
+ const mockMeetings = jest.fn();
74
+ jest.mock("@working-theory/api-client", () => ({
75
+ __esModule: true,
76
+ waitlistSignups: { me: jest.fn() },
77
+ subscription: { me: jest.fn() },
78
+ member: { meetingTypes: (...args: unknown[]) => mockMeetingTypes(...args) },
79
+ schedule: { meetings: (...args: unknown[]) => mockMeetings(...args) },
80
+ }));
81
+
82
+ const mockNotFound = jest.fn(() => {
83
+ throw new Error("NEXT_NOT_FOUND");
84
+ });
85
+ jest.mock("next/navigation", () => ({
86
+ __esModule: true,
87
+ notFound: () => mockNotFound(),
88
+ useRouter: () => ({ push: jest.fn(), refresh: jest.fn() }),
89
+ usePathname: () => "/account/appointments",
90
+ }));
91
+
92
+ // Render the real catalog, keeping the sections the page handed it: the Cal.com
93
+ // island mounts its iframe in an effect, so the calLink is read from the data.
94
+ const capturedSections: unknown[] = [];
95
+ jest.mock("@working-theory/ui/sections", () => {
96
+ const actual = jest.requireActual<
97
+ typeof import("@working-theory/ui/sections")
98
+ >("@working-theory/ui/sections");
99
+ return {
100
+ __esModule: true,
101
+ ...actual,
102
+ SectionRenderer: (props: Parameters<typeof actual.SectionRenderer>[0]) => {
103
+ capturedSections.splice(0, capturedSections.length, ...props.sections);
104
+ return actual.SectionRenderer(props);
105
+ },
106
+ };
107
+ });
108
+
109
+ import BookingPage, { memberBookerSection } from "../[slug]/page";
110
+ import ListPage from "../page";
111
+
112
+ /** The cookie a single site forwards (`forwardedCookieInit()`). */
113
+ const INIT = { headers: { cookie: "session=abc" } };
114
+
115
+ const VERIFIED = {
116
+ user: {
117
+ id: "user_1",
118
+ name: "Ada",
119
+ email: "ada@example.com",
120
+ emailVerified: true,
121
+ },
122
+ };
123
+ const UNVERIFIED = { user: { ...VERIFIED.user, emailVerified: false } };
124
+
125
+ const TYPES = [
126
+ {
127
+ slug: "consult",
128
+ title: "Consultation",
129
+ durationMinutes: 30,
130
+ price: { amountMinor: 5000, currency: "usd" },
131
+ calLink: "sam/consult",
132
+ },
133
+ {
134
+ slug: "review",
135
+ title: "Design review",
136
+ durationMinutes: 60,
137
+ calLink: "sam/review",
138
+ },
139
+ {
140
+ slug: "free-chat",
141
+ title: "Free chat",
142
+ durationMinutes: 15,
143
+ price: { amountMinor: 0, currency: "usd" },
144
+ },
145
+ ];
146
+
147
+ /** The public read: never consulted by the member pages (#11154); kept to assert it. */
148
+ const MEETINGS = [
149
+ {
150
+ slug: "consult",
151
+ visibility: "public",
152
+ position: 0,
153
+ bookable: true,
154
+ calLink: "sam/consult",
155
+ title: "Consultation",
156
+ durationMinutes: 30,
157
+ },
158
+ {
159
+ slug: "review",
160
+ visibility: "public",
161
+ position: 1,
162
+ bookable: true,
163
+ calLink: "sam/review",
164
+ title: "Design review",
165
+ durationMinutes: 60,
166
+ },
167
+ { slug: "gone", visibility: "public", position: 2, bookable: false },
168
+ ];
169
+
170
+ const ok = <T,>(body: T) => ({ ok: true, body });
171
+ const refused = (status: number, code = "x") => ({
172
+ ok: false,
173
+ status,
174
+ body: { ok: false, error: { code, message: "x" } },
175
+ });
176
+
177
+ beforeEach(() => {
178
+ mockGetSession.mockReset().mockResolvedValue(VERIFIED);
179
+ mockMeetingTypes.mockReset().mockResolvedValue(ok({ items: TYPES }));
180
+ mockMeetings.mockReset().mockResolvedValue(ok({ meetings: MEETINGS }));
181
+ mockNotFound.mockClear();
182
+ capturedSections.length = 0;
183
+ jest.spyOn(console, "error").mockImplementation(() => undefined);
184
+ });
185
+
186
+ afterEach(() => {
187
+ jest.restoreAllMocks();
188
+ });
189
+
190
+ async function renderList(): Promise<void> {
191
+ render(await ListPage({ params: Promise.resolve({ locale: "en" }) }));
192
+ }
193
+
194
+ async function renderBooking(slug: string): Promise<void> {
195
+ render(
196
+ await BookingPage({ params: Promise.resolve({ locale: "en", slug }) }),
197
+ );
198
+ }
199
+
200
+ describe("/account/appointments — the types the member read serves (AC-1)", () => {
201
+ it("renders Title · Duration · Price in the read's order, a chevron per row, each row opening its booking page", async () => {
202
+ await renderList();
203
+ expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
204
+ "Appointments",
205
+ );
206
+ expect(mockMeetingTypes).toHaveBeenCalledWith(INIT);
207
+
208
+ const table = screen.getByTestId("appointments-table");
209
+ expect(
210
+ within(table)
211
+ .getAllByRole("columnheader")
212
+ .map((h) => h.textContent),
213
+ ).toEqual(["Title", "Duration", "Price", ""]);
214
+ const titles = within(table).getAllByTestId(/-title$/);
215
+ expect(titles.map((t) => t.textContent)).toEqual([
216
+ "Consultation",
217
+ "Design review",
218
+ "Free chat",
219
+ ]);
220
+ expect(titles.map((t) => t.getAttribute("href"))).toEqual([
221
+ "/account/appointments/consult",
222
+ "/account/appointments/review",
223
+ "/account/appointments/free-chat",
224
+ ]);
225
+ for (const slug of ["consult", "review", "free-chat"]) {
226
+ expect(
227
+ screen.getByTestId(`appointments-table-row-${slug}-chevron`),
228
+ ).toBeInTheDocument();
229
+ }
230
+
231
+ const consult = screen.getByTestId("appointments-table-row-consult");
232
+ expect(consult).toHaveTextContent("30 min");
233
+ expect(consult).toHaveTextContent("$50");
234
+ expect(
235
+ screen.getByTestId("appointments-table-row-review"),
236
+ ).toHaveTextContent("Free");
237
+ expect(
238
+ screen.getByTestId("appointments-table-row-free-chat"),
239
+ ).toHaveTextContent("Free");
240
+
241
+ // The phone rows render the same read: their captions exist in the DOM.
242
+ expect(
243
+ screen.getAllByTestId("appointments-row").map((r) => r.textContent),
244
+ ).toEqual([
245
+ expect.stringContaining("30 min · $50"),
246
+ expect.stringContaining("60 min · Free"),
247
+ expect.stringContaining("15 min · Free"),
248
+ ]);
249
+
250
+ const nav = screen.getByTestId("appointments-facets");
251
+ const items = within(nav).getAllByTestId(/^appointments-facets-item-/);
252
+ expect(items.map((i) => i.getAttribute("data-testid"))).toEqual([
253
+ "appointments-facets-item-all",
254
+ ]);
255
+ expect(items[0]).toHaveTextContent("All appointments");
256
+ expect(items[0]).toHaveTextContent("3");
257
+ // No public read serves the list: the member read alone decides it.
258
+ expect(mockMeetings).not.toHaveBeenCalled();
259
+ });
260
+
261
+ it.each([
262
+ ["an empty offer", ok({ items: [] }), VERIFIED],
263
+ ["a 404 (no scheduling module)", refused(404, "not_found"), VERIFIED],
264
+ [
265
+ "a 403 while the email is unverified",
266
+ refused(403, "forbidden"),
267
+ UNVERIFIED,
268
+ ],
269
+ ])(
270
+ "%s is the empty line, never the error row",
271
+ async (_name, answer, session) => {
272
+ mockGetSession.mockResolvedValue(session);
273
+ mockMeetingTypes.mockResolvedValue(answer);
274
+ await renderList();
275
+ expect(screen.getByTestId("appointments-empty")).toHaveTextContent(
276
+ "No appointment types are offered right now.",
277
+ );
278
+ expect(
279
+ screen.getByTestId("appointments-facets-item-all"),
280
+ ).toHaveTextContent("0");
281
+ expect(screen.queryByTestId("appointments-table")).toBeNull();
282
+ expect(screen.queryByTestId("inbox-error")).toBeNull();
283
+ },
284
+ );
285
+
286
+ it.each([
287
+ ["a 500", refused(500, "failed"), VERIFIED],
288
+ ["a 403 with a verified email", refused(403, "forbidden"), VERIFIED],
289
+ ])(
290
+ "%s is the error row with Retry and no frame (7423 D12)",
291
+ async (_name, answer, session) => {
292
+ mockGetSession.mockResolvedValue(session);
293
+ mockMeetingTypes.mockResolvedValue(answer);
294
+ await renderList();
295
+ expect(screen.getByTestId("inbox-error")).toHaveTextContent(
296
+ "We couldn't load your appointment types.",
297
+ );
298
+ expect(screen.getByRole("button", { name: "Retry" })).toBeInTheDocument();
299
+ expect(screen.queryByTestId("appointments-facets")).toBeNull();
300
+ expect(screen.queryByTestId("appointments-empty")).toBeNull();
301
+ },
302
+ );
303
+
304
+ it("signed out renders the heading alone and reads nothing", async () => {
305
+ mockGetSession.mockResolvedValue(null);
306
+ await renderList();
307
+ expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
308
+ "Appointments",
309
+ );
310
+ expect(mockMeetingTypes).not.toHaveBeenCalled();
311
+ expect(mockNotFound).not.toHaveBeenCalled();
312
+ });
313
+ });
314
+
315
+ describe("/account/appointments/<slug> — the member's booking page (AC-2)", () => {
316
+ it("renders one H1, the booker from the member read's Cal.com link pre-bound to the member, and the back link", async () => {
317
+ await renderBooking("consult");
318
+ const h1s = screen.getAllByRole("heading", { level: 1 });
319
+ expect(h1s).toHaveLength(1);
320
+ expect(h1s[0]).toHaveTextContent("Schedule a consultation meeting");
321
+
322
+ expect(screen.getByTestId("scheduler-embed-section")).toBeInTheDocument();
323
+ expect(screen.getByTestId("scheduler-embed-cal")).toHaveAttribute(
324
+ "data-provider",
325
+ "cal",
326
+ );
327
+ expect(capturedSections).toEqual([
328
+ {
329
+ id: "appointment-consult",
330
+ type: "scheduler-embed",
331
+ data: {
332
+ provider: "cal",
333
+ calLink: "sam/consult",
334
+ prefill: { email: "ada@example.com", name: "Ada" },
335
+ layout: "month_view",
336
+ gapAbove: "tight",
337
+ },
338
+ },
339
+ ]);
340
+ // The member's own credential reads the offer and its link (#11154); the
341
+ // public read, whose Live set excludes client-only slugs, is never used.
342
+ expect(mockMeetingTypes).toHaveBeenCalledWith(INIT);
343
+ expect(mockMeetings).not.toHaveBeenCalled();
344
+
345
+ expect(screen.getByTestId("appointment-back")).toHaveTextContent(
346
+ "← All appointments",
347
+ );
348
+ expect(screen.getByTestId("appointment-back")).toHaveAttribute(
349
+ "href",
350
+ "/account/appointments",
351
+ );
352
+ expect(screen.queryByTestId("appointment-not-offered")).toBeNull();
353
+ expect(mockNotFound).not.toHaveBeenCalled();
354
+ });
355
+
356
+ it("the booker section carries the email alone when the session has no name", () => {
357
+ expect(
358
+ memberBookerSection("review", "sam/review", {
359
+ name: null,
360
+ email: "ada@example.com",
361
+ }),
362
+ ).toEqual({
363
+ id: "appointment-review",
364
+ type: "scheduler-embed",
365
+ data: {
366
+ provider: "cal",
367
+ calLink: "sam/review",
368
+ prefill: { email: "ada@example.com" },
369
+ layout: "month_view",
370
+ gapAbove: "tight",
371
+ },
372
+ });
373
+ });
374
+
375
+ it("a slug the member read does not serve says the type is no longer offered — no embed, no public read", async () => {
376
+ await renderBooking("gone");
377
+ expect(screen.getByTestId("appointment-not-offered")).toHaveTextContent(
378
+ "This appointment type is no longer offered.",
379
+ );
380
+ expect(screen.queryByTestId("scheduler-embed-section")).toBeNull();
381
+ expect(mockMeetings).not.toHaveBeenCalled();
382
+ expect(screen.getByTestId("appointment-back")).toHaveAttribute(
383
+ "href",
384
+ "/account/appointments",
385
+ );
386
+ expect(mockNotFound).not.toHaveBeenCalled();
387
+ });
388
+
389
+ it("an offered type the member read carries no link for is the error row under its heading", async () => {
390
+ mockMeetingTypes.mockResolvedValue(
391
+ ok({ items: TYPES.map(({ calLink: _link, ...type }) => type) }),
392
+ );
393
+ await renderBooking("consult");
394
+ expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
395
+ "Schedule a consultation meeting",
396
+ );
397
+ expect(screen.getByTestId("inbox-error")).toHaveTextContent(
398
+ "We couldn't load this appointment type.",
399
+ );
400
+ expect(screen.queryByTestId("scheduler-embed-section")).toBeNull();
401
+ });
402
+
403
+ it("a failed member read is the error row, with no public read", async () => {
404
+ mockMeetingTypes.mockResolvedValue(refused(500, "failed"));
405
+ await renderBooking("consult");
406
+ expect(screen.getByTestId("inbox-error")).toHaveTextContent(
407
+ "We couldn't load this appointment type.",
408
+ );
409
+ expect(mockMeetings).not.toHaveBeenCalled();
410
+ });
411
+
412
+ it.each(["intro.html", "Bad Slug", ""])(
413
+ "the segment %p is not found before any read",
414
+ async (slug) => {
415
+ await expect(renderBooking(slug)).rejects.toThrow("NEXT_NOT_FOUND");
416
+ expect(mockMeetingTypes).not.toHaveBeenCalled();
417
+ expect(mockMeetings).not.toHaveBeenCalled();
418
+ },
419
+ );
420
+
421
+ it("no session is not found", async () => {
422
+ mockGetSession.mockResolvedValue(null);
423
+ await expect(renderBooking("consult")).rejects.toThrow("NEXT_NOT_FOUND");
424
+ expect(mockMeetingTypes).not.toHaveBeenCalled();
425
+ });
426
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * appointments/appointments-data.ts — the Appointments pages' reads and
3
+ * helpers (#11154).
4
+ *
5
+ * The list and the booking page read the same offer, so the read lives here
6
+ * (the `artifacts/artifact-data.ts` shape): `GET /v1/member/meeting-types`,
7
+ * the types the provider offers its clients — `customerSlugs` ∩ `enabledSlugs`
8
+ * (#11122 D6) — through `member.meetingTypes` with the caller's forwarded
9
+ * credential. The account area's read rule is restated: a 404 (no tenancy
10
+ * module, or a spoke route the hub does not admit) is "nothing offered"; a
11
+ * 401 or 403 is the same while the person's email is unverified; anything
12
+ * else throws, so the page shows its error row with Retry (spec 7423 D12),
13
+ * never an empty list.
14
+ *
15
+ * The member read carries each type's Cal.com link (`calLink`, #11154), read
16
+ * from the account handle on the server. The public meetings read is never
17
+ * used: its Live set excludes the client-only slugs (#11122 D6), so it never
18
+ * lists an offered type. A type with no link (the handle could not be read)
19
+ * makes the booking page say it could not load.
20
+ *
21
+ * These are BASE files, like the New menu's (#8233 C1): the reads 404 on a
22
+ * build without the scheduling module, so nothing here imports the module's
23
+ * own `lib/meetings.tsx`.
24
+ */
25
+
26
+ import { member } from "@working-theory/api-client";
27
+ import type { AccountContext } from "@working-theory/templates/account";
28
+ import { localeHref } from "@working-theory/ui";
29
+ import {
30
+ meetingSlugSchema,
31
+ type MemberMeetingType,
32
+ } from "@working-theory/validation";
33
+ import { formatMoney } from "@working-theory/web-i18n";
34
+ import { cache } from "react";
35
+
36
+ import { unwrapApiResult } from "../../../../../lib/server-api";
37
+
38
+ /** The types the member may book, in the workspace's stored order. One read per request. */
39
+ export const loadMeetingTypes = cache(
40
+ async (ctx: AccountContext): Promise<MemberMeetingType[]> => {
41
+ const res = await member.meetingTypes(ctx.init);
42
+ if (!res.ok) {
43
+ if (res.status === 404) return [];
44
+ if (!ctx.user.emailVerified && (res.status === 401 || res.status === 403))
45
+ return [];
46
+ }
47
+ return (await unwrapApiResult(Promise.resolve(res))).items;
48
+ },
49
+ );
50
+
51
+ /**
52
+ * Whether a segment can be a type's page: the one slug grammar, and no `.`
53
+ * — a dotted path skips the middleware matcher, so its page would carry no
54
+ * security headers (the `/meet/<slug>` rule, SEC-8843-F).
55
+ */
56
+ export function isTypePath(slug: string): boolean {
57
+ return meetingSlugSchema.safeParse(slug).success && !slug.includes(".");
58
+ }
59
+
60
+ /** The booking page of one type. */
61
+ export function appointmentHref(locale: string, slug: string): string {
62
+ return localeHref(
63
+ locale,
64
+ `/account/appointments/${encodeURIComponent(slug)}`,
65
+ );
66
+ }
67
+
68
+ /** A type's price in the reader's locale; none, or none to pay, reads `free`. */
69
+ export function formatTypePrice(
70
+ price: MemberMeetingType["price"],
71
+ locale: string,
72
+ free: string,
73
+ ): string {
74
+ if (price === undefined || price.amountMinor === 0) return free;
75
+ return formatMoney(price.amountMinor, price.currency, locale);
76
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * /[locale]/account/appointments — Library › Appointments (#11154).
3
+ *
4
+ * RSC, inside the account layout's SignedInShell (the rail's Appointments
5
+ * row is selected here). Lists exactly the types the member read serves
6
+ * (`loadMeetingTypes`) in the Admin Appointments list's layout
7
+ * (`AccountListFrame`, the member twin of `MeetingsListPage`): a table of
8
+ * Title · Duration · Price with a chevron per row, each row opening the
9
+ * type's booking page, `/account/appointments/<slug>`. No facet group: a
10
+ * member has nothing to narrow by, so the second column reads the All count
11
+ * alone. Below `md` the table becomes the phone row list, each row's caption
12
+ * "<duration> · <price>".
13
+ *
14
+ * A 404 read (no scheduling module, or a spoke route the hub does not admit)
15
+ * and an empty offer both show the frame's empty line; any other failed read
16
+ * renders the error row with Retry and no frame (spec 7423 D12). Nothing
17
+ * here tests the topology: the same file serves a single site and a
18
+ * hub-mode spoke.
19
+ */
20
+
21
+ import {
22
+ AccountListFrame,
23
+ type AccountListFrameRow,
24
+ } from "@working-theory/templates/account";
25
+ import { Heading, Text } from "@working-theory/ui/primitives";
26
+ import type { MemberMeetingType } from "@working-theory/validation";
27
+ import type { Metadata } from "next";
28
+ import { getTranslations } from "next-intl/server";
29
+ import type { ReactElement } from "react";
30
+
31
+ import { accountSession, logReadFailure } from "../account-data";
32
+ import { ErrorRow } from "../error-row";
33
+
34
+ import {
35
+ appointmentHref,
36
+ formatTypePrice,
37
+ loadMeetingTypes,
38
+ } from "./appointments-data";
39
+
40
+ interface Props {
41
+ params: Promise<{ locale: string }>;
42
+ }
43
+
44
+ export async function generateMetadata({ params }: Props): Promise<Metadata> {
45
+ const { locale } = await params;
46
+ const t = await getTranslations({ locale, namespace: "account" });
47
+ return { title: t("appointments.title") };
48
+ }
49
+
50
+ export default async function AccountAppointmentsPage({
51
+ params,
52
+ }: Props): Promise<ReactElement> {
53
+ const { locale } = await params;
54
+ const t = await getTranslations({ locale, namespace: "account" });
55
+ const session = await accountSession(locale);
56
+
57
+ const heading = (
58
+ <>
59
+ <Heading level={1} visual={2}>
60
+ {t("appointments.title")}
61
+ </Heading>
62
+ <Text as="p" variant="body-sm" tone="muted" className="mt-block-tight">
63
+ {t("appointments.lead")}
64
+ </Text>
65
+ </>
66
+ );
67
+
68
+ // Unreachable behind the (authed) gate, which renders the sign-in gate in
69
+ // this page's place — but the page still renders in parallel with it, so
70
+ // no `notFound()` here (the Artifacts page's rule): the heading alone.
71
+ if (!session) {
72
+ return (
73
+ <div className="max-w-3xl py-8" data-testid="appointments">
74
+ {heading}
75
+ </div>
76
+ );
77
+ }
78
+
79
+ let types: MemberMeetingType[] | null;
80
+ try {
81
+ types = await loadMeetingTypes(session.ctx);
82
+ } catch (err) {
83
+ logReadFailure("appointments", err);
84
+ types = null;
85
+ }
86
+
87
+ if (types === null) {
88
+ return (
89
+ <div className="max-w-3xl py-8" data-testid="appointments">
90
+ {heading}
91
+ <ErrorRow
92
+ className="mt-block-loose"
93
+ message={t("appointments.error")}
94
+ retryLabel={t("appointments.retry")}
95
+ />
96
+ </div>
97
+ );
98
+ }
99
+
100
+ const row = (type: MemberMeetingType): AccountListFrameRow => {
101
+ const duration = t("appointments.duration", {
102
+ minutes: type.durationMinutes,
103
+ });
104
+ const price = formatTypePrice(type.price, locale, t("appointments.free"));
105
+ return {
106
+ id: type.slug,
107
+ title: type.title,
108
+ href: appointmentHref(locale, type.slug),
109
+ caption: `${duration} · ${price}`,
110
+ cells: { duration, price },
111
+ };
112
+ };
113
+
114
+ return (
115
+ <AccountListFrame
116
+ title={t("appointments.title")}
117
+ lead={t("appointments.lead")}
118
+ glyph="calendar-clock"
119
+ all={{ label: t("appointments.all") }}
120
+ columns={[
121
+ { key: "title", header: t("appointments.columns.title") },
122
+ {
123
+ key: "duration",
124
+ header: t("appointments.columns.duration"),
125
+ width: "1/6",
126
+ },
127
+ { key: "price", header: t("appointments.columns.price"), width: "1/6" },
128
+ ]}
129
+ rows={types.map(row)}
130
+ chevron
131
+ labels={{
132
+ nav: t("appointments.facets"),
133
+ table: t("appointments.title"),
134
+ empty: t("appointments.empty"),
135
+ }}
136
+ testIdPrefix="appointments"
137
+ />
138
+ );
139
+ }