@nextblock-cms/ecom 0.8.1 → 0.8.6
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/AddToCartButton-DsSEH9yp.cjs +1 -0
- package/AddToCartButton-ffE0DhHu.js +59 -0
- package/CouponForm-BI_5SBHQ.js +152 -0
- package/CouponForm-D_uu2bLP.cjs +1 -0
- package/CurrencyProvider-Cg-Q6ucj.cjs +1 -0
- package/CurrencyProvider-OzlRN96V.js +120 -0
- package/CurrencyProvider.cjs.js +1 -0
- package/CurrencyProvider.es.js +10 -0
- package/ProductDetailsLayout-BxJH_BxR.cjs +1 -0
- package/ProductDetailsLayout-Dg8dRTYp.js +530 -0
- package/ProductGrid-BdL7iglO.cjs +1 -0
- package/ProductGrid-D3AWM8sr.js +130 -0
- package/actions-AHmBrS5e.cjs +48 -0
- package/actions-j5fuSZX-.js +820 -0
- package/cart-store.cjs.js +1 -0
- package/cart-store.es.js +116 -0
- package/components/Cart.cjs.js +1 -0
- package/components/Cart.es.js +259 -0
- package/components/CartDrawer.cjs.js +1 -0
- package/components/CartDrawer.es.js +118 -0
- package/components/CartIcon.cjs.js +1 -0
- package/components/CartIcon.es.js +33 -0
- package/components/Checkout.cjs.js +1 -0
- package/components/Checkout.es.js +1020 -0
- package/components/CurrencySwitcher.cjs.js +1 -0
- package/components/CurrencySwitcher.es.js +17 -0
- package/components/FeaturedProduct.cjs.js +1 -0
- package/components/FeaturedProduct.es.js +71 -0
- package/components/ProductDetailsLayout.cjs.js +1 -0
- package/components/ProductDetailsLayout.es.js +19 -0
- package/components/ProductGrid.cjs.js +1 -0
- package/components/ProductGrid.es.js +6 -0
- package/components/SimpleTiptapRenderer.cjs.js +1 -0
- package/components/SimpleTiptapRenderer.es.js +187 -0
- package/coupon-server-C9ySm3I5.cjs +1 -0
- package/coupon-server-DUKVtyYs.js +248 -0
- package/currency-constants.cjs.js +1 -0
- package/currency-constants.es.js +4 -0
- package/currency.cjs.js +1 -0
- package/currency.es.js +312 -0
- package/customer-C-UPvrYN.cjs +1 -0
- package/customer-C3xccjUg.js +57 -0
- package/index.cjs.js +1 -1
- package/index.es.js +414 -3105
- package/invoice-ui-CAnJPu6n.cjs +29 -0
- package/invoice-ui-DtpbTJE1.js +2886 -0
- package/package.json +10 -5
- package/product-actions-CONBF8i6.cjs +251 -0
- package/product-actions-DjlIWCMH.js +691 -0
- package/resolver-Fz_FKsfX.cjs +7 -0
- package/resolver-cfrCaHpE.js +128 -0
- package/server-actions/product-actions.cjs.js +1 -0
- package/server-actions/product-actions.es.js +15 -0
- package/server.cjs.js +27 -27
- package/server.es.js +478 -463
- package/shipping-actions-BnHjlo2q.js +25 -0
- package/shipping-actions-D6zt20gg.cjs +1 -0
- package/states-CWYRxV4B.cjs +1 -0
- package/states-DlHJezQ1.js +200 -0
- package/tax-calculation-Dab89aHd.js +181 -0
- package/tax-calculation-MkDKOEkL.cjs +1 -0
- package/trials-DvZaOtNy.cjs +1 -0
- package/trials-RDcRAZKx.js +29 -0
- package/types.cjs.js +1 -0
- package/types.es.js +33 -0
- package/use-cart.cjs.js +1 -0
- package/use-cart.es.js +43 -0
- package/variation-utils.cjs.js +1 -0
- package/variation-utils.es.js +246 -0
- package/invoice-ui-BJZfedDd.cjs +0 -332
- package/invoice-ui-GJ1ADAjn.js +0 -5759
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("zustand"),p=require("zustand/middleware"),o=require("./types.cjs.js"),k=require("./CurrencyProvider-Cg-Q6ucj.cjs"),S=require("./currency.cjs.js");function a(r,c,e){return r.reduce((t,s)=>o.isDigitalItem(s)||s.sku!==c||e&&s.id===e?t:t+s.quantity,0)}const l=y.create()(p.persist((r,c)=>({items:[],appliedCoupon:null,isOpen:!1,addItem:e=>{const{items:t}=c(),s=e.quantity??1,i=typeof e.stock=="number"?e.stock:null,u=i!==null?a(t,e.sku):0;if(o.isDigitalItem(e))return t.find(d=>d.product_id===e.product_id&&o.isDigitalItem(d))?{success:!1,error:"This software license is already in your cart."}:(r({items:[...t,{...e,quantity:1}],isOpen:!0}),{success:!0});const C=t.find(n=>n.id===e.id);return i!==null&&i<=0?{success:!1,error:"This item is out of stock."}:i!==null&&u+s>i?{success:!1,error:`Only ${i} available for this SKU.`}:(r(C?{items:t.map(n=>n.id===e.id?{...n,...e,quantity:n.quantity+s}:n),isOpen:!0}:{items:[...t,{...e,quantity:s}],isOpen:!0}),{success:!0})},removeItem:e=>{const{items:t}=c();r({items:t.filter(s=>s.id!==e)})},updateQuantity:(e,t)=>{const{items:s}=c(),i=s.find(u=>u.id===e);i&&o.isDigitalItem(i)||(i&&typeof i.stock=="number"&&t+a(s,i.sku,e)>i.stock&&(t=Math.max(i.stock-a(s,i.sku,e),0)),t<=0?r({items:s.filter(u=>u.id!==e)}):r({items:s.map(u=>u.id===e?{...u,quantity:t}:u)}))},setAppliedCoupon:e=>{const t=c().appliedCoupon;t?.code===e?.code&&t?.couponId===e?.couponId||r({appliedCoupon:e})},removeCoupon:()=>{c().appliedCoupon&&r({appliedCoupon:null})},clearCart:()=>r({items:[],appliedCoupon:null}),toggleCart:()=>r(e=>({isOpen:!e.isOpen})),setIsOpen:e=>r({isOpen:e}),setItems:e=>r({items:e})}),{name:"cart-storage",storage:p.createJSONStorage(()=>localStorage),skipHydration:!0})),g=()=>l(c=>c.items).reduce((c,e)=>c+e.quantity,0);function f(r,c){return S.resolveEffectivePriceForCurrency({prices:r.prices,salePrices:r.sale_prices,fallbackPrice:r.price,fallbackSalePrice:r.sale_price,saleStartAt:r.sale_start_at,saleEndAt:r.sale_end_at,scheduledPrice:r.scheduled_price,scheduledPrices:r.scheduled_prices,scheduledPriceAt:r.scheduled_price_at,currencyCode:c.currencyCode,currencies:c.currencies})}const _=()=>{const r=l(t=>t.items),{activeCurrencyCode:c,currencies:e}=k.useCurrency();return r.reduce((t,s)=>{const{price:i,sale_price:u}=f(s,{currencyCode:c,currencies:e});return t+(u??i)*s.quantity},0)};exports.getCartItemActivePrice=f;exports.useCartStore=l;exports.useCartSubtotal=_;exports.useCartTotalItems=g;
|
package/cart-store.es.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { create as f } from "zustand";
|
|
2
|
+
import { persist as C, createJSONStorage as y } from "zustand/middleware";
|
|
3
|
+
import { isDigitalItem as n } from "./types.es.js";
|
|
4
|
+
import { u as k } from "./CurrencyProvider-OzlRN96V.js";
|
|
5
|
+
import { resolveEffectivePriceForCurrency as _ } from "./currency.es.js";
|
|
6
|
+
function a(r, i, e) {
|
|
7
|
+
return r.reduce((s, t) => n(t) || t.sku !== i || e && t.id === e ? s : s + t.quantity, 0);
|
|
8
|
+
}
|
|
9
|
+
const p = f()(
|
|
10
|
+
C(
|
|
11
|
+
(r, i) => ({
|
|
12
|
+
items: [],
|
|
13
|
+
appliedCoupon: null,
|
|
14
|
+
isOpen: !1,
|
|
15
|
+
addItem: (e) => {
|
|
16
|
+
const { items: s } = i(), t = e.quantity ?? 1, c = typeof e.stock == "number" ? e.stock : null, u = c !== null ? a(s, e.sku) : 0;
|
|
17
|
+
if (n(e))
|
|
18
|
+
return s.find(
|
|
19
|
+
(l) => l.product_id === e.product_id && n(l)
|
|
20
|
+
) ? {
|
|
21
|
+
success: !1,
|
|
22
|
+
error: "This software license is already in your cart."
|
|
23
|
+
} : (r({
|
|
24
|
+
items: [...s, { ...e, quantity: 1 }],
|
|
25
|
+
isOpen: !0
|
|
26
|
+
}), { success: !0 });
|
|
27
|
+
const d = s.find((o) => o.id === e.id);
|
|
28
|
+
return c !== null && c <= 0 ? {
|
|
29
|
+
success: !1,
|
|
30
|
+
error: "This item is out of stock."
|
|
31
|
+
} : c !== null && u + t > c ? {
|
|
32
|
+
success: !1,
|
|
33
|
+
error: `Only ${c} available for this SKU.`
|
|
34
|
+
} : (r(d ? {
|
|
35
|
+
items: s.map(
|
|
36
|
+
(o) => o.id === e.id ? {
|
|
37
|
+
...o,
|
|
38
|
+
...e,
|
|
39
|
+
quantity: o.quantity + t
|
|
40
|
+
} : o
|
|
41
|
+
),
|
|
42
|
+
isOpen: !0
|
|
43
|
+
} : {
|
|
44
|
+
items: [...s, { ...e, quantity: t }],
|
|
45
|
+
isOpen: !0
|
|
46
|
+
}), { success: !0 });
|
|
47
|
+
},
|
|
48
|
+
removeItem: (e) => {
|
|
49
|
+
const { items: s } = i();
|
|
50
|
+
r({
|
|
51
|
+
items: s.filter((t) => t.id !== e)
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
updateQuantity: (e, s) => {
|
|
55
|
+
const { items: t } = i(), c = t.find((u) => u.id === e);
|
|
56
|
+
c && n(c) || (c && typeof c.stock == "number" && s + a(t, c.sku, e) > c.stock && (s = Math.max(
|
|
57
|
+
c.stock - a(t, c.sku, e),
|
|
58
|
+
0
|
|
59
|
+
)), s <= 0 ? r({
|
|
60
|
+
items: t.filter((u) => u.id !== e)
|
|
61
|
+
}) : r({
|
|
62
|
+
items: t.map(
|
|
63
|
+
(u) => u.id === e ? { ...u, quantity: s } : u
|
|
64
|
+
)
|
|
65
|
+
}));
|
|
66
|
+
},
|
|
67
|
+
setAppliedCoupon: (e) => {
|
|
68
|
+
const s = i().appliedCoupon;
|
|
69
|
+
s?.code === e?.code && s?.couponId === e?.couponId || r({ appliedCoupon: e });
|
|
70
|
+
},
|
|
71
|
+
removeCoupon: () => {
|
|
72
|
+
i().appliedCoupon && r({ appliedCoupon: null });
|
|
73
|
+
},
|
|
74
|
+
clearCart: () => r({ items: [], appliedCoupon: null }),
|
|
75
|
+
toggleCart: () => r((e) => ({ isOpen: !e.isOpen })),
|
|
76
|
+
setIsOpen: (e) => r({ isOpen: e }),
|
|
77
|
+
setItems: (e) => r({ items: e })
|
|
78
|
+
}),
|
|
79
|
+
{
|
|
80
|
+
name: "cart-storage",
|
|
81
|
+
storage: y(() => localStorage),
|
|
82
|
+
skipHydration: !0
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
), b = () => p((i) => i.items).reduce((i, e) => i + e.quantity, 0);
|
|
86
|
+
function S(r, i) {
|
|
87
|
+
return _({
|
|
88
|
+
prices: r.prices,
|
|
89
|
+
salePrices: r.sale_prices,
|
|
90
|
+
fallbackPrice: r.price,
|
|
91
|
+
fallbackSalePrice: r.sale_price,
|
|
92
|
+
saleStartAt: r.sale_start_at,
|
|
93
|
+
saleEndAt: r.sale_end_at,
|
|
94
|
+
scheduledPrice: r.scheduled_price,
|
|
95
|
+
scheduledPrices: r.scheduled_prices,
|
|
96
|
+
scheduledPriceAt: r.scheduled_price_at,
|
|
97
|
+
currencyCode: i.currencyCode,
|
|
98
|
+
currencies: i.currencies
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const g = () => {
|
|
102
|
+
const r = p((s) => s.items), { activeCurrencyCode: i, currencies: e } = k();
|
|
103
|
+
return r.reduce((s, t) => {
|
|
104
|
+
const { price: c, sale_price: u } = S(t, {
|
|
105
|
+
currencyCode: i,
|
|
106
|
+
currencies: e
|
|
107
|
+
});
|
|
108
|
+
return s + (u ?? c) * t.quantity;
|
|
109
|
+
}, 0);
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
S as getCartItemActivePrice,
|
|
113
|
+
p as useCartStore,
|
|
114
|
+
g as useCartSubtotal,
|
|
115
|
+
b as useCartTotalItems
|
|
116
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),z=require("@nextblock-cms/ui/badge"),g=require("@nextblock-cms/ui/button"),l=require("@nextblock-cms/ui/table"),x=require("lucide-react"),k=require("../cart-store.cjs.js"),H=require("../use-cart.cjs.js"),f=require("../types.cjs.js"),D=require("next/navigation"),m=require("@nextblock-cms/utils"),E=require("@nextblock-cms/ui/input"),T=require("@nextblock-cms/ui/label"),_=require("../states-CWYRxV4B.cjs"),M=require("../shipping-actions-D6zt20gg.cjs"),P=require("../CurrencyProvider-Cg-Q6ucj.cjs"),O=require("../trials-DvZaOtNy.cjs"),Q=require("../CouponForm-D_uu2bLP.cjs"),K=({physicalSubtotal:S})=>{const[o,w]=u.useState("CA"),[a,n]=u.useState(""),[h,i]=u.useState(""),[N,j]=u.useState(!1),[d,v]=u.useState(null),[b,s]=u.useState(null),{t:r,lang:c}=m.useTranslations(),{activeCurrencyCode:p}=P.useCurrency(),q=(t,y)=>{const C=r(t);return C===t?y:C},A=_.getStatesForCountry(o),B=_.countryUsesStructuredStates(o),F=q("select_an_option","Select an option"),I=q("state_province","State / Province"),R=async()=>{j(!0),s(null),v(null);const t=await M.getShippingEstimates(S,{country:o,state:a||void 0,postal_code:h},c,p);t.success&&t.methods?v(t.methods):s(t.errorKey?q(t.errorKey,t.error||r("ecommerce.no_rates_found")):t.error||r("ecommerce.no_rates_found")),j(!1)};return e.jsxs("div",{className:"space-y-4 rounded-lg border bg-muted/30 p-4 mt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold text-sm",children:[e.jsx(x.Truck,{className:"h-4 w-4"}),e.jsx("span",{children:r("ecommerce.estimate_shipping")})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T.Label,{htmlFor:"estimate-country",className:"text-xs uppercase tracking-wider text-muted-foreground",children:r("ecommerce.country")}),e.jsx("select",{id:"estimate-country",value:o,onChange:t=>{const y=t.target.value,C=_.getStatesForCountry(y);w(y),n(C.some(L=>L.code===a)?a:"")},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:_.countries.map(t=>e.jsx("option",{value:t.code,children:t.name},t.code))})]}),B&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T.Label,{htmlFor:"estimate-state",className:"text-xs uppercase tracking-wider text-muted-foreground",children:r("state_province")}),e.jsxs("select",{id:"estimate-state",value:a,onChange:t=>n(t.target.value),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:`${F}: ${I}`}),A.map(t=>e.jsx("option",{value:t.code,children:t.name},t.code))]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T.Label,{htmlFor:"estimate-postal",className:"text-xs uppercase tracking-wider text-muted-foreground",children:r("ecommerce.postal_code")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E.Input,{id:"estimate-postal",placeholder:"A1A 1A1",value:h,onChange:t=>i(t.target.value),className:"h-9 text-sm bg-background"}),e.jsxs(g.Button,{size:"sm",variant:"secondary",onClick:R,disabled:N,className:"shrink-0",children:[N?e.jsx(x.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(x.Calculator,{className:"h-4 w-4 mr-1.5"}),r("ecommerce.calculate")]})]})]})]}),b&&e.jsx("p",{className:"text-xs text-destructive mt-2",children:b}),d&&d.length>0&&e.jsxs("div",{className:"mt-4 space-y-2 border-t pt-3",children:[e.jsxs("p",{className:"text-xs font-medium text-muted-foreground uppercase",children:[r("ecommerce.available_rates"),":"]}),d.map(t=>e.jsxs("div",{className:"flex justify-between items-center p-3 border rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x.Truck,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:t.name})]}),e.jsx("span",{className:"text-sm font-bold",children:t.amount===0?r("ecommerce.free"):m.formatPrice(t.amount,p)})]},t.id))]}),d&&d.length===0&&!b&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2 italic",children:r("ecommerce.no_rates_found")})]})},$=()=>{const S=D.useRouter(),o=H.useCart(s=>s),w=k.useCartSubtotal(),{t:a}=m.useTranslations(),{activeCurrencyCode:n,currencies:h}=P.useCurrency(),i=o?.items??[],N=u.useMemo(()=>i.reduce((s,r)=>{if(f.isDigitalItem(r))return s;const c=k.getCartItemActivePrice(r,{currencyCode:n,currencies:h});return s+(c.sale_price??c.price)*r.quantity},0),[n,h,i]);if(!o)return null;const{updateQuantity:j,removeItem:d}=o,v=s=>i.reduce((r,c)=>f.isDigitalItem(c)||c.sku!==s?r:r+c.quantity,0),b=()=>{S.push("/checkout")};return i.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 py-12",children:[e.jsx("h2",{className:"text-2xl font-bold",children:a("ecommerce.cart_empty")}),e.jsx("p",{className:"text-muted-foreground",children:a("ecommerce.cart_empty_description")}),e.jsx(g.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:a("ecommerce.continue_shopping")})})]}):e.jsxs("div",{className:"container mx-auto py-12",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:a("ecommerce.shopping_cart")}),e.jsxs("div",{className:"grid gap-12 lg:grid-cols-12 lg:items-start",children:[e.jsx("div",{className:"lg:col-span-8",children:e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(l.Table,{children:[e.jsx(l.TableHeader,{children:e.jsxs(l.TableRow,{children:[e.jsx(l.TableHead,{children:a("ecommerce.product")}),e.jsx(l.TableHead,{children:a("ecommerce.quantity")}),e.jsx(l.TableHead,{className:"text-right",children:a("ecommerce.price")}),e.jsx(l.TableHead,{className:"text-right",children:a("ecommerce.total")}),e.jsx(l.TableHead,{className:"w-[50px]"})]})}),e.jsx(l.TableBody,{children:i.map(s=>{const r=v(s.sku),c=k.getCartItemActivePrice(s,{currencyCode:n,currencies:h}),p=O.getTrialSummary(s);return e.jsxs(l.TableRow,{children:[e.jsx(l.TableCell,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[s.image_url?e.jsx("div",{className:"h-16 w-16 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover"})}):e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded bg-secondary",children:e.jsx("span",{className:"text-[10px] text-muted-foreground",children:a("ecommerce.no_image")})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.title}),s.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s.variant_label}),f.isDigitalItem(s)&&s.billing_cycle&&e.jsxs("div",{className:"mt-1 text-xs capitalize text-muted-foreground",children:[s.billing_cycle," Subscription"]}),p&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[p.label," - ",p.paymentRequirementLabel]})]})]})}),e.jsx(l.TableCell,{children:f.isDigitalItem(s)?e.jsx(z.Badge,{variant:"secondary",className:"font-normal text-xs",children:"1 (License)"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>j(s.id,s.quantity-1),children:e.jsx(x.Minus,{className:"h-4 w-4"})}),e.jsx("span",{className:"w-8 text-center",children:s.quantity}),e.jsx(g.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>j(s.id,s.quantity+1),disabled:typeof s.stock=="number"&&r>=s.stock,children:e.jsx(x.Plus,{className:"h-4 w-4"})})]})}),e.jsx(l.TableCell,{className:"text-right",children:e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-medium",children:m.formatPrice(c.sale_price??c.price,n)}),c.sale_price&&e.jsx("span",{className:"text-xs text-muted-foreground line-through",children:m.formatPrice(c.price,n)})]})}),e.jsx(l.TableCell,{className:"text-right font-medium",children:m.formatPrice((c.sale_price??c.price)*s.quantity,n)}),e.jsx(l.TableCell,{children:e.jsx(g.Button,{variant:"ghost",size:"icon",onClick:()=>d(s.id),className:"text-muted-foreground hover:text-destructive",children:e.jsx(x.Trash2,{className:"h-4 w-4"})})})]},s.id)})})]})})}),e.jsx("div",{className:"lg:col-span-4",children:e.jsxs("div",{className:"rounded-lg border bg-card p-6 shadow-sm",children:[e.jsx("h2",{className:"mb-4 text-lg font-semibold",children:a("ecommerce.order_summary")}),e.jsxs("div",{className:"flex justify-between border-b pb-4",children:[e.jsx("span",{children:a("ecommerce.subtotal")}),e.jsx("span",{className:"font-medium",children:m.formatPrice(w,n)})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:a("ecommerce.shipping_taxes_calculated")}),i.some(s=>!f.isDigitalItem(s))&&e.jsx(K,{physicalSubtotal:N}),e.jsx(Q.CouponForm,{items:i,currencyCode:n,compact:!0}),e.jsx(g.Button,{className:"w-full mt-4",size:"lg",onClick:b,children:a("ecommerce.proceed_to_checkout")})]})]})})]})]})};exports.Cart=$;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { jsxs as a, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { useState as h, useMemo as K } from "react";
|
|
3
|
+
import { Badge as M } from "@nextblock-cms/ui/badge";
|
|
4
|
+
import { Button as p } from "@nextblock-cms/ui/button";
|
|
5
|
+
import { Table as O, TableHeader as $, TableRow as P, TableHead as x, TableBody as D, TableCell as N } from "@nextblock-cms/ui/table";
|
|
6
|
+
import { Truck as j, Loader2 as U, Calculator as G, Minus as J, Plus as V, Trash2 as W } from "lucide-react";
|
|
7
|
+
import { useCartSubtotal as X, getCartItemActivePrice as z } from "../cart-store.es.js";
|
|
8
|
+
import { useCart as Y } from "../use-cart.es.js";
|
|
9
|
+
import { isDigitalItem as v } from "../types.es.js";
|
|
10
|
+
import { useRouter as Z } from "next/navigation";
|
|
11
|
+
import { useTranslations as F, formatPrice as b } from "@nextblock-cms/utils";
|
|
12
|
+
import { Input as ee } from "@nextblock-cms/ui/input";
|
|
13
|
+
import { Label as q } from "@nextblock-cms/ui/label";
|
|
14
|
+
import { g as A, a as te, c as re } from "../states-DlHJezQ1.js";
|
|
15
|
+
import { g as ae } from "../shipping-actions-BnHjlo2q.js";
|
|
16
|
+
import { u as L } from "../CurrencyProvider-OzlRN96V.js";
|
|
17
|
+
import { d as ce } from "../trials-RDcRAZKx.js";
|
|
18
|
+
import { C as se } from "../CouponForm-BI_5SBHQ.js";
|
|
19
|
+
const le = ({ physicalSubtotal: k }) => {
|
|
20
|
+
const [i, S] = h("CA"), [s, n] = h(""), [m, o] = h(""), [y, g] = h(!1), [d, C] = h(null), [f, t] = h(null), { t: c, lang: l } = F(), { activeCurrencyCode: u } = L(), T = (r, _) => {
|
|
21
|
+
const w = c(r);
|
|
22
|
+
return w === r ? _ : w;
|
|
23
|
+
}, R = A(i), B = te(i), E = T("select_an_option", "Select an option"), I = T("state_province", "State / Province"), Q = async () => {
|
|
24
|
+
g(!0), t(null), C(null);
|
|
25
|
+
const r = await ae(
|
|
26
|
+
k,
|
|
27
|
+
{
|
|
28
|
+
country: i,
|
|
29
|
+
state: s || void 0,
|
|
30
|
+
postal_code: m
|
|
31
|
+
},
|
|
32
|
+
l,
|
|
33
|
+
u
|
|
34
|
+
);
|
|
35
|
+
r.success && r.methods ? C(r.methods) : t(
|
|
36
|
+
r.errorKey ? T(
|
|
37
|
+
r.errorKey,
|
|
38
|
+
r.error || c("ecommerce.no_rates_found")
|
|
39
|
+
) : r.error || c("ecommerce.no_rates_found")
|
|
40
|
+
), g(!1);
|
|
41
|
+
};
|
|
42
|
+
return /* @__PURE__ */ a("div", { className: "space-y-4 rounded-lg border bg-muted/30 p-4 mt-6", children: [
|
|
43
|
+
/* @__PURE__ */ a("div", { className: "flex items-center gap-2 font-semibold text-sm", children: [
|
|
44
|
+
/* @__PURE__ */ e(j, { className: "h-4 w-4" }),
|
|
45
|
+
/* @__PURE__ */ e("span", { children: c("ecommerce.estimate_shipping") })
|
|
46
|
+
] }),
|
|
47
|
+
/* @__PURE__ */ a("div", { className: "grid gap-3", children: [
|
|
48
|
+
/* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
|
|
49
|
+
/* @__PURE__ */ e(q, { htmlFor: "estimate-country", className: "text-xs uppercase tracking-wider text-muted-foreground", children: c("ecommerce.country") }),
|
|
50
|
+
/* @__PURE__ */ e(
|
|
51
|
+
"select",
|
|
52
|
+
{
|
|
53
|
+
id: "estimate-country",
|
|
54
|
+
value: i,
|
|
55
|
+
onChange: (r) => {
|
|
56
|
+
const _ = r.target.value, w = A(_);
|
|
57
|
+
S(_), n(
|
|
58
|
+
w.some((H) => H.code === s) ? s : ""
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
className: "flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
|
|
62
|
+
children: re.map((r) => /* @__PURE__ */ e("option", { value: r.code, children: r.name }, r.code))
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
] }),
|
|
66
|
+
B && /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
|
|
67
|
+
/* @__PURE__ */ e(q, { htmlFor: "estimate-state", className: "text-xs uppercase tracking-wider text-muted-foreground", children: c("state_province") }),
|
|
68
|
+
/* @__PURE__ */ a(
|
|
69
|
+
"select",
|
|
70
|
+
{
|
|
71
|
+
id: "estimate-state",
|
|
72
|
+
value: s,
|
|
73
|
+
onChange: (r) => n(r.target.value),
|
|
74
|
+
className: "flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ e("option", { value: "", children: `${E}: ${I}` }),
|
|
77
|
+
R.map((r) => /* @__PURE__ */ e("option", { value: r.code, children: r.name }, r.code))
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
] }),
|
|
82
|
+
/* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
|
|
83
|
+
/* @__PURE__ */ e(q, { htmlFor: "estimate-postal", className: "text-xs uppercase tracking-wider text-muted-foreground", children: c("ecommerce.postal_code") }),
|
|
84
|
+
/* @__PURE__ */ a("div", { className: "flex gap-2", children: [
|
|
85
|
+
/* @__PURE__ */ e(
|
|
86
|
+
ee,
|
|
87
|
+
{
|
|
88
|
+
id: "estimate-postal",
|
|
89
|
+
placeholder: "A1A 1A1",
|
|
90
|
+
value: m,
|
|
91
|
+
onChange: (r) => o(r.target.value),
|
|
92
|
+
className: "h-9 text-sm bg-background"
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ a(
|
|
96
|
+
p,
|
|
97
|
+
{
|
|
98
|
+
size: "sm",
|
|
99
|
+
variant: "secondary",
|
|
100
|
+
onClick: Q,
|
|
101
|
+
disabled: y,
|
|
102
|
+
className: "shrink-0",
|
|
103
|
+
children: [
|
|
104
|
+
y ? /* @__PURE__ */ e(U, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(G, { className: "h-4 w-4 mr-1.5" }),
|
|
105
|
+
c("ecommerce.calculate")
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
] })
|
|
110
|
+
] })
|
|
111
|
+
] }),
|
|
112
|
+
f && /* @__PURE__ */ e("p", { className: "text-xs text-destructive mt-2", children: f }),
|
|
113
|
+
d && d.length > 0 && /* @__PURE__ */ a("div", { className: "mt-4 space-y-2 border-t pt-3", children: [
|
|
114
|
+
/* @__PURE__ */ a("p", { className: "text-xs font-medium text-muted-foreground uppercase", children: [
|
|
115
|
+
c("ecommerce.available_rates"),
|
|
116
|
+
":"
|
|
117
|
+
] }),
|
|
118
|
+
d.map((r) => /* @__PURE__ */ a("div", { className: "flex justify-between items-center p-3 border rounded-lg bg-muted/30", children: [
|
|
119
|
+
/* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
|
|
120
|
+
/* @__PURE__ */ e(j, { className: "h-4 w-4 text-muted-foreground" }),
|
|
121
|
+
/* @__PURE__ */ e("span", { className: "text-sm font-medium", children: r.name })
|
|
122
|
+
] }),
|
|
123
|
+
/* @__PURE__ */ e("span", { className: "text-sm font-bold", children: r.amount === 0 ? c("ecommerce.free") : b(r.amount, u) })
|
|
124
|
+
] }, r.id))
|
|
125
|
+
] }),
|
|
126
|
+
d && d.length === 0 && !f && /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground mt-2 italic", children: c("ecommerce.no_rates_found") })
|
|
127
|
+
] });
|
|
128
|
+
}, ke = () => {
|
|
129
|
+
const k = Z(), i = Y((t) => t), S = X(), { t: s } = F(), { activeCurrencyCode: n, currencies: m } = L(), o = i?.items ?? [], y = K(
|
|
130
|
+
() => o.reduce((t, c) => {
|
|
131
|
+
if (v(c))
|
|
132
|
+
return t;
|
|
133
|
+
const l = z(c, {
|
|
134
|
+
currencyCode: n,
|
|
135
|
+
currencies: m
|
|
136
|
+
});
|
|
137
|
+
return t + (l.sale_price ?? l.price) * c.quantity;
|
|
138
|
+
}, 0),
|
|
139
|
+
[n, m, o]
|
|
140
|
+
);
|
|
141
|
+
if (!i) return null;
|
|
142
|
+
const { updateQuantity: g, removeItem: d } = i, C = (t) => o.reduce((c, l) => v(l) || l.sku !== t ? c : c + l.quantity, 0), f = () => {
|
|
143
|
+
k.push("/checkout");
|
|
144
|
+
};
|
|
145
|
+
return o.length === 0 ? /* @__PURE__ */ a("div", { className: "flex flex-col items-center justify-center space-y-4 py-12", children: [
|
|
146
|
+
/* @__PURE__ */ e("h2", { className: "text-2xl font-bold", children: s("ecommerce.cart_empty") }),
|
|
147
|
+
/* @__PURE__ */ e("p", { className: "text-muted-foreground", children: s("ecommerce.cart_empty_description") }),
|
|
148
|
+
/* @__PURE__ */ e(p, { asChild: !0, children: /* @__PURE__ */ e("a", { href: "/shop", children: s("ecommerce.continue_shopping") }) })
|
|
149
|
+
] }) : /* @__PURE__ */ a("div", { className: "container mx-auto py-12", children: [
|
|
150
|
+
/* @__PURE__ */ e("h1", { className: "mb-8 text-3xl font-bold", children: s("ecommerce.shopping_cart") }),
|
|
151
|
+
/* @__PURE__ */ a("div", { className: "grid gap-12 lg:grid-cols-12 lg:items-start", children: [
|
|
152
|
+
/* @__PURE__ */ e("div", { className: "lg:col-span-8", children: /* @__PURE__ */ e("div", { className: "rounded-lg border overflow-hidden", children: /* @__PURE__ */ a(O, { children: [
|
|
153
|
+
/* @__PURE__ */ e($, { children: /* @__PURE__ */ a(P, { children: [
|
|
154
|
+
/* @__PURE__ */ e(x, { children: s("ecommerce.product") }),
|
|
155
|
+
/* @__PURE__ */ e(x, { children: s("ecommerce.quantity") }),
|
|
156
|
+
/* @__PURE__ */ e(x, { className: "text-right", children: s("ecommerce.price") }),
|
|
157
|
+
/* @__PURE__ */ e(x, { className: "text-right", children: s("ecommerce.total") }),
|
|
158
|
+
/* @__PURE__ */ e(x, { className: "w-[50px]" })
|
|
159
|
+
] }) }),
|
|
160
|
+
/* @__PURE__ */ e(D, { children: o.map((t) => {
|
|
161
|
+
const c = C(t.sku), l = z(t, {
|
|
162
|
+
currencyCode: n,
|
|
163
|
+
currencies: m
|
|
164
|
+
}), u = ce(t);
|
|
165
|
+
return /* @__PURE__ */ a(P, { children: [
|
|
166
|
+
/* @__PURE__ */ e(N, { children: /* @__PURE__ */ a("div", { className: "flex items-center gap-4", children: [
|
|
167
|
+
t.image_url ? /* @__PURE__ */ e("div", { className: "h-16 w-16 overflow-hidden rounded border bg-neutral-100", children: /* @__PURE__ */ e(
|
|
168
|
+
"img",
|
|
169
|
+
{
|
|
170
|
+
src: t.image_url,
|
|
171
|
+
alt: t.title,
|
|
172
|
+
className: "h-full w-full object-cover"
|
|
173
|
+
}
|
|
174
|
+
) }) : /* @__PURE__ */ e("div", { className: "flex h-16 w-16 items-center justify-center rounded bg-secondary", children: /* @__PURE__ */ e("span", { className: "text-[10px] text-muted-foreground", children: s("ecommerce.no_image") }) }),
|
|
175
|
+
/* @__PURE__ */ a("div", { children: [
|
|
176
|
+
/* @__PURE__ */ e("div", { className: "font-medium", children: t.title }),
|
|
177
|
+
t.variant_label && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: t.variant_label }),
|
|
178
|
+
v(t) && t.billing_cycle && /* @__PURE__ */ a("div", { className: "mt-1 text-xs capitalize text-muted-foreground", children: [
|
|
179
|
+
t.billing_cycle,
|
|
180
|
+
" Subscription"
|
|
181
|
+
] }),
|
|
182
|
+
u && /* @__PURE__ */ a("div", { className: "mt-1 text-xs font-medium text-emerald-700", children: [
|
|
183
|
+
u.label,
|
|
184
|
+
" - ",
|
|
185
|
+
u.paymentRequirementLabel
|
|
186
|
+
] })
|
|
187
|
+
] })
|
|
188
|
+
] }) }),
|
|
189
|
+
/* @__PURE__ */ e(N, { children: v(t) ? /* @__PURE__ */ e(M, { variant: "secondary", className: "font-normal text-xs", children: "1 (License)" }) : /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
|
|
190
|
+
/* @__PURE__ */ e(
|
|
191
|
+
p,
|
|
192
|
+
{
|
|
193
|
+
variant: "outline",
|
|
194
|
+
size: "icon",
|
|
195
|
+
className: "h-8 w-8",
|
|
196
|
+
onClick: () => g(t.id, t.quantity - 1),
|
|
197
|
+
children: /* @__PURE__ */ e(J, { className: "h-4 w-4" })
|
|
198
|
+
}
|
|
199
|
+
),
|
|
200
|
+
/* @__PURE__ */ e("span", { className: "w-8 text-center", children: t.quantity }),
|
|
201
|
+
/* @__PURE__ */ e(
|
|
202
|
+
p,
|
|
203
|
+
{
|
|
204
|
+
variant: "outline",
|
|
205
|
+
size: "icon",
|
|
206
|
+
className: "h-8 w-8",
|
|
207
|
+
onClick: () => g(t.id, t.quantity + 1),
|
|
208
|
+
disabled: typeof t.stock == "number" && c >= t.stock,
|
|
209
|
+
children: /* @__PURE__ */ e(V, { className: "h-4 w-4" })
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
] }) }),
|
|
213
|
+
/* @__PURE__ */ e(N, { className: "text-right", children: /* @__PURE__ */ a("div", { className: "flex flex-col items-end", children: [
|
|
214
|
+
/* @__PURE__ */ e("span", { className: "font-medium", children: b(l.sale_price ?? l.price, n) }),
|
|
215
|
+
l.sale_price && /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground line-through", children: b(l.price, n) })
|
|
216
|
+
] }) }),
|
|
217
|
+
/* @__PURE__ */ e(N, { className: "text-right font-medium", children: b(
|
|
218
|
+
(l.sale_price ?? l.price) * t.quantity,
|
|
219
|
+
n
|
|
220
|
+
) }),
|
|
221
|
+
/* @__PURE__ */ e(N, { children: /* @__PURE__ */ e(
|
|
222
|
+
p,
|
|
223
|
+
{
|
|
224
|
+
variant: "ghost",
|
|
225
|
+
size: "icon",
|
|
226
|
+
onClick: () => d(t.id),
|
|
227
|
+
className: "text-muted-foreground hover:text-destructive",
|
|
228
|
+
children: /* @__PURE__ */ e(W, { className: "h-4 w-4" })
|
|
229
|
+
}
|
|
230
|
+
) })
|
|
231
|
+
] }, t.id);
|
|
232
|
+
}) })
|
|
233
|
+
] }) }) }),
|
|
234
|
+
/* @__PURE__ */ e("div", { className: "lg:col-span-4", children: /* @__PURE__ */ a("div", { className: "rounded-lg border bg-card p-6 shadow-sm", children: [
|
|
235
|
+
/* @__PURE__ */ e("h2", { className: "mb-4 text-lg font-semibold", children: s("ecommerce.order_summary") }),
|
|
236
|
+
/* @__PURE__ */ a("div", { className: "flex justify-between border-b pb-4", children: [
|
|
237
|
+
/* @__PURE__ */ e("span", { children: s("ecommerce.subtotal") }),
|
|
238
|
+
/* @__PURE__ */ e("span", { className: "font-medium", children: b(S, n) })
|
|
239
|
+
] }),
|
|
240
|
+
/* @__PURE__ */ a("div", { className: "mt-4 flex flex-col gap-4", children: [
|
|
241
|
+
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: s("ecommerce.shipping_taxes_calculated") }),
|
|
242
|
+
o.some((t) => !v(t)) && /* @__PURE__ */ e(le, { physicalSubtotal: y }),
|
|
243
|
+
/* @__PURE__ */ e(
|
|
244
|
+
se,
|
|
245
|
+
{
|
|
246
|
+
items: o,
|
|
247
|
+
currencyCode: n,
|
|
248
|
+
compact: !0
|
|
249
|
+
}
|
|
250
|
+
),
|
|
251
|
+
/* @__PURE__ */ e(p, { className: "w-full mt-4", size: "lg", onClick: f, children: s("ecommerce.proceed_to_checkout") })
|
|
252
|
+
] })
|
|
253
|
+
] }) })
|
|
254
|
+
] })
|
|
255
|
+
] });
|
|
256
|
+
};
|
|
257
|
+
export {
|
|
258
|
+
ke as Cart
|
|
259
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("@nextblock-cms/ui/sheet"),q=require("@nextblock-cms/ui/badge"),d=require("@nextblock-cms/ui/button"),_=require("next/navigation"),m=require("lucide-react"),j=require("../cart-store.cjs.js"),k=require("../use-cart.cjs.js"),o=require("@nextblock-cms/utils"),p=require("../types.cjs.js"),S=require("../CurrencyProvider-Cg-Q6ucj.cjs"),P=require("../trials-DvZaOtNy.cjs"),D=require("../CouponForm-D_uu2bLP.cjs"),T=()=>{const x=_.useRouter(),h=k.useCart(t=>t),g=j.useCartSubtotal(),{t:s}=o.useTranslations(),{activeCurrencyCode:c,currencies:y}=S.useCurrency();if(!h)return null;const{isOpen:b,setIsOpen:a,items:n,updateQuantity:f,removeItem:v}=h,N=t=>n.reduce((i,r)=>p.isDigitalItem(r)||r.sku!==t?i:i+r.quantity,0),w=()=>{a(!1),x.push("/cart")},C=()=>{a(!1),x.push("/checkout")};return e.jsx(l.Sheet,{open:b,onOpenChange:a,children:e.jsxs(l.SheetContent,{className:"flex w-full flex-col pr-0 sm:max-w-lg",children:[e.jsxs(l.SheetHeader,{className:"px-1 text-left",children:[e.jsxs(l.SheetTitle,{children:[s("ecommerce.shopping_cart")," (",n.length,")"]}),e.jsx(l.SheetDescription,{className:"sr-only",children:s("ecommerce.shopping_cart")})]}),n.length>0?e.jsx("div",{className:"flex flex-1 flex-col gap-5 overflow-y-auto p-1 pr-6 pt-4",children:n.map(t=>{const i=N(t.sku);return e.jsx("div",{className:"flex gap-4",children:(()=>{const r=j.getCartItemActivePrice(t,{currencyCode:c,currencies:y}),u=P.getTrialSummary(t);return e.jsxs(e.Fragment,{children:[t.image_url?e.jsx("div",{className:"relative aspect-square h-20 w-20 min-w-fit overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:t.image_url,alt:t.title,className:"h-full w-full object-cover"})}):e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded bg-secondary",children:e.jsx("span",{className:"text-xs text-muted-foreground",children:s("ecommerce.no_image")})}),e.jsxs("div",{className:"flex flex-1 flex-col justify-between",children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"line-clamp-2 text-sm font-medium leading-tight",children:t.title}),t.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:t.variant_label}),u&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[u.label," - ",u.paymentRequirementLabel]})]}),e.jsxs("span",{className:"text-sm font-semibold",children:[r.sale_price&&e.jsx("span",{className:"mr-1.5 text-xs font-normal text-muted-foreground line-through",children:o.formatPrice(r.price,c)}),o.formatPrice(r.sale_price??r.price,c)]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[p.isDigitalItem(t)?e.jsx(q.Badge,{variant:"secondary",className:"font-normal text-xs",children:"1 (License)"}):e.jsxs("div",{className:"flex items-center rounded-md border text-xs",children:[e.jsx("button",{onClick:()=>f(t.id,t.quantity-1),className:"flex h-7 w-7 items-center justify-center border-r",type:"button",children:e.jsx(m.Minus,{className:"h-3 w-3"})}),e.jsx("span",{className:"flex h-7 w-8 items-center justify-center",children:t.quantity}),e.jsx("button",{onClick:()=>f(t.id,t.quantity+1),className:"flex h-7 w-7 items-center justify-center border-l",type:"button",disabled:typeof t.stock=="number"&&i>=t.stock,children:e.jsx(m.Plus,{className:"h-3 w-3"})})]}),e.jsx("button",{onClick:()=>v(t.id),className:"text-muted-foreground hover:text-destructive",type:"button",children:e.jsx(m.Trash2,{className:"h-4 w-4"})})]})]})]})})()},t.id)})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center space-y-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s("ecommerce.cart_empty")}),e.jsx(d.Button,{variant:"outline",onClick:()=>a(!1),children:s("ecommerce.continue_shopping")})]}),n.length>0&&e.jsxs("div",{className:"border-t pr-6 pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-base font-medium",children:[e.jsx("span",{children:s("ecommerce.subtotal")}),e.jsx("span",{children:o.formatPrice(g,c)})]}),e.jsx("p",{className:"mb-4 mt-1 text-xs text-muted-foreground",children:s("ecommerce.shipping_taxes_calculated")}),e.jsx("div",{className:"mb-4",children:e.jsx(D.CouponForm,{items:n,currencyCode:c,compact:!0})}),e.jsx(d.Button,{variant:"outline",className:"w-full mb-3",onClick:w,children:s("ecommerce.view_full_cart")}),e.jsx(d.Button,{className:"w-full",onClick:C,children:s("ecommerce.ready_to_checkout")})]})]})})};exports.CartDrawer=T;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { jsx as e, jsxs as r, Fragment as C } from "react/jsx-runtime";
|
|
2
|
+
import { Sheet as _, SheetContent as k, SheetHeader as j, SheetTitle as S, SheetDescription as q } from "@nextblock-cms/ui/sheet";
|
|
3
|
+
import { Badge as P } from "@nextblock-cms/ui/badge";
|
|
4
|
+
import { Button as m } from "@nextblock-cms/ui/button";
|
|
5
|
+
import { useRouter as T } from "next/navigation";
|
|
6
|
+
import { Minus as D, Plus as O, Trash2 as Q } from "lucide-react";
|
|
7
|
+
import { useCartSubtotal as A, getCartItemActivePrice as B } from "../cart-store.es.js";
|
|
8
|
+
import { useCart as F } from "../use-cart.es.js";
|
|
9
|
+
import { useTranslations as I, formatPrice as d } from "@nextblock-cms/utils";
|
|
10
|
+
import { isDigitalItem as p } from "../types.es.js";
|
|
11
|
+
import { u as L } from "../CurrencyProvider-OzlRN96V.js";
|
|
12
|
+
import { d as R } from "../trials-RDcRAZKx.js";
|
|
13
|
+
import { C as H } from "../CouponForm-BI_5SBHQ.js";
|
|
14
|
+
const ee = () => {
|
|
15
|
+
const u = T(), h = F((t) => t), x = A(), { t: l } = I(), { activeCurrencyCode: n, currencies: y } = L();
|
|
16
|
+
if (!h) return null;
|
|
17
|
+
const { isOpen: N, setIsOpen: a, items: c, updateQuantity: f, removeItem: g } = h, b = (t) => c.reduce((i, s) => p(s) || s.sku !== t ? i : i + s.quantity, 0), v = () => {
|
|
18
|
+
a(!1), u.push("/cart");
|
|
19
|
+
}, w = () => {
|
|
20
|
+
a(!1), u.push("/checkout");
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ e(_, { open: N, onOpenChange: a, children: /* @__PURE__ */ r(k, { className: "flex w-full flex-col pr-0 sm:max-w-lg", children: [
|
|
23
|
+
/* @__PURE__ */ r(j, { className: "px-1 text-left", children: [
|
|
24
|
+
/* @__PURE__ */ r(S, { children: [
|
|
25
|
+
l("ecommerce.shopping_cart"),
|
|
26
|
+
" (",
|
|
27
|
+
c.length,
|
|
28
|
+
")"
|
|
29
|
+
] }),
|
|
30
|
+
/* @__PURE__ */ e(q, { className: "sr-only", children: l("ecommerce.shopping_cart") })
|
|
31
|
+
] }),
|
|
32
|
+
c.length > 0 ? /* @__PURE__ */ e("div", { className: "flex flex-1 flex-col gap-5 overflow-y-auto p-1 pr-6 pt-4", children: c.map((t) => {
|
|
33
|
+
const i = b(t.sku);
|
|
34
|
+
return /* @__PURE__ */ e("div", { className: "flex gap-4", children: (() => {
|
|
35
|
+
const s = B(t, {
|
|
36
|
+
currencyCode: n,
|
|
37
|
+
currencies: y
|
|
38
|
+
}), o = R(t);
|
|
39
|
+
return /* @__PURE__ */ r(C, { children: [
|
|
40
|
+
t.image_url ? /* @__PURE__ */ e("div", { className: "relative aspect-square h-20 w-20 min-w-fit overflow-hidden rounded border bg-neutral-100", children: /* @__PURE__ */ e(
|
|
41
|
+
"img",
|
|
42
|
+
{
|
|
43
|
+
src: t.image_url,
|
|
44
|
+
alt: t.title,
|
|
45
|
+
className: "h-full w-full object-cover"
|
|
46
|
+
}
|
|
47
|
+
) }) : /* @__PURE__ */ e("div", { className: "flex h-20 w-20 items-center justify-center rounded bg-secondary", children: /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground", children: l("ecommerce.no_image") }) }),
|
|
48
|
+
/* @__PURE__ */ r("div", { className: "flex flex-1 flex-col justify-between", children: [
|
|
49
|
+
/* @__PURE__ */ r("div", { className: "flex justify-between gap-2", children: [
|
|
50
|
+
/* @__PURE__ */ r("div", { children: [
|
|
51
|
+
/* @__PURE__ */ e("span", { className: "line-clamp-2 text-sm font-medium leading-tight", children: t.title }),
|
|
52
|
+
t.variant_label && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: t.variant_label }),
|
|
53
|
+
o && /* @__PURE__ */ r("div", { className: "mt-1 text-xs font-medium text-emerald-700", children: [
|
|
54
|
+
o.label,
|
|
55
|
+
" - ",
|
|
56
|
+
o.paymentRequirementLabel
|
|
57
|
+
] })
|
|
58
|
+
] }),
|
|
59
|
+
/* @__PURE__ */ r("span", { className: "text-sm font-semibold", children: [
|
|
60
|
+
s.sale_price && /* @__PURE__ */ e("span", { className: "mr-1.5 text-xs font-normal text-muted-foreground line-through", children: d(s.price, n) }),
|
|
61
|
+
d(s.sale_price ?? s.price, n)
|
|
62
|
+
] })
|
|
63
|
+
] }),
|
|
64
|
+
/* @__PURE__ */ r("div", { className: "flex items-center justify-between text-sm", children: [
|
|
65
|
+
p(t) ? /* @__PURE__ */ e(P, { variant: "secondary", className: "font-normal text-xs", children: "1 (License)" }) : /* @__PURE__ */ r("div", { className: "flex items-center rounded-md border text-xs", children: [
|
|
66
|
+
/* @__PURE__ */ e(
|
|
67
|
+
"button",
|
|
68
|
+
{
|
|
69
|
+
onClick: () => f(t.id, t.quantity - 1),
|
|
70
|
+
className: "flex h-7 w-7 items-center justify-center border-r",
|
|
71
|
+
type: "button",
|
|
72
|
+
children: /* @__PURE__ */ e(D, { className: "h-3 w-3" })
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
/* @__PURE__ */ e("span", { className: "flex h-7 w-8 items-center justify-center", children: t.quantity }),
|
|
76
|
+
/* @__PURE__ */ e(
|
|
77
|
+
"button",
|
|
78
|
+
{
|
|
79
|
+
onClick: () => f(t.id, t.quantity + 1),
|
|
80
|
+
className: "flex h-7 w-7 items-center justify-center border-l",
|
|
81
|
+
type: "button",
|
|
82
|
+
disabled: typeof t.stock == "number" && i >= t.stock,
|
|
83
|
+
children: /* @__PURE__ */ e(O, { className: "h-3 w-3" })
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
] }),
|
|
87
|
+
/* @__PURE__ */ e(
|
|
88
|
+
"button",
|
|
89
|
+
{
|
|
90
|
+
onClick: () => g(t.id),
|
|
91
|
+
className: "text-muted-foreground hover:text-destructive",
|
|
92
|
+
type: "button",
|
|
93
|
+
children: /* @__PURE__ */ e(Q, { className: "h-4 w-4" })
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
] })
|
|
97
|
+
] })
|
|
98
|
+
] });
|
|
99
|
+
})() }, t.id);
|
|
100
|
+
}) }) : /* @__PURE__ */ r("div", { className: "flex h-full flex-col items-center justify-center space-y-2", children: [
|
|
101
|
+
/* @__PURE__ */ e("span", { className: "text-muted-foreground", children: l("ecommerce.cart_empty") }),
|
|
102
|
+
/* @__PURE__ */ e(m, { variant: "outline", onClick: () => a(!1), children: l("ecommerce.continue_shopping") })
|
|
103
|
+
] }),
|
|
104
|
+
c.length > 0 && /* @__PURE__ */ r("div", { className: "border-t pr-6 pt-4", children: [
|
|
105
|
+
/* @__PURE__ */ r("div", { className: "flex items-center justify-between text-base font-medium", children: [
|
|
106
|
+
/* @__PURE__ */ e("span", { children: l("ecommerce.subtotal") }),
|
|
107
|
+
/* @__PURE__ */ e("span", { children: d(x, n) })
|
|
108
|
+
] }),
|
|
109
|
+
/* @__PURE__ */ e("p", { className: "mb-4 mt-1 text-xs text-muted-foreground", children: l("ecommerce.shipping_taxes_calculated") }),
|
|
110
|
+
/* @__PURE__ */ e("div", { className: "mb-4", children: /* @__PURE__ */ e(H, { items: c, currencyCode: n, compact: !0 }) }),
|
|
111
|
+
/* @__PURE__ */ e(m, { variant: "outline", className: "w-full mb-3", onClick: v, children: l("ecommerce.view_full_cart") }),
|
|
112
|
+
/* @__PURE__ */ e(m, { className: "w-full", onClick: w, children: l("ecommerce.ready_to_checkout") })
|
|
113
|
+
] })
|
|
114
|
+
] }) });
|
|
115
|
+
};
|
|
116
|
+
export {
|
|
117
|
+
ee as CartDrawer
|
|
118
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("@nextblock-cms/ui/badge"),a=require("@nextblock-cms/ui/button"),s=require("lucide-react"),n=require("../cart-store.cjs.js"),c=require("../use-cart.cjs.js"),l=()=>{const i=n.useCartStore(t=>t.toggleCart),r=n.useCartTotalItems();return c.useCart(t=>t.isOpen)!==void 0?e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"relative",onClick:i,"aria-label":"Open cart",children:[e.jsx(s.ShoppingBag,{className:"h-5 w-5"}),r>0&&e.jsx(o.Badge,{variant:"destructive",className:"absolute -right-1 -top-1 h-4 w-4 items-center justify-center p-0 text-[10px]",children:r})]}):e.jsx(a.Button,{variant:"ghost",size:"icon",className:"relative","aria-label":"Open cart",children:e.jsx(s.ShoppingBag,{className:"h-5 w-5"})})};exports.CartIcon=l;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as t, jsxs as i } from "react/jsx-runtime";
|
|
2
|
+
import { Badge as n } from "@nextblock-cms/ui/badge";
|
|
3
|
+
import { Button as a } from "@nextblock-cms/ui/button";
|
|
4
|
+
import { ShoppingBag as o } from "lucide-react";
|
|
5
|
+
import { useCartStore as c, useCartTotalItems as l } from "../cart-store.es.js";
|
|
6
|
+
import { useCart as m } from "../use-cart.es.js";
|
|
7
|
+
const C = () => {
|
|
8
|
+
const s = c((e) => e.toggleCart), r = l();
|
|
9
|
+
return m((e) => e.isOpen) !== void 0 ? /* @__PURE__ */ i(
|
|
10
|
+
a,
|
|
11
|
+
{
|
|
12
|
+
variant: "ghost",
|
|
13
|
+
size: "icon",
|
|
14
|
+
className: "relative",
|
|
15
|
+
onClick: s,
|
|
16
|
+
"aria-label": "Open cart",
|
|
17
|
+
children: [
|
|
18
|
+
/* @__PURE__ */ t(o, { className: "h-5 w-5" }),
|
|
19
|
+
r > 0 && /* @__PURE__ */ t(
|
|
20
|
+
n,
|
|
21
|
+
{
|
|
22
|
+
variant: "destructive",
|
|
23
|
+
className: "absolute -right-1 -top-1 h-4 w-4 items-center justify-center p-0 text-[10px]",
|
|
24
|
+
children: r
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
) : /* @__PURE__ */ t(a, { variant: "ghost", size: "icon", className: "relative", "aria-label": "Open cart", children: /* @__PURE__ */ t(o, { className: "h-5 w-5" }) });
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
C as CartIcon
|
|
33
|
+
};
|