@nextblock-cms/ecom 0.8.6 → 0.8.7
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 +4 -4
- 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 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),n=require("react"),I=require("@nextblock-cms/ui/badge"),K=require("@nextblock-cms/ui/button"),R=require("@nextblock-cms/ui/input"),E=require("@nextblock-cms/ui/label"),$=require("lucide-react"),k=require("@nextblock-cms/utils"),w=require("../coupons.cjs.js"),q=require("../use-cart.cjs.js"),T=require("../server-actions/coupon-actions.cjs.js");function z({items:s,currencyCode:i,onQuoteChange:l,compact:C=!1}){const f=q.useCart(e=>e.appliedCoupon),d=q.useCart(e=>e.setAppliedCoupon),c=q.useCart(e=>e.removeCoupon),{t:g}=k.useTranslations(),[j,h]=n.useState(""),[a,p]=n.useState(null),[N,u]=n.useState(""),[A,_]=n.useState(!1),x=n.useRef(null),S=n.useMemo(()=>s.map(e=>`${e.product_id}:${e.variant_id||"base"}:${e.quantity}`).sort().join("|"),[s]),r=n.useCallback((e,b)=>{const m=g(e);return m===e?b:m},[g]),v=n.useCallback(e=>`${w.normalizeCouponCode(e)}:${i}:${S}`,[S,i]),y=n.useCallback(async(e,b)=>{const m=w.normalizeCouponCode(e);if(!m){u(r("ecommerce.coupon_code_required","Enter a coupon code."));return}_(!0),u("");try{const t=await T.getCouponQuoteAction({code:m,items:s,currencyCode:i});if(!t.success){p(null),l?.(null),c?.(),u(t.errorKey?r(t.errorKey,t.error):t.error);return}x.current=v(t.quote.code),p(t.quote),l?.(t.quote),b?.silent||(d?.({code:t.quote.code,couponId:t.quote.couponId}),h("")),b?.silent||u("")}catch(t){console.error("Failed to validate coupon:",t),p(null),l?.(null),u(r("ecommerce.coupon_validation_failed","Failed to validate coupon."))}finally{_(!1)}},[c,i,v,s,l,d,r]);if(n.useEffect(()=>{if(!d||!c)return;if(!f||s.length===0){x.current=null,p(null),l?.(null);return}const e=v(f.code);x.current!==e&&(x.current=e,y(f.code,{silent:!0}))},[f?.code,y,c,v,s.length,l,d]),!d||!c)return null;const F=()=>{c(),p(null),l?.(null),u("")};return o.jsxs("div",{className:C?"space-y-2":"rounded-lg border bg-muted/10 p-4 space-y-3",children:[o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsxs(E.Label,{htmlFor:C?"coupon-code-compact":"coupon-code",className:"flex items-center gap-2 text-sm font-medium",children:[o.jsx($.Tag,{className:"h-4 w-4"}),r("ecommerce.coupon","Coupon")]}),a?o.jsxs(I.Badge,{variant:"secondary",className:"gap-1",children:[a.code,o.jsx("button",{type:"button",onClick:F,"aria-label":`Remove coupon ${a.code}`,children:o.jsx($.X,{className:"h-3 w-3"})})]}):null]}),a?o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:a.name}),o.jsxs("span",{className:"font-medium text-emerald-600",children:["-",k.formatPrice(a.discountTotal,i)]})]}):o.jsxs("div",{className:"flex gap-2",children:[o.jsx(R.Input,{id:C?"coupon-code-compact":"coupon-code",value:j,onChange:e=>h(e.target.value.toUpperCase()),placeholder:r("ecommerce.coupon_placeholder","Code"),className:"uppercase",onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),y(j))}}),o.jsx(K.Button,{type:"button",variant:"outline",disabled:A||s.length===0,onClick:()=>{y(j)},children:A?r("ecommerce.applying","Applying..."):r("ecommerce.apply","Apply")})]}),N?o.jsx("p",{className:"text-xs text-destructive",children:N}):null]})}exports.CouponForm=z;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs as l, jsx as c } from "react/jsx-runtime";
|
|
3
|
+
import { useState as x, useRef as F, useMemo as k, useCallback as N, useEffect as R } from "react";
|
|
4
|
+
import { Badge as T } from "@nextblock-cms/ui/badge";
|
|
5
|
+
import { Button as z } from "@nextblock-cms/ui/button";
|
|
6
|
+
import { Input as B } from "@nextblock-cms/ui/input";
|
|
7
|
+
import { Label as D } from "@nextblock-cms/ui/label";
|
|
8
|
+
import { Tag as S, X as V } from "lucide-react";
|
|
9
|
+
import { useTranslations as L, formatPrice as M } from "@nextblock-cms/utils";
|
|
10
|
+
import { normalizeCouponCode as j } from "../coupons.es.js";
|
|
11
|
+
import { useCart as q } from "../use-cart.es.js";
|
|
12
|
+
import { getCouponQuoteAction as O } from "../server-actions/coupon-actions.es.js";
|
|
13
|
+
function oe({
|
|
14
|
+
items: r,
|
|
15
|
+
currencyCode: u,
|
|
16
|
+
onQuoteChange: n,
|
|
17
|
+
compact: b = !1
|
|
18
|
+
}) {
|
|
19
|
+
const f = q((e) => e.appliedCoupon), p = q((e) => e.setAppliedCoupon), a = q((e) => e.removeCoupon), { t: A } = L(), [C, _] = x(""), [s, d] = x(null), [$, i] = x(""), [w, I] = x(!1), v = F(null), K = k(
|
|
20
|
+
() => r.map((e) => `${e.product_id}:${e.variant_id || "base"}:${e.quantity}`).sort().join("|"),
|
|
21
|
+
[r]
|
|
22
|
+
), t = N((e, h) => {
|
|
23
|
+
const m = A(e);
|
|
24
|
+
return m === e ? h : m;
|
|
25
|
+
}, [A]), y = N(
|
|
26
|
+
(e) => `${j(e)}:${u}:${K}`,
|
|
27
|
+
[K, u]
|
|
28
|
+
), g = N(async (e, h) => {
|
|
29
|
+
const m = j(e);
|
|
30
|
+
if (!m) {
|
|
31
|
+
i(t("ecommerce.coupon_code_required", "Enter a coupon code."));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
I(!0), i("");
|
|
35
|
+
try {
|
|
36
|
+
const o = await O({
|
|
37
|
+
code: m,
|
|
38
|
+
items: r,
|
|
39
|
+
currencyCode: u
|
|
40
|
+
});
|
|
41
|
+
if (!o.success) {
|
|
42
|
+
d(null), n?.(null), a?.(), i(o.errorKey ? t(o.errorKey, o.error) : o.error);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
v.current = y(o.quote.code), d(o.quote), n?.(o.quote), h?.silent || (p?.({
|
|
46
|
+
code: o.quote.code,
|
|
47
|
+
couponId: o.quote.couponId
|
|
48
|
+
}), _("")), h?.silent || i("");
|
|
49
|
+
} catch (o) {
|
|
50
|
+
console.error("Failed to validate coupon:", o), d(null), n?.(null), i(
|
|
51
|
+
t("ecommerce.coupon_validation_failed", "Failed to validate coupon.")
|
|
52
|
+
);
|
|
53
|
+
} finally {
|
|
54
|
+
I(!1);
|
|
55
|
+
}
|
|
56
|
+
}, [
|
|
57
|
+
a,
|
|
58
|
+
u,
|
|
59
|
+
y,
|
|
60
|
+
r,
|
|
61
|
+
n,
|
|
62
|
+
p,
|
|
63
|
+
t
|
|
64
|
+
]);
|
|
65
|
+
if (R(() => {
|
|
66
|
+
if (!p || !a)
|
|
67
|
+
return;
|
|
68
|
+
if (!f || r.length === 0) {
|
|
69
|
+
v.current = null, d(null), n?.(null);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const e = y(f.code);
|
|
73
|
+
v.current !== e && (v.current = e, g(f.code, { silent: !0 }));
|
|
74
|
+
}, [
|
|
75
|
+
f?.code,
|
|
76
|
+
g,
|
|
77
|
+
a,
|
|
78
|
+
y,
|
|
79
|
+
r.length,
|
|
80
|
+
n,
|
|
81
|
+
p
|
|
82
|
+
]), !p || !a)
|
|
83
|
+
return null;
|
|
84
|
+
const E = () => {
|
|
85
|
+
a(), d(null), n?.(null), i("");
|
|
86
|
+
};
|
|
87
|
+
return /* @__PURE__ */ l("div", { className: b ? "space-y-2" : "rounded-lg border bg-muted/10 p-4 space-y-3", children: [
|
|
88
|
+
/* @__PURE__ */ l("div", { className: "flex items-center justify-between gap-3", children: [
|
|
89
|
+
/* @__PURE__ */ l(D, { htmlFor: b ? "coupon-code-compact" : "coupon-code", className: "flex items-center gap-2 text-sm font-medium", children: [
|
|
90
|
+
/* @__PURE__ */ c(S, { className: "h-4 w-4" }),
|
|
91
|
+
t("ecommerce.coupon", "Coupon")
|
|
92
|
+
] }),
|
|
93
|
+
s ? /* @__PURE__ */ l(T, { variant: "secondary", className: "gap-1", children: [
|
|
94
|
+
s.code,
|
|
95
|
+
/* @__PURE__ */ c("button", { type: "button", onClick: E, "aria-label": `Remove coupon ${s.code}`, children: /* @__PURE__ */ c(V, { className: "h-3 w-3" }) })
|
|
96
|
+
] }) : null
|
|
97
|
+
] }),
|
|
98
|
+
s ? /* @__PURE__ */ l("div", { className: "flex items-center justify-between text-sm", children: [
|
|
99
|
+
/* @__PURE__ */ c("span", { className: "text-muted-foreground", children: s.name }),
|
|
100
|
+
/* @__PURE__ */ l("span", { className: "font-medium text-emerald-600", children: [
|
|
101
|
+
"-",
|
|
102
|
+
M(s.discountTotal, u)
|
|
103
|
+
] })
|
|
104
|
+
] }) : /* @__PURE__ */ l("div", { className: "flex gap-2", children: [
|
|
105
|
+
/* @__PURE__ */ c(
|
|
106
|
+
B,
|
|
107
|
+
{
|
|
108
|
+
id: b ? "coupon-code-compact" : "coupon-code",
|
|
109
|
+
value: C,
|
|
110
|
+
onChange: (e) => _(e.target.value.toUpperCase()),
|
|
111
|
+
placeholder: t("ecommerce.coupon_placeholder", "Code"),
|
|
112
|
+
className: "uppercase",
|
|
113
|
+
onKeyDown: (e) => {
|
|
114
|
+
e.key === "Enter" && (e.preventDefault(), g(C));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
/* @__PURE__ */ c(
|
|
119
|
+
z,
|
|
120
|
+
{
|
|
121
|
+
type: "button",
|
|
122
|
+
variant: "outline",
|
|
123
|
+
disabled: w || r.length === 0,
|
|
124
|
+
onClick: () => {
|
|
125
|
+
g(C);
|
|
126
|
+
},
|
|
127
|
+
children: w ? t("ecommerce.applying", "Applying...") : t("ecommerce.apply", "Apply")
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
] }),
|
|
131
|
+
$ ? /* @__PURE__ */ c("p", { className: "text-xs text-destructive", children: $ }) : null
|
|
132
|
+
] });
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
oe as CouponForm
|
|
136
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@nextblock-cms/ui/select"),i=require("../CurrencyProvider.cjs.js");function s(){const{activeCurrencyCode:c,currencies:n,setActiveCurrencyCode:l}=i.useCurrency();return n.length<=1?null:e.jsxs(r.Select,{value:c,onValueChange:l,children:[e.jsx(r.SelectTrigger,{className:"h-9 w-[88px] text-xs font-semibold",children:e.jsx(r.SelectValue,{placeholder:c})}),e.jsx(r.SelectContent,{children:n.map(t=>e.jsx(r.SelectItem,{value:t.code,children:t.code},t.code))})]})}exports.CurrencySwitcher=s;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsxs as n, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { Select as o, SelectTrigger as i, SelectValue as u, SelectContent as
|
|
3
|
-
import {
|
|
3
|
+
import { Select as o, SelectTrigger as i, SelectValue as u, SelectContent as d, SelectItem as s } from "@nextblock-cms/ui/select";
|
|
4
|
+
import { useCurrency as a } from "../CurrencyProvider.es.js";
|
|
4
5
|
function p() {
|
|
5
6
|
const {
|
|
6
7
|
activeCurrencyCode: t,
|
|
7
8
|
currencies: c,
|
|
8
9
|
setActiveCurrencyCode: l
|
|
9
|
-
} =
|
|
10
|
+
} = a();
|
|
10
11
|
return c.length <= 1 ? null : /* @__PURE__ */ n(o, { value: t, onValueChange: l, children: [
|
|
11
12
|
/* @__PURE__ */ e(i, { className: "h-9 w-[88px] text-xs font-semibold", children: /* @__PURE__ */ e(u, { placeholder: t }) }),
|
|
12
|
-
/* @__PURE__ */ e(
|
|
13
|
+
/* @__PURE__ */ e(d, { children: c.map((r) => /* @__PURE__ */ e(s, { value: r.code, children: r.code }, r.code)) })
|
|
13
14
|
] });
|
|
14
15
|
}
|
|
15
16
|
export {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),_=require("react"),K=require("react-hook-form"),Q=require("./AccountNavigationMenu.cjs.js"),L=require("@nextblock-cms/ui/avatar"),Y=require("@nextblock-cms/ui/badge"),T=require("@nextblock-cms/ui/button"),o=require("@nextblock-cms/ui/card"),Z=require("@nextblock-cms/ui/checkbox"),i=require("@nextblock-cms/ui/input"),a=require("@nextblock-cms/ui/label"),x=require("@nextblock-cms/ui/select"),D=require("@nextblock-cms/ui/separator"),ee=require("../server-actions/customer-actions.cjs.js"),w=require("../customer.cjs.js"),G=require("@nextblock-cms/db"),u=require("lucide-react"),H=require("@nextblock-cms/utils"),V=require("../countries.cjs.js");function F(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:V.normalizeCountryCode(s?.country_code)||"CA"}}function B({prefix:s,title:j,register:c}){const{t:n}=H.useTranslations(),C=n("company_name")==="company_name"?"Company name":n("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:j}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("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:C}),e.jsx(i.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:n("full_name")}),e.jsx(i.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:n("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:V.countries.map(g=>e.jsx("option",{value:g.code,children:g.name},g.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-line1`,children:n("address_line_1")}),e.jsx(i.Input,{id:`${s}-line1`,...c(`${s}.line1`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-line2`,children:n("address_line_2")}),e.jsx(i.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:n("city")}),e.jsx(i.Input,{id:`${s}-city`,...c(`${s}.city`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-state`,children:n("state_province")}),e.jsx(i.Input,{id:`${s}-state`,...c(`${s}.state`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:`${s}-postal_code`,children:n("postal_zip_code")}),e.jsx(i.Input,{id:`${s}-postal_code`,...c(`${s}.postal_code`)})]})]})]})}function se({initialData:s,MediaPickerComponent:j,isAdmin:c,email:n,accountLinks:C,onAction:g,initialSuccessMessage:f}){const{t:l}=H.useTranslations(),[S,E]=_.useState(!1),[I,y]=_.useState(f?{type:"success",text:f}:null),[k,z]=_.useState(!1),[q,P]=_.useState(null),M=s?.use_billing_for_shipping??(!s?.shipping_address||w.addressesMatch(s?.billing_address,s?.shipping_address)),{register:h,handleSubmit:W,setValue:m,getValues:$,watch:N,reset:A}=K.useForm({defaultValues:{full_name:s?.full_name||"",avatar_url:s?.avatar_url||"",website:s?.website||"",github_username:s?.github_username||"",phone:s?.phone||"",role:s?.role,use_billing_for_shipping:M,billing_address:F(s?.billing_address),shipping_address:F(s?.shipping_address)}});_.useEffect(()=>{s&&A({full_name:s.full_name||"",avatar_url:s.avatar_url||"",website:s.website||"",github_username:s.github_username||"",phone:s.phone||"",role:s.role,use_billing_for_shipping:s.use_billing_for_shipping??(!s.shipping_address||w.addressesMatch(s.billing_address,s.shipping_address)),billing_address:F(s.billing_address),shipping_address:F(s.shipping_address)})},[s,A]),_.useEffect(()=>{f&&y({type:"success",text:f})},[f]),_.useEffect(()=>{const r=G.createClient();(async()=>{const{data:{user:d}}=await r.auth.getUser();if(!d)return;const t=d.identities?.find(b=>b.provider==="github");if(t){z(!0);const b=t.identity_data?.email||(d.app_metadata.provider==="github"?d.email:null);if(P(b),!$("website")){const v=t.identity_data?.custom_claims?.blog||t.identity_data?.blog||t.identity_data?.html_url;v&&m("website",v)}if(!$("avatar_url")){const v=t.identity_data?.avatar_url;v&&m("avatar_url",v)}const R=t.identity_data?.user_name||t.identity_data?.preferred_username;R&&m("github_username",R)}!$("full_name")&&d.user_metadata?.full_name&&m("full_name",d.user_metadata.full_name)})()},[$,m]);const X=async()=>{const r=G.createClient(),{error:p}=await r.auth.linkIdentity({provider:"github"});p&&(console.error("Error linking GitHub:",p),y({type:"error",text:l("github_link_failed")||"Failed to link GitHub account"}))},O=r=>{const d=`${process.env.NEXT_PUBLIC_R2_BASE_URL||"https://assets.nextblock.com"}/${r.object_key}`;m("avatar_url",d)},J=async r=>{E(!0),y(null);const p=w.normalizeCustomerAddress(r.billing_address)??w.emptyCustomerAddress(),d=r.use_billing_for_shipping?p:w.normalizeCustomerAddress(r.shipping_address);try{const t={...r,billing_address:p,shipping_address:d};if(g){const b=await g(t);if(b?.error)throw new Error(b.error)}else await ee.updateProfile(t);y({type:"success",text:l("profile_updated_success")})}catch(t){if(t.message==="NEXT_REDIRECT"||t.message?.includes("NEXT_REDIRECT"))return;console.error(t),y({type:"error",text:t.message||l("profile_update_failed")})}finally{E(!1)}},U=N("use_billing_for_shipping");return e.jsxs("div",{className:"grid gap-6 md:grid-cols-12 max-w-5xl mx-auto",children:[e.jsxs(o.Card,{className:"md:col-span-4 h-fit",children:[e.jsx(o.CardHeader,{children:e.jsx(o.CardTitle,{className:"text-xl",children:l("public_profile")})}),e.jsxs(o.CardContent,{className:"flex flex-col items-center text-center space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs(L.Avatar,{className:"h-32 w-32 border-4 border-muted",children:[e.jsx(L.AvatarImage,{src:N("avatar_url")||void 0,className:"object-cover"}),e.jsx(L.AvatarFallback,{className:"text-4xl bg-secondary",children:N("full_name")?.charAt(0)?.toUpperCase()||e.jsx(u.User,{className:"h-12 w-12"})})]}),j&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-black/40 rounded-full cursor-pointer",children:e.jsx(j,{triggerLabel:e.jsx(u.Upload,{className:"h-6 w-6 text-white"}),triggerVariant:"ghost",title:l("customer_profile"),onSelect:O,accept:r=>r.file_type.startsWith("image/"),hideTrigger:!1})})]}),!j&&e.jsxs("div",{className:"w-full",children:[e.jsx(a.Label,{htmlFor:"avatar_url",className:"sr-only",children:l("avatar_url")}),e.jsx(i.Input,{id:"avatar_url",...h("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:N("full_name")||l("full_name")})}),k&&e.jsxs(Y.Badge,{variant:"secondary",className:"mt-2 w-fit gap-1",children:[e.jsx(u.Github,{className:"h-3 w-3"})," ",l("github_connected")||"GitHub Connected"]})]}),C?.length?e.jsx(Q.AccountNavigationMenu,{links:C,className:"mt-2 text-left"}):null]})]}),e.jsx(o.Card,{className:"md:col-span-8",children:e.jsxs("form",{onSubmit:W(J),children:[e.jsx(o.CardHeader,{children:e.jsx(o.CardTitle,{children:l("details")})}),e.jsxs(o.CardContent,{className:"space-y-6",children:[n&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(a.Label,{htmlFor:"email",children:[l("email")||"Email"," (Read-only)"]}),e.jsx(i.Input,{id:"email",value:n,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(u.User,{className:"h-4 w-4"})," ",l("full_name")]}),e.jsx(i.Input,{id:"full_name",...h("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(u.Phone,{className:"h-4 w-4"})," ",l("phone_number")]}),e.jsx(i.Input,{id:"phone",...h("phone")})]})]}),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:"website",className:"flex items-center gap-2",children:[e.jsx(u.Globe,{className:"h-4 w-4"})," ",l("website")]}),e.jsx(i.Input,{id:"website",...h("website"),placeholder:"https://example.com"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(a.Label,{htmlFor:"github_username",className:"flex items-center gap-2",children:[e.jsx(u.Github,{className:"h-4 w-4"})," ",l("github_username")]}),k?e.jsxs("div",{className:"space-y-2",children:[e.jsx(i.Input,{id:"github_username",...h("github_username"),disabled:!0,className:"bg-muted"}),q&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(u.Mail,{className:"h-3 w-3"})," ",l("linked_to")||"Linked to"," ",q]})]}):e.jsxs(T.Button,{type:"button",variant:"outline",className:"w-full",onClick:X,children:[e.jsx(u.Github,{className:"mr-2 h-4 w-4"}),l("connect_github")]})]})]}),e.jsx(D.Separator,{className:"my-2"}),e.jsx(B,{prefix:"billing_address",title:l("billing_address"),register:h}),e.jsxs("div",{className:"flex items-center space-x-3 rounded-lg border p-4",children:[e.jsx(Z.Checkbox,{id:"use_billing_for_shipping",checked:!!U,onCheckedChange:r=>m("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")})]})]}),!U&&e.jsx(B,{prefix:"shipping_address",title:l("shipping_address"),register:h}),I&&e.jsx("div",{className:`mt-4 rounded-xl border p-4 text-sm ${I.type==="success"?"border-emerald-200 bg-emerald-50 text-emerald-700":"border-red-200 bg-red-50 text-red-700"}`,children:I.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(x.Select,{value:N("role")||"USER",onValueChange:r=>m("role",r),children:[e.jsx(x.SelectTrigger,{children:e.jsx(x.SelectValue,{placeholder:"Select role"})}),e.jsxs(x.SelectContent,{children:[e.jsx(x.SelectItem,{value:"USER",children:"User"}),e.jsx(x.SelectItem,{value:"WRITER",children:"Writer"}),e.jsx(x.SelectItem,{value:"ADMIN",children:"Admin"})]})]})]})]})]}),e.jsx(o.CardFooter,{className:"flex justify-end",children:e.jsx(T.Button,{type:"submit",disabled:S,size:"lg",children:l(S?"saving":"save_changes")})})]})})]})}exports.CustomerProfileForm=se;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs as l, jsx as e } from "react/jsx-runtime";
|
|
3
|
+
import F, { useState as w } from "react";
|
|
4
|
+
import { useForm as ee } from "react-hook-form";
|
|
5
|
+
import { AccountNavigationMenu as se } from "./AccountNavigationMenu.es.js";
|
|
6
|
+
import { Avatar as le, AvatarImage as re, AvatarFallback as ae } from "@nextblock-cms/ui/avatar";
|
|
7
|
+
import { Badge as te } from "@nextblock-cms/ui/badge";
|
|
8
|
+
import { Button as B } from "@nextblock-cms/ui/button";
|
|
9
|
+
import { Card as L, CardHeader as j, CardTitle as V, CardContent as z, CardFooter as ie } from "@nextblock-cms/ui/card";
|
|
10
|
+
import { Checkbox as ne } from "@nextblock-cms/ui/checkbox";
|
|
11
|
+
import { Input as d } from "@nextblock-cms/ui/input";
|
|
12
|
+
import { Label as i } from "@nextblock-cms/ui/label";
|
|
13
|
+
import { Select as de, SelectTrigger as ce, SelectValue as oe, SelectContent as me, SelectItem as E } from "@nextblock-cms/ui/select";
|
|
14
|
+
import { Separator as he } from "@nextblock-cms/ui/separator";
|
|
15
|
+
import { updateProfile as ue } from "../server-actions/customer-actions.es.js";
|
|
16
|
+
import { addressesMatch as H, normalizeCustomerAddress as W, emptyCustomerAddress as pe } from "../customer.es.js";
|
|
17
|
+
import { createClient as X } from "@nextblock-cms/db";
|
|
18
|
+
import { User as P, Upload as _e, Github as k, Phone as ge, Globe as be, Mail as fe } from "lucide-react";
|
|
19
|
+
import { useTranslations as q } from "@nextblock-cms/utils";
|
|
20
|
+
import { normalizeCountryCode as ye, countries as Ne } from "../countries.es.js";
|
|
21
|
+
function $(s) {
|
|
22
|
+
return {
|
|
23
|
+
company_name: s?.company_name || "",
|
|
24
|
+
recipient_name: s?.recipient_name || "",
|
|
25
|
+
line1: s?.line1 || "",
|
|
26
|
+
line2: s?.line2 || "",
|
|
27
|
+
city: s?.city || "",
|
|
28
|
+
state: s?.state || "",
|
|
29
|
+
postal_code: s?.postal_code || "",
|
|
30
|
+
country_code: ye(s?.country_code) || "CA"
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function O({
|
|
34
|
+
prefix: s,
|
|
35
|
+
title: g,
|
|
36
|
+
register: c
|
|
37
|
+
}) {
|
|
38
|
+
const { t: n } = q(), v = n("company_name") === "company_name" ? "Company name" : n("company_name");
|
|
39
|
+
return /* @__PURE__ */ l("div", { className: "space-y-4 rounded-xl border p-4", children: [
|
|
40
|
+
/* @__PURE__ */ l("div", { children: [
|
|
41
|
+
/* @__PURE__ */ e("h3", { className: "text-lg font-medium", children: g }),
|
|
42
|
+
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: n("profile_address_defaults_help") })
|
|
43
|
+
] }),
|
|
44
|
+
/* @__PURE__ */ l("div", { className: "grid gap-4 md:grid-cols-3", children: [
|
|
45
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
46
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-company_name`, children: v }),
|
|
47
|
+
/* @__PURE__ */ e(d, { id: `${s}-company_name`, ...c(`${s}.company_name`) })
|
|
48
|
+
] }),
|
|
49
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
50
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-recipient_name`, children: n("full_name") }),
|
|
51
|
+
/* @__PURE__ */ e(d, { id: `${s}-recipient_name`, ...c(`${s}.recipient_name`) })
|
|
52
|
+
] }),
|
|
53
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
54
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-country_code`, children: n("country") }),
|
|
55
|
+
/* @__PURE__ */ e(
|
|
56
|
+
"select",
|
|
57
|
+
{
|
|
58
|
+
id: `${s}-country_code`,
|
|
59
|
+
className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
|
|
60
|
+
...c(`${s}.country_code`),
|
|
61
|
+
children: Ne.map((p) => /* @__PURE__ */ e("option", { value: p.code, children: p.name }, p.code))
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
] })
|
|
65
|
+
] }),
|
|
66
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
67
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-line1`, children: n("address_line_1") }),
|
|
68
|
+
/* @__PURE__ */ e(d, { id: `${s}-line1`, ...c(`${s}.line1`) })
|
|
69
|
+
] }),
|
|
70
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
71
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-line2`, children: n("address_line_2") }),
|
|
72
|
+
/* @__PURE__ */ e(d, { id: `${s}-line2`, ...c(`${s}.line2`) })
|
|
73
|
+
] }),
|
|
74
|
+
/* @__PURE__ */ l("div", { className: "grid gap-4 md:grid-cols-3", children: [
|
|
75
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
76
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-city`, children: n("city") }),
|
|
77
|
+
/* @__PURE__ */ e(d, { id: `${s}-city`, ...c(`${s}.city`) })
|
|
78
|
+
] }),
|
|
79
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
80
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-state`, children: n("state_province") }),
|
|
81
|
+
/* @__PURE__ */ e(d, { id: `${s}-state`, ...c(`${s}.state`) })
|
|
82
|
+
] }),
|
|
83
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
84
|
+
/* @__PURE__ */ e(i, { htmlFor: `${s}-postal_code`, children: n("postal_zip_code") }),
|
|
85
|
+
/* @__PURE__ */ e(d, { id: `${s}-postal_code`, ...c(`${s}.postal_code`) })
|
|
86
|
+
] })
|
|
87
|
+
] })
|
|
88
|
+
] });
|
|
89
|
+
}
|
|
90
|
+
function ze({
|
|
91
|
+
initialData: s,
|
|
92
|
+
MediaPickerComponent: g,
|
|
93
|
+
isAdmin: c,
|
|
94
|
+
email: n,
|
|
95
|
+
accountLinks: v,
|
|
96
|
+
onAction: p,
|
|
97
|
+
initialSuccessMessage: b
|
|
98
|
+
}) {
|
|
99
|
+
const { t: r } = q(), [A, S] = w(!1), [C, f] = w(
|
|
100
|
+
b ? { type: "success", text: b } : null
|
|
101
|
+
), [U, J] = w(!1), [R, K] = w(null), M = s?.use_billing_for_shipping ?? (!s?.shipping_address || H(s?.billing_address, s?.shipping_address)), {
|
|
102
|
+
register: h,
|
|
103
|
+
handleSubmit: Q,
|
|
104
|
+
setValue: m,
|
|
105
|
+
getValues: x,
|
|
106
|
+
watch: y,
|
|
107
|
+
reset: I
|
|
108
|
+
} = ee({
|
|
109
|
+
defaultValues: {
|
|
110
|
+
full_name: s?.full_name || "",
|
|
111
|
+
avatar_url: s?.avatar_url || "",
|
|
112
|
+
website: s?.website || "",
|
|
113
|
+
github_username: s?.github_username || "",
|
|
114
|
+
phone: s?.phone || "",
|
|
115
|
+
role: s?.role,
|
|
116
|
+
use_billing_for_shipping: M,
|
|
117
|
+
billing_address: $(s?.billing_address),
|
|
118
|
+
shipping_address: $(s?.shipping_address)
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
F.useEffect(() => {
|
|
122
|
+
s && I({
|
|
123
|
+
full_name: s.full_name || "",
|
|
124
|
+
avatar_url: s.avatar_url || "",
|
|
125
|
+
website: s.website || "",
|
|
126
|
+
github_username: s.github_username || "",
|
|
127
|
+
phone: s.phone || "",
|
|
128
|
+
role: s.role,
|
|
129
|
+
use_billing_for_shipping: s.use_billing_for_shipping ?? (!s.shipping_address || H(s.billing_address, s.shipping_address)),
|
|
130
|
+
billing_address: $(s.billing_address),
|
|
131
|
+
shipping_address: $(s.shipping_address)
|
|
132
|
+
});
|
|
133
|
+
}, [s, I]), F.useEffect(() => {
|
|
134
|
+
b && f({ type: "success", text: b });
|
|
135
|
+
}, [b]), F.useEffect(() => {
|
|
136
|
+
const a = X();
|
|
137
|
+
(async () => {
|
|
138
|
+
const {
|
|
139
|
+
data: { user: o }
|
|
140
|
+
} = await a.auth.getUser();
|
|
141
|
+
if (!o)
|
|
142
|
+
return;
|
|
143
|
+
const t = o.identities?.find((_) => _.provider === "github");
|
|
144
|
+
if (t) {
|
|
145
|
+
J(!0);
|
|
146
|
+
const _ = t.identity_data?.email || (o.app_metadata.provider === "github" ? o.email : null);
|
|
147
|
+
if (K(_), !x("website")) {
|
|
148
|
+
const N = t.identity_data?.custom_claims?.blog || t.identity_data?.blog || t.identity_data?.html_url;
|
|
149
|
+
N && m("website", N);
|
|
150
|
+
}
|
|
151
|
+
if (!x("avatar_url")) {
|
|
152
|
+
const N = t.identity_data?.avatar_url;
|
|
153
|
+
N && m("avatar_url", N);
|
|
154
|
+
}
|
|
155
|
+
const G = t.identity_data?.user_name || t.identity_data?.preferred_username;
|
|
156
|
+
G && m("github_username", G);
|
|
157
|
+
}
|
|
158
|
+
!x("full_name") && o.user_metadata?.full_name && m("full_name", o.user_metadata.full_name);
|
|
159
|
+
})();
|
|
160
|
+
}, [x, m]);
|
|
161
|
+
const Y = async () => {
|
|
162
|
+
const a = X(), { error: u } = await a.auth.linkIdentity({ provider: "github" });
|
|
163
|
+
u && (console.error("Error linking GitHub:", u), f({
|
|
164
|
+
type: "error",
|
|
165
|
+
text: r("github_link_failed") || "Failed to link GitHub account"
|
|
166
|
+
}));
|
|
167
|
+
}, Z = (a) => {
|
|
168
|
+
const o = `${process.env.NEXT_PUBLIC_R2_BASE_URL || "https://assets.nextblock.com"}/${a.object_key}`;
|
|
169
|
+
m("avatar_url", o);
|
|
170
|
+
}, D = async (a) => {
|
|
171
|
+
S(!0), f(null);
|
|
172
|
+
const u = W(a.billing_address) ?? pe(), o = a.use_billing_for_shipping ? u : W(a.shipping_address);
|
|
173
|
+
try {
|
|
174
|
+
const t = {
|
|
175
|
+
...a,
|
|
176
|
+
billing_address: u,
|
|
177
|
+
shipping_address: o
|
|
178
|
+
};
|
|
179
|
+
if (p) {
|
|
180
|
+
const _ = await p(t);
|
|
181
|
+
if (_?.error)
|
|
182
|
+
throw new Error(_.error);
|
|
183
|
+
} else
|
|
184
|
+
await ue(t);
|
|
185
|
+
f({ type: "success", text: r("profile_updated_success") });
|
|
186
|
+
} catch (t) {
|
|
187
|
+
if (t.message === "NEXT_REDIRECT" || t.message?.includes("NEXT_REDIRECT"))
|
|
188
|
+
return;
|
|
189
|
+
console.error(t), f({ type: "error", text: t.message || r("profile_update_failed") });
|
|
190
|
+
} finally {
|
|
191
|
+
S(!1);
|
|
192
|
+
}
|
|
193
|
+
}, T = y("use_billing_for_shipping");
|
|
194
|
+
return /* @__PURE__ */ l("div", { className: "grid gap-6 md:grid-cols-12 max-w-5xl mx-auto", children: [
|
|
195
|
+
/* @__PURE__ */ l(L, { className: "md:col-span-4 h-fit", children: [
|
|
196
|
+
/* @__PURE__ */ e(j, { children: /* @__PURE__ */ e(V, { className: "text-xl", children: r("public_profile") }) }),
|
|
197
|
+
/* @__PURE__ */ l(z, { className: "flex flex-col items-center text-center space-y-4", children: [
|
|
198
|
+
/* @__PURE__ */ l("div", { className: "relative group", children: [
|
|
199
|
+
/* @__PURE__ */ l(le, { className: "h-32 w-32 border-4 border-muted", children: [
|
|
200
|
+
/* @__PURE__ */ e(re, { src: y("avatar_url") || void 0, className: "object-cover" }),
|
|
201
|
+
/* @__PURE__ */ e(ae, { className: "text-4xl bg-secondary", children: y("full_name")?.charAt(0)?.toUpperCase() || /* @__PURE__ */ e(P, { className: "h-12 w-12" }) })
|
|
202
|
+
] }),
|
|
203
|
+
g && /* @__PURE__ */ e("div", { className: "absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-black/40 rounded-full cursor-pointer", children: /* @__PURE__ */ e(
|
|
204
|
+
g,
|
|
205
|
+
{
|
|
206
|
+
triggerLabel: /* @__PURE__ */ e(_e, { className: "h-6 w-6 text-white" }),
|
|
207
|
+
triggerVariant: "ghost",
|
|
208
|
+
title: r("customer_profile"),
|
|
209
|
+
onSelect: Z,
|
|
210
|
+
accept: (a) => a.file_type.startsWith("image/"),
|
|
211
|
+
hideTrigger: !1
|
|
212
|
+
}
|
|
213
|
+
) })
|
|
214
|
+
] }),
|
|
215
|
+
!g && /* @__PURE__ */ l("div", { className: "w-full", children: [
|
|
216
|
+
/* @__PURE__ */ e(i, { htmlFor: "avatar_url", className: "sr-only", children: r("avatar_url") }),
|
|
217
|
+
/* @__PURE__ */ e(d, { id: "avatar_url", ...h("avatar_url"), placeholder: "https://...", className: "mt-2" })
|
|
218
|
+
] }),
|
|
219
|
+
/* @__PURE__ */ l("div", { className: "w-full space-y-1 text-left mt-4", children: [
|
|
220
|
+
/* @__PURE__ */ e("div", { className: "text-sm font-medium text-muted-foreground uppercase tracking-wider", children: r("identity") }),
|
|
221
|
+
/* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ e("span", { className: "font-semibold text-lg", children: y("full_name") || r("full_name") }) }),
|
|
222
|
+
U && /* @__PURE__ */ l(te, { variant: "secondary", className: "mt-2 w-fit gap-1", children: [
|
|
223
|
+
/* @__PURE__ */ e(k, { className: "h-3 w-3" }),
|
|
224
|
+
" ",
|
|
225
|
+
r("github_connected") || "GitHub Connected"
|
|
226
|
+
] })
|
|
227
|
+
] }),
|
|
228
|
+
v?.length ? /* @__PURE__ */ e(
|
|
229
|
+
se,
|
|
230
|
+
{
|
|
231
|
+
links: v,
|
|
232
|
+
className: "mt-2 text-left"
|
|
233
|
+
}
|
|
234
|
+
) : null
|
|
235
|
+
] })
|
|
236
|
+
] }),
|
|
237
|
+
/* @__PURE__ */ e(L, { className: "md:col-span-8", children: /* @__PURE__ */ l("form", { onSubmit: Q(D), children: [
|
|
238
|
+
/* @__PURE__ */ e(j, { children: /* @__PURE__ */ e(V, { children: r("details") }) }),
|
|
239
|
+
/* @__PURE__ */ l(z, { className: "space-y-6", children: [
|
|
240
|
+
n && /* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
241
|
+
/* @__PURE__ */ l(i, { htmlFor: "email", children: [
|
|
242
|
+
r("email") || "Email",
|
|
243
|
+
" (Read-only)"
|
|
244
|
+
] }),
|
|
245
|
+
/* @__PURE__ */ e(d, { id: "email", value: n, readOnly: !0, disabled: !0, className: "bg-muted/50" })
|
|
246
|
+
] }),
|
|
247
|
+
/* @__PURE__ */ e("div", { className: "rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground", children: r("profile_basic_info_help") }),
|
|
248
|
+
/* @__PURE__ */ l("div", { className: "grid gap-4 md:grid-cols-2", children: [
|
|
249
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
250
|
+
/* @__PURE__ */ l(i, { htmlFor: "full_name", className: "flex items-center gap-2", children: [
|
|
251
|
+
/* @__PURE__ */ e(P, { className: "h-4 w-4" }),
|
|
252
|
+
" ",
|
|
253
|
+
r("full_name")
|
|
254
|
+
] }),
|
|
255
|
+
/* @__PURE__ */ e(d, { id: "full_name", ...h("full_name") })
|
|
256
|
+
] }),
|
|
257
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
258
|
+
/* @__PURE__ */ l(i, { htmlFor: "phone", className: "flex items-center gap-2", children: [
|
|
259
|
+
/* @__PURE__ */ e(ge, { className: "h-4 w-4" }),
|
|
260
|
+
" ",
|
|
261
|
+
r("phone_number")
|
|
262
|
+
] }),
|
|
263
|
+
/* @__PURE__ */ e(d, { id: "phone", ...h("phone") })
|
|
264
|
+
] })
|
|
265
|
+
] }),
|
|
266
|
+
/* @__PURE__ */ l("div", { className: "grid gap-4 md:grid-cols-2", children: [
|
|
267
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
268
|
+
/* @__PURE__ */ l(i, { htmlFor: "website", className: "flex items-center gap-2", children: [
|
|
269
|
+
/* @__PURE__ */ e(be, { className: "h-4 w-4" }),
|
|
270
|
+
" ",
|
|
271
|
+
r("website")
|
|
272
|
+
] }),
|
|
273
|
+
/* @__PURE__ */ e(d, { id: "website", ...h("website"), placeholder: "https://example.com" })
|
|
274
|
+
] }),
|
|
275
|
+
/* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
276
|
+
/* @__PURE__ */ l(i, { htmlFor: "github_username", className: "flex items-center gap-2", children: [
|
|
277
|
+
/* @__PURE__ */ e(k, { className: "h-4 w-4" }),
|
|
278
|
+
" ",
|
|
279
|
+
r("github_username")
|
|
280
|
+
] }),
|
|
281
|
+
U ? /* @__PURE__ */ l("div", { className: "space-y-2", children: [
|
|
282
|
+
/* @__PURE__ */ e(d, { id: "github_username", ...h("github_username"), disabled: !0, className: "bg-muted" }),
|
|
283
|
+
R && /* @__PURE__ */ l("p", { className: "text-xs text-muted-foreground flex items-center gap-1", children: [
|
|
284
|
+
/* @__PURE__ */ e(fe, { className: "h-3 w-3" }),
|
|
285
|
+
" ",
|
|
286
|
+
r("linked_to") || "Linked to",
|
|
287
|
+
" ",
|
|
288
|
+
R
|
|
289
|
+
] })
|
|
290
|
+
] }) : /* @__PURE__ */ l(B, { type: "button", variant: "outline", className: "w-full", onClick: Y, children: [
|
|
291
|
+
/* @__PURE__ */ e(k, { className: "mr-2 h-4 w-4" }),
|
|
292
|
+
r("connect_github")
|
|
293
|
+
] })
|
|
294
|
+
] })
|
|
295
|
+
] }),
|
|
296
|
+
/* @__PURE__ */ e(he, { className: "my-2" }),
|
|
297
|
+
/* @__PURE__ */ e(O, { prefix: "billing_address", title: r("billing_address"), register: h }),
|
|
298
|
+
/* @__PURE__ */ l("div", { className: "flex items-center space-x-3 rounded-lg border p-4", children: [
|
|
299
|
+
/* @__PURE__ */ e(
|
|
300
|
+
ne,
|
|
301
|
+
{
|
|
302
|
+
id: "use_billing_for_shipping",
|
|
303
|
+
checked: !!T,
|
|
304
|
+
onCheckedChange: (a) => m("use_billing_for_shipping", !!a, { shouldDirty: !0 })
|
|
305
|
+
}
|
|
306
|
+
),
|
|
307
|
+
/* @__PURE__ */ l("div", { className: "space-y-1", children: [
|
|
308
|
+
/* @__PURE__ */ e(i, { htmlFor: "use_billing_for_shipping", className: "cursor-pointer", children: r("use_billing_for_shipping") }),
|
|
309
|
+
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: r("profile_use_billing_for_shipping_help") })
|
|
310
|
+
] })
|
|
311
|
+
] }),
|
|
312
|
+
!T && /* @__PURE__ */ e(
|
|
313
|
+
O,
|
|
314
|
+
{
|
|
315
|
+
prefix: "shipping_address",
|
|
316
|
+
title: r("shipping_address"),
|
|
317
|
+
register: h
|
|
318
|
+
}
|
|
319
|
+
),
|
|
320
|
+
C && /* @__PURE__ */ e(
|
|
321
|
+
"div",
|
|
322
|
+
{
|
|
323
|
+
className: `mt-4 rounded-xl border p-4 text-sm ${C.type === "success" ? "border-emerald-200 bg-emerald-50 text-emerald-700" : "border-red-200 bg-red-50 text-red-700"}`,
|
|
324
|
+
children: C.text
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
c && /* @__PURE__ */ l("div", { className: "border-t pt-4 mt-4", children: [
|
|
328
|
+
/* @__PURE__ */ e("h3", { className: "text-sm font-medium mb-3", children: "Admin Settings" }),
|
|
329
|
+
/* @__PURE__ */ l("div", { className: "grid gap-2", children: [
|
|
330
|
+
/* @__PURE__ */ e(i, { htmlFor: "role", children: "Role" }),
|
|
331
|
+
/* @__PURE__ */ l(
|
|
332
|
+
de,
|
|
333
|
+
{
|
|
334
|
+
value: y("role") || "USER",
|
|
335
|
+
onValueChange: (a) => m("role", a),
|
|
336
|
+
children: [
|
|
337
|
+
/* @__PURE__ */ e(ce, { children: /* @__PURE__ */ e(oe, { placeholder: "Select role" }) }),
|
|
338
|
+
/* @__PURE__ */ l(me, { children: [
|
|
339
|
+
/* @__PURE__ */ e(E, { value: "USER", children: "User" }),
|
|
340
|
+
/* @__PURE__ */ e(E, { value: "WRITER", children: "Writer" }),
|
|
341
|
+
/* @__PURE__ */ e(E, { value: "ADMIN", children: "Admin" })
|
|
342
|
+
] })
|
|
343
|
+
]
|
|
344
|
+
}
|
|
345
|
+
)
|
|
346
|
+
] })
|
|
347
|
+
] })
|
|
348
|
+
] }),
|
|
349
|
+
/* @__PURE__ */ e(ie, { className: "flex justify-end", children: /* @__PURE__ */ e(B, { type: "submit", disabled: A, size: "lg", children: r(A ? "saving" : "save_changes") }) })
|
|
350
|
+
] }) })
|
|
351
|
+
] });
|
|
352
|
+
}
|
|
353
|
+
export {
|
|
354
|
+
ze as CustomerProfileForm
|
|
355
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),h=require("./AddToCartButton.cjs.js"),s=require("@nextblock-cms/utils"),o=require("next/link"),g=require("../CurrencyProvider.cjs.js"),m=require("../currency.cjs.js"),b=require("../trials.cjs.js"),v=({product:e,className:x,imagePosition:u="left"})=>{const{t:c}=s.useTranslations(),{activeCurrencyCode:l,currencies:n}=g.useCurrency(),a=m.resolvePriceRangeForCurrency({entries:e.variants?.length?e.variants:e.product_variants?.length?e.product_variants:[],currencyCode:l,currencies:n}),d=!!(e.has_variants&&a),i=m.resolveEffectivePriceForCurrency({prices:e.prices,salePrices:e.sale_prices,fallbackPrice:e.price,fallbackSalePrice:e.sale_price,saleStartAt:e.sale_start_at,saleEndAt:e.sale_end_at,scheduledPrice:e.scheduled_price,scheduledPrices:e.scheduled_prices,scheduledPriceAt:e.scheduled_price_at,currencyCode:l,currencies:n}),f=d&&a?a.min===a.max?s.formatPrice(a.min,l):`${s.formatPrice(a.min,l)} - ${s.formatPrice(a.max,l)}`:s.formatPrice(i.sale_price??i.price,l),t=b.getTrialSummary(e);return r.jsx("div",{className:s.cn("overflow-hidden rounded-xl border bg-card shadow-sm",x),children:r.jsxs("div",{className:s.cn("flex flex-col gap-8 md:flex-row",u==="right"&&"md:flex-row-reverse"),children:[r.jsx("div",{className:"relative aspect-square w-full md:w-1/2",children:e.image_url?r.jsx("img",{src:e.image_url,alt:e.title,className:"h-full w-full object-cover"}):r.jsx("div",{className:"flex h-full w-full items-center justify-center bg-secondary text-muted-foreground",children:c("ecommerce.no_image")})}),r.jsxs("div",{className:"flex flex-1 flex-col justify-center p-6 md:p-12",children:[r.jsx(o,{href:`/product/${e.slug}`,children:r.jsx("h2",{className:"mb-4 text-3xl font-bold tracking-tight hover:underline md:text-4xl",children:e.title})}),r.jsxs("div",{className:"mb-6 flex items-baseline gap-3",children:[r.jsx("span",{className:"text-3xl font-bold text-primary",children:f}),!d&&i.sale_price&&r.jsx("span",{className:"text-lg text-muted-foreground line-through",children:s.formatPrice(i.price,l)})]}),t&&r.jsxs("div",{className:"mb-6 inline-flex w-fit flex-col rounded-md border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-900",children:[r.jsx("span",{className:"font-semibold",children:t.label}),r.jsx("span",{className:"text-emerald-700",children:t.paymentRequirementLabel})]}),e.short_description&&r.jsx("p",{className:"mb-8 text-lg text-muted-foreground",children:e.short_description}),r.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row",children:[r.jsx(h.AddToCartButton,{product:e,className:"h-12 w-full px-8 text-lg sm:w-auto"}),r.jsx(o,{href:`/product/${e.slug}`,className:"inline-flex h-12 items-center justify-center rounded-md border border-input bg-background px-8 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground",children:c("ecommerce.view_details")})]})]})]})})};exports.FeaturedProduct=v;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx as r, jsxs as s } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useTranslations as v, formatPrice as i, cn as
|
|
3
|
+
import { AddToCartButton as g } from "./AddToCartButton.es.js";
|
|
4
|
+
import { useTranslations as v, formatPrice as i, cn as d } from "@nextblock-cms/utils";
|
|
4
5
|
import f from "next/link";
|
|
5
|
-
import {
|
|
6
|
+
import { useCurrency as b } from "../CurrencyProvider.es.js";
|
|
6
7
|
import { resolvePriceRangeForCurrency as p, resolveEffectivePriceForCurrency as _ } from "../currency.es.js";
|
|
7
|
-
import {
|
|
8
|
+
import { getTrialSummary as N } from "../trials.es.js";
|
|
8
9
|
const R = ({ product: e, className: h, imagePosition: x = "left" }) => {
|
|
9
10
|
const { t: c } = v(), { activeCurrencyCode: l, currencies: m } = b(), a = p({
|
|
10
11
|
entries: e.variants?.length ? e.variants : e.product_variants?.length ? e.product_variants : [],
|
|
11
12
|
currencyCode: l,
|
|
12
13
|
currencies: m
|
|
13
|
-
}),
|
|
14
|
+
}), o = !!(e.has_variants && a), t = _({
|
|
14
15
|
prices: e.prices,
|
|
15
16
|
salePrices: e.sale_prices,
|
|
16
17
|
fallbackPrice: e.price,
|
|
@@ -22,11 +23,11 @@ const R = ({ product: e, className: h, imagePosition: x = "left" }) => {
|
|
|
22
23
|
scheduledPriceAt: e.scheduled_price_at,
|
|
23
24
|
currencyCode: l,
|
|
24
25
|
currencies: m
|
|
25
|
-
}), u =
|
|
26
|
+
}), u = o && a ? a.min === a.max ? i(a.min, l) : `${i(a.min, l)} - ${i(
|
|
26
27
|
a.max,
|
|
27
28
|
l
|
|
28
29
|
)}` : i(t.sale_price ?? t.price, l), n = N(e);
|
|
29
|
-
return /* @__PURE__ */ r("div", { className:
|
|
30
|
+
return /* @__PURE__ */ r("div", { className: d("overflow-hidden rounded-xl border bg-card shadow-sm", h), children: /* @__PURE__ */ s("div", { className: d("flex flex-col gap-8 md:flex-row", x === "right" && "md:flex-row-reverse"), children: [
|
|
30
31
|
/* @__PURE__ */ r("div", { className: "relative aspect-square w-full md:w-1/2", children: e.image_url ? /* @__PURE__ */ r(
|
|
31
32
|
"img",
|
|
32
33
|
{
|
|
@@ -39,7 +40,7 @@ const R = ({ product: e, className: h, imagePosition: x = "left" }) => {
|
|
|
39
40
|
/* @__PURE__ */ r(f, { href: `/product/${e.slug}`, children: /* @__PURE__ */ r("h2", { className: "mb-4 text-3xl font-bold tracking-tight hover:underline md:text-4xl", children: e.title }) }),
|
|
40
41
|
/* @__PURE__ */ s("div", { className: "mb-6 flex items-baseline gap-3", children: [
|
|
41
42
|
/* @__PURE__ */ r("span", { className: "text-3xl font-bold text-primary", children: u }),
|
|
42
|
-
!
|
|
43
|
+
!o && t.sale_price && /* @__PURE__ */ r("span", { className: "text-lg text-muted-foreground line-through", children: i(t.price, l) })
|
|
43
44
|
] }),
|
|
44
45
|
n && /* @__PURE__ */ s("div", { className: "mb-6 inline-flex w-fit flex-col rounded-md border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-900", children: [
|
|
45
46
|
/* @__PURE__ */ r("span", { className: "font-semibold", children: n.label }),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("next/image"),n=require("../invoice.cjs.js"),d=require("../order-tax-details.cjs.js");function y({data:t,labels:r,locale:i="en-US",className:l=""}){const m=n.getInvoiceAddressLines(t.settings.address),u=n.getInvoiceAddressLines(t.order.customer_details?.billing),h=n.getInvoiceAddressLines(t.order.customer_details?.shipping);return e.jsxs("section",{className:`rounded-2xl border bg-white text-slate-900 shadow-sm print:rounded-none print:border-0 print:text-[10px] print:shadow-none ${l}`,children:[e.jsx("div",{className:"border-b px-6 py-6 print:px-0",children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] md:items-start print:grid-cols-[minmax(0,1fr)_72px_280px] print:items-start print:gap-4",children:[e.jsxs("div",{className:"order-2 max-w-md space-y-4 print:order-none print:max-w-none print:space-y-2 md:order-none",children:[e.jsxs("div",{className:"space-y-1 text-sm print:text-[10px]",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-slate-500",children:r.from}),t.settings.businessName?e.jsx("p",{className:"text-base font-semibold",children:t.settings.businessName}):null,m.map((s,p)=>e.jsx("p",{children:s},`seller-${p}-${s}`)),t.settings.email?e.jsx("p",{children:t.settings.email}):null,t.settings.phone?e.jsx("p",{children:t.settings.phone}):null]}),t.settings.taxRegistrations.length>0?e.jsxs("div",{className:"rounded-xl border bg-slate-50 px-4 py-3 text-sm print:px-3 print:py-2 print:text-[10px]",children:[e.jsx("p",{className:"mb-2 font-semibold",children:r.taxRegistrations}),e.jsx("div",{className:"space-y-1",children:t.settings.taxRegistrations.map((s,p)=>e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:s.label}),s.label&&s.value?": ":"",s.value]},`${s.label}-${s.value}-${p}`))})]}):null]}),e.jsx("div",{className:"order-1 flex justify-center md:order-none md:pt-2 print:order-none print:pt-1",children:t.logo?.url?e.jsx(j,{src:t.logo.url,alt:t.logo.name||t.settings.businessName||"Logo",className:"mx-auto h-24 w-auto object-contain print:h-14",width:t.logo.width||320,height:t.logo.height||120}):null}),e.jsx("div",{className:"order-3 flex justify-start md:order-none md:justify-end print:order-none",children:e.jsxs("div",{className:"w-full max-w-[380px] rounded-2xl bg-slate-950 px-5 py-5 text-white print:max-w-none print:border print:border-slate-300 print:bg-white print:px-3 print:py-3 print:text-[10px] print:text-slate-950",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-white/70 print:text-slate-500",children:r.invoice}),e.jsxs("div",{className:"mt-4 space-y-3 text-sm print:mt-3 print:space-y-2 print:text-[10px]",children:[e.jsx(c,{label:r.invoiceNumber,value:t.order.invoice_number||"--"}),e.jsx(c,{label:r.orderNumber,value:t.order.id}),e.jsx(c,{label:r.paidOn,value:n.formatInvoiceDate(t.order.paid_at||t.order.created_at,i)||"--"}),e.jsx(c,{label:r.status,value:t.order.status})]})]})})]})}),e.jsxs("div",{className:"grid gap-4 border-b px-6 py-6 md:grid-cols-2 print:grid-cols-2 print:gap-3 print:px-0 print:py-3",children:[e.jsx(a,{title:r.billTo,lines:u}),e.jsx(a,{title:r.shipTo,lines:h})]}),e.jsxs("div",{className:"px-6 py-6 print:px-0 print:py-3",children:[e.jsx("div",{className:"overflow-hidden rounded-2xl border",children:e.jsxs("table",{className:"w-full border-collapse text-sm print:table-fixed print:text-[9px]",children:[e.jsx("thead",{className:"bg-slate-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left font-semibold print:w-[22%] print:px-2 print:py-1.5",children:r.item}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold print:w-[38%] print:px-2 print:py-1.5",children:r.details}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold print:w-[10%] print:px-2 print:py-1.5",children:r.quantity}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold print:w-[15%] print:px-2 print:py-1.5",children:r.price}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold print:w-[15%] print:px-2 print:py-1.5",children:r.amount})]})}),e.jsx("tbody",{children:t.order.items.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"px-4 py-4 font-medium print:px-2 print:py-1.5",children:s.title}),e.jsx("td",{className:"px-4 py-4 text-slate-600 print:px-2 print:py-1.5",children:s.description||"--"}),e.jsx("td",{className:"px-4 py-4 text-right print:px-2 print:py-1.5",children:s.quantity}),e.jsx("td",{className:"px-4 py-4 text-right print:px-2 print:py-1.5",children:n.formatInvoiceCurrency(s.unit_amount,t.order.currency,i)}),e.jsx("td",{className:"px-4 py-4 text-right font-medium print:px-2 print:py-1.5",children:n.formatInvoiceCurrency(s.total_amount,t.order.currency,i)})]},s.id))})]})}),e.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-[minmax(0,1fr)_320px] print:mt-4 print:grid-cols-[minmax(0,1fr)_220px] print:items-start print:gap-4",children:[e.jsx("div",{children:t.order.tax_details?.lines?.length?e.jsxs("div",{className:"rounded-xl border bg-slate-50 px-5 py-4 print:break-inside-avoid print:px-3 print:py-2.5 print:text-[10px]",children:[e.jsx("p",{className:"mb-3 font-semibold",children:r.taxBreakdown}),e.jsx("div",{className:"space-y-3 text-sm print:space-y-2 print:text-[10px]",children:t.order.tax_details.lines.map((s,p)=>{const o=d.getOrderTaxRatePercentage(s.rate);return e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[d.getOrderTaxRateLabel(s.rate),typeof o=="number"?` - ${o.toFixed(4)}%`:""]}),d.getOrderTaxRateJurisdiction(s.rate)?e.jsx("p",{className:"text-xs text-slate-500 print:text-[9px]",children:d.getOrderTaxRateJurisdiction(s.rate)}):null]}),e.jsx("span",{children:n.formatInvoiceCurrency(s.amount,t.order.currency,i)})]},`${s.rate.display_name}-${s.description||"tax"}-${p}`)})})]}):null}),e.jsxs("div",{className:"rounded-xl border bg-slate-950 px-5 py-5 text-sm text-white print:break-inside-avoid print:border-slate-300 print:bg-white print:px-3 print:py-3 print:text-[10px] print:text-slate-950",children:[e.jsxs("div",{className:"space-y-3 print:space-y-2",children:[e.jsx(x,{label:r.subtotal,value:n.formatInvoiceCurrency(t.order.subtotal,t.order.currency,i)}),t.order.discount_total>0?e.jsx(x,{label:t.order.coupon_code?`${r.discount} (${t.order.coupon_code})`:r.discount,value:`-${n.formatInvoiceCurrency(t.order.discount_total,t.order.currency,i)}`}):null,e.jsx(x,{label:r.shipping,value:n.formatInvoiceCurrency(t.order.shipping_total,t.order.currency,i)}),e.jsx(x,{label:r.tax,value:n.formatInvoiceCurrency(t.order.tax_total,t.order.currency,i)})]}),e.jsx("div",{className:"mt-4 border-t border-white/15 pt-4 print:mt-3 print:border-slate-300 print:pt-3",children:e.jsx(x,{label:r.total,value:n.formatInvoiceCurrency(t.order.total,t.order.currency,i),strong:!0})})]})]})]})]})}function a({title:t,lines:r}){return e.jsxs("div",{className:"rounded-xl border bg-slate-50 px-5 py-4 print:break-inside-avoid print:px-3 print:py-2.5 print:text-[10px]",children:[e.jsx("p",{className:"mb-3 text-xs font-semibold uppercase tracking-[0.2em] text-slate-500",children:t}),r.length?e.jsx("div",{className:"space-y-1 text-sm print:text-[10px]",children:r.map((i,l)=>e.jsx("p",{children:i},`${t}-${l}-${i}`))}):e.jsx("p",{className:"text-sm text-slate-500",children:"--"})]})}function c({label:t,value:r}){return e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-white/70 print:text-[9px] print:text-slate-500",children:t}),e.jsx("span",{className:"text-right font-medium",children:r})]})}function x({label:t,value:r,strong:i=!1}){return e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:i?"text-base font-semibold print:text-sm":"text-white/75 print:text-[9px] print:text-slate-500",children:t}),e.jsx("span",{className:i?"text-lg font-semibold print:text-base":"font-medium",children:r})]})}exports.InvoiceDocument=y;
|