create-ailk 0.36.0 → 0.37.1

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 (101) hide show
  1. package/README.md +20 -2
  2. package/component-catalog.json +40 -1
  3. package/component-catalog.md +7 -5
  4. package/dist/add-route.d.ts +5 -0
  5. package/dist/add-route.js +10 -2
  6. package/dist/surfaces.js +60 -19
  7. package/dist/sync-routes.d.ts +15 -1
  8. package/dist/sync-routes.js +58 -6
  9. package/dist/template-record.d.ts +11 -0
  10. package/dist/template-record.js +18 -0
  11. package/dist/update.d.ts +33 -1
  12. package/dist/update.js +439 -56
  13. package/package.json +3 -3
  14. package/templates/.env.example +17 -0
  15. package/templates/apps/api/.env.example +38 -0
  16. package/templates/apps/api/CLAUDE.md +3 -0
  17. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  18. package/templates/apps/mcp/CLAUDE.md +1 -1
  19. package/templates/apps/web/CLAUDE.md +28 -1
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  22. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  38. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  39. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  40. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  45. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  46. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  47. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  50. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  54. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  56. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  59. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  60. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  62. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  63. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  64. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  65. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  70. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  71. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  72. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  73. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  75. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  76. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  77. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  79. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  80. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  81. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  82. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  83. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  84. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  85. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  86. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  87. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  88. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  89. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  90. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  91. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  92. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  93. package/templates/apps/web/lib/account-config.ts +132 -8
  94. package/templates/apps/web/lib/auth-routes.ts +11 -6
  95. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  96. package/templates/apps/web/messages/en.json +156 -80
  97. package/versions.json +48 -48
  98. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  99. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  101. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -1,44 +1,74 @@
1
1
  /**
2
- * /[locale]/account/billing — User settings › Billing (#8339 D8; builds on
3
- * #8232 D9, AC-MAA-19).
2
+ * /[locale]/account/billing — User settings › Billing (#8339 D8; #11165,
3
+ * the operator's rulings of 2026-11-08 against the organization Billing's
4
+ * card shape).
4
5
  *
5
6
  * RSC, outside the account layout's SignedInShell (#8430), in the member's
6
- * four-tab settings frame (D7) — standalone, the Admin's shape. Lays out like the Admin's
7
- * organization Billing page (`OrgBillingPanel`'s `current-plan` layout):
8
- * the shared `CurrentPlanCard` (@working-theory/templates/account, spec
9
- * 8339 D5), by `loadBilling()`'s answer (`billing-source.ts`, the billing
10
- * topology seam):
7
+ * settings frame (D7) — since #11167 every group is a card the pane draws.
8
+ * The page, top to bottom, by `loadBilling()` and `loadBillingOfferings()`
9
+ * (`billing-source.ts`, the billing topology seam):
11
10
  *
12
- * - a subscription — the plan (or `unnamedPlan`), the status plus when
13
- * access ends (when set, C4 — `subscription.me` carries no price), the
14
- * card on file, then Manage billing when a portal is available;
15
- * - no subscription — the same card shape with the plain line and no
16
- * button (C5);
17
- * - a failed read — the area's error row with Retry, never a false "you
18
- * have no subscription".
11
+ * (A) the OFFER CARD — the first live Offer product of the shown set
12
+ * (#11166), when the workspace shows one: its Stripe name, description
13
+ * and first image, Claim offer to the Offerings checkout, an x that
14
+ * dismisses it for this person (`OfferCard`, remembered under a key
15
+ * derived from the person's email, never the email itself);
16
+ * (B) the PLAN CARD, one of two (`CurrentPlanCard`): (B1) a current
17
+ * subscription — the plan name with its price beside it, one line
18
+ * ("Renews on December 1 · Visa 4242"; "Payment due"; "Access ends
19
+ * <date>") and Manage plan, which opens Stripe's Customer Portal and
20
+ * returns here; (B2) no subscription — the shown set's lowest-priced
21
+ * live plan, its Stripe description (or the fallback line until the
22
+ * operator sets one) and Upgrade to the Offerings checkout for the
23
+ * next live plan above it by price; a shown set with no live plan
24
+ * renders no plan card. A failed read is the error row with Retry,
25
+ * never a false "no subscription";
26
+ * (C) HISTORY — the member's paid invoices and purchases, newest first,
27
+ * Date (MM/DD/YYYY) · Offering · Amount · Receipt (`BillingHistoryCard`),
28
+ * absent when there are none.
19
29
  *
20
- * After any of the three, one plain line when some of the member's billing
21
- * is on a Stripe account this spoke's key cannot read (#8217 D12); on a spoke
22
- * that signs in through its hub, the member's Purchases (`loadPurchases()`,
23
- * #11096 D9: offering, amount, date; nothing when there are none, the error
24
- * row when the read fails); then each section a module contributes
25
- * (`accountBillingSections`, #8231 D4), then each section the site adds
26
- * (`siteBillingSections`, #9401 D7).
30
+ * Then one plain line when some of the member's billing is on a Stripe
31
+ * account this spoke's key cannot read (#8217 D12), each section a module
32
+ * contributes (`accountBillingSections`, #8231 D4) and each the site adds
33
+ * (`siteBillingSections`, #9401 D7). The old "Current plan" heading, the
34
+ * plain purchases list and "You don't have a subscription." are gone.
27
35
  */
