@thorprovider/storefront 0.4.0-mvp.2 → 0.5.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 +13 -13
- package/assets/templates/app/app/[[...slug]]/page.tsx +32 -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__/composition.ts +1 -1
- 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 +60 -29
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +83 -15
- package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +3 -5
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +25 -0
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +7 -10
- 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 +26 -19
- package/assets/templates/features/checkout/state.ts +0 -5
- 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 +263 -155
- package/assets/templates/views/account/schema.ts +1 -1
- 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 +2 -2
- package/assets/templates/views/category/assembly/index.skeleton.tsx +11 -7
- package/assets/templates/views/category/assembly/registry.skeleton.tsx +9 -9
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +1 -1
- package/assets/templates/views/category/assembly/slots/filter/CategoryListing/catalog.part +5 -0
- package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/element.part +5 -3
- package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/registry.part +9 -5
- package/assets/templates/views/category/content.ts +2 -1
- package/assets/templates/views/category/index.tsx +19 -13
- package/assets/templates/views/category/props.ts +1 -1
- package/assets/templates/views/category/registry.tsx +19 -15
- package/assets/templates/views/category/schema.ts +48 -21
- package/assets/templates/views/checkout/content.ts +60 -0
- package/assets/templates/views/checkout/props.ts +4 -5
- package/assets/templates/views/checkout/registry.tsx +12 -10
- package/assets/templates/views/checkout/schema.ts +10 -16
- package/assets/templates/views/home/assembly/assembly.json +4 -4
- package/assets/templates/views/home/assembly/index.skeleton.tsx +2 -3
- 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/cards/registry.part +17 -0
- package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → split}/registry.part +6 -2
- 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 -8
- 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/examples/merchandising/category-led.json +1 -1
- package/examples/merchandising/collection-led.json +1 -1
- package/package.json +4 -5
- package/recipes/archetypes.json +39 -43
- package/recipes/catalog.json +212 -202
- package/recipes/catalog.mjs +10 -0
- package/recipes/catalog.schema.json +4 -0
- package/recipes/features.json +5 -5
- package/recipes/recipes.json +137 -43
- package/recipes/sections.json +4 -4
- package/recipes/validate.mjs +21 -4
- package/scripts/candidate.mjs +2 -2
- package/scripts/composers.mjs +2 -2
- package/scripts/file-classes.mjs +10 -0
- package/scripts/logical-controls.mjs +4 -4
- package/scripts/operation-registry.mjs +1 -1
- package/scripts/ownership-conflict.mjs +5 -2
- package/scripts/view-assembly.mjs +12 -4
- package/scripts/view-selection.mjs +1 -1
- package/skills/sf-view-gen/assets/recipes/archetypes.json +39 -43
- package/skills/sf-view-gen/assets/recipes/catalog.json +212 -202
- package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
- package/skills/sf-view-gen/assets/recipes/features.json +5 -5
- package/skills/sf-view-gen/assets/recipes/recipes.json +137 -43
- package/skills/sf-view-gen/assets/recipes/sections.json +4 -4
- 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/schema.testimonials.ts +21 -11
- 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 +2 -8
- package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
- package/skills/sf-view-gen/scripts/validate.mjs +21 -4
- package/assets/templates/views/category/assembly/slots/filter/CategoryFilter2/catalog.part +0 -5
- 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/benefits/Feature2/registry.part +0 -10
- 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,18 @@
|
|
|
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
|
-
|
|
20
|
-
} from '@thorprovider/blocks'
|
|
14
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
15
|
+
import type { ReactNode } from 'react'
|
|
16
|
+
import { Button } from '@thorprovider/blocks/ui/button'
|
|
17
|
+
import { LoginPage } from '@thorprovider/blocks'
|
|
18
|
+
import OrderHistory2 from '@thorprovider/blocks/blocks/e-commerce/order-history/order-history-2'
|
|
19
|
+
import SignUpBlock from '@thorprovider/blocks/blocks/application/signup-forms/signup-page-1'
|
|
21
20
|
import { useStateStore } from '@json-render/react'
|
|
22
21
|
import type { Customer } from '@thorprovider/types'
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
logoutAction,
|
|
28
|
-
registerAction,
|
|
29
|
-
} from '../../actions'
|
|
22
|
+
import { loadOrdersPageAction } from '../../actions'
|
|
23
|
+
import { ACCOUNT_ORDERS_DEFAULT_PAGE_SIZE, accountIdentityKey } from '../../account-private.core'
|
|
24
|
+
import { AccountBoundary } from '../../account-boundary.client'
|
|
25
|
+
import { useAccountLifecycle } from '../../account-lifecycle.client'
|
|
30
26
|
import type { AccountOrderView } from '../../state.core'
|
|
31
27
|
import type { ViewRegistry } from '../types'
|
|
32
28
|
import {
|
|
@@ -35,39 +31,8 @@ import {
|
|
|
35
31
|
accountRegisterPropsSchema,
|
|
36
32
|
} from './schema'
|
|
37
33
|
|
|
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
34
|
/** 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
|
-
}
|
|
35
|
+
const ORDERS_PAGE_SIZE = ACCOUNT_ORDERS_DEFAULT_PAGE_SIZE
|
|
71
36
|
|
|
72
37
|
// Non-secret status surface for the block pages, which expose no error/pending
|
|
73
38
|
// prop of their own. Renders nothing when there is no pending work or error.
|
|
@@ -84,6 +49,46 @@ function AuthNotice({ pending, error }: { pending: boolean; error: string | null
|
|
|
84
49
|
)
|
|
85
50
|
}
|
|
86
51
|
|
|
52
|
+
// The page side of the auth contract. The blocks render only the form: they no
|
|
53
|
+
// longer paint a viewport-height surface, declare a page landmark, or centre
|
|
54
|
+
// themselves, because a generated storefront mounts them inside the default
|
|
55
|
+
// chrome (notice + banner + navbar + footer) and the page — not the block — owns
|
|
56
|
+
// the viewport. This wrapper is the extracted shell, kept so the shopper-visible
|
|
57
|
+
// result of every auth surface is unchanged. It lives in a derived template
|
|
58
|
+
// (CLI-owned) and stays theme-driven: the backdrop uses the same semantic
|
|
59
|
+
// tokens, so dark mode and any preset resolve here too.
|
|
60
|
+
function AuthCanvas({ stack = false, children }: { stack?: boolean; children: ReactNode }) {
|
|
61
|
+
return (
|
|
62
|
+
<section
|
|
63
|
+
className={`from-background to-muted/50 relative isolate flex min-h-dvh w-full items-center justify-center overflow-hidden bg-linear-to-br ${stack ? 'flex-col' : ''}`}
|
|
64
|
+
>
|
|
65
|
+
<div
|
|
66
|
+
className={`relative z-10 container mx-auto flex min-h-dvh items-center justify-center px-4 py-12 ${stack ? 'flex-col' : ''}`}
|
|
67
|
+
>
|
|
68
|
+
{children}
|
|
69
|
+
</div>
|
|
70
|
+
</section>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Neutral pending surface shown while a cross-tab/foreground reconciliation is
|
|
75
|
+
// in flight (task 4.2). It replaces the previously held identity/orders so no
|
|
76
|
+
// stale private data is presented as current during the server round-trip; it
|
|
77
|
+
// is NOT a signed-out or unavailable state, and the held data is never
|
|
78
|
+
// destroyed (a same-identity re-resolution re-presents it without a refetch).
|
|
79
|
+
function ReconcilingStatus() {
|
|
80
|
+
return (
|
|
81
|
+
<p
|
|
82
|
+
role="status"
|
|
83
|
+
aria-live="polite"
|
|
84
|
+
data-account-reconciling="1"
|
|
85
|
+
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
86
|
+
>
|
|
87
|
+
Actualizando tu cuenta…
|
|
88
|
+
</p>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
87
92
|
// The OrderHistory2 block's order shape (see @thorprovider/blocks). Kept local
|
|
88
93
|
// so the registry maps the account order rows to the block contract without a
|
|
89
94
|
// shared dependency on block internals.
|
|
@@ -126,8 +131,10 @@ function toBlockOrder(order: AccountOrderView): BlockOrder {
|
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
// Inline order detail assembled from the already-fetched list row (no second
|
|
129
|
-
// backend request). Only fields the backend supplied are shown.
|
|
130
|
-
|
|
134
|
+
// backend request). Only fields the backend supplied are shown. `onClose` clears
|
|
135
|
+
// the selection so the detail is dismissible (a real open/close cycle, no
|
|
136
|
+
// navigation and no second destination).
|
|
137
|
+
function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: () => void }) {
|
|
131
138
|
const totals = (
|
|
132
139
|
[
|
|
133
140
|
{ label: 'Subtotal', value: order.subtotal },
|
|
@@ -139,10 +146,17 @@ function OrderDetail({ order }: { order: AccountOrderView }) {
|
|
|
139
146
|
return (
|
|
140
147
|
<div className="mx-auto w-full max-w-7xl px-4 pb-12 sm:px-6 lg:px-8">
|
|
141
148
|
<div className="rounded-lg border p-6">
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
<div className="flex items-start justify-between gap-4">
|
|
150
|
+
<div>
|
|
151
|
+
<h3 className="text-lg font-semibold">Pedido {order.number}</h3>
|
|
152
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
153
|
+
{order.date} · {order.status}
|
|
154
|
+
</p>
|
|
155
|
+
</div>
|
|
156
|
+
<Button type="button" variant="outline" size="sm" onClick={onClose}>
|
|
157
|
+
Cerrar
|
|
158
|
+
</Button>
|
|
159
|
+
</div>
|
|
146
160
|
{order.address ? (
|
|
147
161
|
<p className="text-muted-foreground mt-2 text-sm">{order.address}</p>
|
|
148
162
|
) : null}
|
|
@@ -175,107 +189,99 @@ function OrderDetail({ order }: { order: AccountOrderView }) {
|
|
|
175
189
|
|
|
176
190
|
export const registry: ViewRegistry = {
|
|
177
191
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
192
|
+
* Passive account boundary. It renders only the retryable "unavailable"
|
|
193
|
+
* status (via the shared lifecycle's `retryAccountSession` action) and NEVER
|
|
194
|
+
* fetches or owns identity on mount: the shared lifecycle/SSR seed already
|
|
195
|
+
* supplies the account state on every route, so `/account` introduces no
|
|
196
|
+
* competing identity bootstrap or mount race.
|
|
181
197
|
*/
|
|
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
|
-
},
|
|
198
|
+
AccountBoot: ({ emit }) => <AccountBoundary emit={emit} />,
|
|
212
199
|
AccountLogin: ({ props, emit }) => {
|
|
213
|
-
const { state
|
|
200
|
+
const { state } = useStateStore()
|
|
201
|
+
const lifecycle = useAccountLifecycle()
|
|
214
202
|
const parsed = accountLoginPropsSchema.parse(props)
|
|
215
203
|
const error = typeof state.accountError === 'string' ? state.accountError : null
|
|
216
204
|
const pending = Boolean(state.accountPending)
|
|
217
205
|
return (
|
|
218
206
|
<>
|
|
219
207
|
<AuthNotice pending={pending} error={error} />
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
.
|
|
235
|
-
.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
208
|
+
{/* The block exposes no pending/disabled prop, so the registry disables
|
|
209
|
+
the whole form natively while a mutation is pending: a disabled
|
|
210
|
+
fieldset freezes the submit control and the inputs without clearing
|
|
211
|
+
them, and `display: contents` leaves the layout untouched. The
|
|
212
|
+
shared lifecycle also drops a same-tick duplicate before React
|
|
213
|
+
re-renders, so no duplicate request is issued in the interim. */}
|
|
214
|
+
<AuthCanvas>
|
|
215
|
+
<fieldset disabled={pending} aria-busy={pending} className="contents">
|
|
216
|
+
<LoginPage
|
|
217
|
+
presentation="card"
|
|
218
|
+
logoText={parsed.logoText}
|
|
219
|
+
welcomeTitleLabel={parsed.welcomeTitleLabel}
|
|
220
|
+
welcomeDescriptionLabel={parsed.welcomeDescriptionLabel}
|
|
221
|
+
emailLabel={parsed.emailLabel}
|
|
222
|
+
passwordLabel={parsed.passwordLabel}
|
|
223
|
+
signInLabel={parsed.signInLabel}
|
|
224
|
+
createAccountLabel={parsed.createAccountLabel}
|
|
225
|
+
rememberMeLabel="Recuérdame"
|
|
226
|
+
// The credentials stay in the block's local state and go straight to
|
|
227
|
+
// the shared lifecycle (which calls the Server Action); they are never
|
|
228
|
+
// written to the store. The lifecycle owns pending/error, the
|
|
229
|
+
// generation guard, duplicate prevention, and the server refresh, so
|
|
230
|
+
// the mounted form is never remounted and its input survives a failure.
|
|
231
|
+
onSubmit={(data) => {
|
|
232
|
+
void lifecycle.login({ email: data.email, password: data.password })
|
|
233
|
+
}}
|
|
234
|
+
onCreateAccount={() => emit('showRegister')}
|
|
235
|
+
/>
|
|
236
|
+
</fieldset>
|
|
237
|
+
</AuthCanvas>
|
|
239
238
|
</>
|
|
240
239
|
)
|
|
241
240
|
},
|
|
242
241
|
AccountRegister: ({ props, emit }) => {
|
|
243
|
-
const { state
|
|
242
|
+
const { state } = useStateStore()
|
|
243
|
+
const lifecycle = useAccountLifecycle()
|
|
244
244
|
const parsed = accountRegisterPropsSchema.parse(props)
|
|
245
245
|
const error = typeof state.accountError === 'string' ? state.accountError : null
|
|
246
246
|
const pending = Boolean(state.accountPending)
|
|
247
247
|
return (
|
|
248
248
|
<>
|
|
249
249
|
<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
|
-
|
|
250
|
+
{/* Same native pending-disable as the login form (the block exposes no
|
|
251
|
+
pending prop); input values persist across a failed mutation. */}
|
|
252
|
+
<AuthCanvas stack>
|
|
253
|
+
<fieldset disabled={pending} aria-busy={pending} className="contents">
|
|
254
|
+
<SignUpBlock
|
|
255
|
+
logoText={parsed.logoText}
|
|
256
|
+
createAccountTitleLabel={parsed.createAccountTitleLabel}
|
|
257
|
+
createAccountDescriptionLabel={parsed.createAccountDescriptionLabel}
|
|
258
|
+
fullNameLabel={parsed.fullNameLabel}
|
|
259
|
+
emailLabel={parsed.emailLabel}
|
|
260
|
+
passwordLabel={parsed.passwordLabel}
|
|
261
|
+
createAccountLabel={parsed.createAccountLabel}
|
|
262
|
+
signInLabel={parsed.signInLabel}
|
|
263
|
+
onSubmit={(data) => {
|
|
264
|
+
const parts = data.fullName.trim().split(/\s+/).filter(Boolean)
|
|
265
|
+
void lifecycle.register({
|
|
266
|
+
email: data.email,
|
|
267
|
+
password: data.password,
|
|
268
|
+
firstName: parts[0] ?? '',
|
|
269
|
+
lastName: parts.slice(1).join(' '),
|
|
270
|
+
})
|
|
271
|
+
}}
|
|
272
|
+
onSignIn={() => emit('showLogin')}
|
|
273
|
+
/>
|
|
274
|
+
</fieldset>
|
|
275
|
+
</AuthCanvas>
|
|
274
276
|
</>
|
|
275
277
|
)
|
|
276
278
|
},
|
|
277
279
|
AccountPanel: ({ emit }) => {
|
|
278
280
|
const { state } = useStateStore()
|
|
281
|
+
const { reconciling } = useAccountLifecycle()
|
|
282
|
+
// A reconciliation in flight hides the held identity rather than presenting
|
|
283
|
+
// it as current (task 4.2); the panel stays mounted so nothing is destroyed.
|
|
284
|
+
if (reconciling) return <ReconcilingStatus />
|
|
279
285
|
const customer = (state.accountCustomer ?? null) as Customer | null
|
|
280
286
|
const error = typeof state.accountError === 'string' ? state.accountError : null
|
|
281
287
|
const pending = Boolean(state.accountPending)
|
|
@@ -300,24 +306,78 @@ export const registry: ViewRegistry = {
|
|
|
300
306
|
)
|
|
301
307
|
},
|
|
302
308
|
/**
|
|
303
|
-
* Signed-in order history
|
|
304
|
-
* Server Action; later pages load on
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
+
* Signed-in order history, scoped to the CURRENT shopper identity. The first
|
|
310
|
+
* page loads from the cookie-authorized Server Action; later pages load on
|
|
311
|
+
* demand, each scoped to the authenticated customer's channel. Loading is keyed
|
|
312
|
+
* by the shared lifecycle's `identityKey` (customer id, or `anonymous`) plus a
|
|
313
|
+
* per-component generation:
|
|
314
|
+
*
|
|
315
|
+
* - the first-page effect reloads on an identity CHANGE (a boolean flag
|
|
316
|
+
* cannot detect a customer switch) and lazy-loads only on `/account`;
|
|
317
|
+
* - every `loadPage` captures the live key/generation at request time and
|
|
318
|
+
* discards its result if either changed, so a previous customer's rows,
|
|
319
|
+
* count, page, selection, or detail never reappear;
|
|
320
|
+
* - the private STORE slice is cleared by the shared lifecycle write path
|
|
321
|
+
* (`claimAccount`) AT the trigger, not by this view, so it is cleared even
|
|
322
|
+
* when the panel unmounts (logout/expiry/unavailable); this view only
|
|
323
|
+
* HIDES rows whose key is not the current identity until the new
|
|
324
|
+
* identity's page lands (a render guard, never the clear mechanism).
|
|
325
|
+
*
|
|
326
|
+
* The backend's real `count` drives pagination, so a page length is never
|
|
327
|
+
* presented as the total. Selection is keyed by the REAL backend order id (via
|
|
328
|
+
* a number→id map) and the detail is assembled from the fetched row; the
|
|
329
|
+
* selection id survives paging (returning to the order's page reopens it) and
|
|
330
|
+
* is dismissible with the inline close control. A failed page load shows an
|
|
331
|
+
* actionable retry that re-runs the SAME page (never a fabricated empty
|
|
332
|
+
* history). No token is read, stored, or rendered here.
|
|
309
333
|
*/
|
|
310
334
|
AccountOrders: ({ props }) => {
|
|
311
|
-
const { state, set } = useStateStore()
|
|
335
|
+
const { state, set, getSnapshot } = useStateStore()
|
|
312
336
|
const parsed = accountOrdersPropsSchema.parse(props)
|
|
313
|
-
const
|
|
314
|
-
|
|
337
|
+
const { identityKey, reconciling } = useAccountLifecycle()
|
|
338
|
+
|
|
339
|
+
// Bumped on every identity change so a response from a previous identity — or
|
|
340
|
+
// a previous visit to the same identity — is discarded even if the key later
|
|
341
|
+
// returns.
|
|
342
|
+
const generationRef = useRef(0)
|
|
343
|
+
// The identity key the currently DISPLAYED rows belong to; null until a load
|
|
344
|
+
// for the current identity succeeds. A render whose key differs hides the
|
|
345
|
+
// rows immediately, so a previous customer's orders never paint after the
|
|
346
|
+
// identity changes, before the shared clear even runs.
|
|
347
|
+
const loadedKeyRef = useRef<string | null>(null)
|
|
348
|
+
// The page of the MOST RECENT request (not the last successful one), so the
|
|
349
|
+
// error-state retry re-runs the exact page the shopper asked for — including
|
|
350
|
+
// a failed next/prev page. Local to the panel: an identity change unmounts it
|
|
351
|
+
// (the `/accountAuthenticated` gate), so it never leaks across shoppers.
|
|
352
|
+
const requestedPageRef = useRef(1)
|
|
353
|
+
|
|
354
|
+
// Read the LIVE identity key from the store so an async response can discard
|
|
355
|
+
// itself even if this component has since re-rendered or unmounted: the store
|
|
356
|
+
// outlives the component, unlike a render closure.
|
|
357
|
+
const currentIdentityKey = useCallback(
|
|
358
|
+
() =>
|
|
359
|
+
accountIdentityKey(
|
|
360
|
+
(getSnapshot().accountCustomer ?? null) as { id?: string | null } | null,
|
|
361
|
+
),
|
|
362
|
+
[getSnapshot],
|
|
363
|
+
)
|
|
315
364
|
|
|
316
365
|
const loadPage = (page: number) => {
|
|
366
|
+
// Capture the identity key + generation BEFORE the request; the response is
|
|
367
|
+
// discarded if either changed while it was in flight.
|
|
368
|
+
const capturedKey = currentIdentityKey()
|
|
369
|
+
const capturedGeneration = generationRef.current
|
|
370
|
+
requestedPageRef.current = page
|
|
317
371
|
set('/accountOrdersPending', true)
|
|
318
372
|
set('/accountOrdersError', null)
|
|
319
373
|
void loadOrdersPageAction({ page, pageSize: ORDERS_PAGE_SIZE })
|
|
320
374
|
.then((result) => {
|
|
375
|
+
if (
|
|
376
|
+
currentIdentityKey() !== capturedKey ||
|
|
377
|
+
generationRef.current !== capturedGeneration
|
|
378
|
+
) {
|
|
379
|
+
return
|
|
380
|
+
}
|
|
321
381
|
set('/accountOrdersPending', false)
|
|
322
382
|
if (result.ok) {
|
|
323
383
|
set('/accountOrders', result.orders)
|
|
@@ -325,11 +385,18 @@ export const registry: ViewRegistry = {
|
|
|
325
385
|
set('/accountOrdersPage', page)
|
|
326
386
|
set('/accountOrdersPageSize', result.limit)
|
|
327
387
|
set('/accountOrdersError', null)
|
|
388
|
+
loadedKeyRef.current = capturedKey
|
|
328
389
|
return
|
|
329
390
|
}
|
|
330
391
|
set('/accountOrdersError', result.error)
|
|
331
392
|
})
|
|
332
393
|
.catch((error) => {
|
|
394
|
+
if (
|
|
395
|
+
currentIdentityKey() !== capturedKey ||
|
|
396
|
+
generationRef.current !== capturedGeneration
|
|
397
|
+
) {
|
|
398
|
+
return
|
|
399
|
+
}
|
|
333
400
|
console.error(
|
|
334
401
|
'[storefront/account] loadOrders failed',
|
|
335
402
|
error instanceof Error ? error.message : error,
|
|
@@ -340,24 +407,33 @@ export const registry: ViewRegistry = {
|
|
|
340
407
|
}
|
|
341
408
|
|
|
342
409
|
useEffect(() => {
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
//
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
410
|
+
// On a real identity CHANGE, bump the generation (discarding the previous
|
|
411
|
+
// identity's in-flight page) and forget the displayed key, then load page
|
|
412
|
+
// 1 for the new identity. The private STORE slice is cleared by the shared
|
|
413
|
+
// lifecycle write path (`claimAccount`) at the trigger — NOT here — so the
|
|
414
|
+
// reset already happened even when this panel was unmounted (logout /
|
|
415
|
+
// expiry / unavailable). This effect only drives the fetch; a
|
|
416
|
+
// same-identity re-resolution leaves `identityKey` unchanged, so it does
|
|
417
|
+
// not re-run and the rows/selection survive. A guest/unavailable identity
|
|
418
|
+
// never fetches.
|
|
419
|
+
if (loadedKeyRef.current !== identityKey) {
|
|
420
|
+
generationRef.current += 1
|
|
421
|
+
loadedKeyRef.current = null
|
|
349
422
|
}
|
|
350
|
-
if (
|
|
351
|
-
|
|
423
|
+
if (identityKey === 'anonymous') return
|
|
424
|
+
if (loadedKeyRef.current === identityKey) return
|
|
352
425
|
loadPage(1)
|
|
353
426
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
354
|
-
}, [
|
|
427
|
+
}, [identityKey])
|
|
355
428
|
|
|
356
429
|
const pending = Boolean(state.accountOrdersPending)
|
|
357
430
|
const error = typeof state.accountOrdersError === 'string' ? state.accountOrdersError : null
|
|
358
|
-
const
|
|
431
|
+
const allOrders = Array.isArray(state.accountOrders)
|
|
359
432
|
? (state.accountOrders as AccountOrderView[])
|
|
360
433
|
: []
|
|
434
|
+
// Only rows loaded FOR the current identity may display: a stale row set from
|
|
435
|
+
// a previous customer is hidden until the new identity's page lands.
|
|
436
|
+
const orders = loadedKeyRef.current === identityKey ? allOrders : []
|
|
361
437
|
const count =
|
|
362
438
|
typeof state.accountOrdersCount === 'number' ? state.accountOrdersCount : orders.length
|
|
363
439
|
const page = typeof state.accountOrdersPage === 'number' ? state.accountOrdersPage : 1
|
|
@@ -372,23 +448,53 @@ export const registry: ViewRegistry = {
|
|
|
372
448
|
// The block row carries the display number; resolve it back to the backend id.
|
|
373
449
|
const backendIdByBlockId = new Map(orders.map((order) => [order.number, order.id]))
|
|
374
450
|
|
|
451
|
+
// A reconciliation in flight (task 4.2) hides the held rows rather than
|
|
452
|
+
// presenting them as current. This component stays MOUNTED (its `loadedKeyRef`
|
|
453
|
+
// and generation survive), so a same-identity re-resolution re-presents the
|
|
454
|
+
// held rows after settle WITHOUT a refetch; an identity change still clears
|
|
455
|
+
// through the claim write path.
|
|
456
|
+
if (reconciling) {
|
|
457
|
+
return <ReconcilingStatus />
|
|
458
|
+
}
|
|
375
459
|
if (pending) {
|
|
376
460
|
return (
|
|
377
|
-
<p
|
|
461
|
+
<p
|
|
462
|
+
role="status"
|
|
463
|
+
aria-live="polite"
|
|
464
|
+
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
465
|
+
>
|
|
378
466
|
{parsed.loadingLabel ?? 'Cargando pedidos…'}
|
|
379
467
|
</p>
|
|
380
468
|
)
|
|
381
469
|
}
|
|
382
470
|
if (error) {
|
|
471
|
+
// A failed load is NOT an empty history: the error is announced and the
|
|
472
|
+
// shopper gets an actionable retry that re-runs the page that failed (a
|
|
473
|
+
// button, never inert text). No token, no direct HTTP — the retry calls the
|
|
474
|
+
// same cookie-authorized Server Action as the initial load.
|
|
383
475
|
return (
|
|
384
|
-
<
|
|
385
|
-
|
|
386
|
-
|
|
476
|
+
<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">
|
|
477
|
+
<p role="alert" className="text-destructive text-sm">
|
|
478
|
+
{error}
|
|
479
|
+
</p>
|
|
480
|
+
<Button
|
|
481
|
+
type="button"
|
|
482
|
+
variant="outline"
|
|
483
|
+
size="sm"
|
|
484
|
+
disabled={pending}
|
|
485
|
+
onClick={() => loadPage(requestedPageRef.current)}
|
|
486
|
+
>
|
|
487
|
+
Reintentar
|
|
488
|
+
</Button>
|
|
489
|
+
</div>
|
|
387
490
|
)
|
|
388
491
|
}
|
|
389
492
|
if (orders.length === 0) {
|
|
390
493
|
return (
|
|
391
|
-
<p
|
|
494
|
+
<p
|
|
495
|
+
role="status"
|
|
496
|
+
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
497
|
+
>
|
|
392
498
|
{parsed.emptyLabel ?? 'Aún no tienes pedidos.'}
|
|
393
499
|
</p>
|
|
394
500
|
)
|
|
@@ -432,7 +538,9 @@ export const registry: ViewRegistry = {
|
|
|
432
538
|
</div>
|
|
433
539
|
</div>
|
|
434
540
|
) : null}
|
|
435
|
-
{selected ?
|
|
541
|
+
{selected ? (
|
|
542
|
+
<OrderDetail order={selected} onClose={() => set('/accountSelectedOrderId', null)} />
|
|
543
|
+
) : null}
|
|
436
544
|
</>
|
|
437
545
|
)
|
|
438
546
|
},
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { z } from 'zod'
|
|
11
11
|
|
|
12
|
-
// Mirrors the
|
|
12
|
+
// Mirrors the canonical LoginPage optional props. Every prop is optional with a neutral
|
|
13
13
|
// default in the block, so the curated view forwards only the labels it owns.
|
|
14
14
|
export const accountLoginPropsSchema = z.object({
|
|
15
15
|
logoText: z.string().optional(),
|
|
@@ -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={[]}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"view": "category",
|
|
3
3
|
"slots": [
|
|
4
4
|
{ "id": "category.breadcrumb", "slot": "breadcrumb", "default": "Breadcrumb" },
|
|
5
|
-
{ "id": "category.filter", "slot": "filter", "default": "
|
|
5
|
+
{ "id": "category.filter", "slot": "filter", "default": "CategoryListing" },
|
|
6
6
|
{
|
|
7
7
|
"id": "category.productCard",
|
|
8
8
|
"slot": "productCard",
|
|
9
|
-
"default": "
|
|
9
|
+
"default": "ProductGrid",
|
|
10
10
|
"nested": true
|
|
11
11
|
}
|
|
12
12
|
],
|