@thorprovider/storefront 0.9.0 → 0.11.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 (66) hide show
  1. package/README.md +8 -5
  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 +130 -12
  6. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +156 -9
  7. package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +38 -3
  8. package/assets/templates/app/lib/__STOREFRONT__/fulfillment-evidence-port.ts +31 -0
  9. package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +21 -4
  10. package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +6 -2
  11. package/assets/templates/app/lib/__STOREFRONT__/order-detail-aftersales.ts +55 -0
  12. package/assets/templates/app/lib/__STOREFRONT__/order-detail-capabilities.ts +79 -0
  13. package/assets/templates/app/lib/__STOREFRONT__/order-detail-mapper.ts +653 -0
  14. package/assets/templates/app/lib/__STOREFRONT__/order-detail-money.ts +39 -0
  15. package/assets/templates/app/lib/__STOREFRONT__/order-detail-port.ts +6 -7
  16. package/assets/templates/app/lib/__STOREFRONT__/order-detail-reorder.ts +62 -0
  17. package/assets/templates/app/lib/__STOREFRONT__/ports.ts +13 -3
  18. package/assets/templates/views/account/assembly/assembly.json +0 -5
  19. package/assets/templates/views/account/assembly/index.skeleton.tsx +51 -0
  20. package/assets/templates/views/account/assembly/registry.skeleton.tsx +120 -68
  21. package/assets/templates/views/account/content.ts +13 -7
  22. package/assets/templates/views/account/fulfillment-evidence.client.tsx +34 -0
  23. package/assets/templates/views/account/fulfillment-evidence.defaults.ts +145 -0
  24. package/assets/templates/views/account/fulfillment-evidence.schema.ts +15 -0
  25. package/assets/templates/views/account/index.tsx +44 -3
  26. package/assets/templates/views/account/order-detail-flows.defaults.ts +106 -0
  27. package/assets/templates/views/account/order-detail-invoice.ts +136 -0
  28. package/assets/templates/views/account/order-detail-sheet.tsx +100 -0
  29. package/assets/templates/views/account/order-detail-sheets.tsx +122 -0
  30. package/assets/templates/views/account/order-detail.client.tsx +401 -1
  31. package/assets/templates/views/account/orders-advanced.client.tsx +10 -99
  32. package/assets/templates/views/account/orders-advanced.defaults.ts +7 -7
  33. package/assets/templates/views/account/registry.tsx +120 -69
  34. package/assets/templates/views/account/schema.ts +2 -0
  35. package/assets/templates/views/home/assembly/assembly.json +1 -1
  36. package/assets/templates/views/home/assembly/index.skeleton.tsx +3 -1
  37. package/assets/templates/views/home/assembly/registry.skeleton.tsx +1 -0
  38. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/binding.json +5 -0
  39. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/catalog.part +4 -0
  40. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/element.part +4 -0
  41. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/registry.part +10 -0
  42. package/assets/templates/views/home/content.ts +248 -2
  43. package/assets/templates/views/home/data.ts +10 -1
  44. package/assets/templates/views/home/index.tsx +7 -6
  45. package/assets/templates/views/home/props.ts +7 -1
  46. package/assets/templates/views/home/registry.tsx +11 -28
  47. package/assets/templates/views/home/schema.ts +163 -0
  48. package/assets/templates/views/product/data.ts +13 -6
  49. package/assets/templates/views/product/index.tsx +3 -3
  50. package/bin/storefront.js +18 -18
  51. package/package.json +1 -1
  52. package/recipes/adapter-surface.json +1 -0
  53. package/recipes/archetypes.json +5 -1
  54. package/recipes/catalog.json +9 -1
  55. package/recipes/recipes.json +5 -4
  56. package/scripts/candidate.mjs +59 -14
  57. package/scripts/file-classes.mjs +4 -0
  58. package/scripts/mock-capabilities.mjs +22 -0
  59. package/scripts/reconcile.mjs +5 -2
  60. package/scripts/render-templates.mjs +126 -43
  61. package/skills/sf-view-gen/assets/recipes/archetypes.json +5 -1
  62. package/skills/sf-view-gen/assets/recipes/catalog.json +9 -1
  63. package/skills/sf-view-gen/assets/recipes/recipes.json +5 -4
  64. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/catalog.part +0 -5
  65. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/element.part +0 -5
  66. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/registry.part +0 -1