28
36
 
29
- import { AccountSettingsFrame, AccountSettingsPane, CurrentPlanCard } from "@working-theory/templates/account";
30
- import { Button, MoneyAmount, Text } from "@working-theory/ui/primitives";
37
+ import { createHash } from "node:crypto";
38
+
39
+ import {
40
+ AccountSettingsFrame,
41
+ AccountSettingsPane,
42
+ BillingHistoryCard,
43
+ CurrentPlanCard,
44
+ OfferCard,
45
+ type BillingHistoryRowView,
46
+ } from "@working-theory/templates/account";
47
+ import { Button, Link, MoneyAmount, Text } from "@working-theory/ui/primitives";
31
48
  import type { Metadata } from "next";
32
49
  import { getTranslations } from "next-intl/server";
33
- import type { ReactElement } from "react";
50
+ import type { ReactElement, ReactNode } from "react";
34
51
 
35
52
  import { accountBillingSections } from "../../../../../lib/account-config";
53
+ import { formatMinorUnits } from "../../../../../lib/offerings-pricing";
36
54
  import { siteBillingSections } from "../../../../../lib/site-contributions";
37
55
  import { accountSession } from "../account-data";
38
56
  import { openBillingPortal } from "../actions";
39
- import { type BillingState, type PurchasesState, loadBilling, loadPurchases } from "../billing-source";
57
+ import {
58
+ type BillingHistoryState,
59
+ type BillingPlanState,
60
+ type BillingState,
61
+ loadBilling,
62
+ loadBillingOfferings,
63
+ } from "../billing-source";
40
64
  import { ErrorRow } from "../error-row";
41
- import { memberSettingsFrame, SettingsSection, type Translate as MemberTranslate } from "../settings-frame";
65
+ import {
66
+ memberSettingsFrame,
67
+ SettingsSection,
68
+ type Translate as MemberTranslate,
69
+ } from "../settings-frame";
70
+
71
+ import type { BillingOfferView, BillingPlanView } from "./offerings";
42
72
 
