@thorprovider/storefront 0.10.0 → 0.12.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 (39) hide show
  1. package/README.md +22 -11
  2. package/assets/templates/app/app/globals.css +0 -1
  3. package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +4 -2
  4. package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +2 -1
  5. package/assets/templates/app/lib/__STOREFRONT__/actions.ts +73 -11
  6. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +18 -2
  7. package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +38 -3
  8. package/assets/templates/app/lib/__STOREFRONT__/footer-content.ts +203 -0
  9. package/assets/templates/app/lib/__STOREFRONT__/order-detail-aftersales.ts +55 -0
  10. package/assets/templates/app/lib/__STOREFRONT__/order-detail-capabilities.ts +79 -0
  11. package/assets/templates/app/lib/__STOREFRONT__/order-detail-mapper.ts +13 -2
  12. package/assets/templates/app/lib/__STOREFRONT__/order-detail-money.ts +39 -0
  13. package/assets/templates/app/lib/__STOREFRONT__/order-detail-reorder.ts +62 -0
  14. package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +8 -24
  15. package/assets/templates/app/lib/__STOREFRONT__/schema.ts +5 -3
  16. package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +14 -13
  17. package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +7 -2
  18. package/assets/templates/views/account/assembly/index.skeleton.tsx +3 -0
  19. package/assets/templates/views/account/assembly/registry.skeleton.tsx +115 -4
  20. package/assets/templates/views/account/content.ts +6 -0
  21. package/assets/templates/views/account/index.tsx +3 -0
  22. package/assets/templates/views/account/order-detail-flows.defaults.ts +106 -0
  23. package/assets/templates/views/account/order-detail-invoice.ts +136 -0
  24. package/assets/templates/views/account/order-detail-sheet.tsx +100 -0
  25. package/assets/templates/views/account/order-detail-sheets.tsx +122 -0
  26. package/assets/templates/views/account/order-detail.client.tsx +401 -1
  27. package/assets/templates/views/account/registry.tsx +115 -4
  28. package/assets/templates/views/account/schema.ts +2 -0
  29. package/assets/templates/views/home/content.ts +3 -1
  30. package/assets/templates/views/product/data.ts +13 -6
  31. package/assets/templates/views/product/index.tsx +3 -3
  32. package/bin/storefront.js +59 -23
  33. package/package.json +1 -1
  34. package/scripts/candidate.mjs +8 -4
  35. package/scripts/file-classes.mjs +3 -0
  36. package/scripts/mock-capabilities.mjs +22 -0
  37. package/scripts/reconcile.mjs +5 -2
  38. package/scripts/render-templates.mjs +126 -43
  39. package/scripts/scaffold-env.mjs +48 -0
