@medusajs/draft-order 2.10.4-preview-20251005150154 → 2.10.4-preview-20251005180152
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 +632 -632
- package/.medusa/server/src/admin/index.mjs +632 -632
- package/package.json +16 -16
|
@@ -9573,10 +9573,31 @@ const ID = () => {
|
|
|
9573
9573
|
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
|
|
9574
9574
|
] });
|
|
9575
9575
|
};
|
|
9576
|
-
const
|
|
9576
|
+
const CustomItems = () => {
|
|
9577
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9578
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9579
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9580
|
+
] });
|
|
9581
|
+
};
|
|
9582
|
+
const CustomItemsForm = () => {
|
|
9583
|
+
const form = reactHookForm.useForm({
|
|
9584
|
+
resolver: zod.zodResolver(schema$5)
|
|
9585
|
+
});
|
|
9586
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9587
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9588
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9589
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9590
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9591
|
+
] }) })
|
|
9592
|
+
] }) });
|
|
9593
|
+
};
|
|
9594
|
+
const schema$5 = objectType({
|
|
9595
|
+
email: stringType().email()
|
|
9596
|
+
});
|
|
9597
|
+
const Email = () => {
|
|
9577
9598
|
const { id } = reactRouterDom.useParams();
|
|
9578
9599
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
9579
|
-
fields: "+
|
|
9600
|
+
fields: "+email"
|
|
9580
9601
|
});
|
|
9581
9602
|
if (isError) {
|
|
9582
9603
|
throw error;
|
|
@@ -9584,34 +9605,24 @@ const BillingAddress = () => {
|
|
|
9584
9605
|
const isReady = !isPending && !!order;
|
|
9585
9606
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9586
9607
|
/* @__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
|
|
9608
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
9609
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9589
9610
|
] }),
|
|
9590
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(
|
|
9611
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
9591
9612
|
] });
|
|
9592
9613
|
};
|
|
9593
|
-
const
|
|
9594
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9614
|
+
const EmailForm = ({ order }) => {
|
|
9595
9615
|
const form = reactHookForm.useForm({
|
|
9596
9616
|
defaultValues: {
|
|
9597
|
-
|
|
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) ?? ""
|
|
9617
|
+
email: order.email ?? ""
|
|
9607
9618
|
},
|
|
9608
|
-
resolver: zod.zodResolver(schema$
|
|
9619
|
+
resolver: zod.zodResolver(schema$4)
|
|
9609
9620
|
});
|
|
9610
9621
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9611
9622
|
const { handleSuccess } = useRouteModal();
|
|
9612
9623
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
9613
9624
|
await mutateAsync(
|
|
9614
|
-
{
|
|
9625
|
+
{ email: data.email },
|
|
9615
9626
|
{
|
|
9616
9627
|
onSuccess: () => {
|
|
9617
9628
|
handleSuccess();
|
|
@@ -9628,132 +9639,18 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9628
9639
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
9629
9640
|
onSubmit,
|
|
9630
9641
|
children: [
|
|
9631
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
|
|
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
|
-
] }) }),
|
|
9642
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9643
|
+
Form$2.Field,
|
|
9644
|
+
{
|
|
9645
|
+
control: form.control,
|
|
9646
|
+
name: "email",
|
|
9647
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9648
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
9649
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9650
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9651
|
+
] })
|
|
9652
|
+
}
|
|
9653
|
+
) }),
|
|
9757
9654
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9758
9655
|
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9759
9656
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
@@ -9762,25 +9659,6 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9762
9659
|
}
|
|
9763
9660
|
) });
|
|
9764
9661
|
};
|
|
9765
|
-
const schema$5 = addressSchema;
|
|
9766
|
-
const CustomItems = () => {
|
|
9767
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9768
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9769
|
-
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9770
|
-
] });
|
|
9771
|
-
};
|
|
9772
|
-
const CustomItemsForm = () => {
|
|
9773
|
-
const form = reactHookForm.useForm({
|
|
9774
|
-
resolver: zod.zodResolver(schema$4)
|
|
9775
|
-
});
|
|
9776
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9777
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9778
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9779
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9780
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9781
|
-
] }) })
|
|
9782
|
-
] }) });
|
|
9783
|
-
};
|
|
9784
9662
|
const schema$4 = objectType({
|
|
9785
9663
|
email: stringType().email()
|
|
9786
9664
|
});
|
|
@@ -10758,171 +10636,380 @@ const customItemSchema = objectType({
|
|
|
10758
10636
|
quantity: numberType(),
|
|
10759
10637
|
unit_price: unionType([numberType(), stringType()])
|
|
10760
10638
|
});
|
|
10761
|
-
const
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10639
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10640
|
+
const promotionsQueryKeys = {
|
|
10641
|
+
list: (query2) => [
|
|
10642
|
+
PROMOTION_QUERY_KEY,
|
|
10643
|
+
query2 ? query2 : void 0
|
|
10644
|
+
],
|
|
10645
|
+
detail: (id, query2) => [
|
|
10646
|
+
PROMOTION_QUERY_KEY,
|
|
10647
|
+
id,
|
|
10648
|
+
query2 ? query2 : void 0
|
|
10649
|
+
]
|
|
10650
|
+
};
|
|
10651
|
+
const usePromotions = (query2, options) => {
|
|
10652
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
10653
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10654
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10655
|
+
...options
|
|
10765
10656
|
});
|
|
10766
|
-
|
|
10767
|
-
|
|
10657
|
+
return { ...data, ...rest };
|
|
10658
|
+
};
|
|
10659
|
+
const Promotions = () => {
|
|
10660
|
+
const { id } = reactRouterDom.useParams();
|
|
10661
|
+
const {
|
|
10662
|
+
order: preview,
|
|
10663
|
+
isError: isPreviewError,
|
|
10664
|
+
error: previewError
|
|
10665
|
+
} = useOrderPreview(id, void 0);
|
|
10666
|
+
useInitiateOrderEdit({ preview });
|
|
10667
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10668
|
+
if (isPreviewError) {
|
|
10669
|
+
throw previewError;
|
|
10768
10670
|
}
|
|
10769
|
-
const isReady =
|
|
10770
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10771
|
-
/* @__PURE__ */ jsxRuntime.
|
|
10772
|
-
|
|
10773
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
10774
|
-
] }),
|
|
10775
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
10671
|
+
const isReady = !!preview;
|
|
10672
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10673
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
10674
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
10776
10675
|
] });
|
|
10777
10676
|
};
|
|
10778
|
-
const
|
|
10779
|
-
const
|
|
10780
|
-
|
|
10781
|
-
|
|
10782
|
-
},
|
|
10783
|
-
resolver: zod.zodResolver(schema$3)
|
|
10784
|
-
});
|
|
10785
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10677
|
+
const PromotionForm = ({ preview }) => {
|
|
10678
|
+
const { items, shipping_methods } = preview;
|
|
10679
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
10680
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
10786
10681
|
const { handleSuccess } = useRouteModal();
|
|
10787
|
-
const
|
|
10788
|
-
|
|
10789
|
-
|
|
10682
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10683
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10684
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
10685
|
+
{
|
|
10686
|
+
id: promoIds
|
|
10687
|
+
},
|
|
10688
|
+
{
|
|
10689
|
+
enabled: !!promoIds.length
|
|
10690
|
+
}
|
|
10691
|
+
);
|
|
10692
|
+
const comboboxData = useComboboxData({
|
|
10693
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
10694
|
+
queryFn: async (params) => {
|
|
10695
|
+
return await sdk.admin.promotion.list({
|
|
10696
|
+
...params,
|
|
10697
|
+
id: {
|
|
10698
|
+
$nin: promoIds
|
|
10699
|
+
}
|
|
10700
|
+
});
|
|
10701
|
+
},
|
|
10702
|
+
getOptions: (data) => {
|
|
10703
|
+
return data.promotions.map((promotion) => ({
|
|
10704
|
+
label: promotion.code,
|
|
10705
|
+
value: promotion.code
|
|
10706
|
+
}));
|
|
10707
|
+
}
|
|
10708
|
+
});
|
|
10709
|
+
const add = async (value) => {
|
|
10710
|
+
if (!value) {
|
|
10711
|
+
return;
|
|
10712
|
+
}
|
|
10713
|
+
addPromotions(
|
|
10790
10714
|
{
|
|
10791
|
-
|
|
10792
|
-
|
|
10715
|
+
promo_codes: [value]
|
|
10716
|
+
},
|
|
10717
|
+
{
|
|
10718
|
+
onError: (e) => {
|
|
10719
|
+
ui.toast.error(e.message);
|
|
10720
|
+
comboboxData.onSearchValueChange("");
|
|
10721
|
+
setComboboxValue("");
|
|
10793
10722
|
},
|
|
10794
|
-
|
|
10795
|
-
|
|
10723
|
+
onSuccess: () => {
|
|
10724
|
+
comboboxData.onSearchValueChange("");
|
|
10725
|
+
setComboboxValue("");
|
|
10796
10726
|
}
|
|
10797
10727
|
}
|
|
10798
10728
|
);
|
|
10799
|
-
}
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
}
|
|
10817
|
-
) }),
|
|
10818
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10819
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10820
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10821
|
-
] }) })
|
|
10822
|
-
]
|
|
10729
|
+
};
|
|
10730
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10731
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10732
|
+
const onSubmit = async () => {
|
|
10733
|
+
setIsSubmitting(true);
|
|
10734
|
+
let requestSucceeded = false;
|
|
10735
|
+
await requestOrderEdit(void 0, {
|
|
10736
|
+
onError: (e) => {
|
|
10737
|
+
ui.toast.error(e.message);
|
|
10738
|
+
},
|
|
10739
|
+
onSuccess: () => {
|
|
10740
|
+
requestSucceeded = true;
|
|
10741
|
+
}
|
|
10742
|
+
});
|
|
10743
|
+
if (!requestSucceeded) {
|
|
10744
|
+
setIsSubmitting(false);
|
|
10745
|
+
return;
|
|
10823
10746
|
}
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
"div",
|
|
10834
|
-
{
|
|
10835
|
-
ref,
|
|
10836
|
-
className: ui.clx(
|
|
10837
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10838
|
-
className
|
|
10839
|
-
),
|
|
10840
|
-
...props,
|
|
10841
|
-
children: [
|
|
10842
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10843
|
-
"div",
|
|
10844
|
-
{
|
|
10845
|
-
role: "presentation",
|
|
10846
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10847
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10848
|
-
})
|
|
10849
|
-
}
|
|
10850
|
-
),
|
|
10851
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10852
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10853
|
-
labelValue,
|
|
10854
|
-
":"
|
|
10855
|
-
] }),
|
|
10856
|
-
" ",
|
|
10857
|
-
children
|
|
10858
|
-
] })
|
|
10859
|
-
]
|
|
10747
|
+
await confirmOrderEdit(void 0, {
|
|
10748
|
+
onError: (e) => {
|
|
10749
|
+
ui.toast.error(e.message);
|
|
10750
|
+
},
|
|
10751
|
+
onSuccess: () => {
|
|
10752
|
+
handleSuccess();
|
|
10753
|
+
},
|
|
10754
|
+
onSettled: () => {
|
|
10755
|
+
setIsSubmitting(false);
|
|
10860
10756
|
}
|
|
10861
|
-
);
|
|
10862
|
-
}
|
|
10863
|
-
);
|
|
10864
|
-
InlineTip.displayName = "InlineTip";
|
|
10865
|
-
const MetadataFieldSchema = objectType({
|
|
10866
|
-
key: stringType(),
|
|
10867
|
-
disabled: booleanType().optional(),
|
|
10868
|
-
value: anyType()
|
|
10869
|
-
});
|
|
10870
|
-
const MetadataSchema = objectType({
|
|
10871
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10872
|
-
});
|
|
10873
|
-
const Metadata = () => {
|
|
10874
|
-
const { id } = reactRouterDom.useParams();
|
|
10875
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10876
|
-
fields: "metadata"
|
|
10877
|
-
});
|
|
10757
|
+
});
|
|
10758
|
+
};
|
|
10878
10759
|
if (isError) {
|
|
10879
10760
|
throw error;
|
|
10880
10761
|
}
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
10762
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10763
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10764
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10765
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
10766
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10767
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10768
|
+
] }),
|
|
10769
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10770
|
+
Combobox,
|
|
10771
|
+
{
|
|
10772
|
+
id: "promotion-combobox",
|
|
10773
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
10774
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10775
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
10776
|
+
options: comboboxData.options,
|
|
10777
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10778
|
+
searchValue: comboboxData.searchValue,
|
|
10779
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10780
|
+
onChange: add,
|
|
10781
|
+
value: comboboxValue
|
|
10782
|
+
}
|
|
10783
|
+
)
|
|
10784
|
+
] }),
|
|
10785
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10786
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
10787
|
+
PromotionItem,
|
|
10788
|
+
{
|
|
10789
|
+
promotion,
|
|
10790
|
+
orderId: preview.id,
|
|
10791
|
+
isLoading: isPending
|
|
10792
|
+
},
|
|
10793
|
+
promotion.id
|
|
10794
|
+
)) })
|
|
10795
|
+
] }) }),
|
|
10796
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10797
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10798
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10799
|
+
ui.Button,
|
|
10800
|
+
{
|
|
10801
|
+
size: "small",
|
|
10802
|
+
type: "submit",
|
|
10803
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
10804
|
+
children: "Save"
|
|
10805
|
+
}
|
|
10806
|
+
)
|
|
10807
|
+
] }) })
|
|
10888
10808
|
] });
|
|
10889
10809
|
};
|
|
10890
|
-
const
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
const
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
},
|
|
10900
|
-
resolver: zod.zodResolver(MetadataSchema)
|
|
10901
|
-
});
|
|
10902
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10903
|
-
const parsedData = parseValues(data);
|
|
10904
|
-
await mutateAsync(
|
|
10810
|
+
const PromotionItem = ({
|
|
10811
|
+
promotion,
|
|
10812
|
+
orderId,
|
|
10813
|
+
isLoading
|
|
10814
|
+
}) => {
|
|
10815
|
+
var _a;
|
|
10816
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10817
|
+
const onRemove = async () => {
|
|
10818
|
+
removePromotions(
|
|
10905
10819
|
{
|
|
10906
|
-
|
|
10820
|
+
promo_codes: [promotion.code]
|
|
10907
10821
|
},
|
|
10908
10822
|
{
|
|
10909
|
-
|
|
10910
|
-
ui.toast.
|
|
10911
|
-
handleSuccess();
|
|
10912
|
-
},
|
|
10913
|
-
onError: (error) => {
|
|
10914
|
-
ui.toast.error(error.message);
|
|
10823
|
+
onError: (e) => {
|
|
10824
|
+
ui.toast.error(e.message);
|
|
10915
10825
|
}
|
|
10916
10826
|
}
|
|
10917
10827
|
);
|
|
10918
|
-
}
|
|
10919
|
-
const
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10828
|
+
};
|
|
10829
|
+
const displayValue = getDisplayValue(promotion);
|
|
10830
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10831
|
+
"div",
|
|
10832
|
+
{
|
|
10833
|
+
className: ui.clx(
|
|
10834
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
10835
|
+
{
|
|
10836
|
+
"animate-pulse": isLoading
|
|
10837
|
+
}
|
|
10838
|
+
),
|
|
10839
|
+
children: [
|
|
10840
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10841
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
10842
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
10843
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
10844
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
10845
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
10846
|
+
] }),
|
|
10847
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
10848
|
+
] })
|
|
10849
|
+
] }),
|
|
10850
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10851
|
+
ui.IconButton,
|
|
10852
|
+
{
|
|
10853
|
+
size: "small",
|
|
10854
|
+
type: "button",
|
|
10855
|
+
variant: "transparent",
|
|
10856
|
+
onClick: onRemove,
|
|
10857
|
+
isLoading: isPending || isLoading,
|
|
10858
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
10859
|
+
}
|
|
10860
|
+
)
|
|
10861
|
+
]
|
|
10862
|
+
},
|
|
10863
|
+
promotion.id
|
|
10864
|
+
);
|
|
10865
|
+
};
|
|
10866
|
+
function getDisplayValue(promotion) {
|
|
10867
|
+
var _a, _b, _c, _d;
|
|
10868
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
10869
|
+
if (!value) {
|
|
10870
|
+
return null;
|
|
10871
|
+
}
|
|
10872
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
10873
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
10874
|
+
if (!currency) {
|
|
10875
|
+
return null;
|
|
10876
|
+
}
|
|
10877
|
+
return getLocaleAmount(value, currency);
|
|
10878
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
10879
|
+
return formatPercentage(value);
|
|
10880
|
+
}
|
|
10881
|
+
return null;
|
|
10882
|
+
}
|
|
10883
|
+
const formatter = new Intl.NumberFormat([], {
|
|
10884
|
+
style: "percent",
|
|
10885
|
+
minimumFractionDigits: 2
|
|
10886
|
+
});
|
|
10887
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
10888
|
+
let val = value || 0;
|
|
10889
|
+
if (!isPercentageValue) {
|
|
10890
|
+
val = val / 100;
|
|
10891
|
+
}
|
|
10892
|
+
return formatter.format(val);
|
|
10893
|
+
};
|
|
10894
|
+
function getPromotionIds(items, shippingMethods) {
|
|
10895
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
10896
|
+
for (const item of items) {
|
|
10897
|
+
if (item.adjustments) {
|
|
10898
|
+
for (const adjustment of item.adjustments) {
|
|
10899
|
+
if (adjustment.promotion_id) {
|
|
10900
|
+
promotionIds.add(adjustment.promotion_id);
|
|
10901
|
+
}
|
|
10902
|
+
}
|
|
10903
|
+
}
|
|
10904
|
+
}
|
|
10905
|
+
for (const shippingMethod of shippingMethods) {
|
|
10906
|
+
if (shippingMethod.adjustments) {
|
|
10907
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
10908
|
+
if (adjustment.promotion_id) {
|
|
10909
|
+
promotionIds.add(adjustment.promotion_id);
|
|
10910
|
+
}
|
|
10911
|
+
}
|
|
10912
|
+
}
|
|
10913
|
+
}
|
|
10914
|
+
return Array.from(promotionIds);
|
|
10915
|
+
}
|
|
10916
|
+
const InlineTip = React.forwardRef(
|
|
10917
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10918
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10919
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10920
|
+
"div",
|
|
10921
|
+
{
|
|
10922
|
+
ref,
|
|
10923
|
+
className: ui.clx(
|
|
10924
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10925
|
+
className
|
|
10926
|
+
),
|
|
10927
|
+
...props,
|
|
10928
|
+
children: [
|
|
10929
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10930
|
+
"div",
|
|
10931
|
+
{
|
|
10932
|
+
role: "presentation",
|
|
10933
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10934
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10935
|
+
})
|
|
10936
|
+
}
|
|
10937
|
+
),
|
|
10938
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10939
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10940
|
+
labelValue,
|
|
10941
|
+
":"
|
|
10942
|
+
] }),
|
|
10943
|
+
" ",
|
|
10944
|
+
children
|
|
10945
|
+
] })
|
|
10946
|
+
]
|
|
10947
|
+
}
|
|
10948
|
+
);
|
|
10949
|
+
}
|
|
10950
|
+
);
|
|
10951
|
+
InlineTip.displayName = "InlineTip";
|
|
10952
|
+
const MetadataFieldSchema = objectType({
|
|
10953
|
+
key: stringType(),
|
|
10954
|
+
disabled: booleanType().optional(),
|
|
10955
|
+
value: anyType()
|
|
10956
|
+
});
|
|
10957
|
+
const MetadataSchema = objectType({
|
|
10958
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10959
|
+
});
|
|
10960
|
+
const Metadata = () => {
|
|
10961
|
+
const { id } = reactRouterDom.useParams();
|
|
10962
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10963
|
+
fields: "metadata"
|
|
10964
|
+
});
|
|
10965
|
+
if (isError) {
|
|
10966
|
+
throw error;
|
|
10967
|
+
}
|
|
10968
|
+
const isReady = !isPending && !!order;
|
|
10969
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10970
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
10971
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
10972
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10973
|
+
] }),
|
|
10974
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10975
|
+
] });
|
|
10976
|
+
};
|
|
10977
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10978
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10979
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10980
|
+
const { handleSuccess } = useRouteModal();
|
|
10981
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10982
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10983
|
+
const form = reactHookForm.useForm({
|
|
10984
|
+
defaultValues: {
|
|
10985
|
+
metadata: getDefaultValues(metadata)
|
|
10986
|
+
},
|
|
10987
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
10988
|
+
});
|
|
10989
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10990
|
+
const parsedData = parseValues(data);
|
|
10991
|
+
await mutateAsync(
|
|
10992
|
+
{
|
|
10993
|
+
metadata: parsedData
|
|
10994
|
+
},
|
|
10995
|
+
{
|
|
10996
|
+
onSuccess: () => {
|
|
10997
|
+
ui.toast.success("Metadata updated");
|
|
10998
|
+
handleSuccess();
|
|
10999
|
+
},
|
|
11000
|
+
onError: (error) => {
|
|
11001
|
+
ui.toast.error(error.message);
|
|
11002
|
+
}
|
|
11003
|
+
}
|
|
11004
|
+
);
|
|
11005
|
+
});
|
|
11006
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
11007
|
+
control: form.control,
|
|
11008
|
+
name: "metadata"
|
|
11009
|
+
});
|
|
11010
|
+
function deleteRow(index) {
|
|
11011
|
+
remove(index);
|
|
11012
|
+
if (fields.length === 1) {
|
|
10926
11013
|
insert(0, {
|
|
10927
11014
|
key: "",
|
|
10928
11015
|
value: "",
|
|
@@ -11139,319 +11226,42 @@ function parseValues(values) {
|
|
|
11139
11226
|
if (isEmpty) {
|
|
11140
11227
|
return null;
|
|
11141
11228
|
}
|
|
11142
|
-
const update = {};
|
|
11143
|
-
metadata.forEach((field) => {
|
|
11144
|
-
let key = field.key;
|
|
11145
|
-
let value = field.value;
|
|
11146
|
-
const disabled = field.disabled;
|
|
11147
|
-
if (!key || !value) {
|
|
11148
|
-
return;
|
|
11149
|
-
}
|
|
11150
|
-
if (disabled) {
|
|
11151
|
-
update[key] = value;
|
|
11152
|
-
return;
|
|
11153
|
-
}
|
|
11154
|
-
key = key.trim();
|
|
11155
|
-
value = value.trim();
|
|
11156
|
-
if (value === "true") {
|
|
11157
|
-
update[key] = true;
|
|
11158
|
-
} else if (value === "false") {
|
|
11159
|
-
update[key] = false;
|
|
11160
|
-
} else {
|
|
11161
|
-
const parsedNumber = parseFloat(value);
|
|
11162
|
-
if (!isNaN(parsedNumber)) {
|
|
11163
|
-
update[key] = parsedNumber;
|
|
11164
|
-
} else {
|
|
11165
|
-
update[key] = value;
|
|
11166
|
-
}
|
|
11167
|
-
}
|
|
11168
|
-
});
|
|
11169
|
-
return update;
|
|
11170
|
-
}
|
|
11171
|
-
function getHasUneditableRows(metadata) {
|
|
11172
|
-
if (!metadata) {
|
|
11173
|
-
return false;
|
|
11174
|
-
}
|
|
11175
|
-
return Object.values(metadata).some(
|
|
11176
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11177
|
-
);
|
|
11178
|
-
}
|
|
11179
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
11180
|
-
const promotionsQueryKeys = {
|
|
11181
|
-
list: (query2) => [
|
|
11182
|
-
PROMOTION_QUERY_KEY,
|
|
11183
|
-
query2 ? query2 : void 0
|
|
11184
|
-
],
|
|
11185
|
-
detail: (id, query2) => [
|
|
11186
|
-
PROMOTION_QUERY_KEY,
|
|
11187
|
-
id,
|
|
11188
|
-
query2 ? query2 : void 0
|
|
11189
|
-
]
|
|
11190
|
-
};
|
|
11191
|
-
const usePromotions = (query2, options) => {
|
|
11192
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
11193
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
11194
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11195
|
-
...options
|
|
11196
|
-
});
|
|
11197
|
-
return { ...data, ...rest };
|
|
11198
|
-
};
|
|
11199
|
-
const Promotions = () => {
|
|
11200
|
-
const { id } = reactRouterDom.useParams();
|
|
11201
|
-
const {
|
|
11202
|
-
order: preview,
|
|
11203
|
-
isError: isPreviewError,
|
|
11204
|
-
error: previewError
|
|
11205
|
-
} = useOrderPreview(id, void 0);
|
|
11206
|
-
useInitiateOrderEdit({ preview });
|
|
11207
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11208
|
-
if (isPreviewError) {
|
|
11209
|
-
throw previewError;
|
|
11210
|
-
}
|
|
11211
|
-
const isReady = !!preview;
|
|
11212
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11213
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11214
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11215
|
-
] });
|
|
11216
|
-
};
|
|
11217
|
-
const PromotionForm = ({ preview }) => {
|
|
11218
|
-
const { items, shipping_methods } = preview;
|
|
11219
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11220
|
-
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11221
|
-
const { handleSuccess } = useRouteModal();
|
|
11222
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11223
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11224
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
11225
|
-
{
|
|
11226
|
-
id: promoIds
|
|
11227
|
-
},
|
|
11228
|
-
{
|
|
11229
|
-
enabled: !!promoIds.length
|
|
11230
|
-
}
|
|
11231
|
-
);
|
|
11232
|
-
const comboboxData = useComboboxData({
|
|
11233
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
11234
|
-
queryFn: async (params) => {
|
|
11235
|
-
return await sdk.admin.promotion.list({
|
|
11236
|
-
...params,
|
|
11237
|
-
id: {
|
|
11238
|
-
$nin: promoIds
|
|
11239
|
-
}
|
|
11240
|
-
});
|
|
11241
|
-
},
|
|
11242
|
-
getOptions: (data) => {
|
|
11243
|
-
return data.promotions.map((promotion) => ({
|
|
11244
|
-
label: promotion.code,
|
|
11245
|
-
value: promotion.code
|
|
11246
|
-
}));
|
|
11247
|
-
}
|
|
11248
|
-
});
|
|
11249
|
-
const add = async (value) => {
|
|
11250
|
-
if (!value) {
|
|
11251
|
-
return;
|
|
11252
|
-
}
|
|
11253
|
-
addPromotions(
|
|
11254
|
-
{
|
|
11255
|
-
promo_codes: [value]
|
|
11256
|
-
},
|
|
11257
|
-
{
|
|
11258
|
-
onError: (e) => {
|
|
11259
|
-
ui.toast.error(e.message);
|
|
11260
|
-
comboboxData.onSearchValueChange("");
|
|
11261
|
-
setComboboxValue("");
|
|
11262
|
-
},
|
|
11263
|
-
onSuccess: () => {
|
|
11264
|
-
comboboxData.onSearchValueChange("");
|
|
11265
|
-
setComboboxValue("");
|
|
11266
|
-
}
|
|
11267
|
-
}
|
|
11268
|
-
);
|
|
11269
|
-
};
|
|
11270
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11271
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11272
|
-
const onSubmit = async () => {
|
|
11273
|
-
setIsSubmitting(true);
|
|
11274
|
-
let requestSucceeded = false;
|
|
11275
|
-
await requestOrderEdit(void 0, {
|
|
11276
|
-
onError: (e) => {
|
|
11277
|
-
ui.toast.error(e.message);
|
|
11278
|
-
},
|
|
11279
|
-
onSuccess: () => {
|
|
11280
|
-
requestSucceeded = true;
|
|
11281
|
-
}
|
|
11282
|
-
});
|
|
11283
|
-
if (!requestSucceeded) {
|
|
11284
|
-
setIsSubmitting(false);
|
|
11285
|
-
return;
|
|
11286
|
-
}
|
|
11287
|
-
await confirmOrderEdit(void 0, {
|
|
11288
|
-
onError: (e) => {
|
|
11289
|
-
ui.toast.error(e.message);
|
|
11290
|
-
},
|
|
11291
|
-
onSuccess: () => {
|
|
11292
|
-
handleSuccess();
|
|
11293
|
-
},
|
|
11294
|
-
onSettled: () => {
|
|
11295
|
-
setIsSubmitting(false);
|
|
11296
|
-
}
|
|
11297
|
-
});
|
|
11298
|
-
};
|
|
11299
|
-
if (isError) {
|
|
11300
|
-
throw error;
|
|
11301
|
-
}
|
|
11302
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11303
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11304
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11305
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11306
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11307
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11308
|
-
] }),
|
|
11309
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11310
|
-
Combobox,
|
|
11311
|
-
{
|
|
11312
|
-
id: "promotion-combobox",
|
|
11313
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11314
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11315
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11316
|
-
options: comboboxData.options,
|
|
11317
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11318
|
-
searchValue: comboboxData.searchValue,
|
|
11319
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11320
|
-
onChange: add,
|
|
11321
|
-
value: comboboxValue
|
|
11322
|
-
}
|
|
11323
|
-
)
|
|
11324
|
-
] }),
|
|
11325
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11326
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11327
|
-
PromotionItem,
|
|
11328
|
-
{
|
|
11329
|
-
promotion,
|
|
11330
|
-
orderId: preview.id,
|
|
11331
|
-
isLoading: isPending
|
|
11332
|
-
},
|
|
11333
|
-
promotion.id
|
|
11334
|
-
)) })
|
|
11335
|
-
] }) }),
|
|
11336
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11337
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11338
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11339
|
-
ui.Button,
|
|
11340
|
-
{
|
|
11341
|
-
size: "small",
|
|
11342
|
-
type: "submit",
|
|
11343
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11344
|
-
children: "Save"
|
|
11345
|
-
}
|
|
11346
|
-
)
|
|
11347
|
-
] }) })
|
|
11348
|
-
] });
|
|
11349
|
-
};
|
|
11350
|
-
const PromotionItem = ({
|
|
11351
|
-
promotion,
|
|
11352
|
-
orderId,
|
|
11353
|
-
isLoading
|
|
11354
|
-
}) => {
|
|
11355
|
-
var _a;
|
|
11356
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11357
|
-
const onRemove = async () => {
|
|
11358
|
-
removePromotions(
|
|
11359
|
-
{
|
|
11360
|
-
promo_codes: [promotion.code]
|
|
11361
|
-
},
|
|
11362
|
-
{
|
|
11363
|
-
onError: (e) => {
|
|
11364
|
-
ui.toast.error(e.message);
|
|
11365
|
-
}
|
|
11366
|
-
}
|
|
11367
|
-
);
|
|
11368
|
-
};
|
|
11369
|
-
const displayValue = getDisplayValue(promotion);
|
|
11370
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11371
|
-
"div",
|
|
11372
|
-
{
|
|
11373
|
-
className: ui.clx(
|
|
11374
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11375
|
-
{
|
|
11376
|
-
"animate-pulse": isLoading
|
|
11377
|
-
}
|
|
11378
|
-
),
|
|
11379
|
-
children: [
|
|
11380
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11381
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11382
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11383
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11384
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11385
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11386
|
-
] }),
|
|
11387
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11388
|
-
] })
|
|
11389
|
-
] }),
|
|
11390
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11391
|
-
ui.IconButton,
|
|
11392
|
-
{
|
|
11393
|
-
size: "small",
|
|
11394
|
-
type: "button",
|
|
11395
|
-
variant: "transparent",
|
|
11396
|
-
onClick: onRemove,
|
|
11397
|
-
isLoading: isPending || isLoading,
|
|
11398
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11399
|
-
}
|
|
11400
|
-
)
|
|
11401
|
-
]
|
|
11402
|
-
},
|
|
11403
|
-
promotion.id
|
|
11404
|
-
);
|
|
11405
|
-
};
|
|
11406
|
-
function getDisplayValue(promotion) {
|
|
11407
|
-
var _a, _b, _c, _d;
|
|
11408
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11409
|
-
if (!value) {
|
|
11410
|
-
return null;
|
|
11411
|
-
}
|
|
11412
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11413
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11414
|
-
if (!currency) {
|
|
11415
|
-
return null;
|
|
11416
|
-
}
|
|
11417
|
-
return getLocaleAmount(value, currency);
|
|
11418
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11419
|
-
return formatPercentage(value);
|
|
11420
|
-
}
|
|
11421
|
-
return null;
|
|
11422
|
-
}
|
|
11423
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11424
|
-
style: "percent",
|
|
11425
|
-
minimumFractionDigits: 2
|
|
11426
|
-
});
|
|
11427
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11428
|
-
let val = value || 0;
|
|
11429
|
-
if (!isPercentageValue) {
|
|
11430
|
-
val = val / 100;
|
|
11431
|
-
}
|
|
11432
|
-
return formatter.format(val);
|
|
11433
|
-
};
|
|
11434
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11435
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11436
|
-
for (const item of items) {
|
|
11437
|
-
if (item.adjustments) {
|
|
11438
|
-
for (const adjustment of item.adjustments) {
|
|
11439
|
-
if (adjustment.promotion_id) {
|
|
11440
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11441
|
-
}
|
|
11442
|
-
}
|
|
11443
|
-
}
|
|
11444
|
-
}
|
|
11445
|
-
for (const shippingMethod of shippingMethods) {
|
|
11446
|
-
if (shippingMethod.adjustments) {
|
|
11447
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11448
|
-
if (adjustment.promotion_id) {
|
|
11449
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11450
|
-
}
|
|
11229
|
+
const update = {};
|
|
11230
|
+
metadata.forEach((field) => {
|
|
11231
|
+
let key = field.key;
|
|
11232
|
+
let value = field.value;
|
|
11233
|
+
const disabled = field.disabled;
|
|
11234
|
+
if (!key || !value) {
|
|
11235
|
+
return;
|
|
11236
|
+
}
|
|
11237
|
+
if (disabled) {
|
|
11238
|
+
update[key] = value;
|
|
11239
|
+
return;
|
|
11240
|
+
}
|
|
11241
|
+
key = key.trim();
|
|
11242
|
+
value = value.trim();
|
|
11243
|
+
if (value === "true") {
|
|
11244
|
+
update[key] = true;
|
|
11245
|
+
} else if (value === "false") {
|
|
11246
|
+
update[key] = false;
|
|
11247
|
+
} else {
|
|
11248
|
+
const parsedNumber = parseFloat(value);
|
|
11249
|
+
if (!isNaN(parsedNumber)) {
|
|
11250
|
+
update[key] = parsedNumber;
|
|
11251
|
+
} else {
|
|
11252
|
+
update[key] = value;
|
|
11451
11253
|
}
|
|
11452
11254
|
}
|
|
11255
|
+
});
|
|
11256
|
+
return update;
|
|
11257
|
+
}
|
|
11258
|
+
function getHasUneditableRows(metadata) {
|
|
11259
|
+
if (!metadata) {
|
|
11260
|
+
return false;
|
|
11453
11261
|
}
|
|
11454
|
-
return
|
|
11262
|
+
return Object.values(metadata).some(
|
|
11263
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11264
|
+
);
|
|
11455
11265
|
}
|
|
11456
11266
|
const SalesChannel = () => {
|
|
11457
11267
|
const { id } = reactRouterDom.useParams();
|
|
@@ -11481,7 +11291,7 @@ const SalesChannelForm = ({ order }) => {
|
|
|
11481
11291
|
defaultValues: {
|
|
11482
11292
|
sales_channel_id: order.sales_channel_id || ""
|
|
11483
11293
|
},
|
|
11484
|
-
resolver: zod.zodResolver(schema$
|
|
11294
|
+
resolver: zod.zodResolver(schema$3)
|
|
11485
11295
|
});
|
|
11486
11296
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11487
11297
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11556,7 +11366,7 @@ const SalesChannelField = ({ control, order }) => {
|
|
|
11556
11366
|
}
|
|
11557
11367
|
);
|
|
11558
11368
|
};
|
|
11559
|
-
const schema$
|
|
11369
|
+
const schema$3 = objectType({
|
|
11560
11370
|
sales_channel_id: stringType().min(1)
|
|
11561
11371
|
});
|
|
11562
11372
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
@@ -12398,7 +12208,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12398
12208
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12399
12209
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12400
12210
|
},
|
|
12401
|
-
resolver: zod.zodResolver(schema$
|
|
12211
|
+
resolver: zod.zodResolver(schema$2)
|
|
12402
12212
|
});
|
|
12403
12213
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12404
12214
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12568,7 +12378,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12568
12378
|
}
|
|
12569
12379
|
) });
|
|
12570
12380
|
};
|
|
12571
|
-
const schema$
|
|
12381
|
+
const schema$2 = addressSchema;
|
|
12572
12382
|
const TransferOwnership = () => {
|
|
12573
12383
|
const { id } = reactRouterDom.useParams();
|
|
12574
12384
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12592,7 +12402,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12592
12402
|
defaultValues: {
|
|
12593
12403
|
customer_id: order.customer_id || ""
|
|
12594
12404
|
},
|
|
12595
|
-
resolver: zod.zodResolver(schema)
|
|
12405
|
+
resolver: zod.zodResolver(schema$1)
|
|
12596
12406
|
});
|
|
12597
12407
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12598
12408
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13042,9 +12852,199 @@ const Illustration = () => {
|
|
|
13042
12852
|
}
|
|
13043
12853
|
);
|
|
13044
12854
|
};
|
|
13045
|
-
const schema = objectType({
|
|
12855
|
+
const schema$1 = objectType({
|
|
13046
12856
|
customer_id: stringType().min(1)
|
|
13047
12857
|
});
|
|
12858
|
+
const BillingAddress = () => {
|
|
12859
|
+
const { id } = reactRouterDom.useParams();
|
|
12860
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12861
|
+
fields: "+billing_address"
|
|
12862
|
+
});
|
|
12863
|
+
if (isError) {
|
|
12864
|
+
throw error;
|
|
12865
|
+
}
|
|
12866
|
+
const isReady = !isPending && !!order;
|
|
12867
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12868
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12869
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
|
|
12870
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
12871
|
+
] }),
|
|
12872
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
|
|
12873
|
+
] });
|
|
12874
|
+
};
|
|
12875
|
+
const BillingAddressForm = ({ order }) => {
|
|
12876
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12877
|
+
const form = reactHookForm.useForm({
|
|
12878
|
+
defaultValues: {
|
|
12879
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12880
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12881
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
12882
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12883
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12884
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
12885
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
12886
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12887
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12888
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
12889
|
+
},
|
|
12890
|
+
resolver: zod.zodResolver(schema)
|
|
12891
|
+
});
|
|
12892
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12893
|
+
const { handleSuccess } = useRouteModal();
|
|
12894
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12895
|
+
await mutateAsync(
|
|
12896
|
+
{ billing_address: data },
|
|
12897
|
+
{
|
|
12898
|
+
onSuccess: () => {
|
|
12899
|
+
handleSuccess();
|
|
12900
|
+
},
|
|
12901
|
+
onError: (error) => {
|
|
12902
|
+
ui.toast.error(error.message);
|
|
12903
|
+
}
|
|
12904
|
+
}
|
|
12905
|
+
);
|
|
12906
|
+
});
|
|
12907
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12908
|
+
KeyboundForm,
|
|
12909
|
+
{
|
|
12910
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12911
|
+
onSubmit,
|
|
12912
|
+
children: [
|
|
12913
|
+
/* @__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: [
|
|
12914
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12915
|
+
Form$2.Field,
|
|
12916
|
+
{
|
|
12917
|
+
control: form.control,
|
|
12918
|
+
name: "country_code",
|
|
12919
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12920
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
|
|
12921
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
|
|
12922
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12923
|
+
] })
|
|
12924
|
+
}
|
|
12925
|
+
),
|
|
12926
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12927
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12928
|
+
Form$2.Field,
|
|
12929
|
+
{
|
|
12930
|
+
control: form.control,
|
|
12931
|
+
name: "first_name",
|
|
12932
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12933
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
|
|
12934
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12935
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12936
|
+
] })
|
|
12937
|
+
}
|
|
12938
|
+
),
|
|
12939
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12940
|
+
Form$2.Field,
|
|
12941
|
+
{
|
|
12942
|
+
control: form.control,
|
|
12943
|
+
name: "last_name",
|
|
12944
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12945
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
|
|
12946
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12947
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12948
|
+
] })
|
|
12949
|
+
}
|
|
12950
|
+
)
|
|
12951
|
+
] }),
|
|
12952
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12953
|
+
Form$2.Field,
|
|
12954
|
+
{
|
|
12955
|
+
control: form.control,
|
|
12956
|
+
name: "company",
|
|
12957
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12958
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12959
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12960
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12961
|
+
] })
|
|
12962
|
+
}
|
|
12963
|
+
),
|
|
12964
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12965
|
+
Form$2.Field,
|
|
12966
|
+
{
|
|
12967
|
+
control: form.control,
|
|
12968
|
+
name: "address_1",
|
|
12969
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12970
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
|
|
12971
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12972
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12973
|
+
] })
|
|
12974
|
+
}
|
|
12975
|
+
),
|
|
12976
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12977
|
+
Form$2.Field,
|
|
12978
|
+
{
|
|
12979
|
+
control: form.control,
|
|
12980
|
+
name: "address_2",
|
|
12981
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12982
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12983
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12984
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12985
|
+
] })
|
|
12986
|
+
}
|
|
12987
|
+
),
|
|
12988
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12989
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12990
|
+
Form$2.Field,
|
|
12991
|
+
{
|
|
12992
|
+
control: form.control,
|
|
12993
|
+
name: "postal_code",
|
|
12994
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12995
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
|
|
12996
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12997
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12998
|
+
] })
|
|
12999
|
+
}
|
|
13000
|
+
),
|
|
13001
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
13002
|
+
Form$2.Field,
|
|
13003
|
+
{
|
|
13004
|
+
control: form.control,
|
|
13005
|
+
name: "city",
|
|
13006
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
13007
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
|
|
13008
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
13009
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
13010
|
+
] })
|
|
13011
|
+
}
|
|
13012
|
+
)
|
|
13013
|
+
] }),
|
|
13014
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
13015
|
+
Form$2.Field,
|
|
13016
|
+
{
|
|
13017
|
+
control: form.control,
|
|
13018
|
+
name: "province",
|
|
13019
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
13020
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
13021
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
13022
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
13023
|
+
] })
|
|
13024
|
+
}
|
|
13025
|
+
),
|
|
13026
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
13027
|
+
Form$2.Field,
|
|
13028
|
+
{
|
|
13029
|
+
control: form.control,
|
|
13030
|
+
name: "phone",
|
|
13031
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
13032
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
13033
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
13034
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
13035
|
+
] })
|
|
13036
|
+
}
|
|
13037
|
+
)
|
|
13038
|
+
] }) }),
|
|
13039
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13040
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13041
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13042
|
+
] }) })
|
|
13043
|
+
]
|
|
13044
|
+
}
|
|
13045
|
+
) });
|
|
13046
|
+
};
|
|
13047
|
+
const schema = addressSchema;
|
|
13048
13048
|
const widgetModule = { widgets: [] };
|
|
13049
13049
|
const routeModule = {
|
|
13050
13050
|
routes: [
|
|
@@ -13065,30 +13065,26 @@ const routeModule = {
|
|
|
13065
13065
|
handle,
|
|
13066
13066
|
loader,
|
|
13067
13067
|
children: [
|
|
13068
|
-
{
|
|
13069
|
-
Component: BillingAddress,
|
|
13070
|
-
path: "/draft-orders/:id/billing-address"
|
|
13071
|
-
},
|
|
13072
13068
|
{
|
|
13073
13069
|
Component: CustomItems,
|
|
13074
13070
|
path: "/draft-orders/:id/custom-items"
|
|
13075
13071
|
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: Items,
|
|
13078
|
-
path: "/draft-orders/:id/items"
|
|
13079
|
-
},
|
|
13080
13072
|
{
|
|
13081
13073
|
Component: Email,
|
|
13082
13074
|
path: "/draft-orders/:id/email"
|
|
13083
13075
|
},
|
|
13084
13076
|
{
|
|
13085
|
-
Component:
|
|
13086
|
-
path: "/draft-orders/:id/
|
|
13077
|
+
Component: Items,
|
|
13078
|
+
path: "/draft-orders/:id/items"
|
|
13087
13079
|
},
|
|
13088
13080
|
{
|
|
13089
13081
|
Component: Promotions,
|
|
13090
13082
|
path: "/draft-orders/:id/promotions"
|
|
13091
13083
|
},
|
|
13084
|
+
{
|
|
13085
|
+
Component: Metadata,
|
|
13086
|
+
path: "/draft-orders/:id/metadata"
|
|
13087
|
+
},
|
|
13092
13088
|
{
|
|
13093
13089
|
Component: SalesChannel,
|
|
13094
13090
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13104,6 +13100,10 @@ const routeModule = {
|
|
|
13104
13100
|
{
|
|
13105
13101
|
Component: TransferOwnership,
|
|
13106
13102
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13103
|
+
},
|
|
13104
|
+
{
|
|
13105
|
+
Component: BillingAddress,
|
|
13106
|
+
path: "/draft-orders/:id/billing-address"
|
|
13107
13107
|
}
|
|
13108
13108
|
]
|
|
13109
13109
|
}
|