@nextblock-cms/ecom 0.12.12 → 0.12.14
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.d.ts +2 -0
- package/index.es.js +108 -106
- package/lib/components/Checkout.cjs.js +1 -1
- package/lib/components/Checkout.es.js +32 -33
- package/lib/components/CustomerProfileForm.cjs.js +1 -1
- package/lib/components/CustomerProfileForm.es.js +185 -238
- package/lib/components/FreemiusLicensePanel.cjs.js +1 -0
- package/lib/components/FreemiusLicensePanel.d.ts +6 -0
- package/lib/components/FreemiusLicensePanel.es.js +66 -0
- package/lib/components/InvoiceViewerShell.cjs.js +2 -2
- package/lib/components/InvoiceViewerShell.d.ts +3 -1
- package/lib/components/InvoiceViewerShell.es.js +13 -11
- package/lib/customer-orders.cjs.js +1 -1
- package/lib/customer-orders.d.ts +2 -0
- package/lib/customer-orders.es.js +30 -27
- package/lib/freemius-license-types.d.ts +19 -0
- package/lib/freemius-license.cjs.js +1 -0
- package/lib/freemius-license.d.ts +20 -0
- package/lib/freemius-license.es.js +41 -0
- package/lib/freemius-order-sync.cjs.js +1 -1
- package/lib/freemius-order-sync.es.js +62 -52
- package/lib/pages/cms/orders/types.d.ts +0 -1
- package/lib/pages/cms/products/actions.cjs.js +1 -1
- package/lib/pages/cms/products/actions.es.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +104 -62
- package/lib/product-actions.cjs.js +3 -3
- package/lib/product-actions.d.ts +2 -1
- package/lib/product-actions.es.js +45 -44
- package/lib/server-actions/customer-actions.cjs.js +1 -1
- package/lib/server-actions/customer-actions.d.ts +0 -1
- package/lib/server-actions/customer-actions.es.js +12 -13
- package/package.json +4 -4
- package/server.cjs.js +1 -1
- package/server.d.ts +1 -0
- package/server.es.js +77 -75
|
@@ -201,7 +201,7 @@ function Be({
|
|
|
201
201
|
] });
|
|
202
202
|
}
|
|
203
203
|
const Wt = ({ initialCustomer: c }) => {
|
|
204
|
-
const [x, P] = _({}), [l, f] = _(null), [h, I] = _({}), [E, W] = _(c?.email || ""), [q, K] = _(""), [a, U] = _(c?.phone || ""), [de, Z] = _(!1), [Ke, we] = _(null), [Se, ee] = _(!1), [Ue, te] = _(!1), [J, re] = _([]), [b, B] = _(null), [
|
|
204
|
+
const [x, P] = _({}), [l, f] = _(null), [h, I] = _({}), [E, W] = _(c?.email || ""), [q, K] = _(""), [a, U] = _(c?.phone || ""), [de, Z] = _(!1), [Ke, we] = _(null), [Se, ee] = _(!1), [Ue, te] = _(!1), [J, re] = _([]), [b, B] = _(null), [S, ce] = _(null), [D, Je] = _(null), [A, Ce] = _(
|
|
205
205
|
() => ae(c?.billingAddress, c?.fullName)
|
|
206
206
|
), [O, Fe] = _(
|
|
207
207
|
() => ae(
|
|
@@ -213,7 +213,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
213
213
|
), G = dt((t) => t), { t: s, lang: me } = qe(), { activeCurrencyCode: o, currencies: M } = wt(), N = G?.items ?? [], k = $(
|
|
214
214
|
() => N.filter((t) => !xe(t)),
|
|
215
215
|
[N]
|
|
216
|
-
),
|
|
216
|
+
), C = $(
|
|
217
217
|
() => N.filter((t) => xe(t)),
|
|
218
218
|
[N]
|
|
219
219
|
), R = c?.isAuthenticated ?? !1, n = (t, i, u) => {
|
|
@@ -229,27 +229,27 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
229
229
|
String(d)
|
|
230
230
|
);
|
|
231
231
|
}), g;
|
|
232
|
-
},
|
|
232
|
+
}, w = k.length > 0, Ge = $(
|
|
233
233
|
() => be(N, o, M),
|
|
234
234
|
[o, M, N]
|
|
235
235
|
), ue = $(
|
|
236
236
|
() => be(k, o, M),
|
|
237
237
|
[o, M, k]
|
|
238
238
|
), pe = $(
|
|
239
|
-
() => be(
|
|
240
|
-
[o, M,
|
|
239
|
+
() => be(C, o, M),
|
|
240
|
+
[o, M, C]
|
|
241
241
|
), he = D?.providerDiscounts.stripe ?? 0, fe = D?.providerDiscounts.freemius ?? 0, ne = Math.max(0, ue - he), He = Math.max(0, pe - fe), F = $(
|
|
242
242
|
() => L ? A : O,
|
|
243
243
|
[A, O, L]
|
|
244
244
|
), z = $(
|
|
245
|
-
() =>
|
|
246
|
-
[A,
|
|
247
|
-
), se = !
|
|
245
|
+
() => w ? F : A,
|
|
246
|
+
[A, w, F]
|
|
247
|
+
), se = !w || Ft(F), le = $(
|
|
248
248
|
() => J.find((t) => t.id === b),
|
|
249
249
|
[J, b]
|
|
250
250
|
), Te = $(
|
|
251
|
-
() => ne + (le?.amount ?? 0) + (
|
|
252
|
-
[ne, le,
|
|
251
|
+
() => ne + (le?.amount ?? 0) + (S && !S.isPendingExternalCalculation ? S.amount : 0),
|
|
252
|
+
[ne, le, S]
|
|
253
253
|
), Qe = Te + He;
|
|
254
254
|
if (ie(() => {
|
|
255
255
|
if (!(R || typeof window > "u"))
|
|
@@ -289,7 +289,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
289
289
|
O,
|
|
290
290
|
L
|
|
291
291
|
]), ie(() => {
|
|
292
|
-
if (!
|
|
292
|
+
if (!w) {
|
|
293
293
|
re([]), B(null), ee(!1);
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
@@ -319,7 +319,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
319
319
|
};
|
|
320
320
|
}, [
|
|
321
321
|
o,
|
|
322
|
-
|
|
322
|
+
w,
|
|
323
323
|
se,
|
|
324
324
|
me,
|
|
325
325
|
b,
|
|
@@ -329,7 +329,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
329
329
|
ne
|
|
330
330
|
]), ie(() => {
|
|
331
331
|
const i = setTimeout(async () => {
|
|
332
|
-
if (!
|
|
332
|
+
if (!w || !z.country_code) {
|
|
333
333
|
te(!1), ce(null);
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
@@ -353,7 +353,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
353
353
|
return () => clearTimeout(i);
|
|
354
354
|
}, [
|
|
355
355
|
o,
|
|
356
|
-
|
|
356
|
+
w,
|
|
357
357
|
k,
|
|
358
358
|
z.country_code,
|
|
359
359
|
z.state,
|
|
@@ -415,7 +415,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
415
415
|
const i = ve(A);
|
|
416
416
|
if (!Le(i))
|
|
417
417
|
return alert(s("checkout_complete_billing_address")), null;
|
|
418
|
-
const u =
|
|
418
|
+
const u = w ? ve(L ? A : O) : null;
|
|
419
419
|
if (t === "stripe") {
|
|
420
420
|
if (!Le(u))
|
|
421
421
|
return alert(s("checkout_complete_shipping_address")), null;
|
|
@@ -545,7 +545,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
545
545
|
/* @__PURE__ */ e(_e, { asChild: !0, children: /* @__PURE__ */ e("a", { href: "/shop", children: s("ecommerce.go_to_shop") }) })
|
|
546
546
|
] })
|
|
547
547
|
] });
|
|
548
|
-
const ge =
|
|
548
|
+
const ge = w ? se ? Se ? n(
|
|
549
549
|
"ecommerce.calculating_shipping",
|
|
550
550
|
"Calculating shipping..."
|
|
551
551
|
) : b ? null : J.length > 0 ? s("ecommerce.select_rate") : s("ecommerce.no_rates_for_region") : n(
|
|
@@ -555,10 +555,10 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
555
555
|
count: k.length
|
|
556
556
|
}) : n("ecommerce.item_count_other", "{count} items", {
|
|
557
557
|
count: k.length
|
|
558
|
-
}), We =
|
|
559
|
-
count:
|
|
558
|
+
}), We = C.length === 1 ? n("ecommerce.license_count_one", "{count} license", {
|
|
559
|
+
count: C.length
|
|
560
560
|
}) : n("ecommerce.license_count_other", "{count} licenses", {
|
|
561
|
-
count:
|
|
561
|
+
count: C.length
|
|
562
562
|
}), Ze = (t) => xe(t) ? n("ecommerce.digital_label", "Digital") : n("ecommerce.physical_label", "Physical"), et = (t) => t === "monthly" ? n(
|
|
563
563
|
"ecommerce.checkout_billing_cycle_monthly",
|
|
564
564
|
"Monthly subscription"
|
|
@@ -626,7 +626,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
626
626
|
onChange: Ce
|
|
627
627
|
}
|
|
628
628
|
),
|
|
629
|
-
|
|
629
|
+
w ? /* @__PURE__ */ r("div", { className: "flex items-center space-x-3 rounded-xl border bg-muted/20 p-4", children: [
|
|
630
630
|
/* @__PURE__ */ e(
|
|
631
631
|
lt,
|
|
632
632
|
{
|
|
@@ -640,7 +640,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
640
640
|
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: s("checkout_use_billing_for_shipping_help") })
|
|
641
641
|
] })
|
|
642
642
|
] }) : null,
|
|
643
|
-
|
|
643
|
+
w && !L ? /* @__PURE__ */ e(
|
|
644
644
|
ze,
|
|
645
645
|
{
|
|
646
646
|
idPrefix: "shipping",
|
|
@@ -650,7 +650,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
650
650
|
onChange: Fe
|
|
651
651
|
}
|
|
652
652
|
) : null,
|
|
653
|
-
|
|
653
|
+
w ? /* @__PURE__ */ r(Q, { children: [
|
|
654
654
|
/* @__PURE__ */ e(X, { children: /* @__PURE__ */ r(Y, { className: "flex items-center gap-2", children: [
|
|
655
655
|
/* @__PURE__ */ e(ht, { className: "w-5 h-5 text-primary" }),
|
|
656
656
|
s("ecommerce.shipping_method")
|
|
@@ -741,7 +741,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
741
741
|
) }),
|
|
742
742
|
/* @__PURE__ */ e("span", { children: y(ue, o) })
|
|
743
743
|
] }) : null,
|
|
744
|
-
|
|
744
|
+
C.length > 0 ? /* @__PURE__ */ r("div", { className: "flex justify-between text-muted-foreground", children: [
|
|
745
745
|
/* @__PURE__ */ e("span", { children: n(
|
|
746
746
|
"ecommerce.digital_products",
|
|
747
747
|
"Digital products"
|
|
@@ -760,7 +760,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
760
760
|
y(D.discountTotal, o)
|
|
761
761
|
] })
|
|
762
762
|
] }) : null,
|
|
763
|
-
(k.length > 0 ||
|
|
763
|
+
(k.length > 0 || C.length > 0) && /* @__PURE__ */ r("div", { className: "flex justify-between font-bold text-lg pt-2 border-t mt-2", children: [
|
|
764
764
|
/* @__PURE__ */ e("span", { children: n(
|
|
765
765
|
"ecommerce.estimated_total",
|
|
766
766
|
"Estimated total"
|
|
@@ -804,12 +804,12 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
804
804
|
] }),
|
|
805
805
|
/* @__PURE__ */ r("div", { className: "flex justify-between", children: [
|
|
806
806
|
/* @__PURE__ */ e("span", { children: n("ecommerce.tax", "Tax") }),
|
|
807
|
-
/* @__PURE__ */ e("span", { children: Ue ? "..." :
|
|
807
|
+
/* @__PURE__ */ e("span", { children: Ue ? "..." : S?.isPendingExternalCalculation ? n(
|
|
808
808
|
"ecommerce.tax_calculated_on_stripe",
|
|
809
809
|
"Calculated on Stripe"
|
|
810
|
-
) :
|
|
810
|
+
) : S ? y(S.amount, o) : "-" })
|
|
811
811
|
] }),
|
|
812
|
-
|
|
812
|
+
S && S.lines.length > 0 ? /* @__PURE__ */ e("div", { className: "rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground", children: S.lines.map((t) => /* @__PURE__ */ r("div", { className: "flex justify-between gap-3", children: [
|
|
813
813
|
/* @__PURE__ */ r("span", { children: [
|
|
814
814
|
t.name,
|
|
815
815
|
" (",
|
|
@@ -844,7 +844,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
844
844
|
),
|
|
845
845
|
ge && l === null ? /* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: ge }) : null,
|
|
846
846
|
h.stripe ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive", children: h.stripe }) : null,
|
|
847
|
-
/* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children:
|
|
847
|
+
/* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: S?.isPendingExternalCalculation ? n(
|
|
848
848
|
"checkout_stripe_tax_finalized_notice",
|
|
849
849
|
"Tax will be finalized by Stripe Tax on the payment step."
|
|
850
850
|
) : n(
|
|
@@ -854,7 +854,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
854
854
|
]
|
|
855
855
|
}
|
|
856
856
|
) : null,
|
|
857
|
-
|
|
857
|
+
C.length > 0 ? /* @__PURE__ */ r(
|
|
858
858
|
Be,
|
|
859
859
|
{
|
|
860
860
|
title: n(
|
|
@@ -867,7 +867,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
867
867
|
),
|
|
868
868
|
badgeLabel: We,
|
|
869
869
|
children: [
|
|
870
|
-
/* @__PURE__ */ e("div", { className: "space-y-3", children:
|
|
870
|
+
/* @__PURE__ */ e("div", { className: "space-y-3", children: C.map((t) => {
|
|
871
871
|
const i = Ne(t, {
|
|
872
872
|
currencyCode: o,
|
|
873
873
|
currencies: M
|
|
@@ -925,7 +925,6 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
925
925
|
_e,
|
|
926
926
|
{
|
|
927
927
|
className: "w-full h-auto min-h-[2.75rem] py-2",
|
|
928
|
-
variant: w.length > 1 ? "outline" : "default",
|
|
929
928
|
onClick: () => Pe(
|
|
930
929
|
"freemius",
|
|
931
930
|
[
|
|
@@ -939,7 +938,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
939
938
|
disabled: l !== null,
|
|
940
939
|
children: [
|
|
941
940
|
l === m ? /* @__PURE__ */ e(ye, { className: "mr-2 h-4 w-4 shrink-0 animate-spin" }) : /* @__PURE__ */ e(gt, { className: "mr-2 h-4 w-4 shrink-0" }),
|
|
942
|
-
/* @__PURE__ */ e("span", { className: "whitespace-normal text-left", children: l === m ? s("ecommerce.processing") :
|
|
941
|
+
/* @__PURE__ */ e("span", { className: "whitespace-normal text-left", children: l === m ? s("ecommerce.processing") : C.length > 1 ? n(
|
|
943
942
|
"ecommerce.checkout_product",
|
|
944
943
|
"Checkout {title}",
|
|
945
944
|
{ title: t.title }
|
|
@@ -967,7 +966,7 @@ const Wt = ({ initialCustomer: c }) => {
|
|
|
967
966
|
] })
|
|
968
967
|
] }) : null,
|
|
969
968
|
h.freemius ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive", children: h.freemius }) : null,
|
|
970
|
-
/* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children:
|
|
969
|
+
/* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: C.length > 1 ? n(
|
|
971
970
|
"ecommerce.freemius_multi_checkout_notice",
|
|
972
971
|
"Freemius licenses are completed one at a time, so each digital product gets its own checkout action."
|
|
973
972
|
) : n(
|
|
@@ -1 +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"),S=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"),C=require("../customer.cjs.js"),B=require("@nextblock-cms/db"),u=require("lucide-react"),P=require("@nextblock-cms/utils"),H=require("../countries.cjs.js");function se(s){return s?s.startsWith("http")?s:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${s}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${s}`:s:null}function I(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:H.normalizeCountryCode(s?.country_code)||"CA"}}function G({prefix:s,title:j,register:c}){const{t:n}=P.useTranslations(),w=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:w}),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:H.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 le({initialData:s,MediaPickerComponent:j,isAdmin:c,email:n,accountLinks:w,onAction:g,initialSuccessMessage:f}){const{t:l}=P.useTranslations(),[E,F]=_.useState(!1),[L,y]=_.useState(f?{type:"success",text:f}:null),[A,V]=_.useState(!1),[U,X]=_.useState(null),z=s?.use_billing_for_shipping??(!s?.shipping_address||C.addressesMatch(s?.billing_address,s?.shipping_address)),{register:p,handleSubmit:M,setValue:m,getValues:$,watch:v,reset:q}=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:z,billing_address:I(s?.billing_address),shipping_address:I(s?.shipping_address)}});_.useEffect(()=>{s&&q({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||C.addressesMatch(s.billing_address,s.shipping_address)),billing_address:I(s.billing_address),shipping_address:I(s.shipping_address)})},[s,q]),_.useEffect(()=>{f&&y({type:"success",text:f})},[f]),_.useEffect(()=>{const r=B.createClient();(async()=>{const{data:{user:h}}=await r.auth.getUser();if(!h)return;const t=h.identities?.find(b=>b.provider==="github");if(t){V(!0);const b=t.identity_data?.email||(h.app_metadata.provider==="github"?h.email:null);if(X(b),!$("website")){const N=t.identity_data?.custom_claims?.blog||t.identity_data?.blog||t.identity_data?.html_url;N&&m("website",N)}if(!$("avatar_url")){const N=t.identity_data?.avatar_url;N&&m("avatar_url",N)}const k=t.identity_data?.user_name||t.identity_data?.preferred_username;k&&m("github_username",k)}!$("full_name")&&h.user_metadata?.full_name&&m("full_name",h.user_metadata.full_name)})()},[$,m]);const W=async()=>{const r=B.createClient(),{error:d}=await r.auth.linkIdentity({provider:"github"});d&&(console.error("Error linking GitHub:",d),y({type:"error",text:l("github_link_failed")||"Failed to link GitHub account"}))},O=r=>{const d=se(r?.object_key??r?.file_path);d&&m("avatar_url",d)},J=async r=>{F(!0),y(null);const d=C.normalizeCustomerAddress(r.billing_address)??C.emptyCustomerAddress(),h=r.use_billing_for_shipping?d:C.normalizeCustomerAddress(r.shipping_address);try{const t={...r,billing_address:d,shipping_address:h};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{F(!1)}},R=v("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(S.Avatar,{className:"h-32 w-32 border-4 border-muted",children:[e.jsx(S.AvatarImage,{src:v("avatar_url")||void 0,className:"object-cover"}),e.jsx(S.AvatarFallback,{className:"text-4xl bg-secondary",children:v("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",...p("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:v("full_name")||l("full_name")})}),A&&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"]})]}),w?.length?e.jsx(Q.AccountNavigationMenu,{links:w,className:"mt-2 text-left"}):null]})]}),e.jsx(o.Card,{className:"md:col-span-8",children:e.jsxs("form",{onSubmit:M(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",...p("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",...p("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",...p("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")]}),A?e.jsxs("div",{className:"space-y-2",children:[e.jsx(i.Input,{id:"github_username",...p("github_username"),disabled:!0,className:"bg-muted"}),U&&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"," ",U]})]}):e.jsxs(T.Button,{type:"button",variant:"outline",className:"w-full",onClick:W,children:[e.jsx(u.Github,{className:"mr-2 h-4 w-4"}),l("connect_github")]})]})]}),e.jsx(D.Separator,{className:"my-2"}),e.jsx(G,{prefix:"billing_address",title:l("billing_address"),register:p}),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:!!R,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")})]})]}),!R&&e.jsx(G,{prefix:"shipping_address",title:l("shipping_address"),register:p}),L&&e.jsx("div",{className:`mt-4 rounded-xl border p-4 text-sm ${L.type==="success"?"border-emerald-200 bg-emerald-50 text-emerald-700":"border-red-200 bg-red-50 text-red-700"}`,children:L.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:v("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:E,size:"lg",children:l(E?"saving":"save_changes")})})]})})]})}exports.CustomerProfileForm=le;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("react"),V=require("react-hook-form"),X=require("./AccountNavigationMenu.cjs.js"),w=require("@nextblock-cms/ui/avatar"),z=require("@nextblock-cms/ui/button"),d=require("@nextblock-cms/ui/card"),W=require("@nextblock-cms/ui/checkbox"),t=require("@nextblock-cms/ui/input"),n=require("@nextblock-cms/ui/label"),o=require("@nextblock-cms/ui/select"),H=require("@nextblock-cms/ui/separator"),M=require("../server-actions/customer-actions.cjs.js"),f=require("../customer.cjs.js"),O=require("@nextblock-cms/db"),N=require("lucide-react"),R=require("@nextblock-cms/utils"),q=require("../countries.cjs.js");function G(s){return s?s.startsWith("http")?s:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${s}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${s}`:s:null}function C(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:q.normalizeCountryCode(s?.country_code)||"CA"}}function U({prefix:s,title:h,register:c}){const{t:a}=R.useTranslations(),v=a("company_name")==="company_name"?"Company name":a("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:h}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("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(n.Label,{htmlFor:`${s}-company_name`,children:v}),e.jsx(t.Input,{id:`${s}-company_name`,...c(`${s}.company_name`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n.Label,{htmlFor:`${s}-recipient_name`,children:a("full_name")}),e.jsx(t.Input,{id:`${s}-recipient_name`,...c(`${s}.recipient_name`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n.Label,{htmlFor:`${s}-country_code`,children:a("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:q.countries.map(m=>e.jsx("option",{value:m.code,children:m.name},m.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n.Label,{htmlFor:`${s}-line1`,children:a("address_line_1")}),e.jsx(t.Input,{id:`${s}-line1`,...c(`${s}.line1`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n.Label,{htmlFor:`${s}-line2`,children:a("address_line_2")}),e.jsx(t.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(n.Label,{htmlFor:`${s}-city`,children:a("city")}),e.jsx(t.Input,{id:`${s}-city`,...c(`${s}.city`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n.Label,{htmlFor:`${s}-state`,children:a("state_province")}),e.jsx(t.Input,{id:`${s}-state`,...c(`${s}.state`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n.Label,{htmlFor:`${s}-postal_code`,children:a("postal_zip_code")}),e.jsx(t.Input,{id:`${s}-postal_code`,...c(`${s}.postal_code`)})]})]})]})}function J({initialData:s,MediaPickerComponent:h,isAdmin:c,email:a,accountLinks:v,onAction:m,initialSuccessMessage:_}){const{t:l}=R.useTranslations(),[L,S]=b.useState(!1),[$,y]=b.useState(_?{type:"success",text:_}:null),T=s?.use_billing_for_shipping??(!s?.shipping_address||f.addressesMatch(s?.billing_address,s?.shipping_address)),{register:u,handleSubmit:B,setValue:x,getValues:F,watch:g,reset:I}=V.useForm({defaultValues:{full_name:s?.full_name||"",avatar_url:s?.avatar_url||"",website:s?.website||"",phone:s?.phone||"",role:s?.role,use_billing_for_shipping:T,billing_address:C(s?.billing_address),shipping_address:C(s?.shipping_address)}});b.useEffect(()=>{s&&I({full_name:s.full_name||"",avatar_url:s.avatar_url||"",website:s.website||"",phone:s.phone||"",role:s.role,use_billing_for_shipping:s.use_billing_for_shipping??(!s.shipping_address||f.addressesMatch(s.billing_address,s.shipping_address)),billing_address:C(s.billing_address),shipping_address:C(s.shipping_address)})},[s,I]),b.useEffect(()=>{_&&y({type:"success",text:_})},[_]),b.useEffect(()=>{const r=O.createClient();(async()=>{const{data:{user:j}}=await r.auth.getUser();j&&!F("full_name")&&j.user_metadata?.full_name&&x("full_name",j.user_metadata.full_name)})()},[F,x]);const k=r=>{const p=G(r?.object_key??r?.file_path);p&&x("avatar_url",p)},P=async r=>{S(!0),y(null);const p=f.normalizeCustomerAddress(r.billing_address)??f.emptyCustomerAddress(),j=r.use_billing_for_shipping?p:f.normalizeCustomerAddress(r.shipping_address);try{const i={...r,billing_address:p,shipping_address:j};if(m){const E=await m(i);if(E?.error)throw new Error(E.error)}else await M.updateProfile(i);y({type:"success",text:l("profile_updated_success")})}catch(i){if(i.message==="NEXT_REDIRECT"||i.message?.includes("NEXT_REDIRECT"))return;console.error(i),y({type:"error",text:i.message||l("profile_update_failed")})}finally{S(!1)}},A=g("use_billing_for_shipping");return e.jsxs("div",{className:"grid gap-6 md:grid-cols-12 max-w-5xl mx-auto",children:[e.jsxs(d.Card,{className:"md:col-span-4 h-fit",children:[e.jsx(d.CardHeader,{children:e.jsx(d.CardTitle,{className:"text-xl",children:l("public_profile")})}),e.jsxs(d.CardContent,{className:"flex flex-col items-center text-center space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs(w.Avatar,{className:"h-32 w-32 border-4 border-muted",children:[e.jsx(w.AvatarImage,{src:g("avatar_url")||void 0,className:"object-cover"}),e.jsx(w.AvatarFallback,{className:"text-4xl bg-secondary",children:g("full_name")?.charAt(0)?.toUpperCase()||e.jsx(N.User,{className:"h-12 w-12"})})]}),h&&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(h,{triggerLabel:e.jsx(N.Upload,{className:"h-6 w-6 text-white"}),triggerVariant:"ghost",title:l("customer_profile"),onSelect:k,accept:r=>r.file_type.startsWith("image/"),hideTrigger:!1})})]}),!h&&e.jsxs("div",{className:"w-full",children:[e.jsx(n.Label,{htmlFor:"avatar_url",className:"sr-only",children:l("avatar_url")}),e.jsx(t.Input,{id:"avatar_url",...u("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:g("full_name")||l("full_name")})})]}),v?.length?e.jsx(X.AccountNavigationMenu,{links:v,className:"mt-2 text-left"}):null]})]}),e.jsx(d.Card,{className:"md:col-span-8",children:e.jsxs("form",{onSubmit:B(P),children:[e.jsx(d.CardHeader,{children:e.jsx(d.CardTitle,{children:l("details")})}),e.jsxs(d.CardContent,{className:"space-y-6",children:[a&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(n.Label,{htmlFor:"email",children:[l("email")||"Email"," (Read-only)"]}),e.jsx(t.Input,{id:"email",value:a,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(n.Label,{htmlFor:"full_name",className:"flex items-center gap-2",children:[e.jsx(N.User,{className:"h-4 w-4"})," ",l("full_name")]}),e.jsx(t.Input,{id:"full_name",...u("full_name")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(n.Label,{htmlFor:"phone",className:"flex items-center gap-2",children:[e.jsx(N.Phone,{className:"h-4 w-4"})," ",l("phone_number")]}),e.jsx(t.Input,{id:"phone",...u("phone")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(n.Label,{htmlFor:"website",className:"flex items-center gap-2",children:[e.jsx(N.Globe,{className:"h-4 w-4"})," ",l("website")]}),e.jsx(t.Input,{id:"website",...u("website"),placeholder:"https://example.com"})]}),e.jsx(H.Separator,{className:"my-2"}),e.jsx(U,{prefix:"billing_address",title:l("billing_address"),register:u}),e.jsxs("div",{className:"flex items-center space-x-3 rounded-lg border p-4",children:[e.jsx(W.Checkbox,{id:"use_billing_for_shipping",checked:!!A,onCheckedChange:r=>x("use_billing_for_shipping",!!r,{shouldDirty:!0})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(n.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")})]})]}),!A&&e.jsx(U,{prefix:"shipping_address",title:l("shipping_address"),register:u}),$&&e.jsx("div",{className:`mt-4 rounded-xl border p-4 text-sm ${$.type==="success"?"border-emerald-200 bg-emerald-50 text-emerald-700":"border-red-200 bg-red-50 text-red-700"}`,children:$.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(n.Label,{htmlFor:"role",children:"Role"}),e.jsxs(o.Select,{value:g("role")||"USER",onValueChange:r=>x("role",r),children:[e.jsx(o.SelectTrigger,{children:e.jsx(o.SelectValue,{placeholder:"Select role"})}),e.jsxs(o.SelectContent,{children:[e.jsx(o.SelectItem,{value:"USER",children:"User"}),e.jsx(o.SelectItem,{value:"WRITER",children:"Writer"}),e.jsx(o.SelectItem,{value:"ADMIN",children:"Admin"})]})]})]})]})]}),e.jsx(d.CardFooter,{className:"flex justify-end",children:e.jsx(z.Button,{type:"submit",disabled:L,size:"lg",children:l(L?"saving":"save_changes")})})]})})]})}exports.CustomerProfileForm=J;
|