@ecomiq/storefront 2.1.3 → 3.0.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/LICENSE +21 -0
- package/README.md +150 -123
- package/dist/account-Dx4e3syi.js +258 -0
- package/dist/account-forms-AVk71ko7.js +39 -0
- package/dist/account-forms.d.ts +13 -0
- package/dist/account.d.ts +240 -0
- package/dist/address-defaults-BqjRhS82.js +14 -0
- package/dist/address-defaults.d.ts +11 -0
- package/dist/analytics/analytics-CG1Qagwl.js +148 -0
- package/dist/analytics/analytics.d.ts +1 -0
- package/dist/analytics/config-DJr-GRhs.js +62 -0
- package/dist/analytics/config.d.ts +22 -0
- package/dist/analytics/consent-B13rBpBs.js +57 -0
- package/dist/analytics/consent-banner-9QvRRy8v.js +239 -0
- package/dist/analytics/consent-banner.d.ts +20 -0
- package/dist/analytics/cookies-pLozllyB.js +100 -0
- package/dist/analytics/cookies.d.ts +6 -0
- package/dist/analytics/destinations-iECrlLIr.js +144 -0
- package/dist/analytics/events-Dt81tIp1.js +102 -0
- package/dist/analytics/events.d.ts +51 -0
- package/dist/analytics/tracker-p4yaoOyk.js +51 -0
- package/dist/api-cache-DsuIn5hX.js +159 -0
- package/dist/bank-accounts-DlEczQQ5.js +81 -0
- package/dist/bank-accounts.d.ts +4 -0
- package/dist/captcha-DAqaIx8m.js +117 -0
- package/dist/captcha.d.ts +34 -0
- package/dist/cart-D7DxZ2lD.js +30 -0
- package/dist/cart-actions-Bsub_FFG.js +116 -0
- package/dist/cart-actions.d.ts +15 -0
- package/dist/cart-drawer-B7PPsR69.js +22 -0
- package/dist/cart-drawer.d.ts +9 -0
- package/dist/cart-form-y9P1r_EX.js +81 -0
- package/dist/cart-form.d.ts +24 -0
- package/dist/cart-summary-ur2VWKr-.js +89 -0
- package/dist/cart-summary.d.ts +31 -0
- package/dist/cart.d.ts +4 -0
- package/dist/catalog-7gJ-l5hW.js +67 -0
- package/dist/catalog-hooks-B7ZP4wYY.js +312 -0
- package/dist/catalog-hooks.d.ts +111 -0
- package/dist/catalog.d.ts +5 -0
- package/dist/checkout-DVWSXANi.js +474 -0
- package/dist/checkout-form-CbOIdENC.js +131 -0
- package/dist/checkout-form.d.ts +20 -0
- package/dist/checkout.d.ts +86 -0
- package/dist/complaint-book-BvwLvfx0.js +117 -0
- package/dist/complaint-book.d.ts +62 -0
- package/dist/culqi-authentication-BGr20vAJ.js +204 -0
- package/dist/culqi-authentication.d.ts +15 -0
- package/dist/culqi-checkout-CTXpKgp_.js +55 -0
- package/dist/culqi-three-ds-HP3mfrvV.js +33 -0
- package/dist/culqi-three-ds.d.ts +29 -0
- package/dist/customer-avatar-CJXSDroK.js +12 -0
- package/dist/customer-avatar.d.ts +5 -0
- package/dist/customer-cookies-DHOgFAMV.js +45 -0
- package/dist/customer-csrf-C1oDX-Py.js +17 -0
- package/dist/customer-csrf.d.ts +3 -0
- package/dist/customer-document-fields-C1K-_DAD.js +70 -0
- package/dist/customer-document-fields.d.ts +9 -0
- package/dist/customer-login-form-C7AC6vXd.js +144 -0
- package/dist/customer-login-form.d.ts +17 -0
- package/dist/customer-registration-form-BEm_NEfP.js +93 -0
- package/dist/customer-registration-form.d.ts +8 -0
- package/dist/document-url-CGsAl5Tf.js +9 -0
- package/dist/documents-T1mzc_j8.js +38 -0
- package/dist/documents.d.ts +16 -0
- package/dist/entries/account.d.ts +11 -0
- package/dist/entries/account.js +10 -0
- package/dist/entries/analytics.d.ts +6 -0
- package/dist/entries/analytics.js +5 -0
- package/dist/entries/cart.d.ts +8 -0
- package/dist/entries/cart.js +7 -0
- package/dist/entries/checkout.d.ts +12 -0
- package/dist/entries/checkout.js +11 -0
- package/dist/entries/order.d.ts +11 -0
- package/dist/entries/order.js +11 -0
- package/dist/favicon-YpyhVJ9H.js +28 -0
- package/dist/favicon.d.ts +4 -0
- package/dist/form-BtQcbXlJ.js +18 -0
- package/dist/form-contracts-BNpHaTGJ.js +166 -0
- package/dist/form-contracts.d.ts +42 -0
- package/dist/form.d.ts +3 -0
- package/dist/hidden-CCWtOWKR.js +3 -0
- package/dist/hidden.d.ts +4 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +50 -0
- package/dist/invoice-fields-BG0HjL6T.js +103 -0
- package/dist/invoice-fields.d.ts +39 -0
- package/dist/links-kFxBZfdb.js +96 -0
- package/dist/links.d.ts +21 -0
- package/dist/mercadopago-checkout-DC7RXa8k.js +27 -0
- package/dist/mercadopago-dialog-UTQev0MG.js +180 -0
- package/dist/mercadopago-dialog.d.ts +21 -0
- package/dist/money-DtGOtDri.js +32 -0
- package/dist/money.d.ts +1 -0
- package/dist/optimistic-cart-BveVOHuh.js +53 -0
- package/dist/optimistic-cart.d.ts +16 -0
- package/dist/order-display-DTt5WBbc.js +112 -0
- package/dist/order-display.d.ts +20 -0
- package/dist/order-draft-DxV1Uhm3.js +38 -0
- package/dist/order-draft.d.ts +16 -0
- package/dist/order-pages-Dm6l5m0m.js +38 -0
- package/dist/order-pages.d.ts +12 -0
- package/dist/order-payment-continuation-D_d5PGA4.js +212 -0
- package/dist/order-payment-continuation.d.ts +10 -0
- package/dist/order-payment-in-review-x4gdLFHZ.js +65 -0
- package/dist/order-payment-in-review.d.ts +5 -0
- package/dist/order-status-BJXLJwxq.js +162 -0
- package/dist/order-status.d.ts +89 -0
- package/dist/order-view-9IlBg5AF.js +62 -0
- package/dist/order-view.d.ts +12 -0
- package/dist/page-action-Ctkf4xC6.js +7 -0
- package/dist/page-seo-a5FJl8x5.js +262 -0
- package/dist/page-seo.d.ts +34 -0
- package/dist/pages-Ca_Gt6mq.js +150 -0
- package/dist/pages.d.ts +45 -0
- package/dist/payment-dialog-frame-B-Q_xQ94.js +57 -0
- package/dist/payment-logo-BoPaGJc_.js +46 -0
- package/dist/payment-logo-svgs-By9lDTLK.js +20 -0
- package/dist/payment-logo.d.ts +11 -0
- package/dist/payment-logos-BYvdwYyJ.js +23 -0
- package/dist/payment-methods-B8ocTgFZ.js +73 -0
- package/dist/payment-methods.d.ts +58 -0
- package/dist/payment-return-5cjypwIw.js +7 -0
- package/dist/place-CmW4hBWY.js +13 -0
- package/dist/place.d.ts +4 -0
- package/dist/preview-BiIBif3C.js +427 -0
- package/dist/preview-address-Cf0sJ-9p.js +21 -0
- package/dist/preview-cart-Dg2CVktS.js +376 -0
- package/dist/product-preview-BspMAecJ.js +51 -0
- package/dist/product-preview.d.ts +5 -0
- package/dist/product-variants-BNDHvs1y.js +46 -0
- package/dist/product-variants.d.ts +12 -0
- package/dist/public-pages-XtwlaLwt.js +194 -0
- package/dist/public-pages.d.ts +67 -0
- package/dist/registration-CpDcv8ql.js +91 -0
- package/dist/registration.d.ts +12 -0
- package/dist/request-security-CRsRMgwj.js +76 -0
- package/dist/rich-text-M-Ju8RL4.js +9 -0
- package/dist/rich-text.d.ts +5 -0
- package/dist/route-text-DcJw2SsK.js +9 -0
- package/dist/route-text.d.ts +4 -0
- package/dist/section-preview-CmsMl3yu.js +83 -0
- package/dist/section-preview.d.ts +12 -0
- package/dist/sections/account-addresses.d.ts +18 -0
- package/dist/sections/account-addresses.js +375 -0
- package/dist/sections/account-order.d.ts +12 -0
- package/dist/sections/account-order.js +592 -0
- package/dist/sections/account-orders.d.ts +8 -0
- package/dist/sections/account-orders.js +359 -0
- package/dist/sections/account-profile.d.ts +16 -0
- package/dist/sections/account-profile.js +123 -0
- package/dist/sections/checkout.d.ts +24 -0
- package/dist/sections/checkout.js +963 -0
- package/dist/sections/complaint-book.d.ts +8 -0
- package/dist/sections/complaint-book.js +538 -0
- package/dist/sections/design-system.d.ts +1 -0
- package/dist/sections/design-system.js +310 -0
- package/dist/sections/draft-invoice.d.ts +20 -0
- package/dist/sections/draft-invoice.js +158 -0
- package/dist/sections/order-tracking.d.ts +19 -0
- package/dist/sections/order-tracking.js +141 -0
- package/dist/sections-CNUMWTF_.js +77 -0
- package/dist/sections.d.ts +19 -0
- package/dist/seo-GpDRhAAA.js +78 -0
- package/dist/session-CKvmFJyg.js +379 -0
- package/dist/session.d.ts +24 -0
- package/dist/settings-B0NO2A6Y.js +78 -0
- package/dist/settings.d.ts +51 -0
- package/dist/source-marker-DhqSkW7n.js +4 -0
- package/dist/sources-B-3JFJfb.js +46 -0
- package/dist/sources.d.ts +7 -0
- package/dist/store-8Q-_LFrQ.js +152 -0
- package/dist/store-contact--hY6CoFb.js +19 -0
- package/dist/store-contact.d.ts +6 -0
- package/dist/store.d.ts +17 -0
- package/dist/storefront-language-DrMjVbmk.js +29 -0
- package/dist/storefront-language.d.ts +14 -0
- package/dist/storefront-text-D25ae1qf.js +11 -0
- package/dist/storefront-text-en-ljjjSS4q.js +1030 -0
- package/dist/storefront-text-pt-BtHaJLcp.js +1030 -0
- package/dist/storefront-text.d.ts +4 -0
- package/dist/stripe-dialog-Ev9s3Z62.js +396 -0
- package/dist/stripe-dialog.d.ts +30 -0
- package/dist/telemetry-HuZXWBPi.js +114 -0
- package/dist/telemetry.d.ts +10 -0
- package/dist/templates-CAqoNyTW.js +40 -0
- package/dist/templates.d.ts +15 -0
- package/dist/urls-CpGQPxvf.js +71 -0
- package/dist/urls.d.ts +18 -0
- package/dist/use-checkout-CZcxXJXi.js +42 -0
- package/dist/use-checkout-payment-9R-zacrJ.js +80 -0
- package/dist/use-checkout-payment.d.ts +18 -0
- package/dist/use-checkout.d.ts +36 -0
- package/dist/use-culqi-checkout-CrjLAipU.js +109 -0
- package/dist/use-order-payment-BKIz_IO0.js +45 -0
- package/dist/use-order-payment.d.ts +18 -0
- package/dist/use-payment-token-CErx-tN-.js +105 -0
- package/dist/vite-payment-logos-kziu7wKb.js +27 -0
- package/dist/vite-payment-logos.d.ts +24 -0
- package/dist/vite-public-assets-DW2fgtVb.js +209 -0
- package/dist/vite-public-assets.d.ts +29 -0
- package/dist/vite-sections-DTBr0-Kg.js +464 -0
- package/dist/vite-sections.d.ts +21 -0
- package/dist/vite-theme-ui-BMO-CDi3.js +41 -0
- package/dist/vite-theme-ui.d.ts +10 -0
- package/dist/vite.d.ts +36 -0
- package/dist/vite.js +127 -0
- package/dist/voucher-payment-CVFDZ1L8.js +66 -0
- package/dist/worker-CNi-gzCu.js +86 -0
- package/dist/worker.d.ts +27 -0
- package/package.json +100 -81
- package/src/sections/account-addresses.tsx +215 -0
- package/src/sections/account-order.tsx +424 -0
- package/src/sections/account-orders.tsx +259 -0
- package/src/sections/account-profile.tsx +70 -0
- package/src/sections/checkout.tsx +586 -0
- package/src/sections/complaint-book.tsx +325 -0
- package/src/sections/design-system.tsx +146 -0
- package/src/sections/draft-invoice.tsx +105 -0
- package/src/sections/order-tracking.tsx +81 -0
- package/src/vite-client.d.ts +4 -0
- package/bin/ecomiq.mjs +0 -179
- package/public/design-bridge.js +0 -318
- package/src/api-proxy.ts +0 -194
- package/src/auth/create-storefront-auth.ts +0 -94
- package/src/auth/ecomiq-oauth-password-client.ts +0 -26
- package/src/auth/ecomiq-oauth-password-constants.ts +0 -24
- package/src/auth/ecomiq-oauth-password-plugin.ts +0 -294
- package/src/auth/ecomiq-oauth-password-types.ts +0 -24
- package/src/auth/ecomiq-storefront-sign-in.ts +0 -44
- package/src/auth/env.ts +0 -7
- package/src/auth/secure-cookies.ts +0 -23
- package/src/auth/storefront-auth-base-url.ts +0 -117
- package/src/auth/storefront-auth.ts +0 -7
- package/src/cart-session.ts +0 -239
- package/src/client.ts +0 -48
- package/src/cloud-runtime-client.ts +0 -378
- package/src/codegen.mjs +0 -789
- package/src/components/account/customer-addresses-panel.tsx +0 -678
- package/src/components/account/customer-order-detail-panel.tsx +0 -285
- package/src/components/account/customer-orders-panel.tsx +0 -192
- package/src/components/account/customer-profile-panel.tsx +0 -379
- package/src/components/checkout/cart-sync.ts +0 -143
- package/src/components/checkout/checkout-contact-section.tsx +0 -76
- package/src/components/checkout/checkout-external-update-banner.tsx +0 -15
- package/src/components/checkout/checkout-form-controls.tsx +0 -139
- package/src/components/checkout/checkout-line-items.tsx +0 -43
- package/src/components/checkout/checkout-order-summary.tsx +0 -165
- package/src/components/checkout/checkout-payment-section.tsx +0 -212
- package/src/components/checkout/checkout-session-view.tsx +0 -564
- package/src/components/checkout/checkout-shipping-address-section.tsx +0 -400
- package/src/components/checkout/checkout-shipping-section.tsx +0 -98
- package/src/components/checkout/checkout-states.tsx +0 -73
- package/src/components/checkout/checkout-step-card.tsx +0 -101
- package/src/components/checkout/checkout-steps.ts +0 -111
- package/src/components/checkout/form-schema.ts +0 -281
- package/src/components/checkout/format.ts +0 -15
- package/src/components/checkout/index.ts +0 -5
- package/src/components/checkout/map-customer-to-checkout.ts +0 -188
- package/src/components/checkout/types.ts +0 -41
- package/src/components/checkout/use-checkout-customer-prefill.ts +0 -409
- package/src/components/checkout/use-checkout-geo.ts +0 -50
- package/src/components/checkout/use-checkout-session.ts +0 -640
- package/src/components/hero.tsx +0 -291
- package/src/config.d.ts +0 -94
- package/src/config.mjs +0 -146
- package/src/format-money.ts +0 -31
- package/src/health.ts +0 -90
- package/src/hooks/index.ts +0 -9
- package/src/hooks/recently-viewed.ts +0 -125
- package/src/index.ts +0 -354
- package/src/link.tsx +0 -2
- package/src/pages/account/account-page-skeleton.tsx +0 -69
- package/src/pages/account/account-page-view.tsx +0 -270
- package/src/pages/account/account-shell.tsx +0 -101
- package/src/pages/account/parse-account-route.ts +0 -36
- package/src/pages/account.tsx +0 -16
- package/src/pages/api.$.ts +0 -20
- package/src/pages/api.auth.$.ts +0 -16
- package/src/pages/checkout.$checkoutId.tsx +0 -60
- package/src/pages/checkout.tsx +0 -31
- package/src/pages/pages.$pageSlug.tsx +0 -111
- package/src/pages/thank-you.tsx +0 -53
- package/src/providers/auth.tsx +0 -96
- package/src/providers/cart.tsx +0 -275
- package/src/providers/ecomiq.ts +0 -137
- package/src/providers/index.ts +0 -26
- package/src/proxy-api.ts +0 -20
- package/src/public-config.ts +0 -24
- package/src/review-submission.ts +0 -89
- package/src/runtime/context.ts +0 -2
- package/src/runtime/default-layout.tsx +0 -64
- package/src/runtime/head.ts +0 -149
- package/src/runtime/page.tsx +0 -143
- package/src/runtime/postcss-browser-stub.mjs +0 -5
- package/src/server-config-store.ts +0 -35
- package/src/server.ts +0 -301
- package/src/storefront-definition/contract.ts +0 -1
- package/src/storefront-definition/data.ts +0 -188
- package/src/storefront-definition/index.ts +0 -2
- package/src/storefront-definition/renderer.tsx +0 -1481
- package/src/storefront-layout.ts +0 -59
- package/src/storefront-runtime.ts +0 -173
- package/src/styles.css +0 -97
- package/src/ui/badge.tsx +0 -32
- package/src/ui/button.tsx +0 -31
- package/src/ui/card.tsx +0 -31
- package/src/ui/carousel.tsx +0 -218
- package/src/ui/cn.ts +0 -6
- package/src/ui/index.ts +0 -8
- package/src/ui/separator.tsx +0 -6
- package/src/ui/skeleton.tsx +0 -6
- package/src/ui/storefront-error.tsx +0 -49
- package/src/utils.ts +0 -36
- package/src/vite-inline.mjs +0 -263
- package/templates/__root.tsx +0 -83
- package/templates/router.tsx +0 -19
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useRef,
|
|
5
|
-
useState,
|
|
6
|
-
type Dispatch,
|
|
7
|
-
type SetStateAction,
|
|
8
|
-
} from 'react'
|
|
9
|
-
import {
|
|
10
|
-
createCustomerAddress,
|
|
11
|
-
customerMeToProfile,
|
|
12
|
-
getCustomerAddresses,
|
|
13
|
-
getCustomerMe,
|
|
14
|
-
toCustomerSavedAddresses,
|
|
15
|
-
type CustomerProfile,
|
|
16
|
-
type CustomerSavedAddress,
|
|
17
|
-
type Department,
|
|
18
|
-
type District,
|
|
19
|
-
type Province,
|
|
20
|
-
} from '@ecomiq/core'
|
|
21
|
-
import { createStorefrontProxyApi } from '../../proxy-api'
|
|
22
|
-
import {
|
|
23
|
-
buildCheckoutContactStepSchema,
|
|
24
|
-
buildCheckoutDeliveryStepSchema,
|
|
25
|
-
} from './form-schema'
|
|
26
|
-
import {
|
|
27
|
-
applySavedAddressToContact,
|
|
28
|
-
checkoutContactToCustomerAddressUpsert,
|
|
29
|
-
findGeoCodeByName,
|
|
30
|
-
mergeCheckoutContactPrefill,
|
|
31
|
-
customerProfileToCheckoutPatch,
|
|
32
|
-
customerAddressToCheckoutPatch,
|
|
33
|
-
pickDefaultCustomerAddress,
|
|
34
|
-
} from './map-customer-to-checkout'
|
|
35
|
-
import {
|
|
36
|
-
jumpCheckoutToPayment,
|
|
37
|
-
type CheckoutStepFlow,
|
|
38
|
-
} from './checkout-steps'
|
|
39
|
-
import type { CheckoutContactForm } from './types'
|
|
40
|
-
|
|
41
|
-
type ShippingFlatItem = { key: string }
|
|
42
|
-
|
|
43
|
-
type UseCheckoutCustomerPrefillArgs = {
|
|
44
|
-
enabled: boolean
|
|
45
|
-
cartToken: string
|
|
46
|
-
currency: string
|
|
47
|
-
contact: CheckoutContactForm
|
|
48
|
-
setContact: Dispatch<SetStateAction<CheckoutContactForm>>
|
|
49
|
-
departments: Department[]
|
|
50
|
-
provinces: Province[]
|
|
51
|
-
districts: District[]
|
|
52
|
-
selectedShippingKey: string | null
|
|
53
|
-
shippingFlat: ShippingFlatItem[]
|
|
54
|
-
shippingLoading: boolean
|
|
55
|
-
stepFlow: CheckoutStepFlow
|
|
56
|
-
setStepFlow: Dispatch<SetStateAction<CheckoutStepFlow>>
|
|
57
|
-
persistDeliveryStep: () => Promise<void>
|
|
58
|
-
invalidateDeliveryPersistence: () => void
|
|
59
|
-
/** Si el usuario marcó guardar en cuenta, el auto-avance también debe persistirla. */
|
|
60
|
-
saveAddressIntent?: { enabled: boolean; addressKey: string } | null
|
|
61
|
-
onAddressSaveError?: (message: string) => void
|
|
62
|
-
onAddressSaved?: () => void
|
|
63
|
-
/** Asocia el carrito guest al buyer autenticado (PATCH buyer). */
|
|
64
|
-
associateBuyer?: () => Promise<unknown>
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function useCheckoutCustomerPrefill({
|
|
68
|
-
enabled,
|
|
69
|
-
cartToken,
|
|
70
|
-
currency,
|
|
71
|
-
contact,
|
|
72
|
-
setContact,
|
|
73
|
-
departments,
|
|
74
|
-
provinces,
|
|
75
|
-
districts,
|
|
76
|
-
selectedShippingKey,
|
|
77
|
-
shippingFlat,
|
|
78
|
-
shippingLoading,
|
|
79
|
-
stepFlow,
|
|
80
|
-
setStepFlow,
|
|
81
|
-
persistDeliveryStep,
|
|
82
|
-
invalidateDeliveryPersistence,
|
|
83
|
-
saveAddressIntent = null,
|
|
84
|
-
onAddressSaveError,
|
|
85
|
-
onAddressSaved,
|
|
86
|
-
associateBuyer,
|
|
87
|
-
}: UseCheckoutCustomerPrefillArgs) {
|
|
88
|
-
const [profile, setProfile] = useState<CustomerProfile | null>(null)
|
|
89
|
-
const [savedAddresses, setSavedAddresses] = useState<CustomerSavedAddress[]>(
|
|
90
|
-
[],
|
|
91
|
-
)
|
|
92
|
-
const [selectedSavedAddressId, setSelectedSavedAddressId] = useState<
|
|
93
|
-
string | null
|
|
94
|
-
>(null)
|
|
95
|
-
const [isLoadingCustomer, setIsLoadingCustomer] = useState(false)
|
|
96
|
-
|
|
97
|
-
const fetchedRef = useRef(false)
|
|
98
|
-
const profileMergedRef = useRef(false)
|
|
99
|
-
const addressMergedRef = useRef(false)
|
|
100
|
-
const buyerAssociatedRef = useRef(false)
|
|
101
|
-
const autoAdvanceRef = useRef(false)
|
|
102
|
-
const autoAdvanceInFlightRef = useRef(false)
|
|
103
|
-
|
|
104
|
-
useEffect(() => {
|
|
105
|
-
fetchedRef.current = false
|
|
106
|
-
profileMergedRef.current = false
|
|
107
|
-
addressMergedRef.current = false
|
|
108
|
-
buyerAssociatedRef.current = false
|
|
109
|
-
autoAdvanceRef.current = false
|
|
110
|
-
autoAdvanceInFlightRef.current = false
|
|
111
|
-
setProfile(null)
|
|
112
|
-
setSavedAddresses([])
|
|
113
|
-
setSelectedSavedAddressId(null)
|
|
114
|
-
}, [cartToken])
|
|
115
|
-
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
if (!enabled) return
|
|
118
|
-
if (fetchedRef.current) return
|
|
119
|
-
fetchedRef.current = true
|
|
120
|
-
setIsLoadingCustomer(true)
|
|
121
|
-
|
|
122
|
-
void (async () => {
|
|
123
|
-
try {
|
|
124
|
-
const api = createStorefrontProxyApi()
|
|
125
|
-
const [me, addresses] = await Promise.all([
|
|
126
|
-
getCustomerMe(api),
|
|
127
|
-
getCustomerAddresses(api),
|
|
128
|
-
])
|
|
129
|
-
const nextProfile = customerMeToProfile(me)
|
|
130
|
-
const saved = toCustomerSavedAddresses(addresses)
|
|
131
|
-
setProfile(nextProfile)
|
|
132
|
-
setSavedAddresses(saved)
|
|
133
|
-
|
|
134
|
-
const defaultAddress = pickDefaultCustomerAddress(saved)
|
|
135
|
-
if (defaultAddress) setSelectedSavedAddressId(defaultAddress.id)
|
|
136
|
-
} catch {
|
|
137
|
-
// Sin perfil/direcciones: el checkout sigue como invitado/manual.
|
|
138
|
-
} finally {
|
|
139
|
-
setIsLoadingCustomer(false)
|
|
140
|
-
}
|
|
141
|
-
})()
|
|
142
|
-
}, [enabled, cartToken])
|
|
143
|
-
|
|
144
|
-
// Prefill perfil (campos vacíos).
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
if (!enabled || !profile || profileMergedRef.current) return
|
|
147
|
-
profileMergedRef.current = true
|
|
148
|
-
const patch = customerProfileToCheckoutPatch(profile)
|
|
149
|
-
setContact((current) => mergeCheckoutContactPrefill(current, patch))
|
|
150
|
-
}, [enabled, profile, setContact])
|
|
151
|
-
|
|
152
|
-
// Tras login/registro: asociar el carrito al email del customer.
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
if (!enabled || !associateBuyer) return
|
|
155
|
-
if (buyerAssociatedRef.current || isLoadingCustomer) return
|
|
156
|
-
const email = contact.email.trim()
|
|
157
|
-
const firstName = contact.firstName.trim()
|
|
158
|
-
const lastName = contact.lastName.trim()
|
|
159
|
-
const phone = contact.phone.trim()
|
|
160
|
-
if (!email || !firstName || !lastName || !phone) return
|
|
161
|
-
|
|
162
|
-
buyerAssociatedRef.current = true
|
|
163
|
-
void associateBuyer().catch(() => {
|
|
164
|
-
buyerAssociatedRef.current = false
|
|
165
|
-
})
|
|
166
|
-
}, [
|
|
167
|
-
associateBuyer,
|
|
168
|
-
contact.email,
|
|
169
|
-
contact.firstName,
|
|
170
|
-
contact.lastName,
|
|
171
|
-
contact.phone,
|
|
172
|
-
enabled,
|
|
173
|
-
isLoadingCustomer,
|
|
174
|
-
])
|
|
175
|
-
|
|
176
|
-
// Prefill dirección default (campos vacíos).
|
|
177
|
-
useEffect(() => {
|
|
178
|
-
if (!enabled || addressMergedRef.current) return
|
|
179
|
-
if (!savedAddresses.length) return
|
|
180
|
-
addressMergedRef.current = true
|
|
181
|
-
const defaultAddress = pickDefaultCustomerAddress(savedAddresses)
|
|
182
|
-
if (!defaultAddress) return
|
|
183
|
-
const patch = customerAddressToCheckoutPatch(defaultAddress, profile)
|
|
184
|
-
setContact((current) => mergeCheckoutContactPrefill(current, patch))
|
|
185
|
-
}, [enabled, profile, savedAddresses, setContact])
|
|
186
|
-
|
|
187
|
-
// Resolver códigos INEI desde nombres.
|
|
188
|
-
useEffect(() => {
|
|
189
|
-
if (!enabled) return
|
|
190
|
-
const isPe = contact.countryCode.toUpperCase() === 'PE'
|
|
191
|
-
if (!isPe) return
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
contact.departmentName &&
|
|
195
|
-
!contact.departmentCode &&
|
|
196
|
-
departments.length
|
|
197
|
-
) {
|
|
198
|
-
const code = findGeoCodeByName(departments, contact.departmentName)
|
|
199
|
-
if (code) {
|
|
200
|
-
setContact((c) =>
|
|
201
|
-
c.departmentCode ? c : { ...c, departmentCode: code },
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
contact.provinceName &&
|
|
208
|
-
contact.departmentCode &&
|
|
209
|
-
!contact.provinceCode &&
|
|
210
|
-
provinces.length
|
|
211
|
-
) {
|
|
212
|
-
const code = findGeoCodeByName(provinces, contact.provinceName)
|
|
213
|
-
if (code) {
|
|
214
|
-
setContact((c) =>
|
|
215
|
-
c.provinceCode
|
|
216
|
-
? c
|
|
217
|
-
: { ...c, provinceCode: code, province: c.province || c.provinceName },
|
|
218
|
-
)
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
contact.districtName &&
|
|
224
|
-
contact.provinceCode &&
|
|
225
|
-
!contact.districtCode &&
|
|
226
|
-
districts.length
|
|
227
|
-
) {
|
|
228
|
-
const code = findGeoCodeByName(districts, contact.districtName)
|
|
229
|
-
if (code) {
|
|
230
|
-
setContact((c) =>
|
|
231
|
-
c.districtCode
|
|
232
|
-
? c
|
|
233
|
-
: {
|
|
234
|
-
...c,
|
|
235
|
-
districtCode: code,
|
|
236
|
-
city: c.city || c.districtName,
|
|
237
|
-
},
|
|
238
|
-
)
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}, [
|
|
242
|
-
contact.countryCode,
|
|
243
|
-
contact.departmentCode,
|
|
244
|
-
contact.departmentName,
|
|
245
|
-
contact.districtCode,
|
|
246
|
-
contact.districtName,
|
|
247
|
-
contact.provinceCode,
|
|
248
|
-
contact.provinceName,
|
|
249
|
-
departments,
|
|
250
|
-
districts,
|
|
251
|
-
enabled,
|
|
252
|
-
provinces,
|
|
253
|
-
setContact,
|
|
254
|
-
])
|
|
255
|
-
|
|
256
|
-
const saveContactAsCustomerAddress = useCallback(
|
|
257
|
-
async (
|
|
258
|
-
form: CheckoutContactForm,
|
|
259
|
-
options: { addressKey?: string; isDefault?: boolean } = {},
|
|
260
|
-
) => {
|
|
261
|
-
const payload = checkoutContactToCustomerAddressUpsert(form, {
|
|
262
|
-
addressKey: options.addressKey,
|
|
263
|
-
isDefault:
|
|
264
|
-
options.isDefault ??
|
|
265
|
-
(savedAddresses.length === 0 ||
|
|
266
|
-
!savedAddresses.some((a) => a.isDefault)),
|
|
267
|
-
})
|
|
268
|
-
const api = createStorefrontProxyApi()
|
|
269
|
-
const created = await createCustomerAddress(api, payload)
|
|
270
|
-
const createdId =
|
|
271
|
-
created && typeof created === 'object' && 'id' in created
|
|
272
|
-
? String(created.id)
|
|
273
|
-
: null
|
|
274
|
-
const refreshed = toCustomerSavedAddresses(await getCustomerAddresses(api))
|
|
275
|
-
setSavedAddresses(refreshed)
|
|
276
|
-
if (createdId) {
|
|
277
|
-
setSelectedSavedAddressId(createdId)
|
|
278
|
-
return refreshed.find((a) => a.id === createdId) ?? null
|
|
279
|
-
}
|
|
280
|
-
const match =
|
|
281
|
-
refreshed.find(
|
|
282
|
-
(a) =>
|
|
283
|
-
a.addressKey === payload.addressKey &&
|
|
284
|
-
a.postalCode === payload.postalCode &&
|
|
285
|
-
a.addressLine === payload.addressLine,
|
|
286
|
-
) ?? pickDefaultCustomerAddress(refreshed)
|
|
287
|
-
if (match) setSelectedSavedAddressId(match.id)
|
|
288
|
-
return match
|
|
289
|
-
},
|
|
290
|
-
[savedAddresses],
|
|
291
|
-
)
|
|
292
|
-
|
|
293
|
-
// Auto-avanzar a pago cuando contact+delivery están completos.
|
|
294
|
-
useEffect(() => {
|
|
295
|
-
if (!enabled) return
|
|
296
|
-
if (autoAdvanceRef.current || autoAdvanceInFlightRef.current) return
|
|
297
|
-
if (stepFlow.active === 'payment') {
|
|
298
|
-
autoAdvanceRef.current = true
|
|
299
|
-
return
|
|
300
|
-
}
|
|
301
|
-
if (shippingLoading || isLoadingCustomer) return
|
|
302
|
-
if (!selectedShippingKey || shippingFlat.length === 0) return
|
|
303
|
-
|
|
304
|
-
const contactOk = buildCheckoutContactStepSchema().safeParse({
|
|
305
|
-
email: contact.email,
|
|
306
|
-
}).success
|
|
307
|
-
if (!contactOk) return
|
|
308
|
-
|
|
309
|
-
const deliveryOk = buildCheckoutDeliveryStepSchema(currency).safeParse({
|
|
310
|
-
firstName: contact.firstName,
|
|
311
|
-
lastName: contact.lastName,
|
|
312
|
-
countryCode: contact.countryCode,
|
|
313
|
-
address: contact.address,
|
|
314
|
-
phone: contact.phone,
|
|
315
|
-
departmentCode: contact.departmentCode,
|
|
316
|
-
provinceCode: contact.provinceCode,
|
|
317
|
-
districtCode: contact.districtCode,
|
|
318
|
-
city: contact.city,
|
|
319
|
-
province: contact.province,
|
|
320
|
-
selectedShippingKey,
|
|
321
|
-
shippingOptionsCount: shippingFlat.length,
|
|
322
|
-
}).success
|
|
323
|
-
if (!deliveryOk) return
|
|
324
|
-
|
|
325
|
-
autoAdvanceInFlightRef.current = true
|
|
326
|
-
void (async () => {
|
|
327
|
-
try {
|
|
328
|
-
await persistDeliveryStep()
|
|
329
|
-
} catch {
|
|
330
|
-
autoAdvanceInFlightRef.current = false
|
|
331
|
-
return
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (saveAddressIntent?.enabled) {
|
|
335
|
-
try {
|
|
336
|
-
await saveContactAsCustomerAddress(contact, {
|
|
337
|
-
addressKey: saveAddressIntent.addressKey,
|
|
338
|
-
})
|
|
339
|
-
onAddressSaved?.()
|
|
340
|
-
} catch (error) {
|
|
341
|
-
autoAdvanceInFlightRef.current = false
|
|
342
|
-
onAddressSaveError?.(
|
|
343
|
-
error instanceof Error
|
|
344
|
-
? error.message
|
|
345
|
-
: 'No se pudo guardar la dirección en tu cuenta.',
|
|
346
|
-
)
|
|
347
|
-
return
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
autoAdvanceRef.current = true
|
|
352
|
-
setStepFlow(jumpCheckoutToPayment())
|
|
353
|
-
})()
|
|
354
|
-
}, [
|
|
355
|
-
contact,
|
|
356
|
-
currency,
|
|
357
|
-
enabled,
|
|
358
|
-
isLoadingCustomer,
|
|
359
|
-
onAddressSaved,
|
|
360
|
-
onAddressSaveError,
|
|
361
|
-
persistDeliveryStep,
|
|
362
|
-
saveAddressIntent?.addressKey,
|
|
363
|
-
saveAddressIntent?.enabled,
|
|
364
|
-
saveContactAsCustomerAddress,
|
|
365
|
-
selectedShippingKey,
|
|
366
|
-
setStepFlow,
|
|
367
|
-
shippingFlat.length,
|
|
368
|
-
shippingLoading,
|
|
369
|
-
stepFlow.active,
|
|
370
|
-
])
|
|
371
|
-
|
|
372
|
-
const selectSavedAddress = useCallback(
|
|
373
|
-
(addressId: string) => {
|
|
374
|
-
const address = savedAddresses.find((a) => a.id === addressId)
|
|
375
|
-
if (!address) return
|
|
376
|
-
setSelectedSavedAddressId(addressId)
|
|
377
|
-
autoAdvanceRef.current = false
|
|
378
|
-
autoAdvanceInFlightRef.current = false
|
|
379
|
-
invalidateDeliveryPersistence()
|
|
380
|
-
setContact((current) =>
|
|
381
|
-
applySavedAddressToContact(current, address, profile),
|
|
382
|
-
)
|
|
383
|
-
setStepFlow((flow) => ({
|
|
384
|
-
active: flow.completed.contact || flow.active !== 'contact' ? 'delivery' : flow.active,
|
|
385
|
-
completed: {
|
|
386
|
-
contact: flow.completed.contact || flow.active !== 'contact',
|
|
387
|
-
delivery: false,
|
|
388
|
-
payment: false,
|
|
389
|
-
},
|
|
390
|
-
}))
|
|
391
|
-
},
|
|
392
|
-
[
|
|
393
|
-
invalidateDeliveryPersistence,
|
|
394
|
-
profile,
|
|
395
|
-
savedAddresses,
|
|
396
|
-
setContact,
|
|
397
|
-
setStepFlow,
|
|
398
|
-
],
|
|
399
|
-
)
|
|
400
|
-
|
|
401
|
-
return {
|
|
402
|
-
profile,
|
|
403
|
-
savedAddresses,
|
|
404
|
-
selectedSavedAddressId,
|
|
405
|
-
isLoadingCustomer,
|
|
406
|
-
selectSavedAddress,
|
|
407
|
-
saveContactAsCustomerAddress,
|
|
408
|
-
}
|
|
409
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
import type { Country, Department, District, Province } from '@ecomiq/core'
|
|
3
|
-
import { serverApi } from '../../server'
|
|
4
|
-
|
|
5
|
-
/** Carga cascada geo INEI (PE) + países. */
|
|
6
|
-
export function useCheckoutGeo(countryCode: string, departmentCode: string, provinceCode: string) {
|
|
7
|
-
const [countries, setCountries] = useState<Country[]>([])
|
|
8
|
-
const [departments, setDepartments] = useState<Department[]>([])
|
|
9
|
-
const [provinces, setProvinces] = useState<Province[]>([])
|
|
10
|
-
const [districts, setDistricts] = useState<District[]>([])
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
void serverApi.getCountries().then(setCountries).catch(() => setCountries([]))
|
|
14
|
-
}, [])
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (countryCode.toUpperCase() !== 'PE') {
|
|
18
|
-
setDepartments([])
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
void serverApi
|
|
22
|
-
.getDepartments({ countryCode: 'PE' })
|
|
23
|
-
.then(setDepartments)
|
|
24
|
-
.catch(() => setDepartments([]))
|
|
25
|
-
}, [countryCode])
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!departmentCode) {
|
|
29
|
-
setProvinces([])
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
void serverApi
|
|
33
|
-
.getProvinces({ countryCode: 'PE', departmentCode })
|
|
34
|
-
.then(setProvinces)
|
|
35
|
-
.catch(() => setProvinces([]))
|
|
36
|
-
}, [departmentCode])
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (!provinceCode) {
|
|
40
|
-
setDistricts([])
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
void serverApi
|
|
44
|
-
.getDistricts({ countryCode: 'PE', provinceCode })
|
|
45
|
-
.then(setDistricts)
|
|
46
|
-
.catch(() => setDistricts([]))
|
|
47
|
-
}, [provinceCode])
|
|
48
|
-
|
|
49
|
-
return { countries, departments, provinces, districts }
|
|
50
|
-
}
|