@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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CustomerCsrfField, useCustomerCsrfToken } from "./customer-csrf-C1oDX-Py.js";
|
|
2
|
+
import { CUSTOMER_CSRF_FIELD } from "./form-contracts-BNpHaTGJ.js";
|
|
3
|
+
import { Form, useFetcher } from "react-router";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/cart-form.tsx
|
|
6
|
+
const CART_ACTION = "/cart";
|
|
7
|
+
function Hidden({ name, value }) {
|
|
8
|
+
if (value === void 0) return null;
|
|
9
|
+
return /* @__PURE__ */ jsx("input", {
|
|
10
|
+
type: "hidden",
|
|
11
|
+
name,
|
|
12
|
+
value
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function CartForm({ intent, itemId, variantId, product, quantity, next, fetcher, children, ...props }) {
|
|
16
|
+
const Component = fetcher ? fetcher.Form : Form;
|
|
17
|
+
return /* @__PURE__ */ jsxs(Component, {
|
|
18
|
+
method: "post",
|
|
19
|
+
action: CART_ACTION,
|
|
20
|
+
...props,
|
|
21
|
+
children: [
|
|
22
|
+
/* @__PURE__ */ jsx(CustomerCsrfField, {}),
|
|
23
|
+
/* @__PURE__ */ jsx(Hidden, {
|
|
24
|
+
name: "intent",
|
|
25
|
+
value: intent
|
|
26
|
+
}),
|
|
27
|
+
/* @__PURE__ */ jsx(Hidden, {
|
|
28
|
+
name: "itemId",
|
|
29
|
+
value: itemId
|
|
30
|
+
}),
|
|
31
|
+
/* @__PURE__ */ jsx(Hidden, {
|
|
32
|
+
name: "variantId",
|
|
33
|
+
value: variantId
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ jsx(Hidden, {
|
|
36
|
+
name: "product",
|
|
37
|
+
value: product
|
|
38
|
+
}),
|
|
39
|
+
/* @__PURE__ */ jsx(Hidden, {
|
|
40
|
+
name: "quantity",
|
|
41
|
+
value: quantity
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx(Hidden, {
|
|
44
|
+
name: "next",
|
|
45
|
+
value: next
|
|
46
|
+
}),
|
|
47
|
+
children
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function useCart() {
|
|
52
|
+
const fetcher = useFetcher();
|
|
53
|
+
const csrf = useCustomerCsrfToken();
|
|
54
|
+
function submit(intent, fields) {
|
|
55
|
+
const form = new FormData();
|
|
56
|
+
form.set("intent", intent);
|
|
57
|
+
for (const [name, value] of Object.entries(fields)) form.set(name, value);
|
|
58
|
+
if (csrf) form.set(CUSTOMER_CSRF_FIELD, csrf);
|
|
59
|
+
fetcher.submit(form, {
|
|
60
|
+
method: "post",
|
|
61
|
+
action: CART_ACTION
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
let error = null;
|
|
65
|
+
if (fetcher.state === "idle" && fetcher.data?.ok === false) error = fetcher.data.message;
|
|
66
|
+
return {
|
|
67
|
+
fetcher,
|
|
68
|
+
busy: fetcher.state !== "idle",
|
|
69
|
+
error,
|
|
70
|
+
add: (variantId, quantity = 1) => submit("add", {
|
|
71
|
+
variantId,
|
|
72
|
+
quantity: String(Math.max(1, quantity))
|
|
73
|
+
}),
|
|
74
|
+
update: (itemId, quantity) => submit("update", {
|
|
75
|
+
itemId,
|
|
76
|
+
quantity: String(Math.max(0, quantity))
|
|
77
|
+
}),
|
|
78
|
+
remove: (itemId) => submit("remove", { itemId })
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export { CART_ACTION, CartForm, useCart };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CartActionData } from "./cart-actions.js";
|
|
2
|
+
import { CartIntent } from "./form-contracts.js";
|
|
3
|
+
import { FetcherFormProps, FetcherWithComponents } from "react-router";
|
|
4
|
+
import { Ref } from "react";
|
|
5
|
+
export type CartFormProps = Omit<FetcherFormProps, "action" | "method" | "encType"> & {
|
|
6
|
+
ref?: Ref<HTMLFormElement>;
|
|
7
|
+
intent?: CartIntent;
|
|
8
|
+
itemId?: string;
|
|
9
|
+
variantId?: string;
|
|
10
|
+
product?: string;
|
|
11
|
+
quantity?: number;
|
|
12
|
+
next?: string;
|
|
13
|
+
fetcher?: FetcherWithComponents<CartActionData>;
|
|
14
|
+
};
|
|
15
|
+
export type CartControls = {
|
|
16
|
+
fetcher: FetcherWithComponents<CartActionData>;
|
|
17
|
+
busy: boolean;
|
|
18
|
+
error: string | null;
|
|
19
|
+
add: (variantId: string, quantity?: number) => void;
|
|
20
|
+
update: (itemId: string, quantity: number) => void;
|
|
21
|
+
remove: (itemId: string) => void;
|
|
22
|
+
};
|
|
23
|
+
export declare function CartForm({ intent, itemId, variantId, product, quantity, next, fetcher, children, ...props }: CartFormProps): import("react").JSX.Element;
|
|
24
|
+
export declare function useCart(): CartControls;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/cart-summary.ts
|
|
2
|
+
const LABELS = {
|
|
3
|
+
subtotal: "Subtotal",
|
|
4
|
+
discount: "Descuentos",
|
|
5
|
+
shipping: "Envío",
|
|
6
|
+
tax: "Impuestos",
|
|
7
|
+
total: "Total",
|
|
8
|
+
free: "Gratis",
|
|
9
|
+
pending: "Por calcular"
|
|
10
|
+
};
|
|
11
|
+
function lineSubtotal(items) {
|
|
12
|
+
return items.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0);
|
|
13
|
+
}
|
|
14
|
+
function groupBySeller(items, marketplace) {
|
|
15
|
+
if (!marketplace) return [{
|
|
16
|
+
seller: null,
|
|
17
|
+
items: [...items],
|
|
18
|
+
subtotal: lineSubtotal(items)
|
|
19
|
+
}];
|
|
20
|
+
const groups = /* @__PURE__ */ new Map();
|
|
21
|
+
for (const item of items) groups.set(item.sellerName, [...groups.get(item.sellerName) ?? [], item]);
|
|
22
|
+
return [...groups.entries()].map(([seller, list]) => ({
|
|
23
|
+
seller,
|
|
24
|
+
items: list,
|
|
25
|
+
subtotal: lineSubtotal(list)
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
function amountLine(key, label, amount) {
|
|
29
|
+
return {
|
|
30
|
+
key,
|
|
31
|
+
label,
|
|
32
|
+
amount,
|
|
33
|
+
text: null,
|
|
34
|
+
pending: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function lines(totals, shipping, labels) {
|
|
38
|
+
const result = [amountLine("subtotal", labels.subtotal, totals.subtotal)];
|
|
39
|
+
if (totals.discount > 0) result.push(amountLine("discount", labels.discount, -totals.discount));
|
|
40
|
+
if (shipping) result.push(shipping);
|
|
41
|
+
if (totals.tax > 0) result.push(amountLine("tax", labels.tax, totals.tax));
|
|
42
|
+
result.push(amountLine("total", labels.total, totals.total));
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function shippingLine(amount, labels) {
|
|
46
|
+
if (amount === null) return {
|
|
47
|
+
key: "shipping",
|
|
48
|
+
label: labels.shipping,
|
|
49
|
+
amount: null,
|
|
50
|
+
text: labels.pending,
|
|
51
|
+
pending: true
|
|
52
|
+
};
|
|
53
|
+
if (amount === 0) return {
|
|
54
|
+
key: "shipping",
|
|
55
|
+
label: labels.shipping,
|
|
56
|
+
amount: null,
|
|
57
|
+
text: labels.free,
|
|
58
|
+
pending: false
|
|
59
|
+
};
|
|
60
|
+
return amountLine("shipping", labels.shipping, amount);
|
|
61
|
+
}
|
|
62
|
+
function summaryLines(cart, labels = {}) {
|
|
63
|
+
const text = {
|
|
64
|
+
...LABELS,
|
|
65
|
+
...labels
|
|
66
|
+
};
|
|
67
|
+
let shipping = null;
|
|
68
|
+
if (cart.items.some((item) => item.requiresShipping)) shipping = shippingLine(cart.shippingMethods.length > 0 ? cart.totals.shippingTotal : null, text);
|
|
69
|
+
const { subtotal, discountTotal, taxTotal, total } = cart.totals;
|
|
70
|
+
return lines({
|
|
71
|
+
subtotal,
|
|
72
|
+
discount: discountTotal,
|
|
73
|
+
tax: taxTotal,
|
|
74
|
+
total
|
|
75
|
+
}, shipping, text);
|
|
76
|
+
}
|
|
77
|
+
function orderSummaryLines(order, labels = {}) {
|
|
78
|
+
const text = {
|
|
79
|
+
...LABELS,
|
|
80
|
+
...labels
|
|
81
|
+
};
|
|
82
|
+
return lines({
|
|
83
|
+
subtotal: order.subTotal,
|
|
84
|
+
discount: order.discount,
|
|
85
|
+
tax: order.tax,
|
|
86
|
+
total: order.total
|
|
87
|
+
}, shippingLine(order.shipping, text), text);
|
|
88
|
+
}
|
|
89
|
+
export { groupBySeller, orderSummaryLines, summaryLines };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StorefrontCart } from "@ecomiq/core";
|
|
2
|
+
export type SellerLine = {
|
|
3
|
+
sellerName: string | null;
|
|
4
|
+
unitPrice: number;
|
|
5
|
+
quantity: number;
|
|
6
|
+
};
|
|
7
|
+
export type SellerGroup<T extends SellerLine> = {
|
|
8
|
+
seller: string | null;
|
|
9
|
+
items: T[];
|
|
10
|
+
subtotal: number;
|
|
11
|
+
};
|
|
12
|
+
export type SummaryLineKey = "subtotal" | "discount" | "shipping" | "tax" | "total";
|
|
13
|
+
export type SummaryLine = {
|
|
14
|
+
key: SummaryLineKey;
|
|
15
|
+
label: string;
|
|
16
|
+
amount: number | null;
|
|
17
|
+
text: string | null;
|
|
18
|
+
pending: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type SummaryLabels = Partial<Record<SummaryLineKey | "free" | "pending", string>>;
|
|
21
|
+
export type SummaryCart = Pick<StorefrontCart, "items" | "totals" | "shippingMethods">;
|
|
22
|
+
export type SummaryOrder = {
|
|
23
|
+
subTotal: number;
|
|
24
|
+
discount: number;
|
|
25
|
+
shipping: number;
|
|
26
|
+
tax: number;
|
|
27
|
+
total: number;
|
|
28
|
+
};
|
|
29
|
+
export declare function groupBySeller<T extends SellerLine>(items: readonly T[], marketplace: boolean): SellerGroup<T>[];
|
|
30
|
+
export declare function summaryLines(cart: SummaryCart, labels?: SummaryLabels): SummaryLine[];
|
|
31
|
+
export declare function orderSummaryLines(order: SummaryOrder, labels?: SummaryLabels): SummaryLine[];
|
package/dist/cart.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StorefrontCart, StorefrontClient } from "@ecomiq/core";
|
|
2
|
+
export declare const cartCookie: import("react-router").Cookie;
|
|
3
|
+
export declare function cartToken(request: Request): Promise<string | null>;
|
|
4
|
+
export declare function readCart(request: Request, client: StorefrontClient): Promise<StorefrontCart | null>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/catalog.ts
|
|
2
|
+
const LISTS = {
|
|
3
|
+
category: "categories",
|
|
4
|
+
brand: "brands",
|
|
5
|
+
collection: "collections",
|
|
6
|
+
productType: "productTypes",
|
|
7
|
+
tag: "tags",
|
|
8
|
+
seller: "sellers"
|
|
9
|
+
};
|
|
10
|
+
const SORTS = [
|
|
11
|
+
"newest",
|
|
12
|
+
"price_asc",
|
|
13
|
+
"price_desc",
|
|
14
|
+
"name_asc",
|
|
15
|
+
"name_desc"
|
|
16
|
+
];
|
|
17
|
+
const CATALOG_PARAMETERS = /* @__PURE__ */ new Set([
|
|
18
|
+
"q",
|
|
19
|
+
"sort",
|
|
20
|
+
"page",
|
|
21
|
+
"availability",
|
|
22
|
+
"minPrice",
|
|
23
|
+
"maxPrice",
|
|
24
|
+
...Object.keys(LISTS)
|
|
25
|
+
]);
|
|
26
|
+
/** Menus, customer and cart data do not depend on filters in the current catalog. */
|
|
27
|
+
function shouldRevalidateCatalogRoot(args) {
|
|
28
|
+
const { currentUrl, nextUrl, defaultShouldRevalidate, formMethod, actionResult, actionStatus } = args;
|
|
29
|
+
if (!defaultShouldRevalidate || formMethod !== void 0 && formMethod.toUpperCase() !== "GET" || actionResult !== void 0 || actionStatus !== void 0 || currentUrl.origin !== nextUrl.origin || currentUrl.pathname !== nextUrl.pathname || currentUrl.search === nextUrl.search) return defaultShouldRevalidate;
|
|
30
|
+
for (const params of [currentUrl.searchParams, nextUrl.searchParams]) for (const name of params.keys()) if (!CATALOG_PARAMETERS.has(name) && !/^(?:option|attribute):.+$/.test(name)) return defaultShouldRevalidate;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function isSort(value) {
|
|
34
|
+
return SORTS.some((sort) => sort === value);
|
|
35
|
+
}
|
|
36
|
+
function price(value) {
|
|
37
|
+
if (value === null || value.trim() === "") return void 0;
|
|
38
|
+
const number = Number(value);
|
|
39
|
+
return Number.isFinite(number) && number >= 0 ? number : void 0;
|
|
40
|
+
}
|
|
41
|
+
function readCatalog(url, base = {}) {
|
|
42
|
+
const params = url.searchParams;
|
|
43
|
+
const query = {
|
|
44
|
+
...base,
|
|
45
|
+
pageSize: 24,
|
|
46
|
+
page: Math.max(1, Number(params.get("page") ?? "1") || 1)
|
|
47
|
+
};
|
|
48
|
+
const q = params.get("q")?.trim();
|
|
49
|
+
if (q) query.search = q;
|
|
50
|
+
const sort = params.get("sort");
|
|
51
|
+
if (isSort(sort)) query.sort = sort;
|
|
52
|
+
for (const [id, key] of Object.entries(LISTS)) {
|
|
53
|
+
const values = params.getAll(id).filter((value) => value !== "");
|
|
54
|
+
if (values.length > 0) query[key] = values;
|
|
55
|
+
}
|
|
56
|
+
const filters = [...params.entries()].filter(([key]) => key.startsWith("option:") || key.startsWith("attribute:")).map(([key, value]) => `${key}:${value}`);
|
|
57
|
+
if (filters.length > 0) query.filters = filters;
|
|
58
|
+
const availability = params.get("availability");
|
|
59
|
+
if (availability === "in_stock") query.inStock = true;
|
|
60
|
+
if (availability === "out_of_stock") query.inStock = false;
|
|
61
|
+
const minPrice = price(params.get("minPrice"));
|
|
62
|
+
const maxPrice = price(params.get("maxPrice"));
|
|
63
|
+
if (minPrice !== void 0) query.minPrice = minPrice;
|
|
64
|
+
if (maxPrice !== void 0) query.maxPrice = maxPrice;
|
|
65
|
+
return query;
|
|
66
|
+
}
|
|
67
|
+
export { readCatalog, shouldRevalidateCatalogRoot };
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { useStorefrontText } from "./storefront-language-DrMjVbmk.js";
|
|
2
|
+
import { useFetcher, useLocation, useNavigation, useSearchParams, useSubmit } from "react-router";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
// src/catalog-hooks.ts
|
|
5
|
+
const SEARCH_DELAY_MS = 180;
|
|
6
|
+
const SEARCH_MIN_LENGTH = 2;
|
|
7
|
+
const RELEVANCE = "relevance";
|
|
8
|
+
const SORT_OPTIONS = [
|
|
9
|
+
{
|
|
10
|
+
value: RELEVANCE,
|
|
11
|
+
label: "Relevancia"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
value: "newest",
|
|
15
|
+
label: "Más nuevos"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
value: "price_asc",
|
|
19
|
+
label: "Precio: menor a mayor"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
value: "price_desc",
|
|
23
|
+
label: "Precio: mayor a menor"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: "name_asc",
|
|
27
|
+
label: "Nombre: A–Z"
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
const FILTER_LABELS = /* @__PURE__ */ new Map([
|
|
31
|
+
["availability", "Disponibilidad"],
|
|
32
|
+
["price", "Precio"],
|
|
33
|
+
["category", "Categoría"],
|
|
34
|
+
["brand", "Marca"],
|
|
35
|
+
["collection", "Colección"],
|
|
36
|
+
["productType", "Tipo"],
|
|
37
|
+
["tag", "Etiqueta"],
|
|
38
|
+
["seller", "Vendedor"]
|
|
39
|
+
]);
|
|
40
|
+
const FILTER_VALUE_LABELS = /* @__PURE__ */ new Map([
|
|
41
|
+
["in_stock", "Disponible"],
|
|
42
|
+
["out_of_stock", "Agotado"],
|
|
43
|
+
["product", "Producto"],
|
|
44
|
+
["bundle", "Pack"],
|
|
45
|
+
["service", "Servicio"],
|
|
46
|
+
["digital", "Digital"],
|
|
47
|
+
["gift_card", "Tarjeta de regalo"]
|
|
48
|
+
]);
|
|
49
|
+
function filterLabel(filter, labels, translate = (source) => source) {
|
|
50
|
+
const label = labels?.filters?.get(filter.id) ?? FILTER_LABELS.get(filter.id);
|
|
51
|
+
return label === void 0 ? filter.label : translate(label);
|
|
52
|
+
}
|
|
53
|
+
function filterValueLabel(value, label, labels, translate = (source) => source) {
|
|
54
|
+
const known = labels?.values?.get(value) ?? FILTER_VALUE_LABELS.get(value);
|
|
55
|
+
return known === void 0 ? label ?? value : translate(known);
|
|
56
|
+
}
|
|
57
|
+
function isSingleChoiceFilter(filter) {
|
|
58
|
+
return filter.id === "availability" || filter.id.startsWith("option:");
|
|
59
|
+
}
|
|
60
|
+
function selectedFacetCount(filters) {
|
|
61
|
+
return filters.reduce((sum, filter) => sum + filter.values.filter((value) => value.selected).length, 0);
|
|
62
|
+
}
|
|
63
|
+
function activeFilterCount(filters, params) {
|
|
64
|
+
let count = selectedFacetCount(filters);
|
|
65
|
+
if (params.get("minPrice")) count += 1;
|
|
66
|
+
if (params.get("maxPrice")) count += 1;
|
|
67
|
+
return count;
|
|
68
|
+
}
|
|
69
|
+
function clearedFiltersHref(params) {
|
|
70
|
+
const next = new URLSearchParams();
|
|
71
|
+
for (const name of ["q", "sort"]) {
|
|
72
|
+
const current = params.get(name);
|
|
73
|
+
if (current) next.set(name, current);
|
|
74
|
+
}
|
|
75
|
+
return `?${next.toString()}`;
|
|
76
|
+
}
|
|
77
|
+
function activeFilterChips(filters, params, text = {}) {
|
|
78
|
+
const chips = [];
|
|
79
|
+
for (const filter of filters) for (const facet of filter.values) if (facet.selected) chips.push({
|
|
80
|
+
key: filter.id,
|
|
81
|
+
value: facet.value,
|
|
82
|
+
text: `${filterLabel(filter, text.labels, text.translate)}: ${filterValueLabel(facet.value, facet.label, text.labels, text.translate)}`
|
|
83
|
+
});
|
|
84
|
+
const minPrice = params.get("minPrice");
|
|
85
|
+
const maxPrice = params.get("maxPrice");
|
|
86
|
+
const price = text.price ?? ((amount) => amount);
|
|
87
|
+
if (minPrice) chips.push({
|
|
88
|
+
key: "minPrice",
|
|
89
|
+
value: minPrice,
|
|
90
|
+
text: text.translate?.("Desde {value0}", { value0: price(minPrice) }) ?? `Desde ${price(minPrice)}`
|
|
91
|
+
});
|
|
92
|
+
if (maxPrice) chips.push({
|
|
93
|
+
key: "maxPrice",
|
|
94
|
+
value: maxPrice,
|
|
95
|
+
text: text.translate?.("Hasta {value0}", { value0: price(maxPrice) }) ?? `Hasta ${price(maxPrice)}`
|
|
96
|
+
});
|
|
97
|
+
return chips.map((chip) => {
|
|
98
|
+
const next = new URLSearchParams();
|
|
99
|
+
for (const [name, current] of params.entries()) if (name !== "page" && !(name === chip.key && current === chip.value)) next.append(name, current);
|
|
100
|
+
return {
|
|
101
|
+
...chip,
|
|
102
|
+
href: `?${next.toString()}`
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function pageItems(page, pages) {
|
|
107
|
+
const wanted = /* @__PURE__ */ new Set([
|
|
108
|
+
1,
|
|
109
|
+
pages,
|
|
110
|
+
page - 1,
|
|
111
|
+
page,
|
|
112
|
+
page + 1
|
|
113
|
+
]);
|
|
114
|
+
const items = [];
|
|
115
|
+
for (let current = 1; current <= pages; current += 1) {
|
|
116
|
+
if (!wanted.has(current)) continue;
|
|
117
|
+
const previous = items[items.length - 1];
|
|
118
|
+
if (typeof previous === "number" && current - previous > 1) items.push("gap");
|
|
119
|
+
items.push(current);
|
|
120
|
+
}
|
|
121
|
+
return items;
|
|
122
|
+
}
|
|
123
|
+
function useCatalogNavigation() {
|
|
124
|
+
const [params] = useSearchParams();
|
|
125
|
+
const location = useLocation();
|
|
126
|
+
const navigation = useNavigation();
|
|
127
|
+
const submit = useSubmit();
|
|
128
|
+
const pending = useRef(null);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (navigation.state === "idle") pending.current = null;
|
|
131
|
+
}, [location.key, navigation.state]);
|
|
132
|
+
const navigate = (change) => {
|
|
133
|
+
const sameCatalog = navigation.location?.pathname === location.pathname;
|
|
134
|
+
const previous = pending.current;
|
|
135
|
+
const intended = previous?.locationKey === location.key && previous.navigationKey === navigation.location?.key ? previous.params : new URLSearchParams(sameCatalog ? navigation.location.search : params);
|
|
136
|
+
const next = new URLSearchParams(intended);
|
|
137
|
+
next.delete("page");
|
|
138
|
+
change(next);
|
|
139
|
+
if (next.toString() === intended.toString()) return;
|
|
140
|
+
pending.current = {
|
|
141
|
+
locationKey: location.key,
|
|
142
|
+
navigationKey: navigation.location?.key,
|
|
143
|
+
params: next
|
|
144
|
+
};
|
|
145
|
+
submit(next, {
|
|
146
|
+
method: "get",
|
|
147
|
+
preventScrollReset: true
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
params,
|
|
152
|
+
navigate
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function useFacets() {
|
|
156
|
+
const { params, navigate } = useCatalogNavigation();
|
|
157
|
+
const toggle = (filterId, value, checked) => navigate((next) => {
|
|
158
|
+
const kept = next.getAll(filterId).filter((current) => current !== value);
|
|
159
|
+
next.delete(filterId);
|
|
160
|
+
for (const current of kept) next.append(filterId, current);
|
|
161
|
+
if (checked) next.append(filterId, value);
|
|
162
|
+
});
|
|
163
|
+
const choose = (filterId, value) => navigate((next) => {
|
|
164
|
+
next.delete(filterId);
|
|
165
|
+
if (value) next.set(filterId, value);
|
|
166
|
+
});
|
|
167
|
+
const setPrice = (from, to, low, high) => navigate((next) => {
|
|
168
|
+
if (from !== void 0 && from > low) next.set("minPrice", String(from));
|
|
169
|
+
else next.delete("minPrice");
|
|
170
|
+
if (to !== void 0 && to < high) next.set("maxPrice", String(to));
|
|
171
|
+
else next.delete("maxPrice");
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
params,
|
|
175
|
+
navigate,
|
|
176
|
+
toggle,
|
|
177
|
+
choose,
|
|
178
|
+
setPrice,
|
|
179
|
+
clearedHref: clearedFiltersHref(params)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function useSort(labels = {}) {
|
|
183
|
+
const t = useStorefrontText();
|
|
184
|
+
const { params, navigate } = useCatalogNavigation();
|
|
185
|
+
const value = params.get("sort") ?? RELEVANCE;
|
|
186
|
+
const change = (next) => navigate((query) => {
|
|
187
|
+
if (next === RELEVANCE) query.delete("sort");
|
|
188
|
+
else query.set("sort", next);
|
|
189
|
+
});
|
|
190
|
+
const options = SORT_OPTIONS.map((option) => ({
|
|
191
|
+
value: option.value,
|
|
192
|
+
label: t(labels[option.value] ?? option.label)
|
|
193
|
+
}));
|
|
194
|
+
return {
|
|
195
|
+
value,
|
|
196
|
+
label: (options.find((option) => option.value === value) ?? options[0]).label,
|
|
197
|
+
options,
|
|
198
|
+
change
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function usePagination(page, pages) {
|
|
202
|
+
const [params] = useSearchParams();
|
|
203
|
+
const href = (target) => {
|
|
204
|
+
const next = new URLSearchParams(params);
|
|
205
|
+
next.set("page", String(target));
|
|
206
|
+
return `?${next.toString()}`;
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
items: pageItems(page, pages),
|
|
210
|
+
href,
|
|
211
|
+
hasPrevious: page > 1,
|
|
212
|
+
hasNext: page < pages
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function useSearchSuggestions(initial = "") {
|
|
216
|
+
const [q, setQ] = useState(initial);
|
|
217
|
+
const fetcher = useFetcher();
|
|
218
|
+
const trimmed = q.trim();
|
|
219
|
+
const searching = trimmed.length >= SEARCH_MIN_LENGTH;
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
if (!searching) return;
|
|
222
|
+
const timer = setTimeout(() => fetcher.load(`/search/suggest?q=${encodeURIComponent(trimmed)}`), SEARCH_DELAY_MS);
|
|
223
|
+
return () => clearTimeout(timer);
|
|
224
|
+
}, [trimmed]);
|
|
225
|
+
let products = [];
|
|
226
|
+
if (searching) products = fetcher.data?.products ?? [];
|
|
227
|
+
const missing = searching && fetcher.state === "idle" && fetcher.data !== void 0 && products.length === 0;
|
|
228
|
+
return {
|
|
229
|
+
q,
|
|
230
|
+
setQ,
|
|
231
|
+
trimmed,
|
|
232
|
+
searching,
|
|
233
|
+
products,
|
|
234
|
+
missing,
|
|
235
|
+
loading: fetcher.state !== "idle",
|
|
236
|
+
loaded: fetcher.data !== void 0,
|
|
237
|
+
current: fetcher.data?.q === trimmed
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function matchPlace(items, name) {
|
|
241
|
+
const wanted = name?.trim().toLowerCase();
|
|
242
|
+
if (!wanted) return null;
|
|
243
|
+
return items.find((item) => item.name.toLowerCase() === wanted) ?? null;
|
|
244
|
+
}
|
|
245
|
+
function placeValue(place) {
|
|
246
|
+
return place ? `${place.code}|${place.name}` : "";
|
|
247
|
+
}
|
|
248
|
+
function placeByValue(items, value) {
|
|
249
|
+
return items.find((item) => placeValue(item) === value) ?? null;
|
|
250
|
+
}
|
|
251
|
+
function useGeoCascade(defaults) {
|
|
252
|
+
const [country, setCountryState] = useState(defaults.country ?? "");
|
|
253
|
+
const [department, setDepartmentState] = useState(null);
|
|
254
|
+
const [province, setProvinceState] = useState(null);
|
|
255
|
+
const [district, setDistrict] = useState(null);
|
|
256
|
+
const geo = useFetcher();
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
const query = new URLSearchParams({ country });
|
|
259
|
+
if (department) query.set("department", department.code);
|
|
260
|
+
if (province) query.set("province", province.code);
|
|
261
|
+
geo.load(`/geo?${query.toString()}`);
|
|
262
|
+
}, [
|
|
263
|
+
country,
|
|
264
|
+
department?.code,
|
|
265
|
+
province?.code
|
|
266
|
+
]);
|
|
267
|
+
const data = geo.data ?? {
|
|
268
|
+
departments: [],
|
|
269
|
+
provinces: [],
|
|
270
|
+
districts: []
|
|
271
|
+
};
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (department === null) setDepartmentState(matchPlace(data.departments, defaults.department));
|
|
274
|
+
}, [data.departments]);
|
|
275
|
+
useEffect(() => {
|
|
276
|
+
if (province === null) setProvinceState(matchPlace(data.provinces, defaults.province));
|
|
277
|
+
}, [data.provinces]);
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
if (district === null) setDistrict(matchPlace(data.districts, defaults.district));
|
|
280
|
+
}, [data.districts]);
|
|
281
|
+
const setCountry = (next) => {
|
|
282
|
+
setCountryState(next);
|
|
283
|
+
setDepartmentState(null);
|
|
284
|
+
setProvinceState(null);
|
|
285
|
+
setDistrict(null);
|
|
286
|
+
};
|
|
287
|
+
const setDepartment = (next) => {
|
|
288
|
+
setDepartmentState(next);
|
|
289
|
+
setProvinceState(null);
|
|
290
|
+
setDistrict(null);
|
|
291
|
+
};
|
|
292
|
+
const setProvince = (next) => {
|
|
293
|
+
setProvinceState(next);
|
|
294
|
+
setDistrict(null);
|
|
295
|
+
};
|
|
296
|
+
return {
|
|
297
|
+
country,
|
|
298
|
+
setCountry,
|
|
299
|
+
department,
|
|
300
|
+
setDepartment,
|
|
301
|
+
province,
|
|
302
|
+
setProvince,
|
|
303
|
+
district,
|
|
304
|
+
setDistrict,
|
|
305
|
+
setDepartmentValue: (value) => setDepartment(placeByValue(data.departments, value)),
|
|
306
|
+
setProvinceValue: (value) => setProvince(placeByValue(data.provinces, value)),
|
|
307
|
+
setDistrictValue: (value) => setDistrict(placeByValue(data.districts, value)),
|
|
308
|
+
places: data,
|
|
309
|
+
structured: data.departments.length > 0
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
export { SORT_OPTIONS, activeFilterChips, activeFilterCount, clearedFiltersHref, filterLabel, filterValueLabel, isSingleChoiceFilter, pageItems, placeValue, selectedFacetCount, useFacets, useGeoCascade, usePagination, useSearchSuggestions, useSort };
|