@nextblock-cms/ecom 0.20.1 → 0.21.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/_virtual/_rolldown/runtime.cjs.js +1 -0
- package/index.cjs.js +1 -1
- package/index.es.js +38 -146
- package/lib/CurrencyProvider.cjs.js +1 -1
- package/lib/CurrencyProvider.d.ts +1 -1
- package/lib/CurrencyProvider.es.js +85 -95
- package/lib/PaymentReadinessProvider.cjs.js +1 -1
- package/lib/PaymentReadinessProvider.d.ts +1 -1
- package/lib/PaymentReadinessProvider.es.js +24 -27
- package/lib/cart-store.cjs.js +1 -1
- package/lib/cart-store.es.js +109 -121
- package/lib/components/AccountNavigationMenu.cjs.js +1 -1
- package/lib/components/AccountNavigationMenu.d.ts +1 -1
- package/lib/components/AccountNavigationMenu.es.js +36 -50
- package/lib/components/AddToCartButton.cjs.js +1 -1
- package/lib/components/AddToCartButton.d.ts +1 -1
- package/lib/components/AddToCartButton.es.js +94 -89
- package/lib/components/Cart.cjs.js +1 -1
- package/lib/components/Cart.d.ts +1 -1
- package/lib/components/Cart.es.js +261 -180
- package/lib/components/CartDrawer.cjs.js +1 -1
- package/lib/components/CartDrawer.d.ts +1 -1
- package/lib/components/CartDrawer.es.js +218 -148
- package/lib/components/CartIcon.cjs.js +1 -1
- package/lib/components/CartIcon.d.ts +1 -1
- package/lib/components/CartIcon.es.js +33 -35
- package/lib/components/Checkout.cjs.js +1 -1
- package/lib/components/Checkout.d.ts +1 -1
- package/lib/components/Checkout.es.js +1092 -1108
- package/lib/components/CouponForm.cjs.js +1 -1
- package/lib/components/CouponForm.d.ts +1 -1
- package/lib/components/CouponForm.es.js +136 -148
- package/lib/components/CurrencySwitcher.cjs.js +1 -1
- package/lib/components/CurrencySwitcher.d.ts +1 -1
- package/lib/components/CurrencySwitcher.es.js +22 -18
- package/lib/components/CustomerProfileForm.cjs.js +1 -1
- package/lib/components/CustomerProfileForm.es.js +454 -313
- package/lib/components/FeaturedProduct.cjs.js +1 -1
- package/lib/components/FeaturedProduct.d.ts +1 -1
- package/lib/components/FeaturedProduct.es.js +98 -83
- package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
- package/lib/components/FreemiusLicensePanel.d.ts +1 -1
- package/lib/components/FreemiusLicensePanel.es.js +70 -65
- package/lib/components/InvoiceDocument.cjs.js +1 -1
- package/lib/components/InvoiceDocument.es.js +256 -192
- package/lib/components/InvoiceViewerShell.cjs.js +2 -2
- package/lib/components/InvoiceViewerShell.d.ts +1 -1
- package/lib/components/InvoiceViewerShell.es.js +75 -106
- package/lib/components/ProductCard.cjs.js +1 -1
- package/lib/components/ProductCard.d.ts +1 -1
- package/lib/components/ProductCard.es.js +186 -171
- package/lib/components/ProductDetailsLayout.cjs.js +1 -1
- package/lib/components/ProductDetailsLayout.es.js +405 -404
- package/lib/components/ProductGallery.cjs.js +1 -1
- package/lib/components/ProductGallery.d.ts +1 -1
- package/lib/components/ProductGallery.es.js +51 -54
- package/lib/components/ProductGrid.cjs.js +1 -1
- package/lib/components/ProductGrid.d.ts +1 -1
- package/lib/components/ProductGrid.es.js +23 -25
- package/lib/components/ShippingEstimator.cjs.js +1 -1
- package/lib/components/ShippingEstimator.d.ts +1 -1
- package/lib/components/ShippingEstimator.es.js +158 -153
- package/lib/components/ShortDescription.cjs.js +1 -1
- package/lib/components/ShortDescription.es.js +17 -17
- package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
- package/lib/components/SimpleTiptapRenderer.es.js +238 -211
- package/lib/components/SubscriptionSelector.cjs.js +1 -1
- package/lib/components/SubscriptionSelector.es.js +159 -154
- package/lib/countries.cjs.js +1 -1
- package/lib/countries.es.js +232 -75
- package/lib/coupon-server.cjs.js +1 -1
- package/lib/coupon-server.es.js +180 -224
- package/lib/coupons.cjs.js +1 -1
- package/lib/coupons.es.js +12 -14
- package/lib/currency-constants.cjs.js +1 -1
- package/lib/currency-constants.es.js +4 -4
- package/lib/currency-rest-client.cjs.js +1 -1
- package/lib/currency-rest-client.es.js +15 -22
- package/lib/currency-store.cjs.js +1 -1
- package/lib/currency-store.es.js +20 -27
- package/lib/currency-sync.cjs.js +1 -1
- package/lib/currency-sync.es.js +124 -170
- package/lib/currency.cjs.js +1 -1
- package/lib/currency.es.js +242 -310
- package/lib/customer-addresses.cjs.js +1 -1
- package/lib/customer-addresses.es.js +80 -109
- package/lib/customer-orders.cjs.js +1 -1
- package/lib/customer-orders.es.js +31 -43
- package/lib/customer.cjs.js +1 -1
- package/lib/customer.es.js +43 -52
- package/lib/export-helpers.cjs.js +1 -1
- package/lib/export-helpers.es.js +53 -52
- package/lib/factory.cjs.js +1 -1
- package/lib/factory.es.js +10 -7
- package/lib/freemius-coupons.cjs.js +1 -1
- package/lib/freemius-coupons.es.js +245 -262
- package/lib/freemius-license-claim.cjs.js +1 -1
- package/lib/freemius-license-claim.es.js +87 -71
- package/lib/freemius-license.cjs.js +1 -1
- package/lib/freemius-license.es.js +32 -39
- package/lib/freemius-order-sync.cjs.js +1 -1
- package/lib/freemius-order-sync.es.js +226 -290
- package/lib/freemius-trial-provision.cjs.js +1 -1
- package/lib/freemius-trial-provision.es.js +136 -130
- package/lib/inventory-settings.cjs.js +1 -1
- package/lib/inventory-settings.es.js +69 -77
- package/lib/invoice-server.cjs.js +3 -3
- package/lib/invoice-server.es.js +94 -141
- package/lib/invoice-ui.cjs.js +1 -1
- package/lib/invoice-ui.es.js +50 -66
- package/lib/invoice.cjs.js +1 -1
- package/lib/invoice.es.js +85 -94
- package/lib/order-inventory.cjs.js +25 -25
- package/lib/order-inventory.es.js +67 -79
- package/lib/order-tax-details.cjs.js +1 -1
- package/lib/order-tax-details.es.js +142 -153
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
- package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
- package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
- package/lib/pages/cms/coupons/actions.cjs.js +1 -1
- package/lib/pages/cms/coupons/actions.es.js +112 -115
- package/lib/pages/cms/coupons/index.cjs.js +1 -0
- package/lib/pages/cms/coupons/index.es.js +3 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
- package/lib/pages/cms/coupons/product-options.es.js +21 -23
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
- package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
- package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
- package/lib/pages/cms/orders/actions.cjs.js +3 -3
- package/lib/pages/cms/orders/actions.es.js +53 -69
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
- package/lib/pages/cms/orders/export-actions.es.js +23 -26
- package/lib/pages/cms/orders/index.cjs.js +1 -0
- package/lib/pages/cms/orders/index.es.js +6 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
- package/lib/pages/cms/orders/server-actions.es.js +60 -51
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
- package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
- package/lib/pages/cms/payments/actions.cjs.js +1 -1
- package/lib/pages/cms/payments/actions.es.js +38 -48
- package/lib/pages/cms/payments/index.cjs.js +1 -0
- package/lib/pages/cms/payments/index.es.js +3 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -1
- package/lib/pages/cms/payments/queries.es.js +38 -48
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
- package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
- package/lib/pages/cms/products/ProductsPage.es.js +63 -66
- package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
- package/lib/pages/cms/products/actions.cjs.js +4 -4
- package/lib/pages/cms/products/actions.es.js +121 -162
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
- package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
- package/lib/pages/cms/products/index.cjs.js +1 -0
- package/lib/pages/cms/products/index.es.js +8 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
- package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
- package/lib/pages/cms/products/inventory/actions.es.js +83 -91
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
- package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
- package/lib/pages/cms/products/product-price-sync.es.js +74 -89
- package/lib/pages/cms/products/server-actions.cjs.js +1 -1
- package/lib/pages/cms/products/server-actions.es.js +250 -233
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
- package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
- package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
- package/lib/pages/cms/shipping/index.cjs.js +1 -0
- package/lib/pages/cms/shipping/index.es.js +3 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
- package/lib/pages/cms/shipping/server-actions.es.js +131 -149
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
- package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
- package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
- package/lib/pages/cms/taxes/actions.cjs.js +1 -1
- package/lib/pages/cms/taxes/actions.es.js +41 -53
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
- package/lib/pages/cms/taxes/index.cjs.js +1 -0
- package/lib/pages/cms/taxes/index.es.js +3 -0
- package/lib/payment-config.cjs.js +1 -1
- package/lib/payment-config.es.js +110 -126
- package/lib/product-actions.cjs.js +4 -4
- package/lib/product-actions.es.js +289 -544
- package/lib/product-context.cjs.js +1 -1
- package/lib/product-context.es.js +13 -15
- package/lib/product-schema.cjs.js +1 -1
- package/lib/product-schema.es.js +99 -134
- package/lib/providers/freemius.cjs.js +1 -5
- package/lib/providers/freemius.es.js +446 -530
- package/lib/providers/stripe.cjs.js +1 -1
- package/lib/providers/stripe.es.js +417 -477
- package/lib/server-actions/coupon-actions.cjs.js +1 -1
- package/lib/server-actions/coupon-actions.es.js +22 -22
- package/lib/server-actions/customer-actions.cjs.js +1 -1
- package/lib/server-actions/customer-actions.es.js +26 -28
- package/lib/server-actions/product-actions.cjs.js +1 -1
- package/lib/server-actions/product-actions.es.js +9 -15
- package/lib/server-actions/shipping-actions.cjs.js +1 -1
- package/lib/server-actions/shipping-actions.es.js +27 -24
- package/lib/server-actions/tax-actions.cjs.js +1 -1
- package/lib/server-actions/tax-actions.es.js +33 -39
- package/lib/shared-inventory.cjs.js +2 -2
- package/lib/shared-inventory.es.js +111 -160
- package/lib/shipping/resolver.cjs.js +2 -2
- package/lib/shipping/resolver.es.js +44 -61
- package/lib/shipping-rate-currency.cjs.js +1 -1
- package/lib/shipping-rate-currency.es.js +52 -67
- package/lib/states.cjs.js +1 -1
- package/lib/states.es.js +333 -154
- package/lib/stripe/checkout.cjs.js +1 -1
- package/lib/stripe/checkout.es.js +125 -181
- package/lib/stripe/client.cjs.js +1 -1
- package/lib/stripe/client.es.js +14 -19
- package/lib/stripe/order-sync.cjs.js +1 -1
- package/lib/stripe/order-sync.es.js +106 -126
- package/lib/stripe/webhooks.cjs.js +1 -1
- package/lib/stripe/webhooks.es.js +37 -31
- package/lib/tax-calculation.cjs.js +1 -1
- package/lib/tax-calculation.es.js +84 -98
- package/lib/trials.cjs.js +1 -1
- package/lib/trials.es.js +24 -30
- package/lib/types.cjs.js +1 -1
- package/lib/types.es.js +21 -27
- package/lib/use-cart.cjs.js +1 -1
- package/lib/use-cart.es.js +38 -40
- package/lib/use-price-formatter.cjs.js +1 -1
- package/lib/use-price-formatter.es.js +10 -11
- package/lib/variation-utils.cjs.js +1 -1
- package/lib/variation-utils.es.js +199 -261
- package/lib/zod-config.cjs.js +1 -1
- package/lib/zod-config.es.js +5 -6
- package/package.json +16 -16
- package/server.cjs.js +1 -1
- package/server.es.js +56 -211
|
@@ -1 +1 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use client";const e=require("../use-cart.cjs.js"),t=require("../use-price-formatter.cjs.js"),n=require("../coupons.cjs.js"),r=require("../server-actions/coupon-actions.cjs.js");let i=require("@nextblock-cms/ui/badge"),a=require("@nextblock-cms/ui/button"),o=require("react"),s=require("lucide-react"),c=require("@nextblock-cms/utils"),l=require("react/jsx-runtime"),u=require("@nextblock-cms/ui/input"),d=require("@nextblock-cms/ui/label");function f({items:f,currencyCode:p,onQuoteChange:m,compact:h=!1}){let g=e.useCart(e=>e.appliedCoupon),_=e.useCart(e=>e.setAppliedCoupon),v=e.useCart(e=>e.removeCoupon),{t:y}=(0,c.useTranslations)(),b=t.usePriceFormatter(),[x,S]=(0,o.useState)(``),[C,w]=(0,o.useState)(null),[T,E]=(0,o.useState)(``),[D,O]=(0,o.useState)(!1),k=(0,o.useRef)(null),A=(0,o.useMemo)(()=>f.map(e=>`${e.product_id}:${e.variant_id||`base`}:${e.quantity}`).sort().join(`|`),[f]),j=(0,o.useCallback)((e,t)=>{let n=y(e);return n===e?t:n},[y]),M=(0,o.useCallback)(e=>`${n.normalizeCouponCode(e)}:${p}:${A}`,[A,p]),N=(0,o.useCallback)(async(e,t)=>{let i=n.normalizeCouponCode(e);if(!i){E(j(`ecommerce.coupon_code_required`,`Enter a coupon code.`));return}O(!0),E(``);try{let e=await r.getCouponQuoteAction({code:i,items:f,currencyCode:p});if(!e.success){w(null),m?.(null),v?.(),E(e.errorKey?j(e.errorKey,e.error):e.error);return}k.current=M(e.quote.code),w(e.quote),m?.(e.quote),t?.silent||(_?.({code:e.quote.code,couponId:e.quote.couponId}),S(``)),t?.silent||E(``)}catch(e){console.error(`Failed to validate coupon:`,e),k.current=null,w(null),m?.(null),E(j(`ecommerce.coupon_validation_failed`,`Failed to validate coupon.`))}finally{O(!1)}},[v,p,M,f,m,_,j]);return(0,o.useEffect)(()=>{if(!_||!v)return;if(!g||f.length===0){k.current=null,w(null),m?.(null);return}let e=M(g.code);k.current!==e&&(k.current=e,N(g.code,{silent:!0}))},[g?.code,N,v,M,f.length,m,_]),!_||!v?null:(0,l.jsxs)(`div`,{className:h?`space-y-2`:`rounded-lg border bg-muted/10 p-4 space-y-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,l.jsxs)(d.Label,{htmlFor:h?`coupon-code-compact`:`coupon-code`,className:`flex items-center gap-2 text-sm font-medium`,children:[(0,l.jsx)(s.Tag,{className:`h-4 w-4`}),j(`ecommerce.coupon`,`Coupon`)]}),C?(0,l.jsxs)(i.Badge,{variant:`secondary`,className:`gap-1`,children:[C.code,(0,l.jsx)(`button`,{type:`button`,onClick:()=>{v(),w(null),m?.(null),E(``)},"aria-label":j(`ecommerce.remove_coupon`,`Remove coupon {code}`).replace(`{code}`,C.code),className:`-mr-1 inline-flex h-6 w-6 items-center justify-center rounded-full focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring`,children:(0,l.jsx)(s.X,{className:`h-3 w-3`})})]}):null]}),C?(0,l.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm`,children:[(0,l.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:C.name}),(0,l.jsx)(`span`,{className:`shrink-0 font-medium tabular-nums text-emerald-600 dark:text-emerald-400`,children:b(-C.discountTotal,p)})]}):(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(u.Input,{id:h?`coupon-code-compact`:`coupon-code`,name:`coupon`,autoComplete:`off`,autoCapitalize:`characters`,spellCheck:!1,"aria-invalid":T?!0:void 0,"aria-describedby":T?h?`coupon-error-compact`:`coupon-error`:void 0,value:x,onChange:e=>S(e.target.value),placeholder:j(`ecommerce.coupon_placeholder`,`SAVE10…`),className:`uppercase`,onKeyDown:e=>{e.key===`Enter`&&!D&&(e.preventDefault(),N(x))}}),(0,l.jsx)(a.Button,{type:`button`,variant:`outline`,disabled:D||f.length===0,onClick:()=>void N(x),children:D?j(`ecommerce.applying`,`Applying…`):j(`ecommerce.apply`,`Apply`)})]}),T?(0,l.jsx)(`p`,{id:h?`coupon-error-compact`:`coupon-error`,role:`alert`,className:`text-xs text-destructive`,children:T}):null]})}exports.CouponForm=f;
|
|
@@ -1,149 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
variant: "outline",
|
|
136
|
-
disabled: A || n.length === 0,
|
|
137
|
-
onClick: () => {
|
|
138
|
-
g(N);
|
|
139
|
-
},
|
|
140
|
-
children: A ? r("ecommerce.applying", "Applying…") : r("ecommerce.apply", "Apply")
|
|
141
|
-
}
|
|
142
|
-
)
|
|
143
|
-
] }),
|
|
144
|
-
h ? /* @__PURE__ */ t("p", { id: p ? "coupon-error-compact" : "coupon-error", role: "alert", className: "text-xs text-destructive", children: h }) : null
|
|
145
|
-
] });
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCart as e } from "../use-cart.es.js";
|
|
3
|
+
import { usePriceFormatter as t } from "../use-price-formatter.es.js";
|
|
4
|
+
import { normalizeCouponCode as n } from "../coupons.es.js";
|
|
5
|
+
import { getCouponQuoteAction as r } from "../server-actions/coupon-actions.es.js";
|
|
6
|
+
import { Badge as i } from "@nextblock-cms/ui/badge";
|
|
7
|
+
import { Button as a } from "@nextblock-cms/ui/button";
|
|
8
|
+
import { useCallback as o, useEffect as s, useMemo as c, useRef as l, useState as u } from "react";
|
|
9
|
+
import { Tag as d, X as f } from "lucide-react";
|
|
10
|
+
import { useTranslations as p } from "@nextblock-cms/utils";
|
|
11
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
12
|
+
import { Input as g } from "@nextblock-cms/ui/input";
|
|
13
|
+
import { Label as _ } from "@nextblock-cms/ui/label";
|
|
14
|
+
//#region libs/ecommerce/src/lib/components/CouponForm.tsx
|
|
15
|
+
function v({ items: v, currencyCode: y, onQuoteChange: b, compact: x = !1 }) {
|
|
16
|
+
let S = e((e) => e.appliedCoupon), C = e((e) => e.setAppliedCoupon), w = e((e) => e.removeCoupon), { t: T } = p(), E = t(), [D, O] = u(""), [k, A] = u(null), [j, M] = u(""), [N, P] = u(!1), F = l(null), I = c(() => v.map((e) => `${e.product_id}:${e.variant_id || "base"}:${e.quantity}`).sort().join("|"), [v]), L = o((e, t) => {
|
|
17
|
+
let n = T(e);
|
|
18
|
+
return n === e ? t : n;
|
|
19
|
+
}, [T]), R = o((e) => `${n(e)}:${y}:${I}`, [I, y]), z = o(async (e, t) => {
|
|
20
|
+
let i = n(e);
|
|
21
|
+
if (!i) {
|
|
22
|
+
M(L("ecommerce.coupon_code_required", "Enter a coupon code."));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
P(!0), M("");
|
|
26
|
+
try {
|
|
27
|
+
let e = await r({
|
|
28
|
+
code: i,
|
|
29
|
+
items: v,
|
|
30
|
+
currencyCode: y
|
|
31
|
+
});
|
|
32
|
+
if (!e.success) {
|
|
33
|
+
A(null), b?.(null), w?.(), M(e.errorKey ? L(e.errorKey, e.error) : e.error);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
F.current = R(e.quote.code), A(e.quote), b?.(e.quote), t?.silent || (C?.({
|
|
37
|
+
code: e.quote.code,
|
|
38
|
+
couponId: e.quote.couponId
|
|
39
|
+
}), O("")), t?.silent || M("");
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error("Failed to validate coupon:", e), F.current = null, A(null), b?.(null), M(L("ecommerce.coupon_validation_failed", "Failed to validate coupon."));
|
|
42
|
+
} finally {
|
|
43
|
+
P(!1);
|
|
44
|
+
}
|
|
45
|
+
}, [
|
|
46
|
+
w,
|
|
47
|
+
y,
|
|
48
|
+
R,
|
|
49
|
+
v,
|
|
50
|
+
b,
|
|
51
|
+
C,
|
|
52
|
+
L
|
|
53
|
+
]);
|
|
54
|
+
return s(() => {
|
|
55
|
+
if (!C || !w) return;
|
|
56
|
+
if (!S || v.length === 0) {
|
|
57
|
+
F.current = null, A(null), b?.(null);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let e = R(S.code);
|
|
61
|
+
F.current !== e && (F.current = e, z(S.code, { silent: !0 }));
|
|
62
|
+
}, [
|
|
63
|
+
S?.code,
|
|
64
|
+
z,
|
|
65
|
+
w,
|
|
66
|
+
R,
|
|
67
|
+
v.length,
|
|
68
|
+
b,
|
|
69
|
+
C
|
|
70
|
+
]), !C || !w ? null : /* @__PURE__ */ h("div", {
|
|
71
|
+
className: x ? "space-y-2" : "rounded-lg border bg-muted/10 p-4 space-y-3",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ h("div", {
|
|
74
|
+
className: "flex items-center justify-between gap-3",
|
|
75
|
+
children: [/* @__PURE__ */ h(_, {
|
|
76
|
+
htmlFor: x ? "coupon-code-compact" : "coupon-code",
|
|
77
|
+
className: "flex items-center gap-2 text-sm font-medium",
|
|
78
|
+
children: [/* @__PURE__ */ m(d, { className: "h-4 w-4" }), L("ecommerce.coupon", "Coupon")]
|
|
79
|
+
}), k ? /* @__PURE__ */ h(i, {
|
|
80
|
+
variant: "secondary",
|
|
81
|
+
className: "gap-1",
|
|
82
|
+
children: [k.code, /* @__PURE__ */ m("button", {
|
|
83
|
+
type: "button",
|
|
84
|
+
onClick: () => {
|
|
85
|
+
w(), A(null), b?.(null), M("");
|
|
86
|
+
},
|
|
87
|
+
"aria-label": L("ecommerce.remove_coupon", "Remove coupon {code}").replace("{code}", k.code),
|
|
88
|
+
className: "-mr-1 inline-flex h-6 w-6 items-center justify-center rounded-full focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
|
|
89
|
+
children: /* @__PURE__ */ m(f, { className: "h-3 w-3" })
|
|
90
|
+
})]
|
|
91
|
+
}) : null]
|
|
92
|
+
}),
|
|
93
|
+
k ? /* @__PURE__ */ h("div", {
|
|
94
|
+
className: "flex items-center justify-between gap-3 text-sm",
|
|
95
|
+
children: [/* @__PURE__ */ m("span", {
|
|
96
|
+
className: "min-w-0 truncate text-muted-foreground",
|
|
97
|
+
children: k.name
|
|
98
|
+
}), /* @__PURE__ */ m("span", {
|
|
99
|
+
className: "shrink-0 font-medium tabular-nums text-emerald-600 dark:text-emerald-400",
|
|
100
|
+
children: E(-k.discountTotal, y)
|
|
101
|
+
})]
|
|
102
|
+
}) : /* @__PURE__ */ h("div", {
|
|
103
|
+
className: "flex gap-2",
|
|
104
|
+
children: [/* @__PURE__ */ m(g, {
|
|
105
|
+
id: x ? "coupon-code-compact" : "coupon-code",
|
|
106
|
+
name: "coupon",
|
|
107
|
+
autoComplete: "off",
|
|
108
|
+
autoCapitalize: "characters",
|
|
109
|
+
spellCheck: !1,
|
|
110
|
+
"aria-invalid": j ? !0 : void 0,
|
|
111
|
+
"aria-describedby": j ? x ? "coupon-error-compact" : "coupon-error" : void 0,
|
|
112
|
+
value: D,
|
|
113
|
+
onChange: (e) => O(e.target.value),
|
|
114
|
+
placeholder: L("ecommerce.coupon_placeholder", "SAVE10…"),
|
|
115
|
+
className: "uppercase",
|
|
116
|
+
onKeyDown: (e) => {
|
|
117
|
+
e.key === "Enter" && !N && (e.preventDefault(), z(D));
|
|
118
|
+
}
|
|
119
|
+
}), /* @__PURE__ */ m(a, {
|
|
120
|
+
type: "button",
|
|
121
|
+
variant: "outline",
|
|
122
|
+
disabled: N || v.length === 0,
|
|
123
|
+
onClick: () => void z(D),
|
|
124
|
+
children: N ? L("ecommerce.applying", "Applying…") : L("ecommerce.apply", "Apply")
|
|
125
|
+
})]
|
|
126
|
+
}),
|
|
127
|
+
j ? /* @__PURE__ */ m("p", {
|
|
128
|
+
id: x ? "coupon-error-compact" : "coupon-error",
|
|
129
|
+
role: "alert",
|
|
130
|
+
className: "text-xs text-destructive",
|
|
131
|
+
children: j
|
|
132
|
+
}) : null
|
|
133
|
+
]
|
|
134
|
+
});
|
|
146
135
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
};
|
|
136
|
+
//#endregion
|
|
137
|
+
export { v as CouponForm };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../CurrencyProvider.cjs.js");let t=require("@nextblock-cms/utils"),n=require("react/jsx-runtime"),r=require("@nextblock-cms/ui/select");function i(){let{activeCurrencyCode:i,currencies:a,setActiveCurrencyCode:o}=e.useCurrency(),{t:s}=(0,t.useTranslations)(),c=s(`ecommerce.currency`)===`ecommerce.currency`?`Currency`:s(`ecommerce.currency`);return a.length<=1?null:(0,n.jsxs)(r.Select,{value:i,onValueChange:o,children:[(0,n.jsx)(r.SelectTrigger,{"aria-label":c,className:`h-9 w-[88px] text-xs font-semibold`,children:(0,n.jsx)(r.SelectValue,{placeholder:i})}),(0,n.jsx)(r.SelectContent,{children:a.map(e=>(0,n.jsx)(r.SelectItem,{value:e.code,children:e.code},e.code))})]})}exports.CurrencySwitcher=i;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function CurrencySwitcher(): import(
|
|
1
|
+
export declare function CurrencySwitcher(): import('react').JSX.Element | null;
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCurrency as e } from "../CurrencyProvider.es.js";
|
|
3
|
+
import { useTranslations as t } from "@nextblock-cms/utils";
|
|
4
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
5
|
+
import { Select as i, SelectContent as a, SelectItem as o, SelectTrigger as s, SelectValue as c } from "@nextblock-cms/ui/select";
|
|
6
|
+
//#region libs/ecommerce/src/lib/components/CurrencySwitcher.tsx
|
|
7
|
+
function l() {
|
|
8
|
+
let { activeCurrencyCode: l, currencies: u, setActiveCurrencyCode: d } = e(), { t: f } = t(), p = f("ecommerce.currency") === "ecommerce.currency" ? "Currency" : f("ecommerce.currency");
|
|
9
|
+
return u.length <= 1 ? null : /* @__PURE__ */ r(i, {
|
|
10
|
+
value: l,
|
|
11
|
+
onValueChange: d,
|
|
12
|
+
children: [/* @__PURE__ */ n(s, {
|
|
13
|
+
"aria-label": p,
|
|
14
|
+
className: "h-9 w-[88px] text-xs font-semibold",
|
|
15
|
+
children: /* @__PURE__ */ n(c, { placeholder: l })
|
|
16
|
+
}), /* @__PURE__ */ n(a, { children: u.map((e) => /* @__PURE__ */ n(o, {
|
|
17
|
+
value: e.code,
|
|
18
|
+
children: e.code
|
|
19
|
+
}, e.code)) })]
|
|
20
|
+
});
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { l as CurrencySwitcher };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("react"),z=require("react-hook-form"),M=require("./AccountNavigationMenu.cjs.js"),w=require("@nextblock-cms/ui/avatar"),W=require("@nextblock-cms/ui/button"),i=require("@nextblock-cms/ui/card"),H=require("@nextblock-cms/ui/checkbox"),n=require("@nextblock-cms/ui/input"),a=require("@nextblock-cms/ui/label"),d=require("@nextblock-cms/ui/select"),O=require("@nextblock-cms/ui/separator"),G=require("../server-actions/customer-actions.cjs.js"),f=require("../customer.cjs.js"),J=require("@nextblock-cms/db"),y=require("lucide-react"),R=require("@nextblock-cms/utils"),T=require("../countries.cjs.js");function K(s){return s?s.startsWith("http")?s:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${s}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${s}`:s:null}function $(s){return{company_name:s?.company_name||"",recipient_name:s?.recipient_name||"",line1:s?.line1||"",line2:s?.line2||"",city:s?.city||"",state:s?.state||"",postal_code:s?.postal_code||"",country_code:T.normalizeCountryCode(s?.country_code)||"CA"}}function q({prefix:s,title:_,register:c}){const{t}=R.useTranslations(),v=t("company_name")==="company_name"?"Company name":t("company_name");return e.jsxs("div",{className:"space-y-4 rounded-xl border p-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:_}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("profile_address_defaults_help")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-company_name`,children:v}),e.jsx(n.Input,{id:`${s}-company_name`,...c(`${s}.company_name`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-recipient_name`,children:t("full_name")}),e.jsx(n.Input,{id:`${s}-recipient_name`,...c(`${s}.recipient_name`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-country_code`,children:t("country")}),e.jsx("select",{id:`${s}-country_code`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",...c(`${s}.country_code`),children:T.countries.map(o=>e.jsx("option",{value:o.code,children:o.name},o.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-line1`,children:t("address_line_1")}),e.jsx(n.Input,{id:`${s}-line1`,...c(`${s}.line1`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-line2`,children:t("address_line_2")}),e.jsx(n.Input,{id:`${s}-line2`,...c(`${s}.line2`)})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-city`,children:t("city")}),e.jsx(n.Input,{id:`${s}-city`,...c(`${s}.city`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-state`,children:t("state_province")}),e.jsx(n.Input,{id:`${s}-state`,...c(`${s}.state`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-postal_code`,children:t("postal_zip_code")}),e.jsx(n.Input,{id:`${s}-postal_code`,...c(`${s}.postal_code`)})]})]})]})}function Q({initialData:s,MediaPickerComponent:_,isAdmin:c,email:t,accountLinks:v,onAction:o,initialSuccessMessage:x,lockRole:A,lockRoleReason:B}){const{t:l}=R.useTranslations(),[F,L]=b.useState(!1),[N,C]=b.useState(x?{type:"success",text:x}:null),P=s?.use_billing_for_shipping??(!s?.shipping_address||f.addressesMatch(s?.billing_address,s?.shipping_address)),{register:m,handleSubmit:k,setValue:g,getValues:S,watch:u,reset:I}=z.useForm({defaultValues:{full_name:s?.full_name||"",avatar_url:s?.avatar_url||"",website:s?.website||"",phone:s?.phone||"",role:s?.role,use_billing_for_shipping:P,billing_address:$(s?.billing_address),shipping_address:$(s?.shipping_address)}});b.useEffect(()=>{s&&I({full_name:s.full_name||"",avatar_url:s.avatar_url||"",website:s.website||"",phone:s.phone||"",role:s.role,use_billing_for_shipping:s.use_billing_for_shipping??(!s.shipping_address||f.addressesMatch(s.billing_address,s.shipping_address)),billing_address:$(s.billing_address),shipping_address:$(s.shipping_address)})},[s,I]),b.useEffect(()=>{x&&C({type:"success",text:x})},[x]),b.useEffect(()=>{const r=J.createClient();(async()=>{const{data:{user:j}}=await r.auth.getUser();j&&!S("full_name")&&j.user_metadata?.full_name&&g("full_name",j.user_metadata.full_name)})()},[S,g]);const V=r=>{const p=K(r?.object_key??r?.file_path);p&&g("avatar_url",p)},X=async r=>{L(!0),C(null);const p=f.normalizeCustomerAddress(r.billing_address)??f.emptyCustomerAddress(),j=r.use_billing_for_shipping?p:f.normalizeCustomerAddress(r.shipping_address);try{const h={...r,billing_address:p,shipping_address:j};if(o){const U=await o(h);if(U?.error)throw new Error(U.error)}else await G.updateProfile(h);C({type:"success",text:l("profile_updated_success")})}catch(h){if(h.message==="NEXT_REDIRECT"||h.message?.includes("NEXT_REDIRECT"))return;console.error(h),C({type:"error",text:l("profile_update_failed")})}finally{L(!1)}},E=u("use_billing_for_shipping");return e.jsxs("div",{className:"grid gap-6 md:grid-cols-12 max-w-5xl mx-auto",children:[e.jsxs(i.Card,{className:"md:col-span-4 h-fit",children:[e.jsx(i.CardHeader,{children:e.jsx(i.CardTitle,{className:"text-xl",children:l("public_profile")})}),e.jsxs(i.CardContent,{className:"flex flex-col items-center text-center space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs(w.Avatar,{className:"h-32 w-32 border-4 border-muted",children:[e.jsx(w.AvatarImage,{src:u("avatar_url")||void 0,alt:u("full_name")||"",className:"object-cover"}),e.jsx(w.AvatarFallback,{className:"text-4xl bg-secondary",children:u("full_name")?.charAt(0)?.toUpperCase()||e.jsx(y.User,{className:"h-12 w-12"})})]}),_&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity bg-black/40 rounded-full cursor-pointer",children:e.jsx(_,{triggerLabel:e.jsxs(e.Fragment,{children:[e.jsx(y.Upload,{className:"h-6 w-6 text-white"}),e.jsx("span",{className:"sr-only",children:l("profile_change_avatar")==="profile_change_avatar"?"Change profile picture":l("profile_change_avatar")})]}),triggerVariant:"ghost",title:l("customer_profile"),onSelect:V,accept:r=>r.file_type.startsWith("image/"),hideTrigger:!1})})]}),!_&&e.jsxs("div",{className:"w-full",children:[e.jsx(a.Label,{htmlFor:"avatar_url",className:"sr-only",children:l("avatar_url")}),e.jsx(n.Input,{id:"avatar_url",type:"url",autoComplete:"off",...m("avatar_url"),placeholder:"https://…",className:"mt-2"})]}),e.jsxs("div",{className:"w-full space-y-1 text-left mt-4",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:l("identity")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-semibold text-lg",children:u("full_name")||l("full_name")})})]}),v?.length?e.jsx(M.AccountNavigationMenu,{links:v,className:"mt-2 text-left"}):null]})]}),e.jsx(i.Card,{className:"md:col-span-8",children:e.jsxs("form",{onSubmit:k(X),children:[e.jsx(i.CardHeader,{children:e.jsx(i.CardTitle,{children:l("details")})}),e.jsxs(i.CardContent,{className:"space-y-6",children:[t&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(a.Label,{htmlFor:"email",children:[l("email")==="email"?"Email":l("email")," (",l("read_only")==="read_only"?"read-only":l("read_only"),")"]}),e.jsx(n.Input,{id:"email",value:t,readOnly:!0,disabled:!0,className:"bg-muted/50"})]}),e.jsx("div",{className:"rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground",children:l("profile_basic_info_help")}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(a.Label,{htmlFor:"full_name",className:"flex items-center gap-2",children:[e.jsx(y.User,{className:"h-4 w-4"})," ",l("full_name")]}),e.jsx(n.Input,{id:"full_name",autoComplete:"name",...m("full_name")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(a.Label,{htmlFor:"phone",className:"flex items-center gap-2",children:[e.jsx(y.Phone,{className:"h-4 w-4"})," ",l("phone_number")]}),e.jsx(n.Input,{id:"phone",type:"tel",inputMode:"tel",autoComplete:"tel",...m("phone")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(a.Label,{htmlFor:"website",className:"flex items-center gap-2",children:[e.jsx(y.Globe,{className:"h-4 w-4"})," ",l("website")]}),e.jsx(n.Input,{id:"website",type:"url",autoComplete:"url",...m("website"),placeholder:"https://example.com"})]}),e.jsx(O.Separator,{className:"my-2"}),e.jsx(q,{prefix:"billing_address",title:l("billing_address"),register:m}),e.jsxs("div",{className:"flex items-center space-x-3 rounded-lg border p-4",children:[e.jsx(H.Checkbox,{id:"use_billing_for_shipping",checked:!!E,onCheckedChange:r=>g("use_billing_for_shipping",!!r,{shouldDirty:!0})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{htmlFor:"use_billing_for_shipping",className:"cursor-pointer",children:l("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l("profile_use_billing_for_shipping_help")})]})]}),!E&&e.jsx(q,{prefix:"shipping_address",title:l("shipping_address"),register:m}),N&&e.jsx("div",{role:N.type==="error"?"alert":"status",className:`mt-4 rounded-xl border p-4 text-sm ${N.type==="success"?"border-emerald-200 bg-emerald-50 text-emerald-700":"border-red-200 bg-red-50 text-red-700"}`,children:N.text}),c&&e.jsxs("div",{className:"border-t pt-4 mt-4",children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Admin Settings"}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(a.Label,{htmlFor:"role",children:"Role"}),e.jsxs(d.Select,{value:u("role")||"USER",onValueChange:r=>g("role",r),disabled:A,children:[e.jsx(d.SelectTrigger,{children:e.jsx(d.SelectValue,{placeholder:"Select role"})}),e.jsxs(d.SelectContent,{children:[e.jsx(d.SelectItem,{value:"USER",children:"User"}),e.jsx(d.SelectItem,{value:"WRITER",children:"Writer"}),e.jsx(d.SelectItem,{value:"ADMIN",children:"Admin"})]})]}),A&&e.jsx("p",{className:"text-xs text-muted-foreground",children:B||"This is the only Admin account, so its role can't be changed. Promote another user to Admin first."})]})]})]}),e.jsx(i.CardFooter,{className:"flex justify-end",children:e.jsx(W.Button,{type:"submit",disabled:F,size:"lg",children:l(F?"saving":"save_changes")})})]})})]})}exports.CustomerProfileForm=Q;
|
|
1
|
+
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs.js"),t=require("../countries.cjs.js"),n=require("../customer.cjs.js"),r=require("./AccountNavigationMenu.cjs.js"),i=require("../server-actions/customer-actions.cjs.js");let a=require("@nextblock-cms/ui/button"),o=require("react");o=e.__toESM(o,1);let s=require("lucide-react"),c=require("@nextblock-cms/utils"),l=require("react/jsx-runtime"),u=require("@nextblock-cms/ui/input"),d=require("@nextblock-cms/ui/label"),f=require("@nextblock-cms/ui/card"),p=require("@nextblock-cms/ui/checkbox"),m=require("@nextblock-cms/ui/separator"),h=require("@nextblock-cms/ui/select"),g=require("react-hook-form"),_=require("@nextblock-cms/ui/avatar"),v=require("@nextblock-cms/db");function y(e){return e?e.startsWith(`http`)?e:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}`:e:null}function b(e){return{company_name:e?.company_name||``,recipient_name:e?.recipient_name||``,line1:e?.line1||``,line2:e?.line2||``,city:e?.city||``,state:e?.state||``,postal_code:e?.postal_code||``,country_code:t.normalizeCountryCode(e?.country_code)||`CA`}}function x({prefix:e,title:n,register:r}){let{t:i}=(0,c.useTranslations)(),a=i(`company_name`)===`company_name`?`Company name`:i(`company_name`);return(0,l.jsxs)(`div`,{className:`space-y-4 rounded-xl border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h3`,{className:`text-lg font-medium`,children:n}),(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`profile_address_defaults_help`)})]}),(0,l.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-company_name`,children:a}),(0,l.jsx)(u.Input,{id:`${e}-company_name`,...r(`${e}.company_name`)})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-recipient_name`,children:i(`full_name`)}),(0,l.jsx)(u.Input,{id:`${e}-recipient_name`,...r(`${e}.recipient_name`)})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-country_code`,children:i(`country`)}),(0,l.jsx)(`select`,{id:`${e}-country_code`,className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,...r(`${e}.country_code`),children:t.countries.map(e=>(0,l.jsx)(`option`,{value:e.code,children:e.name},e.code))})]})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-line1`,children:i(`address_line_1`)}),(0,l.jsx)(u.Input,{id:`${e}-line1`,...r(`${e}.line1`)})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-line2`,children:i(`address_line_2`)}),(0,l.jsx)(u.Input,{id:`${e}-line2`,...r(`${e}.line2`)})]}),(0,l.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-city`,children:i(`city`)}),(0,l.jsx)(u.Input,{id:`${e}-city`,...r(`${e}.city`)})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-state`,children:i(`state_province`)}),(0,l.jsx)(u.Input,{id:`${e}-state`,...r(`${e}.state`)})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`${e}-postal_code`,children:i(`postal_zip_code`)}),(0,l.jsx)(u.Input,{id:`${e}-postal_code`,...r(`${e}.postal_code`)})]})]})]})}function S({initialData:e,MediaPickerComponent:t,isAdmin:S,email:C,accountLinks:w,onAction:T,initialSuccessMessage:E,lockRole:D,lockRoleReason:O}){let{t:k}=(0,c.useTranslations)(),[A,j]=(0,o.useState)(!1),[M,N]=(0,o.useState)(E?{type:`success`,text:E}:null),P=e?.use_billing_for_shipping??(!e?.shipping_address||n.addressesMatch(e?.billing_address,e?.shipping_address)),{register:F,handleSubmit:I,setValue:L,getValues:R,watch:z,reset:B}=(0,g.useForm)({defaultValues:{full_name:e?.full_name||``,avatar_url:e?.avatar_url||``,website:e?.website||``,phone:e?.phone||``,role:e?.role,use_billing_for_shipping:P,billing_address:b(e?.billing_address),shipping_address:b(e?.shipping_address)}});o.default.useEffect(()=>{e&&B({full_name:e.full_name||``,avatar_url:e.avatar_url||``,website:e.website||``,phone:e.phone||``,role:e.role,use_billing_for_shipping:e.use_billing_for_shipping??(!e.shipping_address||n.addressesMatch(e.billing_address,e.shipping_address)),billing_address:b(e.billing_address),shipping_address:b(e.shipping_address)})},[e,B]),o.default.useEffect(()=>{E&&N({type:`success`,text:E})},[E]),o.default.useEffect(()=>{let e=(0,v.createClient)();(async()=>{let{data:{user:t}}=await e.auth.getUser();t&&!R(`full_name`)&&t.user_metadata?.full_name&&L(`full_name`,t.user_metadata.full_name)})()},[R,L]);let V=e=>{let t=y(e?.object_key??e?.file_path);t&&L(`avatar_url`,t)},H=async e=>{j(!0),N(null);let t=n.normalizeCustomerAddress(e.billing_address)??n.emptyCustomerAddress(),r=e.use_billing_for_shipping?t:n.normalizeCustomerAddress(e.shipping_address);try{let n={...e,billing_address:t,shipping_address:r};if(T){let e=await T(n);if(e?.error)throw Error(e.error)}else await i.updateProfile(n);N({type:`success`,text:k(`profile_updated_success`)})}catch(e){if(e.message===`NEXT_REDIRECT`||e.message?.includes(`NEXT_REDIRECT`))return;console.error(e),N({type:`error`,text:k(`profile_update_failed`)})}finally{j(!1)}},U=z(`use_billing_for_shipping`);return(0,l.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-12 max-w-5xl mx-auto`,children:[(0,l.jsxs)(f.Card,{className:`md:col-span-4 h-fit`,children:[(0,l.jsx)(f.CardHeader,{children:(0,l.jsx)(f.CardTitle,{className:`text-xl`,children:k(`public_profile`)})}),(0,l.jsxs)(f.CardContent,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,l.jsxs)(`div`,{className:`relative group`,children:[(0,l.jsxs)(_.Avatar,{className:`h-32 w-32 border-4 border-muted`,children:[(0,l.jsx)(_.AvatarImage,{src:z(`avatar_url`)||void 0,alt:z(`full_name`)||``,className:`object-cover`}),(0,l.jsx)(_.AvatarFallback,{className:`text-4xl bg-secondary`,children:z(`full_name`)?.charAt(0)?.toUpperCase()||(0,l.jsx)(s.User,{className:`h-12 w-12`})})]}),t&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity bg-black/40 rounded-full cursor-pointer`,children:(0,l.jsx)(t,{triggerLabel:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Upload,{className:`h-6 w-6 text-white`}),(0,l.jsx)(`span`,{className:`sr-only`,children:k(`profile_change_avatar`)===`profile_change_avatar`?`Change profile picture`:k(`profile_change_avatar`)})]}),triggerVariant:`ghost`,title:k(`customer_profile`),onSelect:V,accept:e=>e.file_type.startsWith(`image/`),hideTrigger:!1})})]}),!t&&(0,l.jsxs)(`div`,{className:`w-full`,children:[(0,l.jsx)(d.Label,{htmlFor:`avatar_url`,className:`sr-only`,children:k(`avatar_url`)}),(0,l.jsx)(u.Input,{id:`avatar_url`,type:`url`,autoComplete:`off`,...F(`avatar_url`),placeholder:`https://…`,className:`mt-2`})]}),(0,l.jsxs)(`div`,{className:`w-full space-y-1 text-left mt-4`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:k(`identity`)}),(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,l.jsx)(`span`,{className:`font-semibold text-lg`,children:z(`full_name`)||k(`full_name`)})})]}),w?.length?(0,l.jsx)(r.AccountNavigationMenu,{links:w,className:`mt-2 text-left`}):null]})]}),(0,l.jsx)(f.Card,{className:`md:col-span-8`,children:(0,l.jsxs)(`form`,{onSubmit:I(H),children:[(0,l.jsx)(f.CardHeader,{children:(0,l.jsx)(f.CardTitle,{children:k(`details`)})}),(0,l.jsxs)(f.CardContent,{className:`space-y-6`,children:[C&&(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsxs)(d.Label,{htmlFor:`email`,children:[k(`email`)===`email`?`Email`:k(`email`),` (`,k(`read_only`)===`read_only`?`read-only`:k(`read_only`),`)`]}),(0,l.jsx)(u.Input,{id:`email`,value:C,readOnly:!0,disabled:!0,className:`bg-muted/50`})]}),(0,l.jsx)(`div`,{className:`rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground`,children:k(`profile_basic_info_help`)}),(0,l.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsxs)(d.Label,{htmlFor:`full_name`,className:`flex items-center gap-2`,children:[(0,l.jsx)(s.User,{className:`h-4 w-4`}),` `,k(`full_name`)]}),(0,l.jsx)(u.Input,{id:`full_name`,autoComplete:`name`,...F(`full_name`)})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsxs)(d.Label,{htmlFor:`phone`,className:`flex items-center gap-2`,children:[(0,l.jsx)(s.Phone,{className:`h-4 w-4`}),` `,k(`phone_number`)]}),(0,l.jsx)(u.Input,{id:`phone`,type:`tel`,inputMode:`tel`,autoComplete:`tel`,...F(`phone`)})]})]}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsxs)(d.Label,{htmlFor:`website`,className:`flex items-center gap-2`,children:[(0,l.jsx)(s.Globe,{className:`h-4 w-4`}),` `,k(`website`)]}),(0,l.jsx)(u.Input,{id:`website`,type:`url`,autoComplete:`url`,...F(`website`),placeholder:`https://example.com`})]}),(0,l.jsx)(m.Separator,{className:`my-2`}),(0,l.jsx)(x,{prefix:`billing_address`,title:k(`billing_address`),register:F}),(0,l.jsxs)(`div`,{className:`flex items-center space-x-3 rounded-lg border p-4`,children:[(0,l.jsx)(p.Checkbox,{id:`use_billing_for_shipping`,checked:!!U,onCheckedChange:e=>L(`use_billing_for_shipping`,!!e,{shouldDirty:!0})}),(0,l.jsxs)(`div`,{className:`space-y-1`,children:[(0,l.jsx)(d.Label,{htmlFor:`use_billing_for_shipping`,className:`cursor-pointer`,children:k(`use_billing_for_shipping`)}),(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:k(`profile_use_billing_for_shipping_help`)})]})]}),!U&&(0,l.jsx)(x,{prefix:`shipping_address`,title:k(`shipping_address`),register:F}),M&&(0,l.jsx)(`div`,{role:M.type===`error`?`alert`:`status`,className:`mt-4 rounded-xl border p-4 text-sm ${M.type===`success`?`border-emerald-200 bg-emerald-50 text-emerald-700`:`border-red-200 bg-red-50 text-red-700`}`,children:M.text}),S&&(0,l.jsxs)(`div`,{className:`border-t pt-4 mt-4`,children:[(0,l.jsx)(`h3`,{className:`text-sm font-medium mb-3`,children:`Admin Settings`}),(0,l.jsxs)(`div`,{className:`grid gap-2`,children:[(0,l.jsx)(d.Label,{htmlFor:`role`,children:`Role`}),(0,l.jsxs)(h.Select,{value:z(`role`)||`USER`,onValueChange:e=>L(`role`,e),disabled:D,children:[(0,l.jsx)(h.SelectTrigger,{children:(0,l.jsx)(h.SelectValue,{placeholder:`Select role`})}),(0,l.jsxs)(h.SelectContent,{children:[(0,l.jsx)(h.SelectItem,{value:`USER`,children:`User`}),(0,l.jsx)(h.SelectItem,{value:`WRITER`,children:`Writer`}),(0,l.jsx)(h.SelectItem,{value:`ADMIN`,children:`Admin`})]})]}),D&&(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:O||`This is the only Admin account, so its role can't be changed. Promote another user to Admin first.`})]})]})]}),(0,l.jsx)(f.CardFooter,{className:`flex justify-end`,children:(0,l.jsx)(a.Button,{type:`submit`,disabled:A,size:`lg`,children:k(A?`saving`:`save_changes`)})})]})})]})}exports.CustomerProfileForm=S;
|