@@ -0,0 +1,79 @@
1
+ import type { OrderActionId, OrderDocument } from '@thorprovider/blocks/ports'
2
+
3
+ /**
4
+ * Host capability gate for the order-detail route.
5
+ *
6
+ * The delivered surface renders one control per action in `availableActions`, so
7
+ * an action that reaches the snapshot without a host handler becomes a dead
8
+ * control. This list is therefore the single source of truth for what the host
9
+ * can really serve: project actions through it, and register exactly one handler
10
+ * per entry in the route panel.
11
+ */
12
+ export const ORDER_DETAIL_HOST_ACTIONS: readonly OrderActionId[] = [
13
+ 'reorder',
14
+ 'invoice',
15
+ 'track',
16
+ 'pay-balance',
17
+ 'support',
18
+ 'return',
19
+ 'exchange',
20
+ 'problem',
21
+ 'cancel',
22
+ ]
23
+
24
+ /** Support destination declared by the store. Empty string hides the action. */
25
+ export const ORDER_DETAIL_SUPPORT_HREF = '/contact'
26
+
27
+ /**
28
+ * The actions the host can serve.
29
+ *
30
+ * An empty support destination means the store publishes no contact page, so
31
+ * `support` is dropped from the projection instead of becoming a button whose
32
+ * handler has nowhere to go.
33
+ */
34
+ export function orderDetailHostActions(
35
+ supportHref: string = ORDER_DETAIL_SUPPORT_HREF,
36
+ ): readonly OrderActionId[] {
37
+ if (supportHref !== '') return ORDER_DETAIL_HOST_ACTIONS
38
+ return ORDER_DETAIL_HOST_ACTIONS.filter((action) => action !== 'support')
39
+ }
40
+
41
+ /** Project an authorised action set through the host's real capabilities. */
42
+ export function projectHostActions(
43
+ actions: readonly OrderActionId[],
44
+ supportHref: string = ORDER_DETAIL_SUPPORT_HREF,
45
+ ): OrderActionId[] {
46
+ const served = orderDetailHostActions(supportHref)
47
+ return actions.filter((action) => served.includes(action))
48
+ }
49
+
50
+ /**
51
+ * Documents the demo storefront can actually open.
52
+ *
53
+ * Medusa issues no invoice or receipt file, so these exist only for mock orders,
54
+ * where the host renders a printable demonstration sheet from the snapshot. A
55
+ * live order keeps `documents: []`: an invented invoice on a real storefront
56
+ * would be a defect, not a placeholder.
57
+ */
58
+ export function orderDetailDemoDocuments(
59
+ order: { number: string; createdAt: string },
60
+ isMock: boolean,
61
+ ): OrderDocument[] {
62
+ if (!isMock) return []
63
+ return [
64
+ {
65
+ id: `${order.number}-invoice`,
66
+ kind: 'invoice',
67
+ label: `Factura ${order.number}`,
68
+ issuedAt: order.createdAt,
69
+ available: true,
70
+ },
71
+ {
72
+ id: `${order.number}-receipt`,
73
+ kind: 'receipt',
74
+ label: `Recibo ${order.number}`,
75
+ issuedAt: order.createdAt,
76
+ available: true,
77
+ },
78
+ ]
79
+ }
@@ -32,6 +32,7 @@ import type {
32
32
  TaxLine,
33
33
  Transaction,
34
34
  } from '@thorprovider/blocks/ports'
35
+ import { orderDetailDemoDocuments, projectHostActions } from './order-detail-capabilities'
35
36
 
36
37
  type Money = OrderDetailMoney
37
38
  type FulfillmentStatus = OrderDetailFulfillmentStatus
