@thorprovider/storefront 0.4.0-mvp.2 → 0.4.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 +10 -12
- package/assets/templates/app/app/[[...slug]]/page.tsx +14 -1
- package/assets/templates/app/app/[[...slug]]/renderer.tsx +43 -12
- package/assets/templates/app/lib/__STOREFRONT__/account-boundary.client.tsx +76 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-lifecycle.client.tsx +461 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-mutation.client.ts +46 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-private.core.ts +103 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-reconcile.client.ts +465 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +177 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-session.ts +44 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +65 -0
- package/assets/templates/app/lib/__STOREFRONT__/actions.ts +76 -27
- package/assets/templates/app/lib/__STOREFRONT__/catalog.ts +4 -4
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +0 -10
- package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +3 -3
- package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +17 -18
- package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +209 -0
- package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.ts +247 -0
- package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +48 -19
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +49 -11
- package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +3 -5
- package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +25 -0
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +4 -2
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/cta.client.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/faq.client.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/logoCloud.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/pricing.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.client.tsx +16 -16
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/statistics.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/testimonials.tsx +1 -1
- package/assets/templates/features/customer-auth/handlers.ts +19 -23
- package/assets/templates/features/customer-auth/state.ts +21 -0
- package/assets/templates/views/account/index.tsx +19 -7
- package/assets/templates/views/account/registry.tsx +234 -155
- package/assets/templates/views/cart/data.ts +7 -7
- package/assets/templates/views/cart/registry.tsx +4 -3
- package/assets/templates/views/category/assembly/assembly.json +1 -1
- package/assets/templates/views/category/assembly/registry.skeleton.tsx +6 -6
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +1 -1
- package/assets/templates/views/category/registry.tsx +7 -7
- package/assets/templates/views/checkout/registry.tsx +3 -5
- package/assets/templates/views/home/assembly/assembly.json +4 -4
- package/assets/templates/views/home/assembly/index.skeleton.tsx +2 -1
- package/assets/templates/views/home/assembly/registry.skeleton.tsx +4 -1
- package/assets/templates/views/home/assembly/slots/benefits/cards/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/registry.part +7 -1
- package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/registry.part +6 -1
- package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/catalog.part +8 -0
- package/assets/templates/views/home/assembly/slots/categories/{ProductCategory2 → CategoryGrid}/element.part +1 -1
- package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/registry.part +31 -0
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/catalog.part +4 -0
- package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/registry.part +3 -1
- package/assets/templates/views/home/content.ts +22 -0
- package/assets/templates/views/home/index.tsx +11 -6
- package/assets/templates/views/home/props.ts +1 -0
- package/assets/templates/views/home/registry.tsx +39 -15
- package/assets/templates/views/home/schema.ts +141 -24
- package/assets/templates/views/product/data.ts +1 -1
- package/assets/templates/views/product/registry.tsx +10 -6
- package/assets/templates/views/product/schema.ts +36 -1
- package/package.json +4 -5
- package/recipes/archetypes.json +25 -25
- package/recipes/catalog.json +213 -160
- package/recipes/catalog.mjs +10 -0
- package/recipes/catalog.schema.json +4 -0
- package/recipes/features.json +3 -3
- package/recipes/recipes.json +138 -40
- package/recipes/sections.json +2 -2
- package/recipes/validate.mjs +21 -4
- package/scripts/candidate.mjs +2 -2
- package/scripts/file-classes.mjs +10 -0
- package/scripts/ownership-conflict.mjs +5 -2
- package/scripts/view-assembly.mjs +10 -2
- package/scripts/view-selection.mjs +1 -1
- package/skills/sf-view-gen/assets/recipes/archetypes.json +25 -25
- package/skills/sf-view-gen/assets/recipes/catalog.json +213 -160
- package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
- package/skills/sf-view-gen/assets/recipes/features.json +3 -3
- package/skills/sf-view-gen/assets/recipes/recipes.json +138 -40
- package/skills/sf-view-gen/assets/recipes/sections.json +2 -2
- package/skills/sf-view-gen/assets/templates/views/sections/cta.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/faq.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/logoCloud.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/pricing.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/products.client.tsx +16 -16
- package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/statistics.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/testimonials.client.tsx +1 -1
- package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
- package/skills/sf-view-gen/scripts/validate.mjs +21 -4
- package/assets/templates/views/home/assembly/slots/benefits/Feature1/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/benefits/Feature2/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/catalog.part +0 -4
- package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/registry.part +0 -16
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/catalog.part +0 -4
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/catalog.part +0 -0
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/element.part +0 -0
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/catalog.part +0 -0
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/element.part +0 -0
- /package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/element.part +0 -0
|
@@ -11,22 +11,17 @@
|
|
|
11
11
|
// written to the json-render state store, so no password reaches client state,
|
|
12
12
|
// HTML, or logs. Only the non-secret result (customer/error) is stored.
|
|
13
13
|
|
|
14
|
-
import { useEffect, useRef } from 'react'
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
SignUpPage1 as SignUpBlock,
|
|
20
|
-
} from '@thorprovider/blocks'
|
|
14
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
15
|
+
import { Button } from '@thorprovider/blocks/ui/button'
|
|
16
|
+
import LoginBlock from '@thorprovider/blocks/blocks/application/login-forms/login-page-1'
|
|
17
|
+
import OrderHistory2 from '@thorprovider/blocks/blocks/e-commerce/order-history/order-history-2'
|
|
18
|
+
import SignUpBlock from '@thorprovider/blocks/blocks/application/signup-forms/signup-page-1'
|
|
21
19
|
import { useStateStore } from '@json-render/react'
|
|
22
20
|
import type { Customer } from '@thorprovider/types'
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
logoutAction,
|
|
28
|
-
registerAction,
|
|
29
|
-
} from '../../actions'
|
|
21
|
+
import { loadOrdersPageAction } from '../../actions'
|
|
22
|
+
import { ACCOUNT_ORDERS_DEFAULT_PAGE_SIZE, accountIdentityKey } from '../../account-private.core'
|
|
23
|
+
import { AccountBoundary } from '../../account-boundary.client'
|
|
24
|
+
import { useAccountLifecycle } from '../../account-lifecycle.client'
|
|
30
25
|
import type { AccountOrderView } from '../../state.core'
|
|
31
26
|
import type { ViewRegistry } from '../types'
|
|
32
27
|
import {
|
|
@@ -35,39 +30,8 @@ import {
|
|
|
35
30
|
accountRegisterPropsSchema,
|
|
36
31
|
} from './schema'
|
|
37
32
|
|
|
38
|
-
// The structured result the auth Server Actions return (see ../../actions).
|
|
39
|
-
type AuthResult = { ok: true; customer: Customer | null } | { ok: false; error: string }
|
|
40
|
-
type SetState = (path: string, value: unknown) => void
|
|
41
|
-
|
|
42
33
|
/** Bounded page size for the account order-history window. */
|
|
43
|
-
const ORDERS_PAGE_SIZE =
|
|
44
|
-
|
|
45
|
-
// Apply a settled auth result truthfully: a failure sets an error and NEVER a
|
|
46
|
-
// logged-in state; a success stores the customer (or null) and nothing else.
|
|
47
|
-
function applyAuthResult(set: SetState, result: AuthResult): void {
|
|
48
|
-
set('/accountPending', false)
|
|
49
|
-
if (result.ok) {
|
|
50
|
-
set('/accountCustomer', result.customer)
|
|
51
|
-
set('/accountAuthenticated', result.customer !== null)
|
|
52
|
-
set('/accountError', null)
|
|
53
|
-
set('/accountMode', 'login')
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
set('/accountError', result.error)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// A rejected Server Action (network/RPC) must clear pending and surface a
|
|
60
|
-
// message; never swallow it. Only a non-secret context line is logged.
|
|
61
|
-
function authFailure(set: SetState, scope: string) {
|
|
62
|
-
return (error: unknown) => {
|
|
63
|
-
console.error(
|
|
64
|
-
`[storefront/account] ${scope} failed`,
|
|
65
|
-
error instanceof Error ? error.message : error,
|
|
66
|
-
)
|
|
67
|
-
set('/accountPending', false)
|
|
68
|
-
set('/accountError', 'No se pudo completar la operación. Inténtalo de nuevo.')
|
|
69
|
-
}
|
|
70
|
-
}
|
|
34
|
+
const ORDERS_PAGE_SIZE = ACCOUNT_ORDERS_DEFAULT_PAGE_SIZE
|
|
71
35
|
|
|
72
36
|
// Non-secret status surface for the block pages, which expose no error/pending
|
|
73
37
|
// prop of their own. Renders nothing when there is no pending work or error.
|
|
@@ -84,6 +48,24 @@ function AuthNotice({ pending, error }: { pending: boolean; error: string | null
|
|
|
84
48
|
)
|
|
85
49
|
}
|
|
86
50
|
|
|
51
|
+
// Neutral pending surface shown while a cross-tab/foreground reconciliation is
|
|
52
|
+
// in flight (task 4.2). It replaces the previously held identity/orders so no
|
|
53
|
+
// stale private data is presented as current during the server round-trip; it
|
|
54
|
+
// is NOT a signed-out or unavailable state, and the held data is never
|
|
55
|
+
// destroyed (a same-identity re-resolution re-presents it without a refetch).
|
|
56
|
+
function ReconcilingStatus() {
|
|
57
|
+
return (
|
|
58
|
+
<p
|
|
59
|
+
role="status"
|
|
60
|
+
aria-live="polite"
|
|
61
|
+
data-account-reconciling="1"
|
|
62
|
+
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
63
|
+
>
|
|
64
|
+
Actualizando tu cuenta…
|
|
65
|
+
</p>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
87
69
|
// The OrderHistory2 block's order shape (see @thorprovider/blocks). Kept local
|
|
88
70
|
// so the registry maps the account order rows to the block contract without a
|
|
89
71
|
// shared dependency on block internals.
|
|
@@ -126,8 +108,10 @@ function toBlockOrder(order: AccountOrderView): BlockOrder {
|
|
|
126
108
|
}
|
|
127
109
|
|
|
128
110
|
// Inline order detail assembled from the already-fetched list row (no second
|
|
129
|
-
// backend request). Only fields the backend supplied are shown.
|
|
130
|
-
|
|
111
|
+
// backend request). Only fields the backend supplied are shown. `onClose` clears
|
|
112
|
+
// the selection so the detail is dismissible (a real open/close cycle, no
|
|
113
|
+
// navigation and no second destination).
|
|
114
|
+
function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: () => void }) {
|
|
131
115
|
const totals = (
|
|
132
116
|
[
|
|
133
117
|
{ label: 'Subtotal', value: order.subtotal },
|
|
@@ -139,10 +123,17 @@ function OrderDetail({ order }: { order: AccountOrderView }) {
|
|
|
139
123
|
return (
|
|
140
124
|
<div className="mx-auto w-full max-w-7xl px-4 pb-12 sm:px-6 lg:px-8">
|
|
141
125
|
<div className="rounded-lg border p-6">
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
126
|
+
<div className="flex items-start justify-between gap-4">
|
|
127
|
+
<div>
|
|
128
|
+
<h3 className="text-lg font-semibold">Pedido {order.number}</h3>
|
|
129
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
130
|
+
{order.date} · {order.status}
|
|
131
|
+
</p>
|
|
132
|
+
</div>
|
|
133
|
+
<Button type="button" variant="outline" size="sm" onClick={onClose}>
|
|
134
|
+
Cerrar
|
|
135
|
+
</Button>
|
|
136
|
+
</div>
|
|
146
137
|
{order.address ? (
|
|
147
138
|
<p className="text-muted-foreground mt-2 text-sm">{order.address}</p>
|
|
148
139
|
) : null}
|
|
@@ -175,107 +166,93 @@ function OrderDetail({ order }: { order: AccountOrderView }) {
|
|
|
175
166
|
|
|
176
167
|
export const registry: ViewRegistry = {
|
|
177
168
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
169
|
+
* Passive account boundary. It renders only the retryable "unavailable"
|
|
170
|
+
* status (via the shared lifecycle's `retryAccountSession` action) and NEVER
|
|
171
|
+
* fetches or owns identity on mount: the shared lifecycle/SSR seed already
|
|
172
|
+
* supplies the account state on every route, so `/account` introduces no
|
|
173
|
+
* competing identity bootstrap or mount race.
|
|
181
174
|
*/
|
|
182
|
-
AccountBoot: () => {
|
|
183
|
-
const { set } = useStateStore()
|
|
184
|
-
const booted = useRef(false)
|
|
185
|
-
useEffect(() => {
|
|
186
|
-
if (booted.current) return
|
|
187
|
-
booted.current = true
|
|
188
|
-
void loadAccountAction()
|
|
189
|
-
.then((result) => {
|
|
190
|
-
if (!result.ok) {
|
|
191
|
-
set('/accountCustomer', null)
|
|
192
|
-
set('/accountAuthenticated', false)
|
|
193
|
-
set('/accountError', result.error)
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
set('/accountCustomer', result.customer)
|
|
197
|
-
set('/accountAuthenticated', result.customer !== null)
|
|
198
|
-
set('/accountError', null)
|
|
199
|
-
})
|
|
200
|
-
.catch((error) => {
|
|
201
|
-
console.error(
|
|
202
|
-
'[storefront/account] loadAccount failed',
|
|
203
|
-
error instanceof Error ? error.message : error,
|
|
204
|
-
)
|
|
205
|
-
set('/accountCustomer', null)
|
|
206
|
-
set('/accountAuthenticated', false)
|
|
207
|
-
set('/accountError', 'No se pudo cargar la cuenta. Inténtalo de nuevo.')
|
|
208
|
-
})
|
|
209
|
-
}, [])
|
|
210
|
-
return null
|
|
211
|
-
},
|
|
175
|
+
AccountBoot: ({ emit }) => <AccountBoundary emit={emit} />,
|
|
212
176
|
AccountLogin: ({ props, emit }) => {
|
|
213
|
-
const { state
|
|
177
|
+
const { state } = useStateStore()
|
|
178
|
+
const lifecycle = useAccountLifecycle()
|
|
214
179
|
const parsed = accountLoginPropsSchema.parse(props)
|
|
215
180
|
const error = typeof state.accountError === 'string' ? state.accountError : null
|
|
216
181
|
const pending = Boolean(state.accountPending)
|
|
217
182
|
return (
|
|
218
183
|
<>
|
|
219
184
|
<AuthNotice pending={pending} error={error} />
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
185
|
+
{/* The block exposes no pending/disabled prop, so the registry disables
|
|
186
|
+
the whole form natively while a mutation is pending: a disabled
|
|
187
|
+
fieldset freezes the submit control and the inputs without clearing
|
|
188
|
+
them, and `display: contents` leaves the layout untouched. The
|
|
189
|
+
shared lifecycle also drops a same-tick duplicate before React
|
|
190
|
+
re-renders, so no duplicate request is issued in the interim. */}
|
|
191
|
+
<fieldset disabled={pending} aria-busy={pending} className="contents">
|
|
192
|
+
<LoginBlock
|
|
193
|
+
logoText={parsed.logoText}
|
|
194
|
+
welcomeTitleLabel={parsed.welcomeTitleLabel}
|
|
195
|
+
welcomeDescriptionLabel={parsed.welcomeDescriptionLabel}
|
|
196
|
+
emailLabel={parsed.emailLabel}
|
|
197
|
+
passwordLabel={parsed.passwordLabel}
|
|
198
|
+
signInLabel={parsed.signInLabel}
|
|
199
|
+
createAccountLabel={parsed.createAccountLabel}
|
|
200
|
+
// The credentials stay in the block's local state and go straight to
|
|
201
|
+
// the shared lifecycle (which calls the Server Action); they are never
|
|
202
|
+
// written to the store. The lifecycle owns pending/error, the
|
|
203
|
+
// generation guard, duplicate prevention, and the server refresh, so
|
|
204
|
+
// the mounted form is never remounted and its input survives a failure.
|
|
205
|
+
onSubmit={(data) => {
|
|
206
|
+
void lifecycle.login({ email: data.email, password: data.password })
|
|
207
|
+
}}
|
|
208
|
+
onCreateAccount={() => emit('showRegister')}
|
|
209
|
+
/>
|
|
210
|
+
</fieldset>
|
|
239
211
|
</>
|
|
240
212
|
)
|
|
241
213
|
},
|
|
242
214
|
AccountRegister: ({ props, emit }) => {
|
|
243
|
-
const { state
|
|
215
|
+
const { state } = useStateStore()
|
|
216
|
+
const lifecycle = useAccountLifecycle()
|
|
244
217
|
const parsed = accountRegisterPropsSchema.parse(props)
|
|
245
218
|
const error = typeof state.accountError === 'string' ? state.accountError : null
|
|
246
219
|
const pending = Boolean(state.accountPending)
|
|
247
220
|
return (
|
|
248
221
|
<>
|
|
249
222
|
<AuthNotice pending={pending} error={error} />
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
223
|
+
{/* Same native pending-disable as the login form (the block exposes no
|
|
224
|
+
pending prop); input values persist across a failed mutation. */}
|
|
225
|
+
<fieldset disabled={pending} aria-busy={pending} className="contents">
|
|
226
|
+
<SignUpBlock
|
|
227
|
+
logoText={parsed.logoText}
|
|
228
|
+
createAccountTitleLabel={parsed.createAccountTitleLabel}
|
|
229
|
+
createAccountDescriptionLabel={parsed.createAccountDescriptionLabel}
|
|
230
|
+
fullNameLabel={parsed.fullNameLabel}
|
|
231
|
+
emailLabel={parsed.emailLabel}
|
|
232
|
+
passwordLabel={parsed.passwordLabel}
|
|
233
|
+
createAccountLabel={parsed.createAccountLabel}
|
|
234
|
+
signInLabel={parsed.signInLabel}
|
|
235
|
+
onSubmit={(data) => {
|
|
236
|
+
const parts = data.fullName.trim().split(/\s+/).filter(Boolean)
|
|
237
|
+
void lifecycle.register({
|
|
238
|
+
email: data.email,
|
|
239
|
+
password: data.password,
|
|
240
|
+
firstName: parts[0] ?? '',
|
|
241
|
+
lastName: parts.slice(1).join(' '),
|
|
242
|
+
})
|
|
243
|
+
}}
|
|
244
|
+
onSignIn={() => emit('showLogin')}
|
|
245
|
+
/>
|
|
246
|
+
</fieldset>
|
|
274
247
|
</>
|
|
275
248
|
)
|
|
276
249
|
},
|
|
277
250
|
AccountPanel: ({ emit }) => {
|
|
278
251
|
const { state } = useStateStore()
|
|
252
|
+
const { reconciling } = useAccountLifecycle()
|
|
253
|
+
// A reconciliation in flight hides the held identity rather than presenting
|
|
254
|
+
// it as current (task 4.2); the panel stays mounted so nothing is destroyed.
|
|
255
|
+
if (reconciling) return <ReconcilingStatus />
|
|
279
256
|
const customer = (state.accountCustomer ?? null) as Customer | null
|
|
280
257
|
const error = typeof state.accountError === 'string' ? state.accountError : null
|
|
281
258
|
const pending = Boolean(state.accountPending)
|
|
@@ -300,24 +277,78 @@ export const registry: ViewRegistry = {
|
|
|
300
277
|
)
|
|
301
278
|
},
|
|
302
279
|
/**
|
|
303
|
-
* Signed-in order history
|
|
304
|
-
* Server Action; later pages load on
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
280
|
+
* Signed-in order history, scoped to the CURRENT shopper identity. The first
|
|
281
|
+
* page loads from the cookie-authorized Server Action; later pages load on
|
|
282
|
+
* demand, each scoped to the authenticated customer's channel. Loading is keyed
|
|
283
|
+
* by the shared lifecycle's `identityKey` (customer id, or `anonymous`) plus a
|
|
284
|
+
* per-component generation:
|
|
285
|
+
*
|
|
286
|
+
* - the first-page effect reloads on an identity CHANGE (a boolean flag
|
|
287
|
+
* cannot detect a customer switch) and lazy-loads only on `/account`;
|
|
288
|
+
* - every `loadPage` captures the live key/generation at request time and
|
|
289
|
+
* discards its result if either changed, so a previous customer's rows,
|
|
290
|
+
* count, page, selection, or detail never reappear;
|
|
291
|
+
* - the private STORE slice is cleared by the shared lifecycle write path
|
|
292
|
+
* (`claimAccount`) AT the trigger, not by this view, so it is cleared even
|
|
293
|
+
* when the panel unmounts (logout/expiry/unavailable); this view only
|
|
294
|
+
* HIDES rows whose key is not the current identity until the new
|
|
295
|
+
* identity's page lands (a render guard, never the clear mechanism).
|
|
296
|
+
*
|
|
297
|
+
* The backend's real `count` drives pagination, so a page length is never
|
|
298
|
+
* presented as the total. Selection is keyed by the REAL backend order id (via
|
|
299
|
+
* a number→id map) and the detail is assembled from the fetched row; the
|
|
300
|
+
* selection id survives paging (returning to the order's page reopens it) and
|
|
301
|
+
* is dismissible with the inline close control. A failed page load shows an
|
|
302
|
+
* actionable retry that re-runs the SAME page (never a fabricated empty
|
|
303
|
+
* history). No token is read, stored, or rendered here.
|
|
309
304
|
*/
|
|
310
305
|
AccountOrders: ({ props }) => {
|
|
311
|
-
const { state, set } = useStateStore()
|
|
306
|
+
const { state, set, getSnapshot } = useStateStore()
|
|
312
307
|
const parsed = accountOrdersPropsSchema.parse(props)
|
|
313
|
-
const
|
|
314
|
-
|
|
308
|
+
const { identityKey, reconciling } = useAccountLifecycle()
|
|
309
|
+
|
|
310
|
+
// Bumped on every identity change so a response from a previous identity — or
|
|
311
|
+
// a previous visit to the same identity — is discarded even if the key later
|
|
312
|
+
// returns.
|
|
313
|
+
const generationRef = useRef(0)
|
|
314
|
+
// The identity key the currently DISPLAYED rows belong to; null until a load
|
|
315
|
+
// for the current identity succeeds. A render whose key differs hides the
|
|
316
|
+
// rows immediately, so a previous customer's orders never paint after the
|
|
317
|
+
// identity changes, before the shared clear even runs.
|
|
318
|
+
const loadedKeyRef = useRef<string | null>(null)
|
|
319
|
+
// The page of the MOST RECENT request (not the last successful one), so the
|
|
320
|
+
// error-state retry re-runs the exact page the shopper asked for — including
|
|
321
|
+
// a failed next/prev page. Local to the panel: an identity change unmounts it
|
|
322
|
+
// (the `/accountAuthenticated` gate), so it never leaks across shoppers.
|
|
323
|
+
const requestedPageRef = useRef(1)
|
|
324
|
+
|
|
325
|
+
// Read the LIVE identity key from the store so an async response can discard
|
|
326
|
+
// itself even if this component has since re-rendered or unmounted: the store
|
|
327
|
+
// outlives the component, unlike a render closure.
|
|
328
|
+
const currentIdentityKey = useCallback(
|
|
329
|
+
() =>
|
|
330
|
+
accountIdentityKey(
|
|
331
|
+
(getSnapshot().accountCustomer ?? null) as { id?: string | null } | null,
|
|
332
|
+
),
|
|
333
|
+
[getSnapshot],
|
|
334
|
+
)
|
|
315
335
|
|
|
316
336
|
const loadPage = (page: number) => {
|
|
337
|
+
// Capture the identity key + generation BEFORE the request; the response is
|
|
338
|
+
// discarded if either changed while it was in flight.
|
|
339
|
+
const capturedKey = currentIdentityKey()
|
|
340
|
+
const capturedGeneration = generationRef.current
|
|
341
|
+
requestedPageRef.current = page
|
|
317
342
|
set('/accountOrdersPending', true)
|
|
318
343
|
set('/accountOrdersError', null)
|
|
319
344
|
void loadOrdersPageAction({ page, pageSize: ORDERS_PAGE_SIZE })
|
|
320
345
|
.then((result) => {
|
|
346
|
+
if (
|
|
347
|
+
currentIdentityKey() !== capturedKey ||
|
|
348
|
+
generationRef.current !== capturedGeneration
|
|
349
|
+
) {
|
|
350
|
+
return
|
|
351
|
+
}
|
|
321
352
|
set('/accountOrdersPending', false)
|
|
322
353
|
if (result.ok) {
|
|
323
354
|
set('/accountOrders', result.orders)
|
|
@@ -325,11 +356,18 @@ export const registry: ViewRegistry = {
|
|
|
325
356
|
set('/accountOrdersPage', page)
|
|
326
357
|
set('/accountOrdersPageSize', result.limit)
|
|
327
358
|
set('/accountOrdersError', null)
|
|
359
|
+
loadedKeyRef.current = capturedKey
|
|
328
360
|
return
|
|
329
361
|
}
|
|
330
362
|
set('/accountOrdersError', result.error)
|
|
331
363
|
})
|
|
332
364
|
.catch((error) => {
|
|
365
|
+
if (
|
|
366
|
+
currentIdentityKey() !== capturedKey ||
|
|
367
|
+
generationRef.current !== capturedGeneration
|
|
368
|
+
) {
|
|
369
|
+
return
|
|
370
|
+
}
|
|
333
371
|
console.error(
|
|
334
372
|
'[storefront/account] loadOrders failed',
|
|
335
373
|
error instanceof Error ? error.message : error,
|
|
@@ -340,24 +378,33 @@ export const registry: ViewRegistry = {
|
|
|
340
378
|
}
|
|
341
379
|
|
|
342
380
|
useEffect(() => {
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
//
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
381
|
+
// On a real identity CHANGE, bump the generation (discarding the previous
|
|
382
|
+
// identity's in-flight page) and forget the displayed key, then load page
|
|
383
|
+
// 1 for the new identity. The private STORE slice is cleared by the shared
|
|
384
|
+
// lifecycle write path (`claimAccount`) at the trigger — NOT here — so the
|
|
385
|
+
// reset already happened even when this panel was unmounted (logout /
|
|
386
|
+
// expiry / unavailable). This effect only drives the fetch; a
|
|
387
|
+
// same-identity re-resolution leaves `identityKey` unchanged, so it does
|
|
388
|
+
// not re-run and the rows/selection survive. A guest/unavailable identity
|
|
389
|
+
// never fetches.
|
|
390
|
+
if (loadedKeyRef.current !== identityKey) {
|
|
391
|
+
generationRef.current += 1
|
|
392
|
+
loadedKeyRef.current = null
|
|
349
393
|
}
|
|
350
|
-
if (
|
|
351
|
-
|
|
394
|
+
if (identityKey === 'anonymous') return
|
|
395
|
+
if (loadedKeyRef.current === identityKey) return
|
|
352
396
|
loadPage(1)
|
|
353
397
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
354
|
-
}, [
|
|
398
|
+
}, [identityKey])
|
|
355
399
|
|
|
356
400
|
const pending = Boolean(state.accountOrdersPending)
|
|
357
401
|
const error = typeof state.accountOrdersError === 'string' ? state.accountOrdersError : null
|
|
358
|
-
const
|
|
402
|
+
const allOrders = Array.isArray(state.accountOrders)
|
|
359
403
|
? (state.accountOrders as AccountOrderView[])
|
|
360
404
|
: []
|
|
405
|
+
// Only rows loaded FOR the current identity may display: a stale row set from
|
|
406
|
+
// a previous customer is hidden until the new identity's page lands.
|
|
407
|
+
const orders = loadedKeyRef.current === identityKey ? allOrders : []
|
|
361
408
|
const count =
|
|
362
409
|
typeof state.accountOrdersCount === 'number' ? state.accountOrdersCount : orders.length
|
|
363
410
|
const page = typeof state.accountOrdersPage === 'number' ? state.accountOrdersPage : 1
|
|
@@ -372,23 +419,53 @@ export const registry: ViewRegistry = {
|
|
|
372
419
|
// The block row carries the display number; resolve it back to the backend id.
|
|
373
420
|
const backendIdByBlockId = new Map(orders.map((order) => [order.number, order.id]))
|
|
374
421
|
|
|
422
|
+
// A reconciliation in flight (task 4.2) hides the held rows rather than
|
|
423
|
+
// presenting them as current. This component stays MOUNTED (its `loadedKeyRef`
|
|
424
|
+
// and generation survive), so a same-identity re-resolution re-presents the
|
|
425
|
+
// held rows after settle WITHOUT a refetch; an identity change still clears
|
|
426
|
+
// through the claim write path.
|
|
427
|
+
if (reconciling) {
|
|
428
|
+
return <ReconcilingStatus />
|
|
429
|
+
}
|
|
375
430
|
if (pending) {
|
|
376
431
|
return (
|
|
377
|
-
<p
|
|
432
|
+
<p
|
|
433
|
+
role="status"
|
|
434
|
+
aria-live="polite"
|
|
435
|
+
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
436
|
+
>
|
|
378
437
|
{parsed.loadingLabel ?? 'Cargando pedidos…'}
|
|
379
438
|
</p>
|
|
380
439
|
)
|
|
381
440
|
}
|
|
382
441
|
if (error) {
|
|
442
|
+
// A failed load is NOT an empty history: the error is announced and the
|
|
443
|
+
// shopper gets an actionable retry that re-runs the page that failed (a
|
|
444
|
+
// button, never inert text). No token, no direct HTTP — the retry calls the
|
|
445
|
+
// same cookie-authorized Server Action as the initial load.
|
|
383
446
|
return (
|
|
384
|
-
<
|
|
385
|
-
|
|
386
|
-
|
|
447
|
+
<div className="mx-auto flex w-full max-w-7xl flex-col items-start gap-3 px-4 py-8 sm:px-6 lg:px-8">
|
|
448
|
+
<p role="alert" className="text-destructive text-sm">
|
|
449
|
+
{error}
|
|
450
|
+
</p>
|
|
451
|
+
<Button
|
|
452
|
+
type="button"
|
|
453
|
+
variant="outline"
|
|
454
|
+
size="sm"
|
|
455
|
+
disabled={pending}
|
|
456
|
+
onClick={() => loadPage(requestedPageRef.current)}
|
|
457
|
+
>
|
|
458
|
+
Reintentar
|
|
459
|
+
</Button>
|
|
460
|
+
</div>
|
|
387
461
|
)
|
|
388
462
|
}
|
|
389
463
|
if (orders.length === 0) {
|
|
390
464
|
return (
|
|
391
|
-
<p
|
|
465
|
+
<p
|
|
466
|
+
role="status"
|
|
467
|
+
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
468
|
+
>
|
|
392
469
|
{parsed.emptyLabel ?? 'Aún no tienes pedidos.'}
|
|
393
470
|
</p>
|
|
394
471
|
)
|
|
@@ -432,7 +509,9 @@ export const registry: ViewRegistry = {
|
|
|
432
509
|
</div>
|
|
433
510
|
</div>
|
|
434
511
|
) : null}
|
|
435
|
-
{selected ?
|
|
512
|
+
{selected ? (
|
|
513
|
+
<OrderDetail order={selected} onClose={() => set('/accountSelectedOrderId', null)} />
|
|
514
|
+
) : null}
|
|
436
515
|
</>
|
|
437
516
|
)
|
|
438
517
|
},
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// Thor Commerce view data: cart (user-owned)
|
|
2
|
-
// Pure mapping from the shared host cart state to the
|
|
2
|
+
// Pure mapping from the shared host cart state to the ShoppingCart block props.
|
|
3
3
|
// No React and no server imports so it can be imported from either boundary.
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { ShoppingCartItem } from '@thorprovider/blocks'
|
|
6
6
|
import type { CartLineState } from '../../state'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Maps backend cart lines to the cart block's item shape.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Maps backend cart lines to the cart block's item shape. The block renders the
|
|
10
|
+
* canonical `lineTotal` Money verbatim, so only canonical Money fields are
|
|
11
|
+
* supplied — no legacy numeric `price` placeholder. An absent image is left
|
|
12
|
+
* undefined rather than serialized as "".
|
|
12
13
|
*/
|
|
13
|
-
export const toCartViewItems = (cart: CartLineState[]):
|
|
14
|
+
export const toCartViewItems = (cart: CartLineState[]): ShoppingCartItem[] =>
|
|
14
15
|
cart.map(line => ({
|
|
15
16
|
id: line.id,
|
|
16
17
|
name: line.name,
|
|
17
|
-
price: 0,
|
|
18
18
|
quantity: line.quantity,
|
|
19
19
|
image: line.image,
|
|
20
20
|
variant: line.variant,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
// Thor Commerce view registry: cart
|
|
4
|
-
// Renders the standalone cart review page (page-mode
|
|
4
|
+
// Renders the standalone cart review page (page-mode ShoppingCart) from the
|
|
5
5
|
// shared host cart state. Quantity updates use the ABSOLUTE line quantity keyed
|
|
6
6
|
// by backend line id; removal uses the same line id. Checkout is only offered
|
|
7
7
|
// when the checkout capability is installed and the cart is ready.
|
|
8
8
|
|
|
9
|
-
import { Button
|
|
9
|
+
import { Button } from '@thorprovider/blocks/ui/button'
|
|
10
|
+
import ShoppingCart from '@thorprovider/blocks/blocks/e-commerce/shopping-carts/shopping-cart'
|
|
10
11
|
import { isAvailableMoney } from '@thorprovider/blocks/contracts'
|
|
11
12
|
import { useStateStore } from '@json-render/react'
|
|
12
13
|
import { checkoutAvailable } from '../../composition'
|
|
@@ -49,7 +50,7 @@ export const registry: ViewRegistry = {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
return (
|
|
52
|
-
<
|
|
53
|
+
<ShoppingCart
|
|
53
54
|
presentation='page'
|
|
54
55
|
items={toCartViewItems(cart)}
|
|
55
56
|
promotions={[]}
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
// the client. The search and filter controls are only present because the
|
|
10
10
|
// installed manifest enabled them; the block never adds a second listing.
|
|
11
11
|
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from '@thorprovider/blocks'
|
|
12
|
+
import CategoryFilter2Block from '@thorprovider/blocks/blocks/e-commerce/category-filters/category-filter-2'
|
|
13
|
+
import type {
|
|
14
|
+
CategoryFilter2ActiveFilter,
|
|
15
|
+
CategoryFilter2Filters,
|
|
16
|
+
CategoryFilter2Props,
|
|
17
|
+
} from '@thorprovider/blocks/blocks/e-commerce/category-filters/category-filter-2'
|
|
18
18
|
@@BLOCK_IMPORTS@@@@SECTION_REGISTRY_IMPORTS@@
|
|
19
19
|
import { buildCategoryQueryHref, catalogHistoryMode, type CategoryQueryChange } from '@thorprovider/runtime/commerce'
|
|
20
20
|
import type { CatalogFeatureName } from '@thorprovider/runtime/contracts'
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
// the client. The search and filter controls are only present because the
|
|
10
10
|
// installed manifest enabled them; the block never adds a second listing.
|
|
11
11
|
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from '@thorprovider/blocks'
|
|
18
|
-
import { Breadcrumb as BreadcrumbBlock } from '@thorprovider/blocks'
|
|
12
|
+
import CategoryFilter2Block from '@thorprovider/blocks/blocks/e-commerce/category-filters/category-filter-2'
|
|
13
|
+
import type {
|
|
14
|
+
CategoryFilter2ActiveFilter,
|
|
15
|
+
CategoryFilter2Filters,
|
|
16
|
+
CategoryFilter2Props,
|
|
17
|
+
} from '@thorprovider/blocks/blocks/e-commerce/category-filters/category-filter-2'
|
|
18
|
+
import { Breadcrumb as BreadcrumbBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/breadcrumb'
|
|
19
19
|
import { buildCategoryQueryHref, catalogHistoryMode, type CategoryQueryChange } from '@thorprovider/runtime/commerce'
|
|
20
20
|
import type { CatalogFeatureName } from '@thorprovider/runtime/contracts'
|
|
21
21
|
import { useStateStore } from '@json-render/react'
|