@medusajs/draft-order 2.10.4-preview-20250930031233 → 2.10.4-preview-20250930090157
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/.medusa/server/src/admin/index.js +783 -783
- package/.medusa/server/src/admin/index.mjs +783 -783
- package/package.json +16 -16
|
@@ -9573,10 +9573,10 @@ const ID = () => {
|
|
|
9573
9573
|
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
|
|
9574
9574
|
] });
|
|
9575
9575
|
};
|
|
9576
|
-
const
|
|
9576
|
+
const BillingAddress = () => {
|
|
9577
9577
|
const { id } = reactRouterDom.useParams();
|
|
9578
9578
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
9579
|
-
fields: "+
|
|
9579
|
+
fields: "+billing_address"
|
|
9580
9580
|
});
|
|
9581
9581
|
if (isError) {
|
|
9582
9582
|
throw error;
|
|
@@ -9584,16 +9584,26 @@ const Email = () => {
|
|
|
9584
9584
|
const isReady = !isPending && !!order;
|
|
9585
9585
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9586
9586
|
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9587
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit
|
|
9588
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the
|
|
9587
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
|
|
9588
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9589
9589
|
] }),
|
|
9590
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(
|
|
9590
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
|
|
9591
9591
|
] });
|
|
9592
9592
|
};
|
|
9593
|
-
const
|
|
9593
|
+
const BillingAddressForm = ({ order }) => {
|
|
9594
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9594
9595
|
const form = reactHookForm.useForm({
|
|
9595
9596
|
defaultValues: {
|
|
9596
|
-
|
|
9597
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9598
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9599
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9600
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9601
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9602
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9603
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9604
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9605
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9606
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9597
9607
|
},
|
|
9598
9608
|
resolver: zod.zodResolver(schema$5)
|
|
9599
9609
|
});
|
|
@@ -9601,7 +9611,7 @@ const EmailForm = ({ order }) => {
|
|
|
9601
9611
|
const { handleSuccess } = useRouteModal();
|
|
9602
9612
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
9603
9613
|
await mutateAsync(
|
|
9604
|
-
{
|
|
9614
|
+
{ billing_address: data },
|
|
9605
9615
|
{
|
|
9606
9616
|
onSuccess: () => {
|
|
9607
9617
|
handleSuccess();
|
|
@@ -9618,18 +9628,132 @@ const EmailForm = ({ order }) => {
|
|
|
9618
9628
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
9619
9629
|
onSubmit,
|
|
9620
9630
|
children: [
|
|
9621
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
/* @__PURE__ */ jsxRuntime.
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9631
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
9632
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9633
|
+
Form$2.Field,
|
|
9634
|
+
{
|
|
9635
|
+
control: form.control,
|
|
9636
|
+
name: "country_code",
|
|
9637
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9638
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
|
|
9639
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
|
|
9640
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9641
|
+
] })
|
|
9642
|
+
}
|
|
9643
|
+
),
|
|
9644
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9645
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9646
|
+
Form$2.Field,
|
|
9647
|
+
{
|
|
9648
|
+
control: form.control,
|
|
9649
|
+
name: "first_name",
|
|
9650
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9651
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
|
|
9652
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9653
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9654
|
+
] })
|
|
9655
|
+
}
|
|
9656
|
+
),
|
|
9657
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9658
|
+
Form$2.Field,
|
|
9659
|
+
{
|
|
9660
|
+
control: form.control,
|
|
9661
|
+
name: "last_name",
|
|
9662
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9663
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
|
|
9664
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9665
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9666
|
+
] })
|
|
9667
|
+
}
|
|
9668
|
+
)
|
|
9669
|
+
] }),
|
|
9670
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9671
|
+
Form$2.Field,
|
|
9672
|
+
{
|
|
9673
|
+
control: form.control,
|
|
9674
|
+
name: "company",
|
|
9675
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9676
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9677
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9678
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9679
|
+
] })
|
|
9680
|
+
}
|
|
9681
|
+
),
|
|
9682
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9683
|
+
Form$2.Field,
|
|
9684
|
+
{
|
|
9685
|
+
control: form.control,
|
|
9686
|
+
name: "address_1",
|
|
9687
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9688
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
|
|
9689
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9690
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9691
|
+
] })
|
|
9692
|
+
}
|
|
9693
|
+
),
|
|
9694
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9695
|
+
Form$2.Field,
|
|
9696
|
+
{
|
|
9697
|
+
control: form.control,
|
|
9698
|
+
name: "address_2",
|
|
9699
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9700
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9701
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9702
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9703
|
+
] })
|
|
9704
|
+
}
|
|
9705
|
+
),
|
|
9706
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9707
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9708
|
+
Form$2.Field,
|
|
9709
|
+
{
|
|
9710
|
+
control: form.control,
|
|
9711
|
+
name: "postal_code",
|
|
9712
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9713
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
|
|
9714
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9715
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9716
|
+
] })
|
|
9717
|
+
}
|
|
9718
|
+
),
|
|
9719
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9720
|
+
Form$2.Field,
|
|
9721
|
+
{
|
|
9722
|
+
control: form.control,
|
|
9723
|
+
name: "city",
|
|
9724
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9725
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
|
|
9726
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9727
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9728
|
+
] })
|
|
9729
|
+
}
|
|
9730
|
+
)
|
|
9731
|
+
] }),
|
|
9732
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9733
|
+
Form$2.Field,
|
|
9734
|
+
{
|
|
9735
|
+
control: form.control,
|
|
9736
|
+
name: "province",
|
|
9737
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9738
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9739
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9740
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9741
|
+
] })
|
|
9742
|
+
}
|
|
9743
|
+
),
|
|
9744
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9745
|
+
Form$2.Field,
|
|
9746
|
+
{
|
|
9747
|
+
control: form.control,
|
|
9748
|
+
name: "phone",
|
|
9749
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9750
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9751
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9752
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9753
|
+
] })
|
|
9754
|
+
}
|
|
9755
|
+
)
|
|
9756
|
+
] }) }),
|
|
9633
9757
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9634
9758
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9635
9759
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
@@ -9638,9 +9762,7 @@ const EmailForm = ({ order }) => {
|
|
|
9638
9762
|
}
|
|
9639
9763
|
) });
|
|
9640
9764
|
};
|
|
9641
|
-
const schema$5 =
|
|
9642
|
-
email: stringType().email()
|
|
9643
|
-
});
|
|
9765
|
+
const schema$5 = addressSchema;
|
|
9644
9766
|
const CustomItems = () => {
|
|
9645
9767
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9646
9768
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
@@ -9662,6 +9784,74 @@ const CustomItemsForm = () => {
|
|
|
9662
9784
|
const schema$4 = objectType({
|
|
9663
9785
|
email: stringType().email()
|
|
9664
9786
|
});
|
|
9787
|
+
const Email = () => {
|
|
9788
|
+
const { id } = reactRouterDom.useParams();
|
|
9789
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9790
|
+
fields: "+email"
|
|
9791
|
+
});
|
|
9792
|
+
if (isError) {
|
|
9793
|
+
throw error;
|
|
9794
|
+
}
|
|
9795
|
+
const isReady = !isPending && !!order;
|
|
9796
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9797
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9798
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
9799
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9800
|
+
] }),
|
|
9801
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
9802
|
+
] });
|
|
9803
|
+
};
|
|
9804
|
+
const EmailForm = ({ order }) => {
|
|
9805
|
+
const form = reactHookForm.useForm({
|
|
9806
|
+
defaultValues: {
|
|
9807
|
+
email: order.email ?? ""
|
|
9808
|
+
},
|
|
9809
|
+
resolver: zod.zodResolver(schema$3)
|
|
9810
|
+
});
|
|
9811
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9812
|
+
const { handleSuccess } = useRouteModal();
|
|
9813
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9814
|
+
await mutateAsync(
|
|
9815
|
+
{ email: data.email },
|
|
9816
|
+
{
|
|
9817
|
+
onSuccess: () => {
|
|
9818
|
+
handleSuccess();
|
|
9819
|
+
},
|
|
9820
|
+
onError: (error) => {
|
|
9821
|
+
ui.toast.error(error.message);
|
|
9822
|
+
}
|
|
9823
|
+
}
|
|
9824
|
+
);
|
|
9825
|
+
});
|
|
9826
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9827
|
+
KeyboundForm,
|
|
9828
|
+
{
|
|
9829
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9830
|
+
onSubmit,
|
|
9831
|
+
children: [
|
|
9832
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9833
|
+
Form$2.Field,
|
|
9834
|
+
{
|
|
9835
|
+
control: form.control,
|
|
9836
|
+
name: "email",
|
|
9837
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9838
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
9839
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9840
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9841
|
+
] })
|
|
9842
|
+
}
|
|
9843
|
+
) }),
|
|
9844
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9845
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9846
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9847
|
+
] }) })
|
|
9848
|
+
]
|
|
9849
|
+
}
|
|
9850
|
+
) });
|
|
9851
|
+
};
|
|
9852
|
+
const schema$3 = objectType({
|
|
9853
|
+
email: stringType().email()
|
|
9854
|
+
});
|
|
9665
9855
|
const NumberInput = React.forwardRef(
|
|
9666
9856
|
({
|
|
9667
9857
|
value,
|
|
@@ -10636,126 +10826,403 @@ const customItemSchema = objectType({
|
|
|
10636
10826
|
quantity: numberType(),
|
|
10637
10827
|
unit_price: unionType([numberType(), stringType()])
|
|
10638
10828
|
});
|
|
10639
|
-
const
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
|
|
10651
|
-
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
|
|
10655
|
-
|
|
10656
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10657
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10658
|
-
})
|
|
10659
|
-
}
|
|
10660
|
-
),
|
|
10661
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10662
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10663
|
-
labelValue,
|
|
10664
|
-
":"
|
|
10665
|
-
] }),
|
|
10666
|
-
" ",
|
|
10667
|
-
children
|
|
10668
|
-
] })
|
|
10669
|
-
]
|
|
10670
|
-
}
|
|
10671
|
-
);
|
|
10672
|
-
}
|
|
10673
|
-
);
|
|
10674
|
-
InlineTip.displayName = "InlineTip";
|
|
10675
|
-
const MetadataFieldSchema = objectType({
|
|
10676
|
-
key: stringType(),
|
|
10677
|
-
disabled: booleanType().optional(),
|
|
10678
|
-
value: anyType()
|
|
10679
|
-
});
|
|
10680
|
-
const MetadataSchema = objectType({
|
|
10681
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10682
|
-
});
|
|
10683
|
-
const Metadata = () => {
|
|
10684
|
-
const { id } = reactRouterDom.useParams();
|
|
10685
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10686
|
-
fields: "metadata"
|
|
10829
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10830
|
+
const promotionsQueryKeys = {
|
|
10831
|
+
list: (query2) => [
|
|
10832
|
+
PROMOTION_QUERY_KEY,
|
|
10833
|
+
query2 ? query2 : void 0
|
|
10834
|
+
],
|
|
10835
|
+
detail: (id, query2) => [
|
|
10836
|
+
PROMOTION_QUERY_KEY,
|
|
10837
|
+
id,
|
|
10838
|
+
query2 ? query2 : void 0
|
|
10839
|
+
]
|
|
10840
|
+
};
|
|
10841
|
+
const usePromotions = (query2, options) => {
|
|
10842
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
10843
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10844
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10845
|
+
...options
|
|
10687
10846
|
});
|
|
10688
|
-
|
|
10689
|
-
|
|
10847
|
+
return { ...data, ...rest };
|
|
10848
|
+
};
|
|
10849
|
+
const Promotions = () => {
|
|
10850
|
+
const { id } = reactRouterDom.useParams();
|
|
10851
|
+
const {
|
|
10852
|
+
order: preview,
|
|
10853
|
+
isError: isPreviewError,
|
|
10854
|
+
error: previewError
|
|
10855
|
+
} = useOrderPreview(id, void 0);
|
|
10856
|
+
useInitiateOrderEdit({ preview });
|
|
10857
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10858
|
+
if (isPreviewError) {
|
|
10859
|
+
throw previewError;
|
|
10690
10860
|
}
|
|
10691
|
-
const isReady =
|
|
10692
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10693
|
-
/* @__PURE__ */ jsxRuntime.
|
|
10694
|
-
|
|
10695
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10696
|
-
] }),
|
|
10697
|
-
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10861
|
+
const isReady = !!preview;
|
|
10862
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10863
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
10864
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
10698
10865
|
] });
|
|
10699
10866
|
};
|
|
10700
|
-
const
|
|
10701
|
-
const
|
|
10702
|
-
const
|
|
10867
|
+
const PromotionForm = ({ preview }) => {
|
|
10868
|
+
const { items, shipping_methods } = preview;
|
|
10869
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
10870
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
10703
10871
|
const { handleSuccess } = useRouteModal();
|
|
10704
|
-
const
|
|
10705
|
-
const
|
|
10706
|
-
const
|
|
10707
|
-
|
|
10708
|
-
|
|
10872
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10873
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10874
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
10875
|
+
{
|
|
10876
|
+
id: promoIds
|
|
10709
10877
|
},
|
|
10710
|
-
|
|
10878
|
+
{
|
|
10879
|
+
enabled: !!promoIds.length
|
|
10880
|
+
}
|
|
10881
|
+
);
|
|
10882
|
+
const comboboxData = useComboboxData({
|
|
10883
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
10884
|
+
queryFn: async (params) => {
|
|
10885
|
+
return await sdk.admin.promotion.list({
|
|
10886
|
+
...params,
|
|
10887
|
+
id: {
|
|
10888
|
+
$nin: promoIds
|
|
10889
|
+
}
|
|
10890
|
+
});
|
|
10891
|
+
},
|
|
10892
|
+
getOptions: (data) => {
|
|
10893
|
+
return data.promotions.map((promotion) => ({
|
|
10894
|
+
label: promotion.code,
|
|
10895
|
+
value: promotion.code
|
|
10896
|
+
}));
|
|
10897
|
+
}
|
|
10711
10898
|
});
|
|
10712
|
-
const
|
|
10713
|
-
|
|
10714
|
-
|
|
10899
|
+
const add = async (value) => {
|
|
10900
|
+
if (!value) {
|
|
10901
|
+
return;
|
|
10902
|
+
}
|
|
10903
|
+
addPromotions(
|
|
10715
10904
|
{
|
|
10716
|
-
|
|
10905
|
+
promo_codes: [value]
|
|
10717
10906
|
},
|
|
10718
10907
|
{
|
|
10719
|
-
|
|
10720
|
-
ui.toast.
|
|
10721
|
-
|
|
10908
|
+
onError: (e) => {
|
|
10909
|
+
ui.toast.error(e.message);
|
|
10910
|
+
comboboxData.onSearchValueChange("");
|
|
10911
|
+
setComboboxValue("");
|
|
10722
10912
|
},
|
|
10723
|
-
|
|
10724
|
-
|
|
10913
|
+
onSuccess: () => {
|
|
10914
|
+
comboboxData.onSearchValueChange("");
|
|
10915
|
+
setComboboxValue("");
|
|
10725
10916
|
}
|
|
10726
10917
|
}
|
|
10727
10918
|
);
|
|
10728
|
-
}
|
|
10729
|
-
const {
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
|
|
10740
|
-
}
|
|
10919
|
+
};
|
|
10920
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10921
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10922
|
+
const onSubmit = async () => {
|
|
10923
|
+
setIsSubmitting(true);
|
|
10924
|
+
let requestSucceeded = false;
|
|
10925
|
+
await requestOrderEdit(void 0, {
|
|
10926
|
+
onError: (e) => {
|
|
10927
|
+
ui.toast.error(e.message);
|
|
10928
|
+
},
|
|
10929
|
+
onSuccess: () => {
|
|
10930
|
+
requestSucceeded = true;
|
|
10931
|
+
}
|
|
10932
|
+
});
|
|
10933
|
+
if (!requestSucceeded) {
|
|
10934
|
+
setIsSubmitting(false);
|
|
10935
|
+
return;
|
|
10741
10936
|
}
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10937
|
+
await confirmOrderEdit(void 0, {
|
|
10938
|
+
onError: (e) => {
|
|
10939
|
+
ui.toast.error(e.message);
|
|
10940
|
+
},
|
|
10941
|
+
onSuccess: () => {
|
|
10942
|
+
handleSuccess();
|
|
10943
|
+
},
|
|
10944
|
+
onSettled: () => {
|
|
10945
|
+
setIsSubmitting(false);
|
|
10946
|
+
}
|
|
10748
10947
|
});
|
|
10948
|
+
};
|
|
10949
|
+
if (isError) {
|
|
10950
|
+
throw error;
|
|
10749
10951
|
}
|
|
10750
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
10751
|
-
|
|
10952
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10953
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10954
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10955
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
10956
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10957
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10958
|
+
] }),
|
|
10959
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10960
|
+
Combobox,
|
|
10961
|
+
{
|
|
10962
|
+
id: "promotion-combobox",
|
|
10963
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
10964
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10965
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
10966
|
+
options: comboboxData.options,
|
|
10967
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10968
|
+
searchValue: comboboxData.searchValue,
|
|
10969
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10970
|
+
onChange: add,
|
|
10971
|
+
value: comboboxValue
|
|
10972
|
+
}
|
|
10973
|
+
)
|
|
10974
|
+
] }),
|
|
10975
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10976
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
10977
|
+
PromotionItem,
|
|
10978
|
+
{
|
|
10979
|
+
promotion,
|
|
10980
|
+
orderId: preview.id,
|
|
10981
|
+
isLoading: isPending
|
|
10982
|
+
},
|
|
10983
|
+
promotion.id
|
|
10984
|
+
)) })
|
|
10985
|
+
] }) }),
|
|
10986
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10987
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10988
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10989
|
+
ui.Button,
|
|
10990
|
+
{
|
|
10991
|
+
size: "small",
|
|
10992
|
+
type: "submit",
|
|
10993
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
10994
|
+
children: "Save"
|
|
10995
|
+
}
|
|
10996
|
+
)
|
|
10997
|
+
] }) })
|
|
10998
|
+
] });
|
|
10999
|
+
};
|
|
11000
|
+
const PromotionItem = ({
|
|
11001
|
+
promotion,
|
|
11002
|
+
orderId,
|
|
11003
|
+
isLoading
|
|
11004
|
+
}) => {
|
|
11005
|
+
var _a;
|
|
11006
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11007
|
+
const onRemove = async () => {
|
|
11008
|
+
removePromotions(
|
|
11009
|
+
{
|
|
11010
|
+
promo_codes: [promotion.code]
|
|
11011
|
+
},
|
|
11012
|
+
{
|
|
11013
|
+
onError: (e) => {
|
|
11014
|
+
ui.toast.error(e.message);
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
);
|
|
11018
|
+
};
|
|
11019
|
+
const displayValue = getDisplayValue(promotion);
|
|
11020
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11021
|
+
"div",
|
|
10752
11022
|
{
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
11023
|
+
className: ui.clx(
|
|
11024
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11025
|
+
{
|
|
11026
|
+
"animate-pulse": isLoading
|
|
11027
|
+
}
|
|
11028
|
+
),
|
|
11029
|
+
children: [
|
|
11030
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11031
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11032
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11033
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11034
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11035
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11036
|
+
] }),
|
|
11037
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11038
|
+
] })
|
|
11039
|
+
] }),
|
|
11040
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11041
|
+
ui.IconButton,
|
|
11042
|
+
{
|
|
11043
|
+
size: "small",
|
|
11044
|
+
type: "button",
|
|
11045
|
+
variant: "transparent",
|
|
11046
|
+
onClick: onRemove,
|
|
11047
|
+
isLoading: isPending || isLoading,
|
|
11048
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11049
|
+
}
|
|
11050
|
+
)
|
|
11051
|
+
]
|
|
11052
|
+
},
|
|
11053
|
+
promotion.id
|
|
11054
|
+
);
|
|
11055
|
+
};
|
|
11056
|
+
function getDisplayValue(promotion) {
|
|
11057
|
+
var _a, _b, _c, _d;
|
|
11058
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11059
|
+
if (!value) {
|
|
11060
|
+
return null;
|
|
11061
|
+
}
|
|
11062
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11063
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11064
|
+
if (!currency) {
|
|
11065
|
+
return null;
|
|
11066
|
+
}
|
|
11067
|
+
return getLocaleAmount(value, currency);
|
|
11068
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11069
|
+
return formatPercentage(value);
|
|
11070
|
+
}
|
|
11071
|
+
return null;
|
|
11072
|
+
}
|
|
11073
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11074
|
+
style: "percent",
|
|
11075
|
+
minimumFractionDigits: 2
|
|
11076
|
+
});
|
|
11077
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11078
|
+
let val = value || 0;
|
|
11079
|
+
if (!isPercentageValue) {
|
|
11080
|
+
val = val / 100;
|
|
11081
|
+
}
|
|
11082
|
+
return formatter.format(val);
|
|
11083
|
+
};
|
|
11084
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11085
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11086
|
+
for (const item of items) {
|
|
11087
|
+
if (item.adjustments) {
|
|
11088
|
+
for (const adjustment of item.adjustments) {
|
|
11089
|
+
if (adjustment.promotion_id) {
|
|
11090
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11091
|
+
}
|
|
11092
|
+
}
|
|
11093
|
+
}
|
|
11094
|
+
}
|
|
11095
|
+
for (const shippingMethod of shippingMethods) {
|
|
11096
|
+
if (shippingMethod.adjustments) {
|
|
11097
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11098
|
+
if (adjustment.promotion_id) {
|
|
11099
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11100
|
+
}
|
|
11101
|
+
}
|
|
11102
|
+
}
|
|
11103
|
+
}
|
|
11104
|
+
return Array.from(promotionIds);
|
|
11105
|
+
}
|
|
11106
|
+
const InlineTip = React.forwardRef(
|
|
11107
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11108
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11109
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11110
|
+
"div",
|
|
11111
|
+
{
|
|
11112
|
+
ref,
|
|
11113
|
+
className: ui.clx(
|
|
11114
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11115
|
+
className
|
|
11116
|
+
),
|
|
11117
|
+
...props,
|
|
11118
|
+
children: [
|
|
11119
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11120
|
+
"div",
|
|
11121
|
+
{
|
|
11122
|
+
role: "presentation",
|
|
11123
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11124
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11125
|
+
})
|
|
11126
|
+
}
|
|
11127
|
+
),
|
|
11128
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
11129
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11130
|
+
labelValue,
|
|
11131
|
+
":"
|
|
11132
|
+
] }),
|
|
11133
|
+
" ",
|
|
11134
|
+
children
|
|
11135
|
+
] })
|
|
11136
|
+
]
|
|
11137
|
+
}
|
|
11138
|
+
);
|
|
11139
|
+
}
|
|
11140
|
+
);
|
|
11141
|
+
InlineTip.displayName = "InlineTip";
|
|
11142
|
+
const MetadataFieldSchema = objectType({
|
|
11143
|
+
key: stringType(),
|
|
11144
|
+
disabled: booleanType().optional(),
|
|
11145
|
+
value: anyType()
|
|
11146
|
+
});
|
|
11147
|
+
const MetadataSchema = objectType({
|
|
11148
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
11149
|
+
});
|
|
11150
|
+
const Metadata = () => {
|
|
11151
|
+
const { id } = reactRouterDom.useParams();
|
|
11152
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11153
|
+
fields: "metadata"
|
|
11154
|
+
});
|
|
11155
|
+
if (isError) {
|
|
11156
|
+
throw error;
|
|
11157
|
+
}
|
|
11158
|
+
const isReady = !isPending && !!order;
|
|
11159
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11160
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11161
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
11162
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
11163
|
+
] }),
|
|
11164
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11165
|
+
] });
|
|
11166
|
+
};
|
|
11167
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
11168
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11169
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
11170
|
+
const { handleSuccess } = useRouteModal();
|
|
11171
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11172
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11173
|
+
const form = reactHookForm.useForm({
|
|
11174
|
+
defaultValues: {
|
|
11175
|
+
metadata: getDefaultValues(metadata)
|
|
11176
|
+
},
|
|
11177
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
11178
|
+
});
|
|
11179
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11180
|
+
const parsedData = parseValues(data);
|
|
11181
|
+
await mutateAsync(
|
|
11182
|
+
{
|
|
11183
|
+
metadata: parsedData
|
|
11184
|
+
},
|
|
11185
|
+
{
|
|
11186
|
+
onSuccess: () => {
|
|
11187
|
+
ui.toast.success("Metadata updated");
|
|
11188
|
+
handleSuccess();
|
|
11189
|
+
},
|
|
11190
|
+
onError: (error) => {
|
|
11191
|
+
ui.toast.error(error.message);
|
|
11192
|
+
}
|
|
11193
|
+
}
|
|
11194
|
+
);
|
|
11195
|
+
});
|
|
11196
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
11197
|
+
control: form.control,
|
|
11198
|
+
name: "metadata"
|
|
11199
|
+
});
|
|
11200
|
+
function deleteRow(index) {
|
|
11201
|
+
remove(index);
|
|
11202
|
+
if (fields.length === 1) {
|
|
11203
|
+
insert(0, {
|
|
11204
|
+
key: "",
|
|
11205
|
+
value: "",
|
|
11206
|
+
disabled: false
|
|
11207
|
+
});
|
|
11208
|
+
}
|
|
11209
|
+
}
|
|
11210
|
+
function insertRow(index, position) {
|
|
11211
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
11212
|
+
key: "",
|
|
11213
|
+
value: "",
|
|
11214
|
+
disabled: false
|
|
11215
|
+
});
|
|
11216
|
+
}
|
|
11217
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11218
|
+
KeyboundForm,
|
|
11219
|
+
{
|
|
11220
|
+
onSubmit: handleSubmit,
|
|
11221
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11222
|
+
children: [
|
|
11223
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
11224
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
11225
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10759
11226
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
10760
11227
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
10761
11228
|
] }),
|
|
@@ -10873,395 +11340,118 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
10873
11340
|
)
|
|
10874
11341
|
] })
|
|
10875
11342
|
] })
|
|
10876
|
-
] })
|
|
10877
|
-
},
|
|
10878
|
-
field.id
|
|
10879
|
-
);
|
|
10880
|
-
})
|
|
10881
|
-
] }),
|
|
10882
|
-
hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
10883
|
-
] }),
|
|
10884
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10885
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10886
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10887
|
-
] }) })
|
|
10888
|
-
]
|
|
10889
|
-
}
|
|
10890
|
-
) });
|
|
10891
|
-
};
|
|
10892
|
-
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
10893
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10894
|
-
"input",
|
|
10895
|
-
{
|
|
10896
|
-
ref,
|
|
10897
|
-
...props,
|
|
10898
|
-
autoComplete: "off",
|
|
10899
|
-
className: ui.clx(
|
|
10900
|
-
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
10901
|
-
className
|
|
10902
|
-
)
|
|
10903
|
-
}
|
|
10904
|
-
);
|
|
10905
|
-
});
|
|
10906
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
10907
|
-
const PlaceholderInner = () => {
|
|
10908
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10909
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
10910
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10911
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
10912
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10913
|
-
] }) })
|
|
10914
|
-
] });
|
|
10915
|
-
};
|
|
10916
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
10917
|
-
function getDefaultValues(metadata) {
|
|
10918
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
10919
|
-
return [
|
|
10920
|
-
{
|
|
10921
|
-
key: "",
|
|
10922
|
-
value: "",
|
|
10923
|
-
disabled: false
|
|
10924
|
-
}
|
|
10925
|
-
];
|
|
10926
|
-
}
|
|
10927
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
10928
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
10929
|
-
return {
|
|
10930
|
-
key,
|
|
10931
|
-
value,
|
|
10932
|
-
disabled: true
|
|
10933
|
-
};
|
|
10934
|
-
}
|
|
10935
|
-
let stringValue = value;
|
|
10936
|
-
if (typeof value !== "string") {
|
|
10937
|
-
stringValue = JSON.stringify(value);
|
|
10938
|
-
}
|
|
10939
|
-
return {
|
|
10940
|
-
key,
|
|
10941
|
-
value: stringValue,
|
|
10942
|
-
original_key: key
|
|
10943
|
-
};
|
|
10944
|
-
});
|
|
10945
|
-
}
|
|
10946
|
-
function parseValues(values) {
|
|
10947
|
-
const metadata = values.metadata;
|
|
10948
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
10949
|
-
if (isEmpty) {
|
|
10950
|
-
return null;
|
|
10951
|
-
}
|
|
10952
|
-
const update = {};
|
|
10953
|
-
metadata.forEach((field) => {
|
|
10954
|
-
let key = field.key;
|
|
10955
|
-
let value = field.value;
|
|
10956
|
-
const disabled = field.disabled;
|
|
10957
|
-
if (!key || !value) {
|
|
10958
|
-
return;
|
|
10959
|
-
}
|
|
10960
|
-
if (disabled) {
|
|
10961
|
-
update[key] = value;
|
|
10962
|
-
return;
|
|
10963
|
-
}
|
|
10964
|
-
key = key.trim();
|
|
10965
|
-
value = value.trim();
|
|
10966
|
-
if (value === "true") {
|
|
10967
|
-
update[key] = true;
|
|
10968
|
-
} else if (value === "false") {
|
|
10969
|
-
update[key] = false;
|
|
10970
|
-
} else {
|
|
10971
|
-
const parsedNumber = parseFloat(value);
|
|
10972
|
-
if (!isNaN(parsedNumber)) {
|
|
10973
|
-
update[key] = parsedNumber;
|
|
10974
|
-
} else {
|
|
10975
|
-
update[key] = value;
|
|
10976
|
-
}
|
|
10977
|
-
}
|
|
10978
|
-
});
|
|
10979
|
-
return update;
|
|
10980
|
-
}
|
|
10981
|
-
function getHasUneditableRows(metadata) {
|
|
10982
|
-
if (!metadata) {
|
|
10983
|
-
return false;
|
|
10984
|
-
}
|
|
10985
|
-
return Object.values(metadata).some(
|
|
10986
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10987
|
-
);
|
|
10988
|
-
}
|
|
10989
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
10990
|
-
const promotionsQueryKeys = {
|
|
10991
|
-
list: (query2) => [
|
|
10992
|
-
PROMOTION_QUERY_KEY,
|
|
10993
|
-
query2 ? query2 : void 0
|
|
10994
|
-
],
|
|
10995
|
-
detail: (id, query2) => [
|
|
10996
|
-
PROMOTION_QUERY_KEY,
|
|
10997
|
-
id,
|
|
10998
|
-
query2 ? query2 : void 0
|
|
10999
|
-
]
|
|
11000
|
-
};
|
|
11001
|
-
const usePromotions = (query2, options) => {
|
|
11002
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
11003
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
11004
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11005
|
-
...options
|
|
11006
|
-
});
|
|
11007
|
-
return { ...data, ...rest };
|
|
11008
|
-
};
|
|
11009
|
-
const Promotions = () => {
|
|
11010
|
-
const { id } = reactRouterDom.useParams();
|
|
11011
|
-
const {
|
|
11012
|
-
order: preview,
|
|
11013
|
-
isError: isPreviewError,
|
|
11014
|
-
error: previewError
|
|
11015
|
-
} = useOrderPreview(id, void 0);
|
|
11016
|
-
useInitiateOrderEdit({ preview });
|
|
11017
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11018
|
-
if (isPreviewError) {
|
|
11019
|
-
throw previewError;
|
|
11020
|
-
}
|
|
11021
|
-
const isReady = !!preview;
|
|
11022
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11023
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11024
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11025
|
-
] });
|
|
11026
|
-
};
|
|
11027
|
-
const PromotionForm = ({ preview }) => {
|
|
11028
|
-
const { items, shipping_methods } = preview;
|
|
11029
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11030
|
-
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11031
|
-
const { handleSuccess } = useRouteModal();
|
|
11032
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11033
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11034
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
11035
|
-
{
|
|
11036
|
-
id: promoIds
|
|
11037
|
-
},
|
|
11038
|
-
{
|
|
11039
|
-
enabled: !!promoIds.length
|
|
11040
|
-
}
|
|
11041
|
-
);
|
|
11042
|
-
const comboboxData = useComboboxData({
|
|
11043
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
11044
|
-
queryFn: async (params) => {
|
|
11045
|
-
return await sdk.admin.promotion.list({
|
|
11046
|
-
...params,
|
|
11047
|
-
id: {
|
|
11048
|
-
$nin: promoIds
|
|
11049
|
-
}
|
|
11050
|
-
});
|
|
11051
|
-
},
|
|
11052
|
-
getOptions: (data) => {
|
|
11053
|
-
return data.promotions.map((promotion) => ({
|
|
11054
|
-
label: promotion.code,
|
|
11055
|
-
value: promotion.code
|
|
11056
|
-
}));
|
|
11057
|
-
}
|
|
11058
|
-
});
|
|
11059
|
-
const add = async (value) => {
|
|
11060
|
-
if (!value) {
|
|
11061
|
-
return;
|
|
11062
|
-
}
|
|
11063
|
-
addPromotions(
|
|
11064
|
-
{
|
|
11065
|
-
promo_codes: [value]
|
|
11066
|
-
},
|
|
11067
|
-
{
|
|
11068
|
-
onError: (e) => {
|
|
11069
|
-
ui.toast.error(e.message);
|
|
11070
|
-
comboboxData.onSearchValueChange("");
|
|
11071
|
-
setComboboxValue("");
|
|
11072
|
-
},
|
|
11073
|
-
onSuccess: () => {
|
|
11074
|
-
comboboxData.onSearchValueChange("");
|
|
11075
|
-
setComboboxValue("");
|
|
11076
|
-
}
|
|
11077
|
-
}
|
|
11078
|
-
);
|
|
11079
|
-
};
|
|
11080
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11081
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11082
|
-
const onSubmit = async () => {
|
|
11083
|
-
setIsSubmitting(true);
|
|
11084
|
-
let requestSucceeded = false;
|
|
11085
|
-
await requestOrderEdit(void 0, {
|
|
11086
|
-
onError: (e) => {
|
|
11087
|
-
ui.toast.error(e.message);
|
|
11088
|
-
},
|
|
11089
|
-
onSuccess: () => {
|
|
11090
|
-
requestSucceeded = true;
|
|
11091
|
-
}
|
|
11092
|
-
});
|
|
11093
|
-
if (!requestSucceeded) {
|
|
11094
|
-
setIsSubmitting(false);
|
|
11095
|
-
return;
|
|
11096
|
-
}
|
|
11097
|
-
await confirmOrderEdit(void 0, {
|
|
11098
|
-
onError: (e) => {
|
|
11099
|
-
ui.toast.error(e.message);
|
|
11100
|
-
},
|
|
11101
|
-
onSuccess: () => {
|
|
11102
|
-
handleSuccess();
|
|
11103
|
-
},
|
|
11104
|
-
onSettled: () => {
|
|
11105
|
-
setIsSubmitting(false);
|
|
11106
|
-
}
|
|
11107
|
-
});
|
|
11108
|
-
};
|
|
11109
|
-
if (isError) {
|
|
11110
|
-
throw error;
|
|
11111
|
-
}
|
|
11112
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11113
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11114
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11115
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11116
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11117
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11118
|
-
] }),
|
|
11119
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11120
|
-
Combobox,
|
|
11121
|
-
{
|
|
11122
|
-
id: "promotion-combobox",
|
|
11123
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11124
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11125
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11126
|
-
options: comboboxData.options,
|
|
11127
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11128
|
-
searchValue: comboboxData.searchValue,
|
|
11129
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11130
|
-
onChange: add,
|
|
11131
|
-
value: comboboxValue
|
|
11132
|
-
}
|
|
11133
|
-
)
|
|
11134
|
-
] }),
|
|
11135
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11136
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11137
|
-
PromotionItem,
|
|
11138
|
-
{
|
|
11139
|
-
promotion,
|
|
11140
|
-
orderId: preview.id,
|
|
11141
|
-
isLoading: isPending
|
|
11142
|
-
},
|
|
11143
|
-
promotion.id
|
|
11144
|
-
)) })
|
|
11145
|
-
] }) }),
|
|
11146
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11147
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11148
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11149
|
-
ui.Button,
|
|
11150
|
-
{
|
|
11151
|
-
size: "small",
|
|
11152
|
-
type: "submit",
|
|
11153
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11154
|
-
children: "Save"
|
|
11155
|
-
}
|
|
11156
|
-
)
|
|
11157
|
-
] }) })
|
|
11158
|
-
] });
|
|
11159
|
-
};
|
|
11160
|
-
const PromotionItem = ({
|
|
11161
|
-
promotion,
|
|
11162
|
-
orderId,
|
|
11163
|
-
isLoading
|
|
11164
|
-
}) => {
|
|
11165
|
-
var _a;
|
|
11166
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11167
|
-
const onRemove = async () => {
|
|
11168
|
-
removePromotions(
|
|
11169
|
-
{
|
|
11170
|
-
promo_codes: [promotion.code]
|
|
11171
|
-
},
|
|
11172
|
-
{
|
|
11173
|
-
onError: (e) => {
|
|
11174
|
-
ui.toast.error(e.message);
|
|
11175
|
-
}
|
|
11176
|
-
}
|
|
11177
|
-
);
|
|
11178
|
-
};
|
|
11179
|
-
const displayValue = getDisplayValue(promotion);
|
|
11180
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11181
|
-
"div",
|
|
11182
|
-
{
|
|
11183
|
-
className: ui.clx(
|
|
11184
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11185
|
-
{
|
|
11186
|
-
"animate-pulse": isLoading
|
|
11187
|
-
}
|
|
11188
|
-
),
|
|
11189
|
-
children: [
|
|
11190
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11191
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11192
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11193
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11194
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11195
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11196
|
-
] }),
|
|
11197
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11198
|
-
] })
|
|
11199
|
-
] }),
|
|
11200
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11201
|
-
ui.IconButton,
|
|
11202
|
-
{
|
|
11203
|
-
size: "small",
|
|
11204
|
-
type: "button",
|
|
11205
|
-
variant: "transparent",
|
|
11206
|
-
onClick: onRemove,
|
|
11207
|
-
isLoading: isPending || isLoading,
|
|
11208
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11209
|
-
}
|
|
11210
|
-
)
|
|
11343
|
+
] })
|
|
11344
|
+
},
|
|
11345
|
+
field.id
|
|
11346
|
+
);
|
|
11347
|
+
})
|
|
11348
|
+
] }),
|
|
11349
|
+
hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
11350
|
+
] }),
|
|
11351
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11352
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11353
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11354
|
+
] }) })
|
|
11211
11355
|
]
|
|
11212
|
-
}
|
|
11213
|
-
|
|
11214
|
-
);
|
|
11356
|
+
}
|
|
11357
|
+
) });
|
|
11215
11358
|
};
|
|
11216
|
-
|
|
11217
|
-
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11359
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
11360
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11361
|
+
"input",
|
|
11362
|
+
{
|
|
11363
|
+
ref,
|
|
11364
|
+
...props,
|
|
11365
|
+
autoComplete: "off",
|
|
11366
|
+
className: ui.clx(
|
|
11367
|
+
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
11368
|
+
className
|
|
11369
|
+
)
|
|
11226
11370
|
}
|
|
11227
|
-
|
|
11228
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11229
|
-
return formatPercentage(value);
|
|
11230
|
-
}
|
|
11231
|
-
return null;
|
|
11232
|
-
}
|
|
11233
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11234
|
-
style: "percent",
|
|
11235
|
-
minimumFractionDigits: 2
|
|
11371
|
+
);
|
|
11236
11372
|
});
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11373
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11374
|
+
const PlaceholderInner = () => {
|
|
11375
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11376
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11377
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11378
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11379
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11380
|
+
] }) })
|
|
11381
|
+
] });
|
|
11243
11382
|
};
|
|
11244
|
-
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11383
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11384
|
+
function getDefaultValues(metadata) {
|
|
11385
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11386
|
+
return [
|
|
11387
|
+
{
|
|
11388
|
+
key: "",
|
|
11389
|
+
value: "",
|
|
11390
|
+
disabled: false
|
|
11252
11391
|
}
|
|
11392
|
+
];
|
|
11393
|
+
}
|
|
11394
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11395
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11396
|
+
return {
|
|
11397
|
+
key,
|
|
11398
|
+
value,
|
|
11399
|
+
disabled: true
|
|
11400
|
+
};
|
|
11253
11401
|
}
|
|
11402
|
+
let stringValue = value;
|
|
11403
|
+
if (typeof value !== "string") {
|
|
11404
|
+
stringValue = JSON.stringify(value);
|
|
11405
|
+
}
|
|
11406
|
+
return {
|
|
11407
|
+
key,
|
|
11408
|
+
value: stringValue,
|
|
11409
|
+
original_key: key
|
|
11410
|
+
};
|
|
11411
|
+
});
|
|
11412
|
+
}
|
|
11413
|
+
function parseValues(values) {
|
|
11414
|
+
const metadata = values.metadata;
|
|
11415
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11416
|
+
if (isEmpty) {
|
|
11417
|
+
return null;
|
|
11254
11418
|
}
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
|
|
11419
|
+
const update = {};
|
|
11420
|
+
metadata.forEach((field) => {
|
|
11421
|
+
let key = field.key;
|
|
11422
|
+
let value = field.value;
|
|
11423
|
+
const disabled = field.disabled;
|
|
11424
|
+
if (!key || !value) {
|
|
11425
|
+
return;
|
|
11426
|
+
}
|
|
11427
|
+
if (disabled) {
|
|
11428
|
+
update[key] = value;
|
|
11429
|
+
return;
|
|
11430
|
+
}
|
|
11431
|
+
key = key.trim();
|
|
11432
|
+
value = value.trim();
|
|
11433
|
+
if (value === "true") {
|
|
11434
|
+
update[key] = true;
|
|
11435
|
+
} else if (value === "false") {
|
|
11436
|
+
update[key] = false;
|
|
11437
|
+
} else {
|
|
11438
|
+
const parsedNumber = parseFloat(value);
|
|
11439
|
+
if (!isNaN(parsedNumber)) {
|
|
11440
|
+
update[key] = parsedNumber;
|
|
11441
|
+
} else {
|
|
11442
|
+
update[key] = value;
|
|
11261
11443
|
}
|
|
11262
11444
|
}
|
|
11445
|
+
});
|
|
11446
|
+
return update;
|
|
11447
|
+
}
|
|
11448
|
+
function getHasUneditableRows(metadata) {
|
|
11449
|
+
if (!metadata) {
|
|
11450
|
+
return false;
|
|
11263
11451
|
}
|
|
11264
|
-
return
|
|
11452
|
+
return Object.values(metadata).some(
|
|
11453
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11454
|
+
);
|
|
11265
11455
|
}
|
|
11266
11456
|
const SalesChannel = () => {
|
|
11267
11457
|
const { id } = reactRouterDom.useParams();
|
|
@@ -11288,118 +11478,8 @@ const SalesChannel = () => {
|
|
|
11288
11478
|
};
|
|
11289
11479
|
const SalesChannelForm = ({ order }) => {
|
|
11290
11480
|
const form = reactHookForm.useForm({
|
|
11291
|
-
defaultValues: {
|
|
11292
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11293
|
-
},
|
|
11294
|
-
resolver: zod.zodResolver(schema$3)
|
|
11295
|
-
});
|
|
11296
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11297
|
-
const { handleSuccess } = useRouteModal();
|
|
11298
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11299
|
-
await mutateAsync(
|
|
11300
|
-
{
|
|
11301
|
-
sales_channel_id: data.sales_channel_id
|
|
11302
|
-
},
|
|
11303
|
-
{
|
|
11304
|
-
onSuccess: () => {
|
|
11305
|
-
ui.toast.success("Sales channel updated");
|
|
11306
|
-
handleSuccess();
|
|
11307
|
-
},
|
|
11308
|
-
onError: (error) => {
|
|
11309
|
-
ui.toast.error(error.message);
|
|
11310
|
-
}
|
|
11311
|
-
}
|
|
11312
|
-
);
|
|
11313
|
-
});
|
|
11314
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11315
|
-
KeyboundForm,
|
|
11316
|
-
{
|
|
11317
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11318
|
-
onSubmit,
|
|
11319
|
-
children: [
|
|
11320
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11321
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11322
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11323
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11324
|
-
] }) })
|
|
11325
|
-
]
|
|
11326
|
-
}
|
|
11327
|
-
) });
|
|
11328
|
-
};
|
|
11329
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11330
|
-
const salesChannels = useComboboxData({
|
|
11331
|
-
queryFn: async (params) => {
|
|
11332
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11333
|
-
},
|
|
11334
|
-
queryKey: ["sales-channels"],
|
|
11335
|
-
getOptions: (data) => {
|
|
11336
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11337
|
-
label: salesChannel.name,
|
|
11338
|
-
value: salesChannel.id
|
|
11339
|
-
}));
|
|
11340
|
-
},
|
|
11341
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11342
|
-
});
|
|
11343
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11344
|
-
Form$2.Field,
|
|
11345
|
-
{
|
|
11346
|
-
control,
|
|
11347
|
-
name: "sales_channel_id",
|
|
11348
|
-
render: ({ field }) => {
|
|
11349
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11350
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11351
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11352
|
-
Combobox,
|
|
11353
|
-
{
|
|
11354
|
-
options: salesChannels.options,
|
|
11355
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11356
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11357
|
-
searchValue: salesChannels.searchValue,
|
|
11358
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11359
|
-
placeholder: "Select sales channel",
|
|
11360
|
-
...field
|
|
11361
|
-
}
|
|
11362
|
-
) }),
|
|
11363
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11364
|
-
] });
|
|
11365
|
-
}
|
|
11366
|
-
}
|
|
11367
|
-
);
|
|
11368
|
-
};
|
|
11369
|
-
const schema$3 = objectType({
|
|
11370
|
-
sales_channel_id: stringType().min(1)
|
|
11371
|
-
});
|
|
11372
|
-
const ShippingAddress = () => {
|
|
11373
|
-
const { id } = reactRouterDom.useParams();
|
|
11374
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11375
|
-
fields: "+shipping_address"
|
|
11376
|
-
});
|
|
11377
|
-
if (isError) {
|
|
11378
|
-
throw error;
|
|
11379
|
-
}
|
|
11380
|
-
const isReady = !isPending && !!order;
|
|
11381
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11382
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11383
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
|
|
11384
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
11385
|
-
] }),
|
|
11386
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
|
|
11387
|
-
] });
|
|
11388
|
-
};
|
|
11389
|
-
const ShippingAddressForm = ({ order }) => {
|
|
11390
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
11391
|
-
const form = reactHookForm.useForm({
|
|
11392
|
-
defaultValues: {
|
|
11393
|
-
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
11394
|
-
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
11395
|
-
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
11396
|
-
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
11397
|
-
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
11398
|
-
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
11399
|
-
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
11400
|
-
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
11401
|
-
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11402
|
-
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
11481
|
+
defaultValues: {
|
|
11482
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11403
11483
|
},
|
|
11404
11484
|
resolver: zod.zodResolver(schema$2)
|
|
11405
11485
|
});
|
|
@@ -11408,21 +11488,11 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11408
11488
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
11409
11489
|
await mutateAsync(
|
|
11410
11490
|
{
|
|
11411
|
-
|
|
11412
|
-
first_name: data.first_name,
|
|
11413
|
-
last_name: data.last_name,
|
|
11414
|
-
company: data.company,
|
|
11415
|
-
address_1: data.address_1,
|
|
11416
|
-
address_2: data.address_2,
|
|
11417
|
-
city: data.city,
|
|
11418
|
-
province: data.province,
|
|
11419
|
-
country_code: data.country_code,
|
|
11420
|
-
postal_code: data.postal_code,
|
|
11421
|
-
phone: data.phone
|
|
11422
|
-
}
|
|
11491
|
+
sales_channel_id: data.sales_channel_id
|
|
11423
11492
|
},
|
|
11424
11493
|
{
|
|
11425
11494
|
onSuccess: () => {
|
|
11495
|
+
ui.toast.success("Sales channel updated");
|
|
11426
11496
|
handleSuccess();
|
|
11427
11497
|
},
|
|
11428
11498
|
onError: (error) => {
|
|
@@ -11437,132 +11507,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11437
11507
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
11438
11508
|
onSubmit,
|
|
11439
11509
|
children: [
|
|
11440
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.
|
|
11441
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11442
|
-
Form$2.Field,
|
|
11443
|
-
{
|
|
11444
|
-
control: form.control,
|
|
11445
|
-
name: "country_code",
|
|
11446
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11447
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
|
|
11448
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
|
|
11449
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11450
|
-
] })
|
|
11451
|
-
}
|
|
11452
|
-
),
|
|
11453
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11454
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11455
|
-
Form$2.Field,
|
|
11456
|
-
{
|
|
11457
|
-
control: form.control,
|
|
11458
|
-
name: "first_name",
|
|
11459
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11460
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
|
|
11461
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11462
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11463
|
-
] })
|
|
11464
|
-
}
|
|
11465
|
-
),
|
|
11466
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11467
|
-
Form$2.Field,
|
|
11468
|
-
{
|
|
11469
|
-
control: form.control,
|
|
11470
|
-
name: "last_name",
|
|
11471
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11472
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
|
|
11473
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11474
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11475
|
-
] })
|
|
11476
|
-
}
|
|
11477
|
-
)
|
|
11478
|
-
] }),
|
|
11479
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11480
|
-
Form$2.Field,
|
|
11481
|
-
{
|
|
11482
|
-
control: form.control,
|
|
11483
|
-
name: "company",
|
|
11484
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11485
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
11486
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11487
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11488
|
-
] })
|
|
11489
|
-
}
|
|
11490
|
-
),
|
|
11491
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11492
|
-
Form$2.Field,
|
|
11493
|
-
{
|
|
11494
|
-
control: form.control,
|
|
11495
|
-
name: "address_1",
|
|
11496
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11497
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
|
|
11498
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11499
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11500
|
-
] })
|
|
11501
|
-
}
|
|
11502
|
-
),
|
|
11503
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11504
|
-
Form$2.Field,
|
|
11505
|
-
{
|
|
11506
|
-
control: form.control,
|
|
11507
|
-
name: "address_2",
|
|
11508
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11509
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
11510
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11511
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11512
|
-
] })
|
|
11513
|
-
}
|
|
11514
|
-
),
|
|
11515
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11516
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11517
|
-
Form$2.Field,
|
|
11518
|
-
{
|
|
11519
|
-
control: form.control,
|
|
11520
|
-
name: "postal_code",
|
|
11521
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11522
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
|
|
11523
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11524
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11525
|
-
] })
|
|
11526
|
-
}
|
|
11527
|
-
),
|
|
11528
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11529
|
-
Form$2.Field,
|
|
11530
|
-
{
|
|
11531
|
-
control: form.control,
|
|
11532
|
-
name: "city",
|
|
11533
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11534
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
|
|
11535
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11536
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11537
|
-
] })
|
|
11538
|
-
}
|
|
11539
|
-
)
|
|
11540
|
-
] }),
|
|
11541
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11542
|
-
Form$2.Field,
|
|
11543
|
-
{
|
|
11544
|
-
control: form.control,
|
|
11545
|
-
name: "province",
|
|
11546
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11547
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
11548
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11549
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11550
|
-
] })
|
|
11551
|
-
}
|
|
11552
|
-
),
|
|
11553
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11554
|
-
Form$2.Field,
|
|
11555
|
-
{
|
|
11556
|
-
control: form.control,
|
|
11557
|
-
name: "phone",
|
|
11558
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11559
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
11560
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11561
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11562
|
-
] })
|
|
11563
|
-
}
|
|
11564
|
-
)
|
|
11565
|
-
] }) }),
|
|
11510
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11566
11511
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11567
11512
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11568
11513
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
@@ -11571,7 +11516,49 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11571
11516
|
}
|
|
11572
11517
|
) });
|
|
11573
11518
|
};
|
|
11574
|
-
const
|
|
11519
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11520
|
+
const salesChannels = useComboboxData({
|
|
11521
|
+
queryFn: async (params) => {
|
|
11522
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11523
|
+
},
|
|
11524
|
+
queryKey: ["sales-channels"],
|
|
11525
|
+
getOptions: (data) => {
|
|
11526
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11527
|
+
label: salesChannel.name,
|
|
11528
|
+
value: salesChannel.id
|
|
11529
|
+
}));
|
|
11530
|
+
},
|
|
11531
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11532
|
+
});
|
|
11533
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11534
|
+
Form$2.Field,
|
|
11535
|
+
{
|
|
11536
|
+
control,
|
|
11537
|
+
name: "sales_channel_id",
|
|
11538
|
+
render: ({ field }) => {
|
|
11539
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11540
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11541
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11542
|
+
Combobox,
|
|
11543
|
+
{
|
|
11544
|
+
options: salesChannels.options,
|
|
11545
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11546
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11547
|
+
searchValue: salesChannels.searchValue,
|
|
11548
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11549
|
+
placeholder: "Select sales channel",
|
|
11550
|
+
...field
|
|
11551
|
+
}
|
|
11552
|
+
) }),
|
|
11553
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11554
|
+
] });
|
|
11555
|
+
}
|
|
11556
|
+
}
|
|
11557
|
+
);
|
|
11558
|
+
};
|
|
11559
|
+
const schema$2 = objectType({
|
|
11560
|
+
sales_channel_id: stringType().min(1)
|
|
11561
|
+
});
|
|
11575
11562
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11576
11563
|
const Shipping = () => {
|
|
11577
11564
|
var _a;
|
|
@@ -12855,10 +12842,10 @@ const Illustration = () => {
|
|
|
12855
12842
|
const schema$1 = objectType({
|
|
12856
12843
|
customer_id: stringType().min(1)
|
|
12857
12844
|
});
|
|
12858
|
-
const
|
|
12845
|
+
const ShippingAddress = () => {
|
|
12859
12846
|
const { id } = reactRouterDom.useParams();
|
|
12860
12847
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
12861
|
-
fields: "+
|
|
12848
|
+
fields: "+shipping_address"
|
|
12862
12849
|
});
|
|
12863
12850
|
if (isError) {
|
|
12864
12851
|
throw error;
|
|
@@ -12866,26 +12853,26 @@ const BillingAddress = () => {
|
|
|
12866
12853
|
const isReady = !isPending && !!order;
|
|
12867
12854
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12868
12855
|
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12869
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit
|
|
12870
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the
|
|
12856
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
|
|
12857
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
12871
12858
|
] }),
|
|
12872
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(
|
|
12859
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
|
|
12873
12860
|
] });
|
|
12874
12861
|
};
|
|
12875
|
-
const
|
|
12862
|
+
const ShippingAddressForm = ({ order }) => {
|
|
12876
12863
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12877
12864
|
const form = reactHookForm.useForm({
|
|
12878
12865
|
defaultValues: {
|
|
12879
|
-
first_name: ((_a = order.
|
|
12880
|
-
last_name: ((_b = order.
|
|
12881
|
-
company: ((_c = order.
|
|
12882
|
-
address_1: ((_d = order.
|
|
12883
|
-
address_2: ((_e = order.
|
|
12884
|
-
city: ((_f = order.
|
|
12885
|
-
province: ((_g = order.
|
|
12886
|
-
country_code: ((_h = order.
|
|
12887
|
-
postal_code: ((_i = order.
|
|
12888
|
-
phone: ((_j = order.
|
|
12866
|
+
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12867
|
+
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12868
|
+
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
12869
|
+
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12870
|
+
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12871
|
+
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
12872
|
+
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
12873
|
+
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12874
|
+
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12875
|
+
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12889
12876
|
},
|
|
12890
12877
|
resolver: zod.zodResolver(schema)
|
|
12891
12878
|
});
|
|
@@ -12893,7 +12880,20 @@ const BillingAddressForm = ({ order }) => {
|
|
|
12893
12880
|
const { handleSuccess } = useRouteModal();
|
|
12894
12881
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
12895
12882
|
await mutateAsync(
|
|
12896
|
-
{
|
|
12883
|
+
{
|
|
12884
|
+
shipping_address: {
|
|
12885
|
+
first_name: data.first_name,
|
|
12886
|
+
last_name: data.last_name,
|
|
12887
|
+
company: data.company,
|
|
12888
|
+
address_1: data.address_1,
|
|
12889
|
+
address_2: data.address_2,
|
|
12890
|
+
city: data.city,
|
|
12891
|
+
province: data.province,
|
|
12892
|
+
country_code: data.country_code,
|
|
12893
|
+
postal_code: data.postal_code,
|
|
12894
|
+
phone: data.phone
|
|
12895
|
+
}
|
|
12896
|
+
},
|
|
12897
12897
|
{
|
|
12898
12898
|
onSuccess: () => {
|
|
12899
12899
|
handleSuccess();
|
|
@@ -13066,32 +13066,32 @@ const routeModule = {
|
|
|
13066
13066
|
loader,
|
|
13067
13067
|
children: [
|
|
13068
13068
|
{
|
|
13069
|
-
Component:
|
|
13070
|
-
path: "/draft-orders/:id/
|
|
13069
|
+
Component: BillingAddress,
|
|
13070
|
+
path: "/draft-orders/:id/billing-address"
|
|
13071
13071
|
},
|
|
13072
13072
|
{
|
|
13073
13073
|
Component: CustomItems,
|
|
13074
13074
|
path: "/draft-orders/:id/custom-items"
|
|
13075
13075
|
},
|
|
13076
13076
|
{
|
|
13077
|
-
Component:
|
|
13078
|
-
path: "/draft-orders/:id/
|
|
13077
|
+
Component: Email,
|
|
13078
|
+
path: "/draft-orders/:id/email"
|
|
13079
13079
|
},
|
|
13080
13080
|
{
|
|
13081
|
-
Component:
|
|
13082
|
-
path: "/draft-orders/:id/
|
|
13081
|
+
Component: Items,
|
|
13082
|
+
path: "/draft-orders/:id/items"
|
|
13083
13083
|
},
|
|
13084
13084
|
{
|
|
13085
13085
|
Component: Promotions,
|
|
13086
13086
|
path: "/draft-orders/:id/promotions"
|
|
13087
13087
|
},
|
|
13088
13088
|
{
|
|
13089
|
-
Component:
|
|
13090
|
-
path: "/draft-orders/:id/
|
|
13089
|
+
Component: Metadata,
|
|
13090
|
+
path: "/draft-orders/:id/metadata"
|
|
13091
13091
|
},
|
|
13092
13092
|
{
|
|
13093
|
-
Component:
|
|
13094
|
-
path: "/draft-orders/:id/
|
|
13093
|
+
Component: SalesChannel,
|
|
13094
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13095
13095
|
},
|
|
13096
13096
|
{
|
|
13097
13097
|
Component: Shipping,
|
|
@@ -13102,8 +13102,8 @@ const routeModule = {
|
|
|
13102
13102
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13103
13103
|
},
|
|
13104
13104
|
{
|
|
13105
|
-
Component:
|
|
13106
|
-
path: "/draft-orders/:id/
|
|
13105
|
+
Component: ShippingAddress,
|
|
13106
|
+
path: "/draft-orders/:id/shipping-address"
|
|
13107
13107
|
}
|
|
13108
13108
|
]
|
|
13109
13109
|
}
|