@@ -606,6 +607,10 @@ export function toOrderDetailSnapshot(order: Order): OrderDetailSnapshot {
606
607
 
607
608
  const shippingAddress = toDetailAddress(order.shippingAddress)
608
609
  const billingAddress = toDetailAddress(order.billingAddress)
610
+ const documents = orderDetailDemoDocuments(
611
+ { number: order.orderNumber, createdAt: order.createdAt },
612
+ isMock,
613
+ )
609
614
  const detail: OrderDetailOrder = {
610
615
  id: order.id,
611
616
  number: order.orderNumber,
@@ -623,7 +628,7 @@ export function toOrderDetailSnapshot(order: Order): OrderDetailSnapshot {
623
628
  adjustments,
624
629
  transactions,
625
630
  cases,
626
- documents: [],
631
+ documents,
627
632
  revisions: [],
628
633
  totals: {
629
634
  itemsSubtotal: subtotal,
@@ -635,7 +640,13 @@ export function toOrderDetailSnapshot(order: Order): OrderDetailSnapshot {
635
640
  adjustments: zero(currency),
636
641
  total,
637
642
  },
638
- availableActions: toActionSet({ commercial, paymentStatus, logistics, returns }),
643
+ availableActions: projectHostActions(
644
+ toActionSet({ commercial, paymentStatus, logistics, returns }).filter(
645
+ (action) =>
646
+ action !== 'invoice' ||
647
+ documents.some((document) => document.kind === 'invoice' && document.available),
648
+ ),
649
+ ),
639
650
  }
640
651
 
641
652
  return { order: detail }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Currency-aware conversion between the snapshot's integer minor units and the
3
+ * canonical decimal `Money` the blocks speak.
4
+ *
5
+ * Dividing by 100 is only right for the currencies that happen to have two
6
+ * fraction digits. JPY has none and KWD has three, so the exponent comes from
7
+ * `Intl.NumberFormat`, the same source the platform uses to render the symbol.
8
+ */
9
+ export function currencyDigits(currency: string): number {
10
+ try {
11
+ return (
12
+ new Intl.NumberFormat('en-US', {
13
+ style: 'currency',
14
+ currency,
15
+ }).resolvedOptions().maximumFractionDigits ?? 2
16
+ )
17
+ } catch {
18
+ return 2
19
+ }
20
+ }
21
+
22
+ const scale = (currency: string): number => 10 ** currencyDigits(currency)
23
+
24
+ /** Minor units → canonical decimal string, e.g. `12600, 'USD' → '126.00'`. */
25
+ export function fromMinor(amount: number, currency: string): string {
26
+ const digits = currencyDigits(currency)
27
+ return (amount / scale(currency)).toFixed(digits)
28
+ }
29
+
30
+ /** Minor units → locale-formatted amount. */
31
+ export function formatMinor(amount: number, currency: string, locale: string): string {
32
+ try {
33
+ return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(
34
+ amount / scale(currency),
35
+ )
36
+ } catch {
37
+ return `${fromMinor(amount, currency)} ${currency}`
38
+ }
39
+ }
@@ -0,0 +1,62 @@
1
+ import type { Order } from '@thorprovider/types'
2
+
3
+ /** One cart line a reorder would add, derived from the stored order. */
4
+ export type ReorderLine = {
5
+ variantId: string
6
+ quantity: number
7
+ title: string
8
+ }
9
+
10
+ export type ReorderSkip = { title: string; reason: string }
11
+
12
+ export type ReorderOrderResult =
13
+ | { ok: true; added: number; skipped: ReorderSkip[] }
14
+ | { ok: false; error: string }
15
+
16
+ /**
17
+ * Project a stored order into cart lines.
18
+ *
19
+ * The backend order is the only source: the browser sends an order id, never
20
+ * variants or quantities. A line without a backend variant cannot be re-added,
21
+ * and an empty quantity means there is nothing to buy — both are reported so the
22
+ * shopper sees what was left out instead of a clean "added" claim.
23
+ */
24
+ export function toReorderLines(order: Order): {
25
+ lines: ReorderLine[]
26
+ skipped: ReorderSkip[]
27
+ } {
28
+ const lines: ReorderLine[] = []
29
+ const skipped: ReorderSkip[] = []
30
+
31
+ for (const item of order.items ?? []) {
32
+ const quantity = Math.max(0, Math.floor(Number(item.quantity) || 0))
33
+ if (!item.variantId) {
34
+ skipped.push({ title: item.title, reason: 'Sin variante disponible' })
35
+ continue
36
+ }
37
+ if (quantity === 0) {
38
+ skipped.push({ title: item.title, reason: 'Sin unidades disponibles' })
39
+ continue
40
+ }
41
+ lines.push({ variantId: item.variantId, quantity, title: item.title })
42
+ }
43
+
44
+ return { lines, skipped }
45
+ }
46
+
47
+ /**
48
+ * Run the reorder server action, turning a transport failure into the same
49
+ * readable result the UI already renders. A rejected server-action call is not
50
+ * an exception the shopper can act on, and it must never look like success.
51
+ */
52
+ export async function runReorder(
53
+ action: (input: { orderId: string }) => Promise<ReorderOrderResult>,
54
+ orderId: string,
55
+ fallback = 'No se pudo repetir la compra.',
56
+ ): Promise<ReorderOrderResult> {
57
+ try {
58
+ return await action({ orderId })
59
+ } catch {
60
+ return { ok: false, error: fallback }
61
+ }
62
+ }
@@ -16,7 +16,7 @@ import { BackToTop as BackToTopBlock } from '@thorprovider/blocks/blocks/e-comme
16
16
  import { MobileBottomNav as MobileBottomNavBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
17
17
  import { SkipToContent as SkipToContentBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/skip-to-content'
18
18
  import Banner1 from '@thorprovider/blocks/blocks/marketing/banners/banner-1'
19
- import { FooterSection, Navbar, StorefrontNavbar } from '@thorprovider/blocks'
19
+ import { Navbar, StorefrontNavbar, UniversalFooter } from '@thorprovider/blocks'
20
20
  import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
21
21
  import type { BackToTopProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
22
22
  import type { MobileBottomNavProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
@@ -28,6 +28,7 @@ import type { CartLineState, CartTotalsState } from './state'
28
28
  import { useStorefrontHandlers } from './handlers'
29
29
  import { cartViewAvailable, checkoutAvailable, mountedFeatureNames } from './composition'
30
30
  import { accountStoreUser } from './account-user.core'
31
+ import { toUniversalFooterProps } from './footer-content'
31
32
  import type { AccountIdentity, AccountResolution } from './account-session.core'
32
33
  import {
33
34
  bannerPropsSchema,
@@ -306,29 +307,12 @@ const baseComponents = {
306
307
  },
307
308
  Footer: ({ props }: { props: Record<string, unknown> }) => {
308
309
  const parsed = footerPropsSchema.parse(props)
309
- return (
310
- <FooterSection
311
- presentation="brand-columns"
312
- brandName={parsed.brandName}
313
- brandAccent={parsed.brandAccent}
314
- brandDescription={parsed.brandDescription}
315
- linkColumns={parsed.linkColumns}
316
- className={parsed.className}
317
- linkBehavior="native"
318
- // The scaffold ships no newsletter submit callback. The seam's
319
- // `newsletter` is content only, so the block swallows it and renders no
320
- // form. Wiring a real host callback (which would enable the form) is an
321
- // external integration, out of scope for the scaffold.
322
- newsletter={
323
- parsed.newsletter
324
- ? {
325
- placeholder: parsed.newsletter.placeholder,
326
- buttonLabel: parsed.newsletter.buttonLabel ?? 'Suscribirme',
327
- }
328
- : undefined
329
- }
330
- />
331
- )
310
+ // The storefront shell footer is the design block itself. Brand name,
311
+ // description, accent, surface classes and the content contract all arrive
312
+ // through the shell seam, so the merchant surface stays `shell/content.ts`.
313
+ // No `onSubscribe` is bound: the scaffold ships no newsletter endpoint, and
314
+ // the block disables the form rather than faking a subscription.
315
+ return <UniversalFooter {...toUniversalFooterProps(parsed)} />
332
316
  },
333
317
  }
334
318
 
@@ -6,6 +6,8 @@
6
6
 
7
7
  import { z } from 'zod'
8
8
 
9
+ import { footerContentSchema } from './footer-content'
10
+
9
11
  export const ctaSchema = z.object({
10
12
  label: z.string(),
11
13
  href: z.string().optional(),
@@ -170,9 +172,9 @@ export const footerPropsSchema = z.object({
170
172
  brandDescription: z.string().optional(),
171
173
  linkColumns: z.array(footerLinkColumnSchema),
172
174
  className: z.string().optional(),
173
- newsletter: z
174
- .object({ placeholder: z.string().optional(), buttonLabel: z.string().optional() })
175
- .optional(),
175
+ // The footer's own content contract, shared with `GET /store/footer`. Optional
176
+ // so an older scaffold that predates it keeps rendering from the defaults.
177
+ footerContent: footerContentSchema.optional(),
176
178
  })
177
179
 
178
180
  // Navigability chrome contracts, mirrored from @thorprovider/blocks so the
@@ -10,10 +10,11 @@
10
10
  // `/about`, `/terms`, `/privacy`). Brand colors and copy belong
11
11
  // in your own content, never in the package.
12
12
  //
13
- // The scaffold ships no newsletter submit callback, so the footer newsletter is
14
- // omitted by default. A content-only `newsletter` is swallowed by the block
15
- // (no form renders); wiring a real host callback to enable it is an external
16
- // integration, out of scope for the scaffold.
13
+ // The footer's own copy (newsletter, contact, payments, legal, region) lives in
14
+ // the footer content contract, not here: `GET /store/footer` is what a backend
15
+ // implements, and `../footer-content.ts` documents its shape and defaults.
16
+
17
+ import type { FooterContent } from '../footer-content'
17
18
 
18
19
  export interface ShellAccent {
19
20
  /** Trailing segment of the site-name wordmark to render with the accent. */
@@ -33,11 +34,6 @@ export interface ShellLinkColumn {
33
34
  links: ShellLink[]
34
35
  }
35
36
 
36
- export interface ShellNewsletter {
37
- placeholder?: string
38
- buttonLabel: string
39
- }
40
-
41
37
  /**
42
38
  * Optional trailing accent for the navbar wordmark, e.g. the "Cuba" in
43
39
  * "ElectroCuba". Leave `undefined` to render the wordmark in one colour. The
@@ -97,11 +93,16 @@ export const linkColumns: ShellLinkColumn[] = [
97
93
  ]
98
94
 
99
95
  /**
100
- * Footer newsletter content. The scaffold has no working submit handler, so it
101
- * is omitted by default (`false`). Setting it without a host-provided callback
102
- * renders no form — never a fake one.
96
+ * Footer copy overrides, merged over the package defaults in
97
+ * `../footer-content.ts` (newsletter, contact, apps, payments, legal, region).
98
+ * Same shape as the `GET /store/footer` response, so a backend that owns the
99
+ * footer replaces this seam instead of filling it in. Leave a key out to keep
100
+ * the default; set `undefined` for no overrides.
101
+ *
102
+ * Placeholders shipped by default (contact phone/address, company name, payment
103
+ * methods) are not customer-ready — a merchant must replace them.
103
104
  */
104
- export const newsletter: false | ShellNewsletter = false
105
+ export const footerContent: Partial<FooterContent> | undefined = undefined
105
106
 
106
107
  // Primary destinations for the mobile bottom navigation. Only routes the
107
108
  // storefront actually serves; the icons come from the shared category icon set.
@@ -8,12 +8,13 @@ import {
8
8
  brandAccent,
9
9
  brandDescription,
10
10
  footerClassName,
11
+ footerContent,
11
12
  linkColumns,
12
13
  logoAccent,
13
14
  navbarClassName,
14
- newsletter,
15
15
  shippingNote,
16
16
  } from './content'
17
+ import { footerContentDefaults } from '../footer-content'
17
18
 
18
19
  export const navbarShellProps = {
19
20
  logoAccent,
@@ -34,5 +35,9 @@ export const footerShellProps = {
34
35
  brandDescription,
35
36
  linkColumns,
36
37
  className: footerClassName,
37
- ...(newsletter ? { newsletter } : {}),
38
+ // The footer's own content contract. Neutral defaults ship with the scaffold;
39
+ // a backend that owns the footer replaces this with a `GET /store/footer`
40
+ // read (shape: `footerContentSchema` in ../footer-content.ts). Merchant
41
+ // overrides in `content.ts` win over the package defaults.
42
+ footerContent: { ...footerContentDefaults, ...footerContent },
38
43
  }
@@ -24,6 +24,7 @@ import { registry } from './registry'
24
24
  import { sectionData } from './sections-data'
25
25
  import { accountContent } from './content'
26
26
  import { orderDetailDefaults } from './order-detail.defaults'
27
+ import { orderDetailFlowLabels, orderDetailSupport } from './order-detail-flows.defaults'
27
28
  import { fulfillmentEvidenceDefaults } from './fulfillment-evidence.defaults'
28
29
  import { accountOrdersAdvancedDefaults } from './orders-advanced.defaults'@@SECTION_IMPORTS@@
29
30
  import {
@@ -59,6 +60,8 @@ const elements: Record<string, StorefrontElement> = {
59
60
  props: {
60
61
  orderId: { $state: '/orderDetailId' },
61
62
  ...orderDetailDefaults,
63
+ supportHref: orderDetailSupport.href,
64
+ flows: orderDetailFlowLabels,
62
65
  },
63
66
  },
64
67
  // Headless account boundary. It is fixed infrastructure, not a selectable
@@ -118,6 +118,15 @@ const SHELL_DEFAULTS = {
118
118
  },
119
119
  overview: {
120
120
  sections: 'Secciones de tu cuenta',
121
+ // The card summaries are preformatted text, exactly what the host passes. A
122
+ // module with nothing inside keeps its card summary-less: the overview never
123
+ // prints a zero to fill space.
124
+ summaries: {
125
+ orders: '{count} pedidos',
126
+ ordersOne: '1 pedido',
127
+ addresses: '{count} guardadas',
128
+ addressesOne: '1 guardada',
129
+ },
121
130
  },
122
131
  placeholder: {
123
132
  badge: 'Próximamente',
@@ -182,6 +191,10 @@ const shellContent = {
182
191
  overview: {
183
192
  ...SHELL_DEFAULTS.overview,
184
193
  ...(accountContentCompat.overview ?? {}),
194
+ summaries: {
195
+ ...SHELL_DEFAULTS.overview.summaries,
196
+ ...(accountContentCompat.overview?.summaries ?? {}),
197
+ },
185
198
  },
186
199
  placeholder: {
187
200
  ...SHELL_DEFAULTS.placeholder,
@@ -360,14 +373,29 @@ function shellCustomer(customer: Customer): CustomerAccountV1Props['context']['c
360
373
  .map((part) => part[0])
361
374
  .join('')
362
375
  .toUpperCase() || customer.email.slice(0, 2).toUpperCase()
376
+ const memberSince = memberSinceLabel(customer.createdAt)
363
377
  return {
364
378
  name,
365
379
  email: customer.email,
366
380
  initials,
367
381
  ...(customer.phone ? { phone: customer.phone } : {}),
382
+ ...(memberSince ? { memberSince } : {}),
368
383
  }
369
384
  }
370
385
 
386
+ /**
387
+ * The join date the header prints as "Cliente desde {date}". Only the month and
388
+ * year leave the store ("marzo de 2023"), the same granularity the account
389
+ * surface needs; an absent or unparseable date simply hides the line instead of
390
+ * inventing one.
391
+ */
392
+ function memberSinceLabel(createdAt: string | null | undefined): string | undefined {
393
+ if (!createdAt) return undefined
394
+ const date = new Date(createdAt)
395
+ if (Number.isNaN(date.getTime())) return undefined
396
+ return new Intl.DateTimeFormat('es-ES', { month: 'long', year: 'numeric' }).format(date)
397
+ }
398
+
371
399
  function shellState(state: AccountState): CustomerAccountV1Props['state'] {
372
400
  if (state.accountReconciling === true) return { status: 'loading' }
373
401
  if (state.accountResolution === 'unavailable') {
@@ -432,10 +460,93 @@ function AccountShellPanel({ children }: ShellPanelProps) {
432
460
  )
433
461
  }
434
462
 
463
+ /** One order row is enough to read the authoritative page count. */
464
+ const OVERVIEW_ORDERS_PAGE_SIZE = 1
465
+
466
+ function summaryText(template: string, single: string, count: number): string {
467
+ return count === 1 ? single : template.replaceAll('{count}', String(count))
468
+ }
469
+
470
+ /**
471
+ * Preformatted card summaries. The overview names how much is waiting inside the
472
+ * modules, so it reads the two counters the modules load anyway: the order page
473
+ * count and the saved-address list. Nothing is invented — a module the store
474
+ * does not offer is never counted, a failed read leaves the card summary-less,
475
+ * and an empty module prints no zero.
476
+ */
477
+ function overviewSummaries(
478
+ state: AccountState,
479
+ capabilities: CustomerAccountOverviewProps['capabilities'],
480
+ ): Record<string, string> {
481
+ const summaries: Record<string, string> = {}
482
+ const orderCount =
483
+ typeof state.accountOrdersCount === 'number' ? state.accountOrdersCount : 0
484
+ const addressCount = Array.isArray(state.accountAddresses)
485
+ ? state.accountAddresses.length
486
+ : 0
487
+ if (capabilities.orderHistory === true && orderCount > 0) {
488
+ summaries.orders = summaryText(
489
+ shellContent.overview.summaries.orders,
490
+ shellContent.overview.summaries.ordersOne,
491
+ orderCount,
492
+ )
493
+ }
494
+ if (capabilities.addressBook === true && addressCount > 0) {
495
+ summaries.addresses = summaryText(
496
+ shellContent.overview.summaries.addresses,
497
+ shellContent.overview.summaries.addressesOne,
498
+ addressCount,
499
+ )
500
+ }
501
+ return summaries
502
+ }
503
+
435
504
  function AccountOverviewPanel() {
436
- const { state } = useStateStore()
505
+ const { state, set } = useStateStore()
437
506
  const pathname = usePathname()
438
507
  const router = useRouter()
508
+ const { identityKey, reconciling } = useAccountLifecycle()
509
+ const loadedKeyRef = useRef<string | null>(null)
510
+ const capabilities = shellCapabilities(state)
511
+ const authenticated = state.accountAuthenticated === true
512
+ const wantsOrders = capabilities.orderHistory === true
513
+ const wantsAddresses = capabilities.addressBook === true
514
+
515
+ // The overview is the only surface that needs a count without rendering the
516
+ // module, so it performs the same reads the module would and stores their
517
+ // result in the shared account state. Keyed by identity: a new shopper never
518
+ // inherits the previous one's counters, and a read that lands after an
519
+ // identity change is dropped instead of overwriting the new state.
520
+ useEffect(() => {
521
+ if (!authenticated || reconciling) return
522
+ if (pathname !== '/account') return
523
+ if (identityKey === 'anonymous') return
524
+ if (loadedKeyRef.current === identityKey) return
525
+ loadedKeyRef.current = identityKey
526
+ if (wantsOrders) {
527
+ void loadOrdersPageAction({ page: 1, pageSize: OVERVIEW_ORDERS_PAGE_SIZE })
528
+ .then((result) => {
529
+ if (result.ok && loadedKeyRef.current === identityKey) {
530
+ set('/accountOrdersCount', result.count)
531
+ }
532
+ })
533
+ .catch(() => {
534
+ // A failed count read is not an account error: the card keeps its
535
+ // description and simply shows no summary.
536
+ })
537
+ }
538
+ if (wantsAddresses) {
539
+ void loadAccountAddressesAction()
540
+ .then((result) => {
541
+ if (result.ok && loadedKeyRef.current === identityKey) {
542
+ set('/accountAddresses', result.addresses)
543
+ }
544
+ })
545
+ .catch(() => {
546
+ // Same rule as the order count: no summary beats a made-up number.
547
+ })
548
+ }
549
+ }, [authenticated, reconciling, pathname, identityKey, wantsOrders, wantsAddresses, set])
439
550
 
440
551
  useEffect(() => {
441
552
  if (pathname !== '/account') return
@@ -448,12 +559,12 @@ function AccountOverviewPanel() {
448
559
  return () => cancelAnimationFrame(frame)
449
560
  }, [pathname])
450
561
 
451
- if (!state.accountAuthenticated) return null
562
+ if (!authenticated) return null
452
563
  return (
453
564
  <AccountOverviewBlock
454
565
  title={shellContent.shellModules.overview.label}
455
- model={{ cards: shellCards(), summaries: {}, notice: null }}
456
- capabilities={shellCapabilities(state)}
566
+ model={{ cards: shellCards(), summaries: overviewSummaries(state, capabilities), notice: null }}
567
+ capabilities={capabilities}
457
568
  labels={{ sections: shellContent.overview.sections }}
458
569
  onOpenCard={(cardId) => {
459
570
  sessionStorage.setItem('account:origin-card', cardId)
@@ -29,6 +29,12 @@ export const accountContent = {
29
29
  },
30
30
  overview: {
31
31
  sections: 'Secciones de tu cuenta',
32
+ summaries: {
33
+ orders: '{count} pedidos',
34
+ ordersOne: '1 pedido',
35
+ addresses: '{count} guardadas',
36
+ addressesOne: '1 guardada',
37
+ },
32
38
  },
33
39
  placeholder: {
34
40
  badge: 'Próximamente',
@@ -24,6 +24,7 @@ import { registry } from './registry'
24
24
  import { sectionData } from './sections-data'
25
25
  import { accountContent } from './content'
26
26
  import { orderDetailDefaults } from './order-detail.defaults'
27
+ import { orderDetailFlowLabels, orderDetailSupport } from './order-detail-flows.defaults'
27
28
  import { fulfillmentEvidenceDefaults } from './fulfillment-evidence.defaults'
28
29
  import { accountOrdersAdvancedDefaults } from './orders-advanced.defaults'
29
30
  import {
@@ -59,6 +60,8 @@ const elements: Record<string, StorefrontElement> = {
59
60
  props: {
60
61
  orderId: { $state: '/orderDetailId' },
61
62
  ...orderDetailDefaults,
63
+ supportHref: orderDetailSupport.href,
64
+ flows: orderDetailFlowLabels,
62
65
  },
63
66
  },
64
67
  // Headless account boundary. It is fixed infrastructure, not a selectable