@@ -0,0 +1,122 @@
1
+ 'use client'
2
+
3
+ import type { OrderDetailMoney, OrderDetailOrder, TrackingEvent } from '@thorprovider/blocks/ports'
4
+
5
+ import { formatMinor } from '../../order-detail-money'
6
+ import type { OrderDetailFlowLabels } from './order-detail-flows.defaults'
7
+
8
+ const formatMoney = (money: OrderDetailMoney, locale = 'es-MX'): string =>
9
+ formatMinor(money.amount, money.currency, locale)
10
+
11
+ /** Carrier, number and events the backend reported. Nothing is synthesized. */
12
+ export function trackingFacts(order: OrderDetailOrder): {
13
+ carrier?: string
14
+ number?: string
15
+ events: TrackingEvent[]
16
+ } {
17
+ const carrier = order.fulfillments.find((fulfillment) => fulfillment.carrier)?.carrier
18
+ const number = order.fulfillments.find(
19
+ (fulfillment) => fulfillment.trackingNumber,
20
+ )?.trackingNumber
21
+ const events = order.fulfillments.flatMap((fulfillment) => fulfillment.events ?? [])
22
+ return {
23
+ ...(carrier ? { carrier } : {}),
24
+ ...(number ? { number } : {}),
25
+ events,
26
+ }
27
+ }
28
+
29
+ /** Outstanding balance: total minus captured payments plus refunds. */
30
+ export function dueAmount(order: OrderDetailOrder): OrderDetailMoney {
31
+ const paid = order.transactions
32
+ .filter((transaction) => transaction.status === 'captured')
33
+ .reduce((sum, transaction) => sum + transaction.amount.amount, 0)
34
+ const refunded = order.transactions
35
+ .filter((transaction) => transaction.kind === 'refund' && transaction.status === 'refunded')
36
+ .reduce((sum, transaction) => sum + transaction.amount.amount, 0)
37
+ return {
38
+ amount: Math.max(0, order.totals.total.amount - paid + refunded),
39
+ currency: order.totals.total.currency,
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Tracking sheet. The demo data has no carrier URL, so the sheet reports the
45
+ * identifiers and the events it has instead of linking somewhere invented.
46
+ */
47
+ export function TrackSheet({
48
+ order,
49
+ labels,
50
+ locale,
51
+ }: {
52
+ order: OrderDetailOrder
53
+ labels: OrderDetailFlowLabels
54
+ locale?: string
55
+ }) {
56
+ const facts = trackingFacts(order)
57
+ const copy = labels.track
58
+
59
+ return (
60
+ <div className="space-y-4 text-sm">
61
+ <dl className="grid grid-cols-1 gap-2 sm:grid-cols-2">
62
+ {facts.carrier ? (
63
+ <div>
64
+ <dt className="text-xs text-muted-foreground">{copy.carrier}</dt>
65
+ <dd className="font-medium">{facts.carrier}</dd>
66
+ </div>
67
+ ) : null}
68
+ {facts.number ? (
69
+ <div>
70
+ <dt className="text-xs text-muted-foreground">{copy.number}</dt>
71
+ <dd className="font-medium break-all">{facts.number}</dd>
72
+ </div>
73
+ ) : null}
74
+ </dl>
75
+
76
+ <div className="space-y-2">
77
+ <p className="text-xs font-medium text-muted-foreground">{copy.events}</p>
78
+ {facts.events.length === 0 ? (
79
+ <p className="text-muted-foreground">{copy.noEvents}</p>
80
+ ) : (
81
+ <ol className="space-y-2">
82
+ {facts.events.map((event) => (
83
+ <li key={event.id} className="rounded-md border p-2">
84
+ <p className="font-medium">{event.label}</p>
85
+ <p className="text-xs text-muted-foreground">
86
+ {new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(
87
+ new Date(event.at),
88
+ )}
89
+ {event.place ? ` · ${event.place}` : ''}
90
+ </p>
91
+ </li>
92
+ ))}
93
+ </ol>
94
+ )}
95
+ </div>
96
+ </div>
97
+ )
98
+ }
99
+
100
+ /** Outstanding-balance sheet. A form that cannot charge would be a lie. */
101
+ export function PayBalanceSheet({
102
+ order,
103
+ labels,
104
+ }: {
105
+ order: OrderDetailOrder
106
+ labels: OrderDetailFlowLabels
107
+ locale?: string
108
+ }) {
109
+ const copy = labels.payBalance
110
+
111
+ return (
112
+ <div className="space-y-4 text-sm">
113
+ <div className="flex items-baseline justify-between gap-3 rounded-lg border p-3">
114
+ <span className="text-muted-foreground">{copy.amount}</span>
115
+ <span className="text-lg font-semibold tabular-nums">
116
+ {formatMoney(dueAmount(order))}
117
+ </span>
118
+ </div>
119
+ <p className="rounded-lg border border-dashed p-3 text-muted-foreground">{copy.demoNotice}</p>
120
+ </div>
121
+ )
122
+ }
@@ -1,22 +1,146 @@
1
1
  'use client'
2
2
 
3
+ import { useCallback, useEffect, useState, type ReactNode } from 'react'
4
+ import { useRouter } from 'next/navigation'
5
+ import { AfterSalesFlow } from '@thorprovider/blocks'
3
6
  import { OrderDetail as OrderDetailSurface } from '@thorprovider/blocks'
4
- import type { OrderDetailProps } from '@thorprovider/blocks'
7
+ import type { AfterSalesCaseType, AfterSalesRequest, OrderDetailProps } from '@thorprovider/blocks'
8
+ import type { OrderActionId, OrderDetailSnapshot, OrderDocument } from '@thorprovider/blocks/ports'
5
9
 
6
10
  import { ports } from '../../ports'
11
+ import { reorderOrderAction } from '../../actions'
12
+ import { toAfterSalesLines } from '../../order-detail-aftersales'
13
+ import { runReorder, type ReorderOrderResult } from '../../order-detail-reorder'
14
+ import {
15
+ orderDetailFlowLabels,
16
+ type OrderDetailFlowLabels,
17
+ } from './order-detail-flows.defaults'
18
+ import { buildInvoiceHtml, openPrintable } from './order-detail-invoice'
19
+ import { PayBalanceSheet, TrackSheet } from './order-detail-sheets'
20
+ import { OrderDetailSheet } from './order-detail-sheet'
7
21
  import { accountOrderDetailPropsSchema } from './schema'
8
22
 
9
23
  type PanelProps = {
10
24
  props: Record<string, unknown>
11
25
  }
12
26
 
27
+ type Sheet =
28
+ | { kind: 'reorder-result'; result: ReorderOrderResult }
29
+ | { kind: 'invoice'; document?: OrderDocument }
30
+ | { kind: 'track' }
31
+ | { kind: 'pay-balance' }
32
+ | { kind: 'after-sales'; caseType: AfterSalesCaseType }
33
+
13
34
  /**
14
35
  * Host panel for the /account/orders/[id] route. It parses the element props,
15
36
  * injects the fail-closed `orderDetail` port and renders the landed surface with
16
37
  * its own loading, error, not-found and forbidden states.
38
+ *
39
+ * The delivered surface reports actions, documents and a back request through
40
+ * callbacks; this host answers each one with a real destination or a labelled
41
+ * demonstration sheet, never with an inert control.
17
42
  */
18
43
  export function AccountOrderDetailPanel({ props }: PanelProps) {
19
44
  const parsed = accountOrderDetailPropsSchema.parse(props)
45
+ const router = useRouter()
46
+ const [sheet, setSheet] = useState<Sheet | null>(null)
47
+ const [afterSalesRequest, setAfterSalesRequest] = useState<AfterSalesRequest | null>(null)
48
+ const [busy, setBusy] = useState(false)
49
+
50
+ const labels = (parsed.flows as OrderDetailFlowLabels | undefined) ?? orderDetailFlowLabels
51
+ const supportHref = parsed.supportHref
52
+
53
+ const [snapshot, setSnapshot] = useState<OrderDetailSnapshot | null>(null)
54
+ const [snapshotError, setSnapshotError] = useState(false)
55
+ const [printBlocked, setPrintBlocked] = useState(false)
56
+
57
+ const needsSnapshot =
58
+ sheet?.kind === 'invoice' ||
59
+ sheet?.kind === 'track' ||
60
+ sheet?.kind === 'pay-balance' ||
61
+ sheet?.kind === 'after-sales'
62
+
63
+ useEffect(() => {
64
+ if (!needsSnapshot || snapshot || snapshotError) return
65
+ let active = true
66
+ ports.orderDetail
67
+ .get(parsed.orderId)
68
+ .then((loaded) => {
69
+ if (active) setSnapshot(loaded)
70
+ })
71
+ .catch(() => {
72
+ if (active) setSnapshotError(true)
73
+ })
74
+ return () => {
75
+ active = false
76
+ }
77
+ }, [needsSnapshot, parsed.orderId, snapshot, snapshotError])
78
+
79
+ const openInvoice = useCallback(
80
+ (order: OrderDetailSnapshot['order'], document: OrderDocument) => {
81
+ const html = buildInvoiceHtml({
82
+ order,
83
+ document,
84
+ labels,
85
+ locale: parsed.locale ?? 'es-MX',
86
+ })
87
+ setPrintBlocked(!openPrintable(html))
88
+ },
89
+ [labels, parsed.locale],
90
+ )
91
+
92
+ const closeSheet = useCallback(() => {
93
+ setSheet(null)
94
+ setAfterSalesRequest(null)
95
+ }, [])
96
+
97
+ const onBack = useCallback(() => {
98
+ router.push('/account/orders')
99
+ }, [router])
100
+
101
+ const onAction = async (action: OrderActionId) => {
102
+ switch (action) {
103
+ case 'reorder': {
104
+ if (busy) return
105
+ setBusy(true)
106
+ try {
107
+ const result = await runReorder(reorderOrderAction, parsed.orderId)
108
+ setSheet({ kind: 'reorder-result', result })
109
+ } finally {
110
+ setBusy(false)
111
+ }
112
+ return
113
+ }
114
+ case 'invoice':
115
+ setSheet({ kind: 'invoice' })
116
+ return
117
+ case 'track':
118
+ setSheet({ kind: 'track' })
119
+ return
120
+ case 'pay-balance':
121
+ setSheet({ kind: 'pay-balance' })
122
+ return
123
+ case 'return':
124
+ setSheet({ kind: 'after-sales', caseType: 'return' })
125
+ return
126
+ case 'exchange':
127
+ setSheet({ kind: 'after-sales', caseType: 'exchange' })
128
+ return
129
+ case 'problem':
130
+ setSheet({ kind: 'after-sales', caseType: 'claim' })
131
+ return
132
+ case 'cancel':
133
+ setSheet({ kind: 'after-sales', caseType: 'cancel' })
134
+ return
135
+ case 'support':
136
+ if (supportHref) router.push(supportHref)
137
+ return
138
+ default:
139
+ return
140
+ }
141
+ }
142
+
143
+ const onDocument = (document: OrderDocument) => setSheet({ kind: 'invoice', document })
20
144
 
21
145
  return (
22
146
  <div className="mx-auto w-full max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
@@ -29,7 +153,283 @@ export function AccountOrderDetailPanel({ props }: PanelProps) {
29
153
  openSections={parsed.openSections as OrderDetailProps['openSections']}
30
154
  access={parsed.access}
31
155
  port={ports.orderDetail}
156
+ onBack={onBack}
157
+ onAction={onAction}
158
+ onDocument={onDocument}
32
159
  />
160
+
161
+ {busy ? (
162
+ <p role="status" className="sr-only">
163
+ {labels.reorder.pending}
164
+ </p>
165
+ ) : null}
166
+
167
+ {sheet?.kind === 'reorder-result' ? (
168
+ <OrderDetailSheet
169
+ title={labels.reorder.title}
170
+ closeLabel={labels.dialog.close}
171
+ onClose={closeSheet}
172
+ >
173
+ <ReorderResult
174
+ result={sheet.result}
175
+ labels={labels}
176
+ onGoToCart={() => {
177
+ closeSheet()
178
+ router.push('/cart')
179
+ }}
180
+ />
181
+ </OrderDetailSheet>
182
+ ) : null}
183
+
184
+ {sheet?.kind === 'invoice' ? (
185
+ <OrderDetailSheet
186
+ title={labels.invoice.title}
187
+ closeLabel={labels.dialog.close}
188
+ onClose={closeSheet}
189
+ >
190
+ <InvoiceSheetBody
191
+ sheet={sheet}
192
+ snapshot={snapshot}
193
+ failed={snapshotError}
194
+ blocked={printBlocked}
195
+ labels={labels}
196
+ locale={parsed.locale ?? 'es-MX'}
197
+ onPrint={openInvoice}
198
+ />
199
+ </OrderDetailSheet>
200
+ ) : null}
201
+
202
+ {sheet?.kind === 'track' ? (
203
+ <OrderDetailSheet
204
+ title={labels.track.title}
205
+ closeLabel={labels.dialog.close}
206
+ onClose={closeSheet}
207
+ >
208
+ <SnapshotBody
209
+ snapshot={snapshot}
210
+ failed={snapshotError}
211
+ section="logistics"
212
+ labels={labels}
213
+ >
214
+ {(order) => <TrackSheet order={order} labels={labels} locale={parsed.locale} />}
215
+ </SnapshotBody>
216
+ </OrderDetailSheet>
217
+ ) : null}
218
+
219
+ {sheet?.kind === 'after-sales' && afterSalesRequest ? (
220
+ <OrderDetailSheet
221
+ title={labels.afterSales.resultTitle}
222
+ closeLabel={labels.dialog.close}
223
+ onClose={closeSheet}
224
+ >
225
+ <div className="space-y-3 text-sm">
226
+ <p className="font-medium">{labels.afterSales.resultTitle}</p>
227
+ <p className="text-muted-foreground">{labels.afterSales.resultBody}</p>
228
+ <p className="text-xs text-muted-foreground">
229
+ {labels.afterSales.units.replace(
230
+ '{count}',
231
+ String(
232
+ afterSalesRequest.lines.reduce((total, line) => total + line.quantity, 0),
233
+ ),
234
+ )}
235
+ </p>
236
+ </div>
237
+ </OrderDetailSheet>
238
+ ) : null}
239
+
240
+ {sheet?.kind === 'after-sales' && !afterSalesRequest ? (
241
+ snapshot ? (
242
+ <AfterSalesFlow
243
+ caseType={sheet.caseType}
244
+ orderId={snapshot.order.id}
245
+ orderNumber={snapshot.order.number}
246
+ lines={toAfterSalesLines(snapshot.order)}
247
+ locale={parsed.locale}
248
+ onCancel={closeSheet}
249
+ onSubmit={setAfterSalesRequest}
250
+ />
251
+ ) : (
252
+ <OrderDetailSheet
253
+ title={labels.afterSales.title}
254
+ closeLabel={labels.dialog.close}
255
+ onClose={closeSheet}
256
+ >
257
+ <SnapshotBody snapshot={snapshot} failed={snapshotError} labels={labels}>
258
+ {() => null}
259
+ </SnapshotBody>
260
+ </OrderDetailSheet>
261
+ )
262
+ ) : null}
263
+
264
+ {sheet?.kind === 'pay-balance' ? (
265
+ <OrderDetailSheet
266
+ title={labels.payBalance.title}
267
+ closeLabel={labels.dialog.close}
268
+ onClose={closeSheet}
269
+ >
270
+ <SnapshotBody
271
+ snapshot={snapshot}
272
+ failed={snapshotError}
273
+ section="payments"
274
+ labels={labels}
275
+ >
276
+ {(order) => <PayBalanceSheet order={order} labels={labels} />}
277
+ </SnapshotBody>
278
+ </OrderDetailSheet>
279
+ ) : null}
280
+ </div>
281
+ )
282
+ }
283
+
284
+ function ReorderResult({
285
+ result,
286
+ labels,
287
+ onGoToCart,
288
+ }: {
289
+ result: ReorderOrderResult
290
+ labels: OrderDetailFlowLabels
291
+ onGoToCart: () => void
292
+ }) {
293
+ if (!result.ok) {
294
+ return (
295
+ <div className="space-y-3">
296
+ <p className="text-sm font-medium">{labels.reorder.failedTitle}</p>
297
+ <p className="text-sm text-muted-foreground">{result.error}</p>
298
+ </div>
299
+ )
300
+ }
301
+
302
+ return (
303
+ <div className="space-y-4">
304
+ <p className="text-sm font-medium">
305
+ {result.added === 0
306
+ ? labels.reorder.failedTitle
307
+ : labels.reorder.added.replace('{count}', String(result.added))}
308
+ </p>
309
+ {result.skipped.length > 0 ? (
310
+ <div className="space-y-1">
311
+ <p className="text-sm font-medium">{labels.reorder.skippedTitle}</p>
312
+ <ul className="list-disc space-y-1 pl-5 text-sm text-muted-foreground">
313
+ {result.skipped.map((entry, index) => (
314
+ <li key={`${index}-${entry.title}-${entry.reason}`}>
315
+ {entry.title} · {entry.reason}
316
+ </li>
317
+ ))}
318
+ </ul>
319
+ </div>
320
+ ) : null}
321
+ {result.added > 0 ? (
322
+ <button
323
+ type="button"
324
+ onClick={onGoToCart}
325
+ className="inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground hover:bg-primary/90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring sm:w-auto"
326
+ >
327
+ {labels.reorder.goToCart}
328
+ </button>
329
+ ) : null}
330
+ </div>
331
+ )
332
+ }
333
+
334
+ function SnapshotBody({
335
+ snapshot,
336
+ failed,
337
+ section,
338
+ labels,
339
+ children,
340
+ }: {
341
+ snapshot: OrderDetailSnapshot | null
342
+ failed: boolean
343
+ section?: 'documents' | 'logistics' | 'payments'
344
+ labels: OrderDetailFlowLabels
345
+ children: (order: OrderDetailSnapshot['order']) => ReactNode
346
+ }) {
347
+ if (failed) {
348
+ return <p className="text-sm text-muted-foreground">{labels.dialog.sectionError}</p>
349
+ }
350
+ if (!snapshot) {
351
+ return (
352
+ <p role="status" className="text-sm text-muted-foreground">
353
+ {labels.invoice.loading}
354
+ </p>
355
+ )
356
+ }
357
+ // A partial load reports per-section issues; rendering a section that failed
358
+ // would present missing data as complete.
359
+ if (section && snapshot.issues?.[section]) {
360
+ return <p className="text-sm text-muted-foreground">{labels.dialog.sectionError}</p>
361
+ }
362
+ return <>{children(snapshot.order)}</>
363
+ }
364
+
365
+ function InvoiceSheetBody({
366
+ sheet,
367
+ snapshot,
368
+ failed,
369
+ blocked,
370
+ labels,
371
+ locale,
372
+ onPrint,
373
+ }: {
374
+ sheet: { kind: 'invoice'; document?: OrderDocument }
375
+ snapshot: OrderDetailSnapshot | null
376
+ failed: boolean
377
+ blocked: boolean
378
+ labels: OrderDetailFlowLabels
379
+ locale: string
380
+ onPrint: (order: OrderDetailSnapshot['order'], document: OrderDocument) => void
381
+ }) {
382
+ if (failed || snapshot?.issues?.documents) {
383
+ return <p className="text-sm text-muted-foreground">{labels.invoice.error}</p>
384
+ }
385
+ if (!snapshot) {
386
+ return (
387
+ <p role="status" className="text-sm text-muted-foreground">
388
+ {labels.invoice.loading}
389
+ </p>
390
+ )
391
+ }
392
+
393
+ const available = snapshot.order.documents.filter((document) => document.available)
394
+ const document =
395
+ sheet.document ?? available.find((entry) => entry.kind === 'invoice') ?? available[0]
396
+
397
+ if (!document) {
398
+ return <p className="text-sm text-muted-foreground">{labels.invoice.error}</p>
399
+ }
400
+
401
+ return (
402
+ <div className="space-y-4 text-sm">
403
+ <div className="rounded-lg border border-dashed p-3 text-muted-foreground">
404
+ {labels.invoice.demoBanner}
405
+ </div>
406
+ <div>
407
+ <p className="font-medium">{document.label}</p>
408
+ <p className="text-xs text-muted-foreground">Pedido {snapshot.order.number}</p>
409
+ </div>
410
+ <button
411
+ type="button"
412
+ onClick={() => onPrint(snapshot.order, document)}
413
+ className="inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground hover:bg-primary/90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring sm:w-auto"
414
+ >
415
+ {labels.invoice.print}
416
+ </button>
417
+ {blocked ? (
418
+ <div className="space-y-2">
419
+ <p className="text-sm text-muted-foreground">{labels.invoice.blocked}</p>
420
+ <iframe
421
+ title={document.label}
422
+ sandbox=""
423
+ srcDoc={buildInvoiceHtml({
424
+ order: snapshot.order,
425
+ document,
426
+ labels,
427
+ locale,
428
+ })}
429
+ className="h-[60vh] w-full rounded-md border"
430
+ />
431
+ </div>
432
+ ) : null}
33
433
  </div>
34
434
  )
35
435
  }
@@ -1,19 +1,12 @@
1
1
  'use client'
2
2
 
3
- import { useState } from 'react'
3
+ import { useRouter } from 'next/navigation'
4
4
  import { useStateStore } from '@json-render/react'
5
- import {
6
- OrderHistoryAdvanced,
7
- fillOrderHistoryTemplate,
8
- formatOrderHistoryDate,
9
- formatOrderHistoryMoney,
10
- } from '@thorprovider/blocks'
5
+ import { OrderHistoryAdvanced } from '@thorprovider/blocks'
11
6
  import type {
12
7
  OrderHistoryAdvancedCapabilities,
13
8
  OrderHistoryAdvancedLabels,
14
- OrderHistoryAdvancedRecord,
15
9
  } from '@thorprovider/blocks'
16
- import { Button } from '@thorprovider/blocks/ui/button'
17
10
 
18
11
  import { useAccountLifecycle } from '../../account-lifecycle.client'
19
12
  import { isAccountModuleVisible } from '../../account-private.core'
@@ -27,14 +20,16 @@ type PanelProps = {
27
20
 
28
21
  /**
29
22
  * Host panel for the advanced order-history block. It owns the port wiring, the
30
- * account module visibility and the inline order summary; the block owns the
31
- * collection, its query lifecycle and every loading/error/empty state.
23
+ * account module visibility and the order-detail navigation; the block owns the
24
+ * collection, its query lifecycle and every loading/error/empty state. Opening
25
+ * an order always leaves the list for its own `/account/orders/[id]` page, so
26
+ * the list never renders a second detail surface.
32
27
  */
33
28
  export function AccountOrdersAdvancedPanel({ props }: PanelProps) {
34
29
  const { state } = useStateStore()
30
+ const router = useRouter()
35
31
  const { identityKey, reconciling } = useAccountLifecycle()
36
32
  const parsed = accountOrdersAdvancedPropsSchema.parse(props)
37
- const [selected, setSelected] = useState<OrderHistoryAdvancedRecord | null>(null)
38
33
 
39
34
  const visible = isAccountModuleVisible(
40
35
  typeof state.accountShape === 'string' ? state.accountShape : null,
@@ -73,94 +68,10 @@ export function AccountOrdersAdvancedPanel({ props }: PanelProps) {
73
68
  labels={labels}
74
69
  locale={locale}
75
70
  pageSize={parsed.pageSize ?? 10}
76
- onOrderSelectRecord={setSelected}
71
+ onOrderSelect={(orderId) =>
72
+ router.push(`/account/orders/${encodeURIComponent(orderId)}`)
73
+ }
77
74
  />
78
- {selected ? (
79
- <AdvancedOrderSummary
80
- order={selected}
81
- labels={labels}
82
- locale={locale}
83
- closeLabel={parsed.closeLabel ?? 'Cerrar'}
84
- paymentLabel={parsed.paymentLabel ?? 'Pago'}
85
- fulfilmentLabel={parsed.fulfilmentLabel ?? 'Entrega'}
86
- onClose={() => setSelected(null)}
87
- />
88
- ) : null}
89
- </div>
90
- )
91
- }
92
-
93
- type SummaryProps = {
94
- order: OrderHistoryAdvancedRecord
95
- labels: OrderHistoryAdvancedLabels
96
- locale: string
97
- closeLabel: string
98
- paymentLabel: string
99
- fulfilmentLabel: string
100
- onClose: () => void
101
- }
102
-
103
- /**
104
- * Inline summary for the selected record. The rich `order-detail` delivery
105
- * replaces it; this covers the MVP "view order" without inventing data the
106
- * advanced record does not carry.
107
- */
108
- function AdvancedOrderSummary({
109
- order,
110
- labels,
111
- locale,
112
- closeLabel,
113
- paymentLabel,
114
- fulfilmentLabel,
115
- onClose,
116
- }: SummaryProps) {
117
- const money = (value: OrderHistoryAdvancedRecord['total']) =>
118
- formatOrderHistoryMoney(value, locale, labels.card.amountUnavailable)
119
-
120
- return (
121
- <div className="mt-6 rounded-lg border p-6">
122
- <div className="flex items-start justify-between gap-4">
123
- <div>
124
- <h3 className="text-lg font-semibold">
125
- {fillOrderHistoryTemplate(labels.card.order, { number: order.number })}
126
- </h3>
127
- <p className="text-muted-foreground mt-1 text-sm">
128
- {formatOrderHistoryDate(order.placedAt, locale, order.placedAt)}
129
- </p>
130
- </div>
131
- <Button type="button" variant="outline" size="sm" onClick={onClose}>
132
- {closeLabel}
133
- </Button>
134
- </div>
135
-
136
- <dl className="mt-4 grid gap-3 text-sm sm:grid-cols-3">
137
- <div>
138
- <dt className="text-muted-foreground">{labels.card.total}</dt>
139
- <dd className="mt-0.5 font-medium tabular-nums">{money(order.total)}</dd>
140
- </div>
141
- <div>
142
- <dt className="text-muted-foreground">{paymentLabel}</dt>
143
- <dd className="mt-0.5">{labels.payment[order.payment.status]}</dd>
144
- </div>
145
- <div>
146
- <dt className="text-muted-foreground">{fulfilmentLabel}</dt>
147
- <dd className="mt-0.5">{labels.fulfilment[order.fulfilment.status]}</dd>
148
- </div>
149
- </dl>
150
-
151
- <ul className="mt-4 divide-y">
152
- {order.items.map((item) => (
153
- <li key={item.id} className="flex items-center justify-between gap-4 py-2 text-sm">
154
- <span>
155
- {item.name}
156
- {item.variant ? (
157
- <span className="text-muted-foreground"> · {item.variant}</span>
158
- ) : null}
159
- </span>
160
- <span className="text-muted-foreground shrink-0 tabular-nums">× {item.quantity}</span>
161
- </li>
162
- ))}
163
- </ul>
164
75
  </div>
165
76
  )
166
77
  }