43
73
  interface Props {
44
74
  params: Promise<{ locale: string }>;
@@ -47,14 +77,66 @@ interface Props {
47
77
  export async function generateMetadata({ params }: Props): Promise<Metadata> {
48
78
  const { locale } = await params;
49
79
  const t = await getTranslations({ locale, namespace: "account" });
50
- return { title: t("settings.billing.title"), description: t("settings.billing.lead") };
80
+ return {
81
+ title: t("settings.billing.title"),
82
+ description: t("settings.billing.lead"),
83
+ };
51
84
  }
52
85
 
53
- /** The statuses with a message key; any other renders as the API sent it. */
54
- const KNOWN_STATUSES: ReadonlySet<string> = new Set(["trialing", "active", "past_due", "canceled"]);
55
-
56
86
  type Translate = Awaited<ReturnType<typeof getTranslations<"account">>>;
57
87
 
88
+ // The pill: 44px on a phone (the primary-action floor) and full width there,
89
+ // 36px from md up — the settings cards' one submit style (#11167).
90
+ const PILL_CLASS =
91
+ "max-md:w-full max-md:min-h-11 !rounded-full whitespace-nowrap";
92
+
93
+ /** A day as the mockup writes it — "December 1" — read in UTC, the server's zone. */
94
+ function monthDay(iso: string, locale: string): ReactNode {
95
+ return (
96
+ <time dateTime={iso}>
97
+ {new Intl.DateTimeFormat(locale, {
98
+ month: "long",
99
+ day: "numeric",
100
+ timeZone: "UTC",
101
+ }).format(new Date(iso))}
102
+ </time>
103
+ );
104
+ }
105
+
106
+ /** A History date as MM/DD/YYYY in the page's locale, read in UTC. */
107
+ function numericDate(iso: string, locale: string): string {
108
+ return new Intl.DateTimeFormat(locale, {
109
+ month: "2-digit",
110
+ day: "2-digit",
111
+ year: "numeric",
112
+ timeZone: "UTC",
113
+ }).format(new Date(iso));
114
+ }
115
+
116
+ /** "Visa 4242" — Stripe's lower-case brand, capitalized. */
117
+ function cardLabel(
118
+ card: BillingPlanState["card"],
119
+ t: Translate,
120
+ ): string | null {
121
+ if (card === null) return null;
122
+ const brand = card.brand.charAt(0).toUpperCase() + card.brand.slice(1);
123
+ return t("settings.billing.card", { brand, last4: card.last4 });
124
+ }
125
+
126
+ /** "$12,500/mo" — the amount in the price's currency, with its interval word. */
127
+ function priceLabel(
128
+ price: NonNullable<BillingPlanState["price"]>,
129
+ locale: string,
130
+ t: Translate,
131
+ ): string {
132
+ const amount = formatMinorUnits(price.amountMinor, price.currency, locale);
133
+ if (price.interval === "month")
134
+ return t("settings.billing.perMonth", { amount });
135
+ if (price.interval === "year")
136
+ return t("settings.billing.perYear", { amount });
137
+ return amount;
138
+ }
139
+
58
140
  function Subscription({
59
141
  state,
60
142
  locale,
@@ -64,119 +146,210 @@ function Subscription({
64
146
  locale: string;
65
147
  t: Translate;
66
148
  }): ReactElement {
67
- const card = state.paymentMethod;
68
- const statusLabel = KNOWN_STATUSES.has(state.status)
69
- ? t(`settings.billing.statuses.${state.status}`)
70
- : state.status;
71
- const line = (
72
- <span data-testid="account-billing-status">
73
- {state.accessRevokesAt
74
- ? `${statusLabel} · ${t("settings.billing.accessEnds", {
75
- date: new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(
76
- new Date(state.accessRevokesAt),
77
- ),
78
- })}`
79
- : statusLabel}
80
- </span>
81
- );
82
- const caption = (
83
- <span data-testid="account-billing-payment">
84
- {card !== null
85
- ? t("settings.billing.card", {
86
- brand: card.brand,
87
- last4: card.last4,
88
- month: String(card.expMonth).padStart(2, "0"),
89
- year: String(card.expYear),
149
+ const { plan } = state;
150
+ const { renewsAt, accessEndsAt } = plan;
151
+ // The one line under the name: the renewal while it renews, the access
152
+ // end once it is set to end, else the status word — then the card on file.
153
+ const status: ReactNode =
154
+ renewsAt !== null &&
155
+ (plan.status === "active" || plan.status === "trialing")
156
+ ? t.rich("settings.billing.renews", {
157
+ date: () => monthDay(renewsAt, locale),
158
+ })
159
+ : plan.status === "canceled" && accessEndsAt !== null
160
+ ? t.rich("settings.billing.accessEnds", {
161
+ date: () => monthDay(accessEndsAt, locale),
90
162
  })
91
- : t("settings.billing.noCard")}
92
- </span>
93
- );
163
+ : t(`settings.billing.statuses.${plan.status}`);
164
+ const card = cardLabel(plan.card, t);
94
165
  return (
95
166
  <CurrentPlanCard
96
- title={t("settings.billing.currentPlan")}
97
- heading={
98
- <span data-testid="account-billing-plan">
99
- {state.planName ?? t("settings.billing.unnamedPlan")}
167
+ name={plan.name ?? t("settings.billing.unnamedPlan")}
168
+ price={
169
+ plan.price === null ? undefined : priceLabel(plan.price, locale, t)
170
+ }
171
+ line={
172
+ <span data-testid="account-billing-status">
173
+ {status}
174
+ {card !== null ? (
175
+ <>
176
+ {" · "}
177
+ <span data-testid="account-billing-payment">{card}</span>
178
+ </>
179
+ ) : null}
100
180
  </span>
101
181
  }
102
- line={line}
103
- caption={caption}
104
182
  action={
105
183
  state.portalAvailable ? (
106
184
  <form action={openBillingPortal}>
107
- <Button type="submit" variant="outline" data-testid="account-billing-manage">
185
+ <Button
186
+ type="submit"
187
+ className={PILL_CLASS}
188
+ data-testid="account-billing-manage"
189
+ >
108
190
  {t("settings.billing.manage")}
109
191
  </Button>
110
192
  </form>
111
193
  ) : undefined
112
194
  }
113
195
  testId="account-billing"
114
- cardTestId="account-billing-card"
115
196
  />
116
197
  );
117
198
  }
118
199
 
119
- /** The member's purchases (#11096 D9): one row each — offering, amount, date. */
120
- function Purchases({
121
- state,
200
+ /** The base plan a member without a subscription starts on, with Upgrade to the next (#11165 B2). */
201
+ function BasePlan({
202
+ base,
203
+ next,
204
+ locale,
205
+ t,
206
+ }: {
207
+ base: BillingPlanView;
208
+ next: BillingPlanView | null;
209
+ locale: string;
210
+ t: Translate;
211
+ }): ReactElement {
212
+ const upgradeHref = next?.checkoutHref ?? null;
213
+ return (
214
+ <CurrentPlanCard
215
+ name={base.name}
216
+ price={priceLabel(base.price, locale, t)}
217
+ description={base.description ?? t("settings.billing.planFallback")}
218
+ action={
219
+ upgradeHref !== null ? (
220
+ <Button asChild className={PILL_CLASS}>
221
+ <Link
222
+ href={upgradeHref}
223
+ variant="bare"
224
+ data-testid="account-billing-upgrade"
225
+ >
226
+ {t("settings.billing.upgrade")}
227
+ </Link>
228
+ </Button>
229
+ ) : undefined
230
+ }
231
+ testId="account-billing"
232
+ />
233
+ );
234
+ }
235
+
236
+ /** The History card (#11165 C): the error row for a failed read, else the rows — the page renders it only when there are any. */
237
+ function History({
238
+ history,
122
239
  locale,
123
240
  t,
124
241
  }: {
125
- state: PurchasesState;
242
+ history: BillingHistoryState;
126
243
  locale: string;
127
244
  t: Translate;
128
- }): ReactElement | null {
129
- if (state.kind === "failed") {
245
+ }): ReactElement {
246
+ if (history.kind === "failed") {
130
247
  return (
131
- <div data-testid="account-billing-purchases-error">
132
- <ErrorRow message={t("billing.purchasesUnavailable")} retryLabel={t("inbox.retry")} />
248
+ <div data-testid="account-billing-history-error">
249
+ <ErrorRow
250
+ message={t("settings.billing.historyUnavailable")}
251
+ retryLabel={t("inbox.retry")}
252
+ />
133
253
  </div>
134
254
  );
135
255
  }
136
- if (state.items.length === 0) return null;
137
- const date = new Intl.DateTimeFormat(locale, { dateStyle: "medium" });
256
+ const rows: BillingHistoryRowView[] = history.items.map((item) => ({
257
+ id: item.id,
258
+ date: numericDate(item.paidAt, locale),
259
+ dateTime: item.paidAt,
260
+ offering: item.offering,
261
+ amount:
262
+ item.amountMinor !== null && item.currency !== null ? (
263
+ <MoneyAmount
264
+ amountMinor={item.amountMinor}
265
+ currency={item.currency}
266
+ locale={locale}
267
+ />
268
+ ) : (
269
+ "—"
270
+ ),
271
+ receiptHref: item.receiptUrl,
272
+ }));
138
273
  return (
139
- <div data-testid="account-billing-purchases">
140
- <SettingsSection id="purchases" title={t("billing.purchases")}>
141
- <div className="flex flex-col divide-y divide-(--color-border)">
142
- {state.items.map((purchase) => (
143
- <div
144
- key={purchase.id}
145
- className="flex flex-wrap items-baseline justify-between gap-2 py-3"
146
- data-testid="account-billing-purchase"
147
- >
148
- <Text as="span" variant="body-sm" className="font-medium">
149
- {purchase.offering}
150
- </Text>
151
- <Text as="span" variant="body-sm" tone="muted">
152
- {purchase.amountMinor !== null && purchase.currency !== null ? (
153
- <>
154
- <MoneyAmount amountMinor={purchase.amountMinor} currency={purchase.currency} locale={locale} />
155
- {" · "}
156
- </>
157
- ) : null}
158
- {date.format(new Date(purchase.purchasedAt))}
159
- </Text>
160
- </div>
161
- ))}
162
- </div>
163
- </SettingsSection>
164
- </div>
274
+ <BillingHistoryCard
275
+ rows={rows}
276
+ labels={{
277
+ title: t("settings.billing.history"),
278
+ date: t("settings.billing.historyDate"),
279
+ offering: t("settings.billing.historyOffering"),
280
+ amount: t("settings.billing.historyAmount"),
281
+ receipt: t("settings.billing.historyReceipt"),
282
+ view: t("settings.billing.historyView"),
283
+ }}
284
+ testIdPrefix="account-billing-history"
285
+ />
286
+ );
287
+ }
288
+
289
+ /**
290
+ * The offer dismissal's per-person key: a SHA-256 digest of the person's
291
+ * email under a fixed label, computed on the server, so the browser's store
292
+ * names no address and a shared browser keeps each person's dismissals
293
+ * apart. A pseudonym, not a secret: the stored value is product ids only.
294
+ */
295
+ function offerPersistKey(email: string): string {
296
+ const digest = createHash("sha256")
297
+ .update(`ailk:billing-offer:${email.trim().toLowerCase()}`)
298
+ .digest("hex");
299
+ return `account:billing-offer:${digest.slice(0, 16)}`;
300
+ }
301
+
302
+ /**
303
+ * The offer card (#11165 A), built as the pane's DIRECT child — the pane
304
+ * reads `ownCard` off the element it is given — so it draws its own card and
305
+ * a dismissal leaves no shell; the page builds it only for a live offer.
306
+ */
307
+ function offerCard(
308
+ offer: BillingOfferView & { claimHref: string },
309
+ email: string,
310
+ t: Translate,
311
+ ): ReactElement {
312
+ return (
313
+ <OfferCard
314
+ id={offer.productId}
315
+ persistKey={offerPersistKey(email)}
316
+ title={offer.name}
317
+ description={offer.description}
318
+ image={
319
+ offer.image === null ? null : { src: offer.image, alt: offer.name }
320
+ }
321
+ claimHref={offer.claimHref}
322
+ claimLabel={t("settings.billing.claimOffer")}
323
+ dismissLabel={t("settings.billing.dismissOffer")}
324
+ testId="account-billing-offer"
325
+ cardTestId="account-settings-billing-card"
326
+ ownCard
327
+ />
165
328
  );
166
329
  }
167
330
 
168
- export default async function AccountBillingPage({ params }: Props): Promise<ReactElement> {
331
+ export default async function AccountBillingPage({
332
+ params,
333
+ }: Props): Promise<ReactElement> {
169
334
  const { locale } = await params;
170
335
  const t = await getTranslations({ locale, namespace: "account" });
171
336
  const session = await accountSession(locale);
172
- const frame = memberSettingsFrame(locale, t as unknown as MemberTranslate, "billing");
337
+ const frame = memberSettingsFrame(
338
+ locale,
339
+ t as unknown as MemberTranslate,
340
+ "billing",
341
+ );
173
342
 
174
343
  // Unreachable behind the (authed) gate; a session that expired between
175
344
  // the layout and the page renders the pane's title alone.
176
345
  if (!session) {
177
346
  return (
178
347
  <AccountSettingsFrame {...frame} name="">
179
- <AccountSettingsPane id="account-settings-billing" title={t("settings.billing.title")} lead="">
348
+ <AccountSettingsPane
349
+ id="account-settings-billing"
350
+ title={t("settings.billing.title")}
351
+ lead=""
352
+ >
180
353
  {null}
181
354
  </AccountSettingsPane>
182
355
  </AccountSettingsFrame>
@@ -184,8 +357,18 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
184
357
  }
185
358
 
186
359
  const { ctx } = session;
187
- const [state, purchases] = await Promise.all([loadBilling(ctx.init), loadPurchases(ctx.init)]);
360
+ const [{ state, history }, offerings] = await Promise.all([
361
+ loadBilling(ctx.init),
362
+ loadBillingOfferings(),
363
+ ]);
188
364
  const name = ctx.user.name || ctx.user.email;
365
+ // Every pane child below is one card, so each slot is decided here and a
366
+ // slot with nothing to show passes nothing — never an empty card (#11165).
367
+ const offer =
368
+ offerings.offer !== null && offerings.offer.claimHref !== null
369
+ ? { ...offerings.offer, claimHref: offerings.offer.claimHref }
370
+ : null;
371
+ const hasHistory = history.kind === "failed" || history.items.length > 0;
189
372
 
190
373
  return (
191
374
  <AccountSettingsFrame {...frame} name={name}>
@@ -194,17 +377,24 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
194
377
  title={t("settings.billing.title")}
195
378
  lead={t("settings.billing.lead")}
196
379
  >
380
+ {offer !== null ? offerCard(offer, ctx.user.email, t) : null}
381
+
197
382
  {state.kind === "subscription" ? (
198
383
  <Subscription state={state} locale={locale} t={t} />
199
384
  ) : state.kind === "none" ? (
200
- <CurrentPlanCard
201
- title={t("settings.billing.currentPlan")}
202
- line={<span data-testid="account-billing-none">{t("settings.billing.none")}</span>}
203
- testId="account-billing"
204
- cardTestId="account-billing-card"
205
- />
385
+ offerings.base !== null ? (
386
+ <BasePlan
387
+ base={offerings.base}
388
+ next={offerings.next}
389
+ locale={locale}
390
+ t={t}
391
+ />
392
+ ) : null
206
393
  ) : (
207
- <ErrorRow message={t("settings.billing.unavailable")} retryLabel={t("inbox.retry")} />
394
+ <ErrorRow
395
+ message={t("settings.billing.unavailable")}
396
+ retryLabel={t("inbox.retry")}
397
+ />
208
398
  )}
209
399
 
210
400
  {state.kind !== "failed" && state.unreadable ? (
@@ -215,10 +405,16 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
215
405
  </div>
216
406
  ) : null}
217
407
 
218
- {purchases !== null ? <Purchases state={purchases} locale={locale} t={t} /> : null}
408
+ {hasHistory ? (
409
+ <History history={history} locale={locale} t={t} />
410
+ ) : null}
219
411
 
220
412
  {[...accountBillingSections, ...siteBillingSections].map((section) => (
221
- <SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
413
+ <SettingsSection
414
+ key={section.id}
415
+ id={section.id}
416
+ title={ctx.t(section.title)}
417
+ >
222
418
  {section.render(ctx)}
223
419
  </SettingsSection>
224
420
  ))}