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