@nextblock-cms/ecom 0.8.6 → 0.8.11
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/index.cjs.js +1 -1
- package/index.es.js +136 -533
- package/lib/CurrencyProvider.cjs.js +1 -0
- package/lib/CurrencyProvider.es.js +99 -0
- package/lib/cart-store.cjs.js +1 -0
- package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
- package/lib/components/AccountNavigationMenu.cjs.js +1 -0
- package/lib/components/AccountNavigationMenu.es.js +44 -0
- package/lib/components/AddToCartButton.cjs.js +1 -0
- package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
- package/lib/components/Cart.cjs.js +1 -0
- package/lib/components/Cart.es.js +148 -0
- package/lib/components/CartDrawer.cjs.js +1 -0
- package/{components → lib/components}/CartDrawer.es.js +15 -14
- package/{components → lib/components}/CartIcon.cjs.js +1 -1
- package/{components → lib/components}/CartIcon.es.js +1 -0
- package/lib/components/Checkout.cjs.js +1 -0
- package/{components → lib/components}/Checkout.es.js +330 -363
- package/lib/components/CouponForm.cjs.js +1 -0
- package/lib/components/CouponForm.es.js +136 -0
- package/lib/components/CurrencySwitcher.cjs.js +1 -0
- package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
- package/lib/components/CustomerProfileForm.cjs.js +1 -0
- package/lib/components/CustomerProfileForm.es.js +355 -0
- package/lib/components/FeaturedProduct.cjs.js +1 -0
- package/{components → lib/components}/FeaturedProduct.es.js +9 -8
- package/lib/components/InvoiceDocument.cjs.js +1 -0
- package/lib/components/InvoiceDocument.es.js +196 -0
- package/lib/components/InvoiceViewerShell.cjs.js +29 -0
- package/lib/components/InvoiceViewerShell.es.js +100 -0
- package/lib/components/ProductCard.cjs.js +1 -0
- package/lib/components/ProductCard.es.js +119 -0
- package/lib/components/ProductDetailsLayout.cjs.js +1 -0
- package/lib/components/ProductDetailsLayout.es.js +361 -0
- package/lib/components/ProductGallery.cjs.js +1 -0
- package/lib/components/ProductGallery.es.js +41 -0
- package/lib/components/ProductGrid.cjs.js +1 -0
- package/lib/components/ProductGrid.es.js +19 -0
- package/lib/components/ShippingEstimator.cjs.js +1 -0
- package/lib/components/ShippingEstimator.es.js +125 -0
- package/lib/components/SubscriptionSelector.cjs.js +1 -0
- package/lib/components/SubscriptionSelector.es.js +140 -0
- package/lib/countries.cjs.js +1 -0
- package/lib/countries.es.js +77 -0
- package/lib/coupon-server.cjs.js +1 -0
- package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
- package/lib/coupons.cjs.js +1 -0
- package/lib/coupons.es.js +17 -0
- package/lib/currency-store.cjs.js +1 -0
- package/lib/currency-store.es.js +27 -0
- package/lib/currency-sync.cjs.js +1 -0
- package/lib/currency-sync.es.js +180 -0
- package/lib/customer-addresses.cjs.js +1 -0
- package/lib/customer-addresses.es.js +116 -0
- package/lib/customer-orders.cjs.js +1 -0
- package/lib/customer-orders.es.js +45 -0
- package/lib/customer.cjs.js +1 -0
- package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
- package/lib/export-helpers.cjs.js +1 -0
- package/lib/export-helpers.es.js +56 -0
- package/lib/factory.cjs.js +1 -0
- package/lib/factory.es.js +8 -0
- package/lib/freemius-coupons.cjs.js +1 -0
- package/lib/freemius-coupons.es.js +272 -0
- package/lib/freemius-order-sync.cjs.js +1 -0
- package/lib/freemius-order-sync.es.js +284 -0
- package/lib/inventory-settings.cjs.js +1 -0
- package/lib/inventory-settings.es.js +86 -0
- package/lib/invoice-server.cjs.js +33 -0
- package/lib/invoice-server.es.js +141 -0
- package/lib/invoice-ui.cjs.js +1 -0
- package/lib/invoice-ui.es.js +71 -0
- package/lib/invoice.cjs.js +1 -0
- package/lib/invoice.es.js +102 -0
- package/lib/order-inventory.cjs.js +61 -0
- package/lib/order-inventory.es.js +128 -0
- package/lib/order-tax-details.cjs.js +1 -0
- package/lib/order-tax-details.es.js +164 -0
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
- package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
- package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
- package/lib/pages/cms/coupons/actions.cjs.js +1 -0
- package/lib/pages/cms/coupons/actions.es.js +128 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
- package/lib/pages/cms/coupons/product-options.es.js +27 -0
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
- package/lib/pages/cms/orders/actions.cjs.js +7 -0
- package/lib/pages/cms/orders/actions.es.js +71 -0
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/export-actions.es.js +27 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/server-actions.es.js +55 -0
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
- package/lib/pages/cms/payments/actions.cjs.js +1 -0
- package/lib/pages/cms/payments/actions.es.js +23 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -0
- package/lib/pages/cms/payments/queries.es.js +30 -0
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
- package/lib/pages/cms/products/ProductsPage.es.js +46 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
- package/lib/pages/cms/products/actions.cjs.js +44 -0
- package/lib/pages/cms/products/actions.es.js +175 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
- package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
- package/lib/pages/cms/products/inventory/actions.es.js +95 -0
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
- package/lib/pages/cms/products/product-price-sync.es.js +98 -0
- package/lib/pages/cms/products/server-actions.cjs.js +1 -0
- package/lib/pages/cms/products/server-actions.es.js +193 -0
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
- package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
- package/lib/pages/cms/shipping/server-actions.es.js +159 -0
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
- package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
- package/lib/pages/cms/taxes/actions.cjs.js +1 -0
- package/lib/pages/cms/taxes/actions.es.js +57 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
- package/lib/product-actions.cjs.js +237 -0
- package/lib/product-actions.es.js +524 -0
- package/lib/product-context.cjs.js +1 -0
- package/lib/product-context.es.js +16 -0
- package/lib/product-schema.cjs.js +1 -0
- package/lib/product-schema.es.js +134 -0
- package/lib/providers/freemius.cjs.js +5 -0
- package/lib/providers/freemius.es.js +538 -0
- package/lib/providers/stripe.cjs.js +1 -0
- package/lib/providers/stripe.es.js +473 -0
- package/lib/server-actions/coupon-actions.cjs.js +1 -0
- package/lib/server-actions/coupon-actions.es.js +23 -0
- package/lib/server-actions/customer-actions.cjs.js +1 -0
- package/lib/server-actions/customer-actions.es.js +30 -0
- package/lib/server-actions/product-actions.cjs.js +1 -0
- package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
- package/lib/server-actions/shipping-actions.cjs.js +1 -0
- package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
- package/lib/server-actions/tax-actions.cjs.js +1 -0
- package/lib/server-actions/tax-actions.es.js +40 -0
- package/lib/shared-inventory.cjs.js +15 -0
- package/lib/shared-inventory.es.js +171 -0
- package/lib/shipping/resolver.cjs.js +7 -0
- package/lib/shipping/resolver.es.js +62 -0
- package/lib/shipping-rate-currency.cjs.js +1 -0
- package/lib/shipping-rate-currency.es.js +72 -0
- package/lib/states.cjs.js +1 -0
- package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
- package/lib/stripe/checkout.cjs.js +1 -0
- package/lib/stripe/checkout.es.js +182 -0
- package/lib/stripe/client.cjs.js +1 -0
- package/lib/stripe/client.es.js +7 -0
- package/lib/stripe/order-sync.cjs.js +1 -0
- package/lib/stripe/order-sync.es.js +130 -0
- package/lib/stripe/webhooks.cjs.js +1 -0
- package/lib/stripe/webhooks.es.js +30 -0
- package/lib/tax-calculation.cjs.js +1 -0
- package/lib/tax-calculation.es.js +101 -0
- package/lib/trials.cjs.js +1 -0
- package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
- package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
- package/lib/zod-config.cjs.js +1 -0
- package/lib/zod-config.es.js +6 -0
- package/package.json +6 -6
- package/server.cjs.js +1 -110
- package/server.es.js +178 -6052
- package/AddToCartButton-DsSEH9yp.cjs +0 -1
- package/CouponForm-BI_5SBHQ.js +0 -152
- package/CouponForm-D_uu2bLP.cjs +0 -1
- package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
- package/CurrencyProvider-OzlRN96V.js +0 -120
- package/CurrencyProvider.cjs.js +0 -1
- package/CurrencyProvider.es.js +0 -10
- package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
- package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
- package/ProductGrid-BdL7iglO.cjs +0 -1
- package/ProductGrid-D3AWM8sr.js +0 -130
- package/actions-AHmBrS5e.cjs +0 -48
- package/actions-j5fuSZX-.js +0 -820
- package/cart-store.cjs.js +0 -1
- package/components/Cart.cjs.js +0 -1
- package/components/Cart.es.js +0 -259
- package/components/CartDrawer.cjs.js +0 -1
- package/components/Checkout.cjs.js +0 -1
- package/components/CurrencySwitcher.cjs.js +0 -1
- package/components/FeaturedProduct.cjs.js +0 -1
- package/components/ProductDetailsLayout.cjs.js +0 -1
- package/components/ProductDetailsLayout.es.js +0 -19
- package/components/ProductGrid.cjs.js +0 -1
- package/components/ProductGrid.es.js +0 -6
- package/coupon-server-C9ySm3I5.cjs +0 -1
- package/customer-C-UPvrYN.cjs +0 -1
- package/invoice-ui-CAnJPu6n.cjs +0 -29
- package/invoice-ui-DtpbTJE1.js +0 -2886
- package/product-actions-CONBF8i6.cjs +0 -251
- package/product-actions-DjlIWCMH.js +0 -691
- package/resolver-Fz_FKsfX.cjs +0 -7
- package/resolver-cfrCaHpE.js +0 -128
- package/server-actions/product-actions.cjs.js +0 -1
- package/shipping-actions-D6zt20gg.cjs +0 -1
- package/states-CWYRxV4B.cjs +0 -1
- package/tax-calculation-Dab89aHd.js +0 -181
- package/tax-calculation-MkDKOEkL.cjs +0 -1
- package/trials-DvZaOtNy.cjs +0 -1
- /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
- /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
- /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
- /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
- /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
- /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
- /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
- /package/{currency.es.js → lib/currency.es.js} +0 -0
- /package/{types.cjs.js → lib/types.cjs.js} +0 -0
- /package/{types.es.js → lib/types.es.js} +0 -0
- /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
- /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
- /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs as n, jsx as r } from "react/jsx-runtime";
|
|
3
|
+
import { useState as h, useMemo as C, useEffect as Y } from "react";
|
|
4
|
+
import { Dialog as he, DialogTrigger as pe, Button as z, DialogContent as fe, DialogHeader as ge, DialogTitle as be, DialogDescription as ve, Label as N, Input as O, Select as ee, SelectTrigger as te, SelectValue as re, SelectContent as ne, SelectItem as V, Badge as q, DialogFooter as xe } from "@nextblock-cms/ui";
|
|
5
|
+
import { Edit2 as ye, Plus as Ce, Languages as Ne, DollarSign as B, Gift as _e } from "lucide-react";
|
|
6
|
+
import { updateShippingRate as Ae, createShippingRate as Se } from "../server-actions.es.js";
|
|
7
|
+
import { normalizeCurrencyCode as G, getCurrencyMinorUnitFactor as E, majorUnitAmountToMinor as we, minorUnitAmountToMajor as Me } from "@nextblock-cms/utils";
|
|
8
|
+
import { normalizeCurrencyRecord as oe, convertMinorUnitAmount as ae } from "../../../../currency.es.js";
|
|
9
|
+
import { normalizeShippingRateCurrencyMode as se, sanitizeShippingRateAmountMaps as ke } from "../../../../shipping-rate-currency.es.js";
|
|
10
|
+
function w(u, m) {
|
|
11
|
+
if (typeof u != "number")
|
|
12
|
+
return "";
|
|
13
|
+
const c = Me(u, m);
|
|
14
|
+
return E(m) === 1 ? c.toFixed(0) : c.toFixed(2);
|
|
15
|
+
}
|
|
16
|
+
function Fe(u) {
|
|
17
|
+
return u.reduce((m, c) => (m[c.code] = E(c.code) === 1 ? "0" : "0.00", m), {});
|
|
18
|
+
}
|
|
19
|
+
function _(u, m) {
|
|
20
|
+
const c = String(u || "").trim();
|
|
21
|
+
if (!c)
|
|
22
|
+
return null;
|
|
23
|
+
const f = Number(c);
|
|
24
|
+
return !Number.isFinite(f) || f < 0 ? null : we(f, m);
|
|
25
|
+
}
|
|
26
|
+
function de(u) {
|
|
27
|
+
return u.currencies.reduce((m, c) => (m[c.code] = w(
|
|
28
|
+
u.amounts[c.code],
|
|
29
|
+
c.code
|
|
30
|
+
), m), {});
|
|
31
|
+
}
|
|
32
|
+
function Pe({
|
|
33
|
+
zoneId: u,
|
|
34
|
+
zoneName: m,
|
|
35
|
+
languages: c,
|
|
36
|
+
currencies: f = [],
|
|
37
|
+
defaultCurrencyCode: ce = "USD",
|
|
38
|
+
mode: le = "create",
|
|
39
|
+
initialData: l
|
|
40
|
+
}) {
|
|
41
|
+
const [$, I] = h(!1), A = le === "edit", H = C(
|
|
42
|
+
() => c.find((e) => e.is_default) || c[0] || null,
|
|
43
|
+
[c]
|
|
44
|
+
), X = C(
|
|
45
|
+
() => c.filter((e) => !e.is_default),
|
|
46
|
+
[c]
|
|
47
|
+
), M = G(ce), s = C(() => {
|
|
48
|
+
const e = oe({
|
|
49
|
+
code: M,
|
|
50
|
+
symbol: M,
|
|
51
|
+
exchange_rate: 1,
|
|
52
|
+
is_default: !0,
|
|
53
|
+
is_active: !0
|
|
54
|
+
}), o = (f.length > 0 ? f : [e]).map((t) => oe(t)).filter((t) => t.is_active !== !1).sort((t, d) => t.is_default !== d.is_default ? t.is_default ? -1 : 1 : t.code.localeCompare(d.code));
|
|
55
|
+
return o.length > 0 ? o : [e];
|
|
56
|
+
}, [f, M]), g = C(
|
|
57
|
+
() => s.find((e) => e.is_default) || s[0],
|
|
58
|
+
[s]
|
|
59
|
+
), [k, Z] = h(l?.name || ""), [D, J] = h(
|
|
60
|
+
l?.name_translations || {}
|
|
61
|
+
), [b, K] = h(
|
|
62
|
+
l?.method_type || "flat_rate"
|
|
63
|
+
), [i, Q] = h(
|
|
64
|
+
se(l?.currency_pricing_mode)
|
|
65
|
+
), [a, j] = h(
|
|
66
|
+
G(l?.cost_currency || g?.code || M)
|
|
67
|
+
), [v, S] = h({}), [x, F] = h({}), [L, T] = h(!1), P = C(() => {
|
|
68
|
+
if (i === "manual")
|
|
69
|
+
return s.reduce((t, d) => (t[d.code] = v[d.code] ?? "", t), {});
|
|
70
|
+
const e = s.reduce(
|
|
71
|
+
(t, d) => (t[d.code] = v[d.code] ?? (d.code === a, ""), t),
|
|
72
|
+
{}
|
|
73
|
+
), o = _(
|
|
74
|
+
v[a],
|
|
75
|
+
a
|
|
76
|
+
);
|
|
77
|
+
if (o === null)
|
|
78
|
+
return e;
|
|
79
|
+
for (const t of s) {
|
|
80
|
+
if (t.code === a) {
|
|
81
|
+
e[t.code] = v[t.code] ?? w(o, t.code);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
e[t.code] = w(
|
|
85
|
+
ae({
|
|
86
|
+
amount: o,
|
|
87
|
+
fromCurrencyCode: a,
|
|
88
|
+
toCurrencyCode: t.code,
|
|
89
|
+
currencies: s
|
|
90
|
+
}),
|
|
91
|
+
t.code
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return e;
|
|
95
|
+
}, [s, v, i, a]), U = C(() => {
|
|
96
|
+
if (i === "manual")
|
|
97
|
+
return s.reduce((t, d) => (t[d.code] = x[d.code] ?? "", t), {});
|
|
98
|
+
const e = s.reduce(
|
|
99
|
+
(t, d) => (t[d.code] = x[d.code] ?? "", t),
|
|
100
|
+
{}
|
|
101
|
+
), o = _(
|
|
102
|
+
x[a],
|
|
103
|
+
a
|
|
104
|
+
);
|
|
105
|
+
if (o === null)
|
|
106
|
+
return e;
|
|
107
|
+
for (const t of s) {
|
|
108
|
+
if (t.code === a) {
|
|
109
|
+
e[t.code] = x[t.code] ?? w(o, t.code);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
e[t.code] = w(
|
|
113
|
+
ae({
|
|
114
|
+
amount: o,
|
|
115
|
+
fromCurrencyCode: a,
|
|
116
|
+
toCurrencyCode: t.code,
|
|
117
|
+
currencies: s
|
|
118
|
+
}),
|
|
119
|
+
t.code
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return e;
|
|
123
|
+
}, [s, x, i, a]);
|
|
124
|
+
Y(() => {
|
|
125
|
+
g && (s.some((e) => e.code === a) || j(g.code));
|
|
126
|
+
}, [s, g, a]), Y(() => {
|
|
127
|
+
if (!$ || !g)
|
|
128
|
+
return;
|
|
129
|
+
const e = se(
|
|
130
|
+
l?.currency_pricing_mode
|
|
131
|
+
), o = ke({
|
|
132
|
+
currencies: s,
|
|
133
|
+
mode: e,
|
|
134
|
+
sourceCurrencyCode: l?.cost_currency || g.code,
|
|
135
|
+
costAmounts: l?.cost_amounts || void 0,
|
|
136
|
+
minOrderAmounts: l?.min_order_amounts || void 0,
|
|
137
|
+
fallbackCostAmount: l?.cost_amount,
|
|
138
|
+
fallbackMinOrderAmount: l?.min_order_amount
|
|
139
|
+
});
|
|
140
|
+
Z(l?.name || ""), J(l?.name_translations || {}), K(l?.method_type || "flat_rate"), Q(e), j(o.sourceCurrencyCode), S(
|
|
141
|
+
de({
|
|
142
|
+
amounts: o.costAmounts,
|
|
143
|
+
currencies: s
|
|
144
|
+
})
|
|
145
|
+
), F(
|
|
146
|
+
de({
|
|
147
|
+
amounts: o.minOrderAmounts,
|
|
148
|
+
currencies: s
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
}, [s, g, l, $]);
|
|
152
|
+
const ie = (e) => {
|
|
153
|
+
e !== i && (e === "manual" && (S(P), F(U)), Q(e));
|
|
154
|
+
}, me = (e) => {
|
|
155
|
+
const o = G(e);
|
|
156
|
+
S((t) => ({
|
|
157
|
+
...t,
|
|
158
|
+
[o]: P[o] ?? t[o] ?? ""
|
|
159
|
+
})), F((t) => ({
|
|
160
|
+
...t,
|
|
161
|
+
[o]: U[o] ?? t[o] ?? ""
|
|
162
|
+
})), j(o);
|
|
163
|
+
}, ue = (e) => {
|
|
164
|
+
K(e), e === "free_shipping" && S(Fe(s));
|
|
165
|
+
};
|
|
166
|
+
return /* @__PURE__ */ n(he, { open: $, onOpenChange: I, children: [
|
|
167
|
+
/* @__PURE__ */ r(pe, { asChild: !0, children: A ? /* @__PURE__ */ r(z, { variant: "ghost", size: "icon", className: "h-7 w-7 text-slate-400 hover:text-primary", children: /* @__PURE__ */ r(ye, { className: "h-3 w-3" }) }) : /* @__PURE__ */ n(z, { variant: "outline", size: "sm", className: "h-8 gap-1.5 border-dashed hover:border-solid shadow-sm", children: [
|
|
168
|
+
/* @__PURE__ */ r(Ce, { className: "h-3.5 w-3.5" }),
|
|
169
|
+
"Add Rate"
|
|
170
|
+
] }) }),
|
|
171
|
+
/* @__PURE__ */ r(fe, { className: "max-h-[85vh] max-w-4xl overflow-y-auto", children: /* @__PURE__ */ n("form", { onSubmit: async (e) => {
|
|
172
|
+
e.preventDefault(), T(!0);
|
|
173
|
+
const o = {}, t = {};
|
|
174
|
+
if (i === "manual")
|
|
175
|
+
for (const R of s) {
|
|
176
|
+
const p = R.code;
|
|
177
|
+
if (b === "free_shipping")
|
|
178
|
+
o[p] = 0;
|
|
179
|
+
else {
|
|
180
|
+
const W = _(
|
|
181
|
+
v[p],
|
|
182
|
+
p
|
|
183
|
+
);
|
|
184
|
+
if (W === null) {
|
|
185
|
+
T(!1), alert(`Enter a valid shipping cost for ${p}.`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
o[p] = W;
|
|
189
|
+
}
|
|
190
|
+
t[p] = _(x[p], p) ?? 0;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const R = b === "free_shipping" ? 0 : _(
|
|
194
|
+
v[a],
|
|
195
|
+
a
|
|
196
|
+
);
|
|
197
|
+
if (R === null) {
|
|
198
|
+
T(!1), alert(`Enter a valid shipping cost for ${a}.`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
o[a] = R, t[a] = _(
|
|
202
|
+
x[a],
|
|
203
|
+
a
|
|
204
|
+
) ?? 0;
|
|
205
|
+
}
|
|
206
|
+
const d = {
|
|
207
|
+
name: k,
|
|
208
|
+
nameTranslations: D,
|
|
209
|
+
type: b,
|
|
210
|
+
currencyPricingMode: i,
|
|
211
|
+
sourceCurrencyCode: a,
|
|
212
|
+
costAmounts: o,
|
|
213
|
+
minOrderAmounts: t
|
|
214
|
+
}, y = A && l?.id ? await Ae(l.id, d) : await Se(u, d);
|
|
215
|
+
T(!1), y.success ? I(!1) : y.error && alert(y.error);
|
|
216
|
+
}, children: [
|
|
217
|
+
/* @__PURE__ */ n(ge, { children: [
|
|
218
|
+
/* @__PURE__ */ r(be, { children: A ? "Edit Shipping Rate" : "Add Shipping Rate" }),
|
|
219
|
+
/* @__PURE__ */ n(ve, { children: [
|
|
220
|
+
"Configure shipping costs and localized labels for matching orders in ",
|
|
221
|
+
/* @__PURE__ */ r("strong", { children: m }),
|
|
222
|
+
"."
|
|
223
|
+
] })
|
|
224
|
+
] }),
|
|
225
|
+
/* @__PURE__ */ n("div", { className: "grid gap-5 py-6", children: [
|
|
226
|
+
/* @__PURE__ */ n("div", { className: "space-y-2", children: [
|
|
227
|
+
/* @__PURE__ */ n(N, { htmlFor: "rate-name", children: [
|
|
228
|
+
"Rate Name",
|
|
229
|
+
H ? ` (${H.name})` : ""
|
|
230
|
+
] }),
|
|
231
|
+
/* @__PURE__ */ r(
|
|
232
|
+
O,
|
|
233
|
+
{
|
|
234
|
+
id: "rate-name",
|
|
235
|
+
value: k,
|
|
236
|
+
onChange: (e) => Z(e.target.value),
|
|
237
|
+
placeholder: "e.g. Standard, Express, Free Shipping",
|
|
238
|
+
required: !0
|
|
239
|
+
}
|
|
240
|
+
)
|
|
241
|
+
] }),
|
|
242
|
+
X.length > 0 && /* @__PURE__ */ n("div", { className: "space-y-4 rounded-xl border bg-slate-50/70 p-4 dark:bg-slate-900/40", children: [
|
|
243
|
+
/* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
|
|
244
|
+
/* @__PURE__ */ r(Ne, { className: "h-4 w-4 text-slate-500" }),
|
|
245
|
+
/* @__PURE__ */ n("div", { children: [
|
|
246
|
+
/* @__PURE__ */ r("p", { className: "text-sm font-medium", children: "Translations" }),
|
|
247
|
+
/* @__PURE__ */ r("p", { className: "text-xs text-muted-foreground", children: "Add translated shipping rate labels for the active storefront languages." })
|
|
248
|
+
] })
|
|
249
|
+
] }),
|
|
250
|
+
/* @__PURE__ */ r("div", { className: "grid gap-4 md:grid-cols-2", children: X.map((e) => /* @__PURE__ */ n("div", { className: "space-y-2", children: [
|
|
251
|
+
/* @__PURE__ */ r(N, { htmlFor: `rate-name-${e.code}`, children: e.name }),
|
|
252
|
+
/* @__PURE__ */ r(
|
|
253
|
+
O,
|
|
254
|
+
{
|
|
255
|
+
id: `rate-name-${e.code}`,
|
|
256
|
+
value: D[e.code] || "",
|
|
257
|
+
onChange: (o) => J((t) => ({
|
|
258
|
+
...t,
|
|
259
|
+
[e.code]: o.target.value
|
|
260
|
+
})),
|
|
261
|
+
placeholder: k || "Translated label"
|
|
262
|
+
}
|
|
263
|
+
)
|
|
264
|
+
] }, e.code)) })
|
|
265
|
+
] }),
|
|
266
|
+
/* @__PURE__ */ n("div", { className: "space-y-2", children: [
|
|
267
|
+
/* @__PURE__ */ r(N, { htmlFor: "type", children: "Method Type" }),
|
|
268
|
+
/* @__PURE__ */ n(
|
|
269
|
+
ee,
|
|
270
|
+
{
|
|
271
|
+
value: b,
|
|
272
|
+
onValueChange: ue,
|
|
273
|
+
children: [
|
|
274
|
+
/* @__PURE__ */ r(
|
|
275
|
+
te,
|
|
276
|
+
{
|
|
277
|
+
id: "type",
|
|
278
|
+
className: "bg-slate-50/50 dark:bg-slate-900/50",
|
|
279
|
+
children: /* @__PURE__ */ r(re, { placeholder: "Select type" })
|
|
280
|
+
}
|
|
281
|
+
),
|
|
282
|
+
/* @__PURE__ */ n(ne, { children: [
|
|
283
|
+
/* @__PURE__ */ r(V, { value: "flat_rate", children: /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
|
|
284
|
+
/* @__PURE__ */ r("div", { className: "p-1 min-w-5 h-5 rounded bg-emerald-100 dark:bg-emerald-900/30 text-emerald-600", children: /* @__PURE__ */ r(B, { className: "h-3 w-3" }) }),
|
|
285
|
+
/* @__PURE__ */ r("span", { children: "Flat Rate" })
|
|
286
|
+
] }) }),
|
|
287
|
+
/* @__PURE__ */ r(V, { value: "free_shipping", children: /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
|
|
288
|
+
/* @__PURE__ */ r("div", { className: "p-1 min-w-5 h-5 rounded bg-amber-100 dark:bg-amber-900/30 text-amber-600", children: /* @__PURE__ */ r(_e, { className: "h-3 w-3" }) }),
|
|
289
|
+
/* @__PURE__ */ r("span", { children: "Free Shipping" })
|
|
290
|
+
] }) })
|
|
291
|
+
] })
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
] }),
|
|
296
|
+
/* @__PURE__ */ n("div", { className: "space-y-3 rounded-xl border bg-slate-50/70 p-4 dark:bg-slate-900/40", children: [
|
|
297
|
+
/* @__PURE__ */ n("label", { className: "flex items-start gap-3", children: [
|
|
298
|
+
/* @__PURE__ */ r(
|
|
299
|
+
"input",
|
|
300
|
+
{
|
|
301
|
+
type: "checkbox",
|
|
302
|
+
checked: i === "auto",
|
|
303
|
+
onChange: (e) => ie(
|
|
304
|
+
e.target.checked ? "auto" : "manual"
|
|
305
|
+
),
|
|
306
|
+
className: "mt-1 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"
|
|
307
|
+
}
|
|
308
|
+
),
|
|
309
|
+
/* @__PURE__ */ n("span", { className: "space-y-1", children: [
|
|
310
|
+
/* @__PURE__ */ r("span", { className: "block text-sm font-medium text-slate-900 dark:text-slate-100", children: "Auto-sync all currency rates from one source amount" }),
|
|
311
|
+
/* @__PURE__ */ r("span", { className: "block text-xs text-muted-foreground", children: "Turn this off to set exact shipping costs and free-shipping thresholds for every active currency manually." })
|
|
312
|
+
] })
|
|
313
|
+
] }),
|
|
314
|
+
i === "auto" ? /* @__PURE__ */ n("div", { className: "space-y-2", children: [
|
|
315
|
+
/* @__PURE__ */ r(N, { htmlFor: "rate-currency", children: "Sync From Currency" }),
|
|
316
|
+
/* @__PURE__ */ n(
|
|
317
|
+
ee,
|
|
318
|
+
{
|
|
319
|
+
value: a,
|
|
320
|
+
onValueChange: me,
|
|
321
|
+
children: [
|
|
322
|
+
/* @__PURE__ */ r(
|
|
323
|
+
te,
|
|
324
|
+
{
|
|
325
|
+
id: "rate-currency",
|
|
326
|
+
className: "bg-background",
|
|
327
|
+
children: /* @__PURE__ */ r(re, { placeholder: "Select currency" })
|
|
328
|
+
}
|
|
329
|
+
),
|
|
330
|
+
/* @__PURE__ */ r(ne, { children: s.map((e) => /* @__PURE__ */ n(V, { value: e.code, children: [
|
|
331
|
+
e.code,
|
|
332
|
+
e.is_default ? " (Default)" : ""
|
|
333
|
+
] }, e.code)) })
|
|
334
|
+
]
|
|
335
|
+
}
|
|
336
|
+
),
|
|
337
|
+
/* @__PURE__ */ r("p", { className: "text-[10px] text-slate-500", children: "Enter the source amount once and the other currencies will be derived automatically using the current FX rates." })
|
|
338
|
+
] }) : /* @__PURE__ */ r("p", { className: "text-[10px] text-slate-500", children: "Manual mode stores exact values per currency. This is the best choice when shipping should not follow exchange-rate math directly." })
|
|
339
|
+
] }),
|
|
340
|
+
/* @__PURE__ */ n("div", { className: "space-y-3", children: [
|
|
341
|
+
/* @__PURE__ */ n("div", { children: [
|
|
342
|
+
/* @__PURE__ */ r("p", { className: "text-sm font-medium", children: "Currency Rates" }),
|
|
343
|
+
/* @__PURE__ */ r("p", { className: "text-xs text-muted-foreground", children: b === "free_shipping" ? "Free-shipping methods keep cost at zero, but you can still control the threshold per currency." : i === "auto" ? `Only ${a} is editable. The rest are derived automatically.` : "Set the exact shopper-facing shipping price for each active currency." })
|
|
344
|
+
] }),
|
|
345
|
+
/* @__PURE__ */ r("div", { className: "grid gap-4 md:grid-cols-2 xl:grid-cols-3", children: s.map((e) => {
|
|
346
|
+
const o = i === "auto" && e.code !== a, t = E(e.code) === 1 ? "1" : "0.01";
|
|
347
|
+
return /* @__PURE__ */ n(
|
|
348
|
+
"div",
|
|
349
|
+
{
|
|
350
|
+
className: "space-y-4 rounded-xl border bg-card/70 p-4 shadow-sm",
|
|
351
|
+
children: [
|
|
352
|
+
/* @__PURE__ */ n("div", { className: "flex items-center justify-between gap-2", children: [
|
|
353
|
+
/* @__PURE__ */ n("div", { children: [
|
|
354
|
+
/* @__PURE__ */ r("p", { className: "font-medium", children: e.code }),
|
|
355
|
+
/* @__PURE__ */ n("p", { className: "text-xs text-muted-foreground", children: [
|
|
356
|
+
"Rate ",
|
|
357
|
+
e.exchange_rate
|
|
358
|
+
] })
|
|
359
|
+
] }),
|
|
360
|
+
/* @__PURE__ */ n("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
361
|
+
e.is_default ? /* @__PURE__ */ r(q, { variant: "outline", children: "Default" }) : null,
|
|
362
|
+
i === "auto" && e.code === a ? /* @__PURE__ */ r(q, { children: "Source" }) : null,
|
|
363
|
+
o ? /* @__PURE__ */ r(q, { variant: "outline", children: "Derived" }) : null
|
|
364
|
+
] })
|
|
365
|
+
] }),
|
|
366
|
+
/* @__PURE__ */ n("div", { className: "space-y-2", children: [
|
|
367
|
+
/* @__PURE__ */ n(N, { htmlFor: `rate-cost-${e.code}`, children: [
|
|
368
|
+
"Cost (",
|
|
369
|
+
e.code,
|
|
370
|
+
")"
|
|
371
|
+
] }),
|
|
372
|
+
/* @__PURE__ */ n("div", { className: "relative", children: [
|
|
373
|
+
/* @__PURE__ */ r(B, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-slate-400" }),
|
|
374
|
+
/* @__PURE__ */ r(
|
|
375
|
+
O,
|
|
376
|
+
{
|
|
377
|
+
id: `rate-cost-${e.code}`,
|
|
378
|
+
type: "number",
|
|
379
|
+
step: t,
|
|
380
|
+
min: "0",
|
|
381
|
+
value: P[e.code] ?? "",
|
|
382
|
+
onChange: (d) => S((y) => ({
|
|
383
|
+
...y,
|
|
384
|
+
[e.code]: d.target.value
|
|
385
|
+
})),
|
|
386
|
+
className: "pl-9 bg-slate-50/50 dark:bg-slate-900/50 disabled:opacity-70",
|
|
387
|
+
disabled: b === "free_shipping" || o,
|
|
388
|
+
required: b !== "free_shipping" && i === "manual"
|
|
389
|
+
}
|
|
390
|
+
)
|
|
391
|
+
] })
|
|
392
|
+
] }),
|
|
393
|
+
/* @__PURE__ */ n("div", { className: "space-y-2", children: [
|
|
394
|
+
/* @__PURE__ */ n(N, { htmlFor: `rate-threshold-${e.code}`, children: [
|
|
395
|
+
"Free-Shipping Threshold (",
|
|
396
|
+
e.code,
|
|
397
|
+
")"
|
|
398
|
+
] }),
|
|
399
|
+
/* @__PURE__ */ n("div", { className: "relative", children: [
|
|
400
|
+
/* @__PURE__ */ r(B, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-slate-400" }),
|
|
401
|
+
/* @__PURE__ */ r(
|
|
402
|
+
O,
|
|
403
|
+
{
|
|
404
|
+
id: `rate-threshold-${e.code}`,
|
|
405
|
+
type: "number",
|
|
406
|
+
step: t,
|
|
407
|
+
min: "0",
|
|
408
|
+
value: U[e.code] ?? "",
|
|
409
|
+
onChange: (d) => F((y) => ({
|
|
410
|
+
...y,
|
|
411
|
+
[e.code]: d.target.value
|
|
412
|
+
})),
|
|
413
|
+
className: "pl-9 bg-slate-50/50 dark:bg-slate-900/50 disabled:opacity-70",
|
|
414
|
+
disabled: o,
|
|
415
|
+
placeholder: E(e.code) === 1 ? "0" : "0.00"
|
|
416
|
+
}
|
|
417
|
+
)
|
|
418
|
+
] })
|
|
419
|
+
] }),
|
|
420
|
+
o ? /* @__PURE__ */ n("p", { className: "text-[10px] text-muted-foreground", children: [
|
|
421
|
+
"This currency is synced automatically from ",
|
|
422
|
+
a,
|
|
423
|
+
"."
|
|
424
|
+
] }) : i === "manual" ? /* @__PURE__ */ r("p", { className: "text-[10px] text-muted-foreground", children: "Enter the exact amount shoppers should see in this currency." }) : null
|
|
425
|
+
]
|
|
426
|
+
},
|
|
427
|
+
e.code
|
|
428
|
+
);
|
|
429
|
+
}) })
|
|
430
|
+
] })
|
|
431
|
+
] }),
|
|
432
|
+
/* @__PURE__ */ n(xe, { className: "bg-slate-50 dark:bg-slate-900/50 -mx-6 -mb-6 p-4 border-t dark:border-slate-800", children: [
|
|
433
|
+
/* @__PURE__ */ r(z, { type: "button", variant: "ghost", onClick: () => I(!1), disabled: L, children: "Cancel" }),
|
|
434
|
+
/* @__PURE__ */ r(z, { type: "submit", disabled: L || !k.trim(), children: L ? A ? "Saving..." : "Adding..." : A ? "Save Changes" : "Add Rate" })
|
|
435
|
+
] })
|
|
436
|
+
] }) })
|
|
437
|
+
] });
|
|
438
|
+
}
|
|
439
|
+
export {
|
|
440
|
+
Pe as RateForm
|
|
441
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),r=require("@nextblock-cms/ui"),p=require("lucide-react"),S=require("../../../../countries.cjs.js"),B=require("../../../../states.cjs.js"),_=require("../server-actions.cjs.js");function $(h=[]){return[...new Set(h.map(o=>o.country_code))]}function q(h=[]){return h.reduce((o,a)=>{if(!a.state_code)return o;const i=new Set(o[a.country_code]||[]);return i.add(a.state_code),o[a.country_code]=[...i],o},{})}function E(h,o){return h.flatMap(a=>{const i=o[a]||[];return i.length===0?[{country_code:a,state_code:null}]:i.map(d=>({country_code:a,state_code:d}))})}function I({mode:h="create",initialData:o}){const[a,i]=c.useState(!1),d=h==="edit",[u,g]=c.useState(o?.name||""),[f,j]=c.useState(o?.priority_order||0),[m,v]=c.useState($(o?.locations)),[y,x]=c.useState(q(o?.locations)),[N,b]=c.useState(""),[w,C]=c.useState(!1);c.useEffect(()=>{a&&(g(o?.name||""),j(o?.priority_order||0),v($(o?.locations)),x(q(o?.locations)),b(""))},[o,a]);const Z=c.useMemo(()=>{const s=N.trim().toLowerCase();return s?S.countries.filter(t=>t.name.toLowerCase().includes(s)||t.code.toLowerCase().includes(s)):S.countries},[N]),k=c.useMemo(()=>S.countries.filter(s=>m.includes(s.code)),[m]),F=s=>{v(t=>t.includes(s)?t.filter(n=>n!==s):[...t,s]),x(t=>{if(t[s]){const n={...t};return delete n[s],n}return t})},P=(s,t)=>{x(n=>{const l=new Set(n[s]||[]);return l.has(t)?l.delete(t):l.add(t),{...n,[s]:[...l]}})},z=async s=>{if(s.preventDefault(),!u||m.length===0)return;C(!0);const t=E(m,y),n=d&&o?.id?await _.updateShippingZone(o.id,u,f,t):await _.createShippingZone(u,f,t);C(!1),n.success?(i(!1),d||(g(""),j(0),v([]),x({}),b(""))):n.error&&alert(n.error)};return e.jsxs(r.Dialog,{open:a,onOpenChange:i,children:[e.jsx(r.DialogTrigger,{asChild:!0,children:d?e.jsx(r.Button,{variant:"ghost",size:"icon",className:"h-8 w-8 text-slate-400 hover:text-primary",children:e.jsx(p.Edit2,{className:"h-4 w-4"})}):e.jsxs(r.Button,{className:"gap-2 shadow-sm",children:[e.jsx(p.Plus,{className:"h-4 w-4"}),"New Zone"]})}),e.jsx(r.DialogContent,{className:"max-w-4xl max-h-[90vh] flex flex-col overflow-hidden",children:e.jsxs("form",{onSubmit:z,className:"flex h-full flex-col overflow-hidden",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:d?"Edit Shipping Zone":"Create Shipping Zone"}),e.jsx(r.DialogDescription,{children:"Select countries first, then optionally limit a zone to specific states or provinces. Leaving state selections empty keeps the whole country in the zone."})]}),e.jsxs("div",{className:"grid gap-6 overflow-y-auto py-6 pr-2",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx(r.Label,{htmlFor:"name",className:"text-right",children:"Zone Name"}),e.jsx(r.Input,{id:"name",value:u,onChange:s=>g(s.target.value),placeholder:"e.g. North America, Canada East, US West",className:"col-span-3",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx(r.Label,{htmlFor:"priority",className:"text-right",children:"Priority Order"}),e.jsx(r.Input,{id:"priority",type:"number",value:f,onChange:s=>j(Number(s.target.value)),className:"col-span-3"})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[1.2fr_1fr]",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between gap-3",children:[e.jsxs(r.Label,{className:"text-sm font-semibold",children:["Countries (",m.length,")"]}),e.jsxs("div",{className:"relative w-full max-w-xs",children:[e.jsx(p.Search,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-slate-400"}),e.jsx(r.Input,{placeholder:"Search countries...",className:"pl-9 h-9",value:N,onChange:s=>b(s.target.value)})]})]}),e.jsx(r.Card,{className:"border-slate-200 bg-slate-50/30 p-4 dark:border-slate-800 dark:bg-slate-900/30",children:e.jsx("div",{className:"grid max-h-[360px] grid-cols-1 gap-3 overflow-y-auto pr-1 sm:grid-cols-2",children:Z.map(s=>{const t=m.includes(s.code);return e.jsxs("div",{className:`flex items-center space-x-2 rounded-md border p-2 transition-colors ${t?"border-primary/30 bg-primary/5 text-primary":"border-transparent hover:bg-slate-100 dark:hover:bg-slate-800/60"}`,children:[e.jsx(r.Checkbox,{id:`country-${s.code}`,checked:t,onCheckedChange:()=>F(s.code)}),e.jsxs("label",{htmlFor:`country-${s.code}`,className:"flex-1 cursor-pointer text-xs py-1",children:[s.name," (",s.code,")"]})]},s.code)})})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p.MapPin,{className:"h-4 w-4 text-slate-500"}),e.jsx(r.Label,{className:"text-sm font-semibold",children:"States / Provinces"})]}),k.length===0?e.jsx(r.Card,{className:"border-dashed p-4 text-sm text-muted-foreground",children:"Select one or more countries to optionally narrow the zone to specific states or provinces."}):e.jsx("div",{className:"space-y-4",children:k.map(s=>{const t=B.getStatesForCountry(s.code),n=y[s.code]||[];return e.jsx(r.Card,{className:"p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[s.name," (",s.code,")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.length>0?"Leave all unchecked to apply this zone to the whole country.":"This country uses a country-level zone in the current UI."})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n.length>0?`${n.length} selected`:"Whole country"})]}),t.length>0?e.jsx("div",{className:"grid max-h-[220px] grid-cols-1 gap-2 overflow-y-auto pr-1 sm:grid-cols-2",children:t.map(l=>{const L=n.includes(l.code);return e.jsxs("div",{className:`flex items-center space-x-2 rounded-md border p-2 transition-colors ${L?"border-primary/30 bg-primary/5 text-primary":"border-transparent hover:bg-slate-50 dark:hover:bg-slate-800/60"}`,children:[e.jsx(r.Checkbox,{id:`${s.code}-${l.code}`,checked:L,onCheckedChange:()=>P(s.code,l.code)}),e.jsxs("label",{htmlFor:`${s.code}-${l.code}`,className:"flex-1 cursor-pointer text-xs py-1",children:[l.name," (",l.code,")"]})]},`${s.code}-${l.code}`)})}):null]})},s.code)})})]})]})]}),e.jsxs(r.DialogFooter,{className:"mt-auto border-t pt-4",children:[e.jsx(r.Button,{type:"button",variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),e.jsx(r.Button,{type:"submit",disabled:w||!u||m.length===0,children:w?d?"Updating...":"Creating...":d?"Save Changes":"Create Zone"})]})]})})]})}exports.ZoneForm=I;
|