@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.
- package/README.md +22 -11
- package/assets/templates/app/app/globals.css +0 -1
- package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +4 -2
- package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +2 -1
- package/assets/templates/app/lib/__STOREFRONT__/actions.ts +73 -11
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +18 -2
- package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +38 -3
- package/assets/templates/app/lib/__STOREFRONT__/footer-content.ts +203 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-aftersales.ts +55 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-capabilities.ts +79 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-mapper.ts +13 -2
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-money.ts +39 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-reorder.ts +62 -0
- package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +8 -24
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +5 -3
- package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +14 -13
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +7 -2
- package/assets/templates/views/account/assembly/index.skeleton.tsx +3 -0
- package/assets/templates/views/account/assembly/registry.skeleton.tsx +115 -4
- package/assets/templates/views/account/content.ts +6 -0
- package/assets/templates/views/account/index.tsx +3 -0
- package/assets/templates/views/account/order-detail-flows.defaults.ts +106 -0
- package/assets/templates/views/account/order-detail-invoice.ts +136 -0
- package/assets/templates/views/account/order-detail-sheet.tsx +100 -0
- package/assets/templates/views/account/order-detail-sheets.tsx +122 -0
- package/assets/templates/views/account/order-detail.client.tsx +401 -1
- package/assets/templates/views/account/registry.tsx +115 -4
- package/assets/templates/views/account/schema.ts +2 -0
- package/assets/templates/views/home/content.ts +3 -1
- package/assets/templates/views/product/data.ts +13 -6
- package/assets/templates/views/product/index.tsx +3 -3
- package/bin/storefront.js +59 -23
- package/package.json +1 -1
- package/scripts/candidate.mjs +8 -4
- package/scripts/file-classes.mjs +3 -0
- package/scripts/mock-capabilities.mjs +22 -0
- package/scripts/reconcile.mjs +5 -2
- package/scripts/render-templates.mjs +126 -43
- package/scripts/scaffold-env.mjs +48 -0
|
@@ -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
|
}
|
|
@@ -120,6 +120,15 @@ const SHELL_DEFAULTS = {
|
|
|
120
120
|
},
|
|
121
121
|
overview: {
|
|
122
122
|
sections: 'Secciones de tu cuenta',
|
|
123
|
+
// The card summaries are preformatted text, exactly what the host passes. A
|
|
124
|
+
// module with nothing inside keeps its card summary-less: the overview never
|
|
125
|
+
// prints a zero to fill space.
|
|
126
|
+
summaries: {
|
|
127
|
+
orders: '{count} pedidos',
|
|
128
|
+
ordersOne: '1 pedido',
|
|
129
|
+
addresses: '{count} guardadas',
|
|
130
|
+
addressesOne: '1 guardada',
|
|
131
|
+
},
|
|
123
132
|
},
|
|
124
133
|
placeholder: {
|
|
125
134
|
badge: 'Próximamente',
|
|
@@ -184,6 +193,10 @@ const shellContent = {
|
|
|
184
193
|
overview: {
|
|
185
194
|
...SHELL_DEFAULTS.overview,
|
|
186
195
|
...(accountContentCompat.overview ?? {}),
|
|
196
|
+
summaries: {
|
|
197
|
+
...SHELL_DEFAULTS.overview.summaries,
|
|
198
|
+
...(accountContentCompat.overview?.summaries ?? {}),
|
|
199
|
+
},
|
|
187
200
|
},
|
|
188
201
|
placeholder: {
|
|
189
202
|
...SHELL_DEFAULTS.placeholder,
|
|
@@ -362,14 +375,29 @@ function shellCustomer(customer: Customer): CustomerAccountV1Props['context']['c
|
|
|
362
375
|
.map((part) => part[0])
|
|
363
376
|
.join('')
|
|
364
377
|
.toUpperCase() || customer.email.slice(0, 2).toUpperCase()
|
|
378
|
+
const memberSince = memberSinceLabel(customer.createdAt)
|
|
365
379
|
return {
|
|
366
380
|
name,
|
|
367
381
|
email: customer.email,
|
|
368
382
|
initials,
|
|
369
383
|
...(customer.phone ? { phone: customer.phone } : {}),
|
|
384
|
+
...(memberSince ? { memberSince } : {}),
|
|
370
385
|
}
|
|
371
386
|
}
|
|
372
387
|
|
|
388
|
+
/**
|
|
389
|
+
* The join date the header prints as "Cliente desde {date}". Only the month and
|
|
390
|
+
* year leave the store ("marzo de 2023"), the same granularity the account
|
|
391
|
+
* surface needs; an absent or unparseable date simply hides the line instead of
|
|
392
|
+
* inventing one.
|
|
393
|
+
*/
|
|
394
|
+
function memberSinceLabel(createdAt: string | null | undefined): string | undefined {
|
|
395
|
+
if (!createdAt) return undefined
|
|
396
|
+
const date = new Date(createdAt)
|
|
397
|
+
if (Number.isNaN(date.getTime())) return undefined
|
|
398
|
+
return new Intl.DateTimeFormat('es-ES', { month: 'long', year: 'numeric' }).format(date)
|
|
399
|
+
}
|
|
400
|
+
|
|
373
401
|
function shellState(state: AccountState): CustomerAccountV1Props['state'] {
|
|
374
402
|
if (state.accountReconciling === true) return { status: 'loading' }
|
|
375
403
|
if (state.accountResolution === 'unavailable') {
|
|
@@ -434,10 +462,93 @@ function AccountShellPanel({ children }: ShellPanelProps) {
|
|
|
434
462
|
)
|
|
435
463
|
}
|
|
436
464
|
|
|
465
|
+
/** One order row is enough to read the authoritative page count. */
|
|
466
|
+
const OVERVIEW_ORDERS_PAGE_SIZE = 1
|
|
467
|
+
|
|
468
|
+
function summaryText(template: string, single: string, count: number): string {
|
|
469
|
+
return count === 1 ? single : template.replaceAll('{count}', String(count))
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Preformatted card summaries. The overview names how much is waiting inside the
|
|
474
|
+
* modules, so it reads the two counters the modules load anyway: the order page
|
|
475
|
+
* count and the saved-address list. Nothing is invented — a module the store
|
|
476
|
+
* does not offer is never counted, a failed read leaves the card summary-less,
|
|
477
|
+
* and an empty module prints no zero.
|
|
478
|
+
*/
|
|
479
|
+
function overviewSummaries(
|
|
480
|
+
state: AccountState,
|
|
481
|
+
capabilities: CustomerAccountOverviewProps['capabilities'],
|
|
482
|
+
): Record<string, string> {
|
|
483
|
+
const summaries: Record<string, string> = {}
|
|
484
|
+
const orderCount =
|
|
485
|
+
typeof state.accountOrdersCount === 'number' ? state.accountOrdersCount : 0
|
|
486
|
+
const addressCount = Array.isArray(state.accountAddresses)
|
|
487
|
+
? state.accountAddresses.length
|
|
488
|
+
: 0
|
|
489
|
+
if (capabilities.orderHistory === true && orderCount > 0) {
|
|
490
|
+
summaries.orders = summaryText(
|
|
491
|
+
shellContent.overview.summaries.orders,
|
|
492
|
+
shellContent.overview.summaries.ordersOne,
|
|
493
|
+
orderCount,
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
if (capabilities.addressBook === true && addressCount > 0) {
|
|
497
|
+
summaries.addresses = summaryText(
|
|
498
|
+
shellContent.overview.summaries.addresses,
|
|
499
|
+
shellContent.overview.summaries.addressesOne,
|
|
500
|
+
addressCount,
|
|
501
|
+
)
|
|
502
|
+
}
|
|
503
|
+
return summaries
|
|
504
|
+
}
|
|
505
|
+
|
|
437
506
|
function AccountOverviewPanel() {
|
|
438
|
-
const { state } = useStateStore()
|
|
507
|
+
const { state, set } = useStateStore()
|
|
439
508
|
const pathname = usePathname()
|
|
440
509
|
const router = useRouter()
|
|
510
|
+
const { identityKey, reconciling } = useAccountLifecycle()
|
|
511
|
+
const loadedKeyRef = useRef<string | null>(null)
|
|
512
|
+
const capabilities = shellCapabilities(state)
|
|
513
|
+
const authenticated = state.accountAuthenticated === true
|
|
514
|
+
const wantsOrders = capabilities.orderHistory === true
|
|
515
|
+
const wantsAddresses = capabilities.addressBook === true
|
|
516
|
+
|
|
517
|
+
// The overview is the only surface that needs a count without rendering the
|
|
518
|
+
// module, so it performs the same reads the module would and stores their
|
|
519
|
+
// result in the shared account state. Keyed by identity: a new shopper never
|
|
520
|
+
// inherits the previous one's counters, and a read that lands after an
|
|
521
|
+
// identity change is dropped instead of overwriting the new state.
|
|
522
|
+
useEffect(() => {
|
|
523
|
+
if (!authenticated || reconciling) return
|
|
524
|
+
if (pathname !== '/account') return
|
|
525
|
+
if (identityKey === 'anonymous') return
|
|
526
|
+
if (loadedKeyRef.current === identityKey) return
|
|
527
|
+
loadedKeyRef.current = identityKey
|
|
528
|
+
if (wantsOrders) {
|
|
529
|
+
void loadOrdersPageAction({ page: 1, pageSize: OVERVIEW_ORDERS_PAGE_SIZE })
|
|
530
|
+
.then((result) => {
|
|
531
|
+
if (result.ok && loadedKeyRef.current === identityKey) {
|
|
532
|
+
set('/accountOrdersCount', result.count)
|
|
533
|
+
}
|
|
534
|
+
})
|
|
535
|
+
.catch(() => {
|
|
536
|
+
// A failed count read is not an account error: the card keeps its
|
|
537
|
+
// description and simply shows no summary.
|
|
538
|
+
})
|
|
539
|
+
}
|
|
540
|
+
if (wantsAddresses) {
|
|
541
|
+
void loadAccountAddressesAction()
|
|
542
|
+
.then((result) => {
|
|
543
|
+
if (result.ok && loadedKeyRef.current === identityKey) {
|
|
544
|
+
set('/accountAddresses', result.addresses)
|
|
545
|
+
}
|
|
546
|
+
})
|
|
547
|
+
.catch(() => {
|
|
548
|
+
// Same rule as the order count: no summary beats a made-up number.
|
|
549
|
+
})
|
|
550
|
+
}
|
|
551
|
+
}, [authenticated, reconciling, pathname, identityKey, wantsOrders, wantsAddresses, set])
|
|
441
552
|
|
|
442
553
|
useEffect(() => {
|
|
443
554
|
if (pathname !== '/account') return
|
|
@@ -450,12 +561,12 @@ function AccountOverviewPanel() {
|
|
|
450
561
|
return () => cancelAnimationFrame(frame)
|
|
451
562
|
}, [pathname])
|
|
452
563
|
|
|
453
|
-
if (!
|
|
564
|
+
if (!authenticated) return null
|
|
454
565
|
return (
|
|
455
566
|
<AccountOverviewBlock
|
|
456
567
|
title={shellContent.shellModules.overview.label}
|
|
457
|
-
model={{ cards: shellCards(), summaries:
|
|
458
|
-
capabilities={
|
|
568
|
+
model={{ cards: shellCards(), summaries: overviewSummaries(state, capabilities), notice: null }}
|
|
569
|
+
capabilities={capabilities}
|
|
459
570
|
labels={{ sections: shellContent.overview.sections }}
|
|
460
571
|
onOpenCard={(cardId) => {
|
|
461
572
|
sessionStorage.setItem('account:origin-card', cardId)
|
|
@@ -118,6 +118,8 @@ export const accountOrderDetailPropsSchema = z.object({
|
|
|
118
118
|
presentation: z.record(z.string(), z.unknown()).optional(),
|
|
119
119
|
openSections: z.array(z.string()).optional(),
|
|
120
120
|
access: z.enum(['allowed', 'forbidden']).optional(),
|
|
121
|
+
supportHref: z.string().optional(),
|
|
122
|
+
flows: z.record(z.string(), z.unknown()).optional(),
|
|
121
123
|
})
|
|
122
124
|
|
|
123
125
|
export type AccountOrderDetailProps = z.infer<typeof accountOrderDetailPropsSchema>
|
|
@@ -288,7 +288,9 @@ export const heroBannerData = {
|
|
|
288
288
|
gapX: 'md',
|
|
289
289
|
gapY: 'md',
|
|
290
290
|
maxWidth: 'full',
|
|
291
|
-
|
|
291
|
+
// No media cap: the tall hero spans three grid rows, and a capped media
|
|
292
|
+
// leaves the rest of the card empty. Each cell sizes its own media.
|
|
293
|
+
maxHeight: 'none',
|
|
292
294
|
align: 'center',
|
|
293
295
|
radius: '2xl',
|
|
294
296
|
},
|
|
@@ -40,11 +40,18 @@ export function buildSelectedProduct(
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
43
|
+
* Selection starts empty so a real choice is always the shopper's: with several
|
|
44
|
+
* variants the detail's `onAddToCart` can never silently add the first one
|
|
45
|
+
* (listing cards use the separate first-purchasable-variant shortcut instead).
|
|
46
|
+
* The one exception is a product with a single purchasable variant — there is
|
|
47
|
+
* nothing to choose, and leaving it unselected disabled the only call to action
|
|
48
|
+
* with no visible reason. That variant is preselected.
|
|
47
49
|
*/
|
|
48
|
-
export function initialSelectedVariantId(
|
|
49
|
-
|
|
50
|
+
export function initialSelectedVariantId(
|
|
51
|
+
detail: CatalogProductDetail | null | undefined,
|
|
52
|
+
): string | null {
|
|
53
|
+
if (!detail || detail.variants.length !== 1) return null
|
|
54
|
+
const [only] = detail.variants
|
|
55
|
+
const purchasable = only.availableForSale && only.price.status === 'available'
|
|
56
|
+
return purchasable ? only.id : null
|
|
50
57
|
}
|
|
@@ -130,9 +130,9 @@ export const product: ViewModule = {
|
|
|
130
130
|
|
|
131
131
|
return {
|
|
132
132
|
selectedProduct: buildSelectedProduct(result.detail),
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
selectedVariantId: initialSelectedVariantId(),
|
|
133
|
+
// The shopper selects explicitly; only a single-variant product starts
|
|
134
|
+
// preselected (listing cards use the card shortcut instead).
|
|
135
|
+
selectedVariantId: initialSelectedVariantId(result.detail),
|
|
136
136
|
productQuantity: 1,
|
|
137
137
|
productReviews: [],
|
|
138
138
|
hasProductReviews: false,
|