@medusajs/draft-order 2.11.0-snapshot-20251020120939 → 2.11.1-snapshot-20251021080449
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 +506 -506
- package/.medusa/server/src/admin/index.mjs +506 -506
- package/package.json +16 -16
|
@@ -9565,196 +9565,6 @@ const ID = () => {
|
|
|
9565
9565
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9566
9566
|
] });
|
|
9567
9567
|
};
|
|
9568
|
-
const BillingAddress = () => {
|
|
9569
|
-
const { id } = useParams();
|
|
9570
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
9571
|
-
fields: "+billing_address"
|
|
9572
|
-
});
|
|
9573
|
-
if (isError) {
|
|
9574
|
-
throw error;
|
|
9575
|
-
}
|
|
9576
|
-
const isReady = !isPending && !!order;
|
|
9577
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9578
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9579
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
9580
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9581
|
-
] }),
|
|
9582
|
-
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
9583
|
-
] });
|
|
9584
|
-
};
|
|
9585
|
-
const BillingAddressForm = ({ order }) => {
|
|
9586
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9587
|
-
const form = useForm({
|
|
9588
|
-
defaultValues: {
|
|
9589
|
-
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9590
|
-
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9591
|
-
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9592
|
-
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9593
|
-
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9594
|
-
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9595
|
-
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9596
|
-
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9597
|
-
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9598
|
-
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9599
|
-
},
|
|
9600
|
-
resolver: zodResolver(schema$5)
|
|
9601
|
-
});
|
|
9602
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9603
|
-
const { handleSuccess } = useRouteModal();
|
|
9604
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9605
|
-
await mutateAsync(
|
|
9606
|
-
{ billing_address: data },
|
|
9607
|
-
{
|
|
9608
|
-
onSuccess: () => {
|
|
9609
|
-
handleSuccess();
|
|
9610
|
-
},
|
|
9611
|
-
onError: (error) => {
|
|
9612
|
-
toast.error(error.message);
|
|
9613
|
-
}
|
|
9614
|
-
}
|
|
9615
|
-
);
|
|
9616
|
-
});
|
|
9617
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9618
|
-
KeyboundForm,
|
|
9619
|
-
{
|
|
9620
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
9621
|
-
onSubmit,
|
|
9622
|
-
children: [
|
|
9623
|
-
/* @__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: [
|
|
9624
|
-
/* @__PURE__ */ jsx(
|
|
9625
|
-
Form$2.Field,
|
|
9626
|
-
{
|
|
9627
|
-
control: form.control,
|
|
9628
|
-
name: "country_code",
|
|
9629
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9630
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
9631
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
9632
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9633
|
-
] })
|
|
9634
|
-
}
|
|
9635
|
-
),
|
|
9636
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9637
|
-
/* @__PURE__ */ jsx(
|
|
9638
|
-
Form$2.Field,
|
|
9639
|
-
{
|
|
9640
|
-
control: form.control,
|
|
9641
|
-
name: "first_name",
|
|
9642
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9643
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
9644
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9645
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9646
|
-
] })
|
|
9647
|
-
}
|
|
9648
|
-
),
|
|
9649
|
-
/* @__PURE__ */ jsx(
|
|
9650
|
-
Form$2.Field,
|
|
9651
|
-
{
|
|
9652
|
-
control: form.control,
|
|
9653
|
-
name: "last_name",
|
|
9654
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9655
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
9656
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9657
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9658
|
-
] })
|
|
9659
|
-
}
|
|
9660
|
-
)
|
|
9661
|
-
] }),
|
|
9662
|
-
/* @__PURE__ */ jsx(
|
|
9663
|
-
Form$2.Field,
|
|
9664
|
-
{
|
|
9665
|
-
control: form.control,
|
|
9666
|
-
name: "company",
|
|
9667
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9668
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9669
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9670
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9671
|
-
] })
|
|
9672
|
-
}
|
|
9673
|
-
),
|
|
9674
|
-
/* @__PURE__ */ jsx(
|
|
9675
|
-
Form$2.Field,
|
|
9676
|
-
{
|
|
9677
|
-
control: form.control,
|
|
9678
|
-
name: "address_1",
|
|
9679
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9680
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
9681
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9682
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9683
|
-
] })
|
|
9684
|
-
}
|
|
9685
|
-
),
|
|
9686
|
-
/* @__PURE__ */ jsx(
|
|
9687
|
-
Form$2.Field,
|
|
9688
|
-
{
|
|
9689
|
-
control: form.control,
|
|
9690
|
-
name: "address_2",
|
|
9691
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9692
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9693
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9694
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9695
|
-
] })
|
|
9696
|
-
}
|
|
9697
|
-
),
|
|
9698
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9699
|
-
/* @__PURE__ */ jsx(
|
|
9700
|
-
Form$2.Field,
|
|
9701
|
-
{
|
|
9702
|
-
control: form.control,
|
|
9703
|
-
name: "postal_code",
|
|
9704
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9705
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
9706
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9707
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9708
|
-
] })
|
|
9709
|
-
}
|
|
9710
|
-
),
|
|
9711
|
-
/* @__PURE__ */ jsx(
|
|
9712
|
-
Form$2.Field,
|
|
9713
|
-
{
|
|
9714
|
-
control: form.control,
|
|
9715
|
-
name: "city",
|
|
9716
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9717
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
9718
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9719
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9720
|
-
] })
|
|
9721
|
-
}
|
|
9722
|
-
)
|
|
9723
|
-
] }),
|
|
9724
|
-
/* @__PURE__ */ jsx(
|
|
9725
|
-
Form$2.Field,
|
|
9726
|
-
{
|
|
9727
|
-
control: form.control,
|
|
9728
|
-
name: "province",
|
|
9729
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9730
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9731
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9732
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9733
|
-
] })
|
|
9734
|
-
}
|
|
9735
|
-
),
|
|
9736
|
-
/* @__PURE__ */ jsx(
|
|
9737
|
-
Form$2.Field,
|
|
9738
|
-
{
|
|
9739
|
-
control: form.control,
|
|
9740
|
-
name: "phone",
|
|
9741
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9742
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9743
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9744
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9745
|
-
] })
|
|
9746
|
-
}
|
|
9747
|
-
)
|
|
9748
|
-
] }) }),
|
|
9749
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9750
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9751
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9752
|
-
] }) })
|
|
9753
|
-
]
|
|
9754
|
-
}
|
|
9755
|
-
) });
|
|
9756
|
-
};
|
|
9757
|
-
const schema$5 = addressSchema;
|
|
9758
9568
|
const CustomItems = () => {
|
|
9759
9569
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9760
9570
|
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
@@ -9763,7 +9573,7 @@ const CustomItems = () => {
|
|
|
9763
9573
|
};
|
|
9764
9574
|
const CustomItemsForm = () => {
|
|
9765
9575
|
const form = useForm({
|
|
9766
|
-
resolver: zodResolver(schema$
|
|
9576
|
+
resolver: zodResolver(schema$5)
|
|
9767
9577
|
});
|
|
9768
9578
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9769
9579
|
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
@@ -9773,7 +9583,7 @@ const CustomItemsForm = () => {
|
|
|
9773
9583
|
] }) })
|
|
9774
9584
|
] }) });
|
|
9775
9585
|
};
|
|
9776
|
-
const schema$
|
|
9586
|
+
const schema$5 = objectType({
|
|
9777
9587
|
email: stringType().email()
|
|
9778
9588
|
});
|
|
9779
9589
|
const Email = () => {
|
|
@@ -9798,7 +9608,7 @@ const EmailForm = ({ order }) => {
|
|
|
9798
9608
|
defaultValues: {
|
|
9799
9609
|
email: order.email ?? ""
|
|
9800
9610
|
},
|
|
9801
|
-
resolver: zodResolver(schema$
|
|
9611
|
+
resolver: zodResolver(schema$4)
|
|
9802
9612
|
});
|
|
9803
9613
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9804
9614
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9841,7 +9651,7 @@ const EmailForm = ({ order }) => {
|
|
|
9841
9651
|
}
|
|
9842
9652
|
) });
|
|
9843
9653
|
};
|
|
9844
|
-
const schema$
|
|
9654
|
+
const schema$4 = objectType({
|
|
9845
9655
|
email: stringType().email()
|
|
9846
9656
|
});
|
|
9847
9657
|
const NumberInput = forwardRef(
|
|
@@ -10818,283 +10628,6 @@ const customItemSchema = objectType({
|
|
|
10818
10628
|
quantity: numberType(),
|
|
10819
10629
|
unit_price: unionType([numberType(), stringType()])
|
|
10820
10630
|
});
|
|
10821
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
10822
|
-
const promotionsQueryKeys = {
|
|
10823
|
-
list: (query2) => [
|
|
10824
|
-
PROMOTION_QUERY_KEY,
|
|
10825
|
-
query2 ? query2 : void 0
|
|
10826
|
-
],
|
|
10827
|
-
detail: (id, query2) => [
|
|
10828
|
-
PROMOTION_QUERY_KEY,
|
|
10829
|
-
id,
|
|
10830
|
-
query2 ? query2 : void 0
|
|
10831
|
-
]
|
|
10832
|
-
};
|
|
10833
|
-
const usePromotions = (query2, options) => {
|
|
10834
|
-
const { data, ...rest } = useQuery({
|
|
10835
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
10836
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10837
|
-
...options
|
|
10838
|
-
});
|
|
10839
|
-
return { ...data, ...rest };
|
|
10840
|
-
};
|
|
10841
|
-
const Promotions = () => {
|
|
10842
|
-
const { id } = useParams();
|
|
10843
|
-
const {
|
|
10844
|
-
order: preview,
|
|
10845
|
-
isError: isPreviewError,
|
|
10846
|
-
error: previewError
|
|
10847
|
-
} = useOrderPreview(id, void 0);
|
|
10848
|
-
useInitiateOrderEdit({ preview });
|
|
10849
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10850
|
-
if (isPreviewError) {
|
|
10851
|
-
throw previewError;
|
|
10852
|
-
}
|
|
10853
|
-
const isReady = !!preview;
|
|
10854
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10855
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
10856
|
-
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
10857
|
-
] });
|
|
10858
|
-
};
|
|
10859
|
-
const PromotionForm = ({ preview }) => {
|
|
10860
|
-
const { items, shipping_methods } = preview;
|
|
10861
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10862
|
-
const [comboboxValue, setComboboxValue] = useState("");
|
|
10863
|
-
const { handleSuccess } = useRouteModal();
|
|
10864
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10865
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10866
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10867
|
-
{
|
|
10868
|
-
id: promoIds
|
|
10869
|
-
},
|
|
10870
|
-
{
|
|
10871
|
-
enabled: !!promoIds.length
|
|
10872
|
-
}
|
|
10873
|
-
);
|
|
10874
|
-
const comboboxData = useComboboxData({
|
|
10875
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
10876
|
-
queryFn: async (params) => {
|
|
10877
|
-
return await sdk.admin.promotion.list({
|
|
10878
|
-
...params,
|
|
10879
|
-
id: {
|
|
10880
|
-
$nin: promoIds
|
|
10881
|
-
}
|
|
10882
|
-
});
|
|
10883
|
-
},
|
|
10884
|
-
getOptions: (data) => {
|
|
10885
|
-
return data.promotions.map((promotion) => ({
|
|
10886
|
-
label: promotion.code,
|
|
10887
|
-
value: promotion.code
|
|
10888
|
-
}));
|
|
10889
|
-
}
|
|
10890
|
-
});
|
|
10891
|
-
const add = async (value) => {
|
|
10892
|
-
if (!value) {
|
|
10893
|
-
return;
|
|
10894
|
-
}
|
|
10895
|
-
addPromotions(
|
|
10896
|
-
{
|
|
10897
|
-
promo_codes: [value]
|
|
10898
|
-
},
|
|
10899
|
-
{
|
|
10900
|
-
onError: (e) => {
|
|
10901
|
-
toast.error(e.message);
|
|
10902
|
-
comboboxData.onSearchValueChange("");
|
|
10903
|
-
setComboboxValue("");
|
|
10904
|
-
},
|
|
10905
|
-
onSuccess: () => {
|
|
10906
|
-
comboboxData.onSearchValueChange("");
|
|
10907
|
-
setComboboxValue("");
|
|
10908
|
-
}
|
|
10909
|
-
}
|
|
10910
|
-
);
|
|
10911
|
-
};
|
|
10912
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10913
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10914
|
-
const onSubmit = async () => {
|
|
10915
|
-
setIsSubmitting(true);
|
|
10916
|
-
let requestSucceeded = false;
|
|
10917
|
-
await requestOrderEdit(void 0, {
|
|
10918
|
-
onError: (e) => {
|
|
10919
|
-
toast.error(e.message);
|
|
10920
|
-
},
|
|
10921
|
-
onSuccess: () => {
|
|
10922
|
-
requestSucceeded = true;
|
|
10923
|
-
}
|
|
10924
|
-
});
|
|
10925
|
-
if (!requestSucceeded) {
|
|
10926
|
-
setIsSubmitting(false);
|
|
10927
|
-
return;
|
|
10928
|
-
}
|
|
10929
|
-
await confirmOrderEdit(void 0, {
|
|
10930
|
-
onError: (e) => {
|
|
10931
|
-
toast.error(e.message);
|
|
10932
|
-
},
|
|
10933
|
-
onSuccess: () => {
|
|
10934
|
-
handleSuccess();
|
|
10935
|
-
},
|
|
10936
|
-
onSettled: () => {
|
|
10937
|
-
setIsSubmitting(false);
|
|
10938
|
-
}
|
|
10939
|
-
});
|
|
10940
|
-
};
|
|
10941
|
-
if (isError) {
|
|
10942
|
-
throw error;
|
|
10943
|
-
}
|
|
10944
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10945
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10946
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10947
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10948
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10949
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10950
|
-
] }),
|
|
10951
|
-
/* @__PURE__ */ jsx(
|
|
10952
|
-
Combobox,
|
|
10953
|
-
{
|
|
10954
|
-
id: "promotion-combobox",
|
|
10955
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
10956
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10957
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
10958
|
-
options: comboboxData.options,
|
|
10959
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10960
|
-
searchValue: comboboxData.searchValue,
|
|
10961
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10962
|
-
onChange: add,
|
|
10963
|
-
value: comboboxValue
|
|
10964
|
-
}
|
|
10965
|
-
)
|
|
10966
|
-
] }),
|
|
10967
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10968
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10969
|
-
PromotionItem,
|
|
10970
|
-
{
|
|
10971
|
-
promotion,
|
|
10972
|
-
orderId: preview.id,
|
|
10973
|
-
isLoading: isPending
|
|
10974
|
-
},
|
|
10975
|
-
promotion.id
|
|
10976
|
-
)) })
|
|
10977
|
-
] }) }),
|
|
10978
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10979
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10980
|
-
/* @__PURE__ */ jsx(
|
|
10981
|
-
Button,
|
|
10982
|
-
{
|
|
10983
|
-
size: "small",
|
|
10984
|
-
type: "submit",
|
|
10985
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10986
|
-
children: "Save"
|
|
10987
|
-
}
|
|
10988
|
-
)
|
|
10989
|
-
] }) })
|
|
10990
|
-
] });
|
|
10991
|
-
};
|
|
10992
|
-
const PromotionItem = ({
|
|
10993
|
-
promotion,
|
|
10994
|
-
orderId,
|
|
10995
|
-
isLoading
|
|
10996
|
-
}) => {
|
|
10997
|
-
var _a;
|
|
10998
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10999
|
-
const onRemove = async () => {
|
|
11000
|
-
removePromotions(
|
|
11001
|
-
{
|
|
11002
|
-
promo_codes: [promotion.code]
|
|
11003
|
-
},
|
|
11004
|
-
{
|
|
11005
|
-
onError: (e) => {
|
|
11006
|
-
toast.error(e.message);
|
|
11007
|
-
}
|
|
11008
|
-
}
|
|
11009
|
-
);
|
|
11010
|
-
};
|
|
11011
|
-
const displayValue = getDisplayValue(promotion);
|
|
11012
|
-
return /* @__PURE__ */ jsxs(
|
|
11013
|
-
"div",
|
|
11014
|
-
{
|
|
11015
|
-
className: clx(
|
|
11016
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11017
|
-
{
|
|
11018
|
-
"animate-pulse": isLoading
|
|
11019
|
-
}
|
|
11020
|
-
),
|
|
11021
|
-
children: [
|
|
11022
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11023
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11024
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11025
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11026
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11027
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11028
|
-
] }),
|
|
11029
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11030
|
-
] })
|
|
11031
|
-
] }),
|
|
11032
|
-
/* @__PURE__ */ jsx(
|
|
11033
|
-
IconButton,
|
|
11034
|
-
{
|
|
11035
|
-
size: "small",
|
|
11036
|
-
type: "button",
|
|
11037
|
-
variant: "transparent",
|
|
11038
|
-
onClick: onRemove,
|
|
11039
|
-
isLoading: isPending || isLoading,
|
|
11040
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11041
|
-
}
|
|
11042
|
-
)
|
|
11043
|
-
]
|
|
11044
|
-
},
|
|
11045
|
-
promotion.id
|
|
11046
|
-
);
|
|
11047
|
-
};
|
|
11048
|
-
function getDisplayValue(promotion) {
|
|
11049
|
-
var _a, _b, _c, _d;
|
|
11050
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11051
|
-
if (!value) {
|
|
11052
|
-
return null;
|
|
11053
|
-
}
|
|
11054
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11055
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11056
|
-
if (!currency) {
|
|
11057
|
-
return null;
|
|
11058
|
-
}
|
|
11059
|
-
return getLocaleAmount(value, currency);
|
|
11060
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11061
|
-
return formatPercentage(value);
|
|
11062
|
-
}
|
|
11063
|
-
return null;
|
|
11064
|
-
}
|
|
11065
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11066
|
-
style: "percent",
|
|
11067
|
-
minimumFractionDigits: 2
|
|
11068
|
-
});
|
|
11069
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11070
|
-
let val = value || 0;
|
|
11071
|
-
if (!isPercentageValue) {
|
|
11072
|
-
val = val / 100;
|
|
11073
|
-
}
|
|
11074
|
-
return formatter.format(val);
|
|
11075
|
-
};
|
|
11076
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11077
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11078
|
-
for (const item of items) {
|
|
11079
|
-
if (item.adjustments) {
|
|
11080
|
-
for (const adjustment of item.adjustments) {
|
|
11081
|
-
if (adjustment.promotion_id) {
|
|
11082
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11083
|
-
}
|
|
11084
|
-
}
|
|
11085
|
-
}
|
|
11086
|
-
}
|
|
11087
|
-
for (const shippingMethod of shippingMethods) {
|
|
11088
|
-
if (shippingMethod.adjustments) {
|
|
11089
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11090
|
-
if (adjustment.promotion_id) {
|
|
11091
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11092
|
-
}
|
|
11093
|
-
}
|
|
11094
|
-
}
|
|
11095
|
-
}
|
|
11096
|
-
return Array.from(promotionIds);
|
|
11097
|
-
}
|
|
11098
10631
|
const InlineTip = forwardRef(
|
|
11099
10632
|
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11100
10633
|
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
@@ -11420,30 +10953,307 @@ function parseValues(values) {
|
|
|
11420
10953
|
update[key] = value;
|
|
11421
10954
|
return;
|
|
11422
10955
|
}
|
|
11423
|
-
key = key.trim();
|
|
11424
|
-
value = value.trim();
|
|
11425
|
-
if (value === "true") {
|
|
11426
|
-
update[key] = true;
|
|
11427
|
-
} else if (value === "false") {
|
|
11428
|
-
update[key] = false;
|
|
11429
|
-
} else {
|
|
11430
|
-
const parsedNumber = parseFloat(value);
|
|
11431
|
-
if (!isNaN(parsedNumber)) {
|
|
11432
|
-
update[key] = parsedNumber;
|
|
11433
|
-
} else {
|
|
11434
|
-
update[key] = value;
|
|
10956
|
+
key = key.trim();
|
|
10957
|
+
value = value.trim();
|
|
10958
|
+
if (value === "true") {
|
|
10959
|
+
update[key] = true;
|
|
10960
|
+
} else if (value === "false") {
|
|
10961
|
+
update[key] = false;
|
|
10962
|
+
} else {
|
|
10963
|
+
const parsedNumber = parseFloat(value);
|
|
10964
|
+
if (!isNaN(parsedNumber)) {
|
|
10965
|
+
update[key] = parsedNumber;
|
|
10966
|
+
} else {
|
|
10967
|
+
update[key] = value;
|
|
10968
|
+
}
|
|
10969
|
+
}
|
|
10970
|
+
});
|
|
10971
|
+
return update;
|
|
10972
|
+
}
|
|
10973
|
+
function getHasUneditableRows(metadata) {
|
|
10974
|
+
if (!metadata) {
|
|
10975
|
+
return false;
|
|
10976
|
+
}
|
|
10977
|
+
return Object.values(metadata).some(
|
|
10978
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10979
|
+
);
|
|
10980
|
+
}
|
|
10981
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10982
|
+
const promotionsQueryKeys = {
|
|
10983
|
+
list: (query2) => [
|
|
10984
|
+
PROMOTION_QUERY_KEY,
|
|
10985
|
+
query2 ? query2 : void 0
|
|
10986
|
+
],
|
|
10987
|
+
detail: (id, query2) => [
|
|
10988
|
+
PROMOTION_QUERY_KEY,
|
|
10989
|
+
id,
|
|
10990
|
+
query2 ? query2 : void 0
|
|
10991
|
+
]
|
|
10992
|
+
};
|
|
10993
|
+
const usePromotions = (query2, options) => {
|
|
10994
|
+
const { data, ...rest } = useQuery({
|
|
10995
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10996
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10997
|
+
...options
|
|
10998
|
+
});
|
|
10999
|
+
return { ...data, ...rest };
|
|
11000
|
+
};
|
|
11001
|
+
const Promotions = () => {
|
|
11002
|
+
const { id } = useParams();
|
|
11003
|
+
const {
|
|
11004
|
+
order: preview,
|
|
11005
|
+
isError: isPreviewError,
|
|
11006
|
+
error: previewError
|
|
11007
|
+
} = useOrderPreview(id, void 0);
|
|
11008
|
+
useInitiateOrderEdit({ preview });
|
|
11009
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11010
|
+
if (isPreviewError) {
|
|
11011
|
+
throw previewError;
|
|
11012
|
+
}
|
|
11013
|
+
const isReady = !!preview;
|
|
11014
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11015
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11016
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11017
|
+
] });
|
|
11018
|
+
};
|
|
11019
|
+
const PromotionForm = ({ preview }) => {
|
|
11020
|
+
const { items, shipping_methods } = preview;
|
|
11021
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11022
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
11023
|
+
const { handleSuccess } = useRouteModal();
|
|
11024
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11025
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11026
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11027
|
+
{
|
|
11028
|
+
id: promoIds
|
|
11029
|
+
},
|
|
11030
|
+
{
|
|
11031
|
+
enabled: !!promoIds.length
|
|
11032
|
+
}
|
|
11033
|
+
);
|
|
11034
|
+
const comboboxData = useComboboxData({
|
|
11035
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11036
|
+
queryFn: async (params) => {
|
|
11037
|
+
return await sdk.admin.promotion.list({
|
|
11038
|
+
...params,
|
|
11039
|
+
id: {
|
|
11040
|
+
$nin: promoIds
|
|
11041
|
+
}
|
|
11042
|
+
});
|
|
11043
|
+
},
|
|
11044
|
+
getOptions: (data) => {
|
|
11045
|
+
return data.promotions.map((promotion) => ({
|
|
11046
|
+
label: promotion.code,
|
|
11047
|
+
value: promotion.code
|
|
11048
|
+
}));
|
|
11049
|
+
}
|
|
11050
|
+
});
|
|
11051
|
+
const add = async (value) => {
|
|
11052
|
+
if (!value) {
|
|
11053
|
+
return;
|
|
11054
|
+
}
|
|
11055
|
+
addPromotions(
|
|
11056
|
+
{
|
|
11057
|
+
promo_codes: [value]
|
|
11058
|
+
},
|
|
11059
|
+
{
|
|
11060
|
+
onError: (e) => {
|
|
11061
|
+
toast.error(e.message);
|
|
11062
|
+
comboboxData.onSearchValueChange("");
|
|
11063
|
+
setComboboxValue("");
|
|
11064
|
+
},
|
|
11065
|
+
onSuccess: () => {
|
|
11066
|
+
comboboxData.onSearchValueChange("");
|
|
11067
|
+
setComboboxValue("");
|
|
11068
|
+
}
|
|
11069
|
+
}
|
|
11070
|
+
);
|
|
11071
|
+
};
|
|
11072
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11073
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11074
|
+
const onSubmit = async () => {
|
|
11075
|
+
setIsSubmitting(true);
|
|
11076
|
+
let requestSucceeded = false;
|
|
11077
|
+
await requestOrderEdit(void 0, {
|
|
11078
|
+
onError: (e) => {
|
|
11079
|
+
toast.error(e.message);
|
|
11080
|
+
},
|
|
11081
|
+
onSuccess: () => {
|
|
11082
|
+
requestSucceeded = true;
|
|
11083
|
+
}
|
|
11084
|
+
});
|
|
11085
|
+
if (!requestSucceeded) {
|
|
11086
|
+
setIsSubmitting(false);
|
|
11087
|
+
return;
|
|
11088
|
+
}
|
|
11089
|
+
await confirmOrderEdit(void 0, {
|
|
11090
|
+
onError: (e) => {
|
|
11091
|
+
toast.error(e.message);
|
|
11092
|
+
},
|
|
11093
|
+
onSuccess: () => {
|
|
11094
|
+
handleSuccess();
|
|
11095
|
+
},
|
|
11096
|
+
onSettled: () => {
|
|
11097
|
+
setIsSubmitting(false);
|
|
11098
|
+
}
|
|
11099
|
+
});
|
|
11100
|
+
};
|
|
11101
|
+
if (isError) {
|
|
11102
|
+
throw error;
|
|
11103
|
+
}
|
|
11104
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11105
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11106
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11107
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11108
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11109
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11110
|
+
] }),
|
|
11111
|
+
/* @__PURE__ */ jsx(
|
|
11112
|
+
Combobox,
|
|
11113
|
+
{
|
|
11114
|
+
id: "promotion-combobox",
|
|
11115
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11116
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11117
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11118
|
+
options: comboboxData.options,
|
|
11119
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11120
|
+
searchValue: comboboxData.searchValue,
|
|
11121
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11122
|
+
onChange: add,
|
|
11123
|
+
value: comboboxValue
|
|
11124
|
+
}
|
|
11125
|
+
)
|
|
11126
|
+
] }),
|
|
11127
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11128
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11129
|
+
PromotionItem,
|
|
11130
|
+
{
|
|
11131
|
+
promotion,
|
|
11132
|
+
orderId: preview.id,
|
|
11133
|
+
isLoading: isPending
|
|
11134
|
+
},
|
|
11135
|
+
promotion.id
|
|
11136
|
+
)) })
|
|
11137
|
+
] }) }),
|
|
11138
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11139
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11140
|
+
/* @__PURE__ */ jsx(
|
|
11141
|
+
Button,
|
|
11142
|
+
{
|
|
11143
|
+
size: "small",
|
|
11144
|
+
type: "submit",
|
|
11145
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11146
|
+
children: "Save"
|
|
11147
|
+
}
|
|
11148
|
+
)
|
|
11149
|
+
] }) })
|
|
11150
|
+
] });
|
|
11151
|
+
};
|
|
11152
|
+
const PromotionItem = ({
|
|
11153
|
+
promotion,
|
|
11154
|
+
orderId,
|
|
11155
|
+
isLoading
|
|
11156
|
+
}) => {
|
|
11157
|
+
var _a;
|
|
11158
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11159
|
+
const onRemove = async () => {
|
|
11160
|
+
removePromotions(
|
|
11161
|
+
{
|
|
11162
|
+
promo_codes: [promotion.code]
|
|
11163
|
+
},
|
|
11164
|
+
{
|
|
11165
|
+
onError: (e) => {
|
|
11166
|
+
toast.error(e.message);
|
|
11167
|
+
}
|
|
11168
|
+
}
|
|
11169
|
+
);
|
|
11170
|
+
};
|
|
11171
|
+
const displayValue = getDisplayValue(promotion);
|
|
11172
|
+
return /* @__PURE__ */ jsxs(
|
|
11173
|
+
"div",
|
|
11174
|
+
{
|
|
11175
|
+
className: clx(
|
|
11176
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11177
|
+
{
|
|
11178
|
+
"animate-pulse": isLoading
|
|
11179
|
+
}
|
|
11180
|
+
),
|
|
11181
|
+
children: [
|
|
11182
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11183
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11184
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11185
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11186
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11187
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11188
|
+
] }),
|
|
11189
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11190
|
+
] })
|
|
11191
|
+
] }),
|
|
11192
|
+
/* @__PURE__ */ jsx(
|
|
11193
|
+
IconButton,
|
|
11194
|
+
{
|
|
11195
|
+
size: "small",
|
|
11196
|
+
type: "button",
|
|
11197
|
+
variant: "transparent",
|
|
11198
|
+
onClick: onRemove,
|
|
11199
|
+
isLoading: isPending || isLoading,
|
|
11200
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11201
|
+
}
|
|
11202
|
+
)
|
|
11203
|
+
]
|
|
11204
|
+
},
|
|
11205
|
+
promotion.id
|
|
11206
|
+
);
|
|
11207
|
+
};
|
|
11208
|
+
function getDisplayValue(promotion) {
|
|
11209
|
+
var _a, _b, _c, _d;
|
|
11210
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11211
|
+
if (!value) {
|
|
11212
|
+
return null;
|
|
11213
|
+
}
|
|
11214
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11215
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11216
|
+
if (!currency) {
|
|
11217
|
+
return null;
|
|
11218
|
+
}
|
|
11219
|
+
return getLocaleAmount(value, currency);
|
|
11220
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11221
|
+
return formatPercentage(value);
|
|
11222
|
+
}
|
|
11223
|
+
return null;
|
|
11224
|
+
}
|
|
11225
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11226
|
+
style: "percent",
|
|
11227
|
+
minimumFractionDigits: 2
|
|
11228
|
+
});
|
|
11229
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11230
|
+
let val = value || 0;
|
|
11231
|
+
if (!isPercentageValue) {
|
|
11232
|
+
val = val / 100;
|
|
11233
|
+
}
|
|
11234
|
+
return formatter.format(val);
|
|
11235
|
+
};
|
|
11236
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11237
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11238
|
+
for (const item of items) {
|
|
11239
|
+
if (item.adjustments) {
|
|
11240
|
+
for (const adjustment of item.adjustments) {
|
|
11241
|
+
if (adjustment.promotion_id) {
|
|
11242
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11243
|
+
}
|
|
11244
|
+
}
|
|
11245
|
+
}
|
|
11246
|
+
}
|
|
11247
|
+
for (const shippingMethod of shippingMethods) {
|
|
11248
|
+
if (shippingMethod.adjustments) {
|
|
11249
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11250
|
+
if (adjustment.promotion_id) {
|
|
11251
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11252
|
+
}
|
|
11435
11253
|
}
|
|
11436
11254
|
}
|
|
11437
|
-
});
|
|
11438
|
-
return update;
|
|
11439
|
-
}
|
|
11440
|
-
function getHasUneditableRows(metadata) {
|
|
11441
|
-
if (!metadata) {
|
|
11442
|
-
return false;
|
|
11443
11255
|
}
|
|
11444
|
-
return
|
|
11445
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11446
|
-
);
|
|
11256
|
+
return Array.from(promotionIds);
|
|
11447
11257
|
}
|
|
11448
11258
|
const SalesChannel = () => {
|
|
11449
11259
|
const { id } = useParams();
|
|
@@ -11473,7 +11283,7 @@ const SalesChannelForm = ({ order }) => {
|
|
|
11473
11283
|
defaultValues: {
|
|
11474
11284
|
sales_channel_id: order.sales_channel_id || ""
|
|
11475
11285
|
},
|
|
11476
|
-
resolver: zodResolver(schema$
|
|
11286
|
+
resolver: zodResolver(schema$3)
|
|
11477
11287
|
});
|
|
11478
11288
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11479
11289
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11548,7 +11358,7 @@ const SalesChannelField = ({ control, order }) => {
|
|
|
11548
11358
|
}
|
|
11549
11359
|
);
|
|
11550
11360
|
};
|
|
11551
|
-
const schema$
|
|
11361
|
+
const schema$3 = objectType({
|
|
11552
11362
|
sales_channel_id: stringType().min(1)
|
|
11553
11363
|
});
|
|
11554
11364
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
@@ -12390,7 +12200,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12390
12200
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12391
12201
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12392
12202
|
},
|
|
12393
|
-
resolver: zodResolver(schema$
|
|
12203
|
+
resolver: zodResolver(schema$2)
|
|
12394
12204
|
});
|
|
12395
12205
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12396
12206
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12560,7 +12370,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12560
12370
|
}
|
|
12561
12371
|
) });
|
|
12562
12372
|
};
|
|
12563
|
-
const schema$
|
|
12373
|
+
const schema$2 = addressSchema;
|
|
12564
12374
|
const TransferOwnership = () => {
|
|
12565
12375
|
const { id } = useParams();
|
|
12566
12376
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12584,7 +12394,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12584
12394
|
defaultValues: {
|
|
12585
12395
|
customer_id: order.customer_id || ""
|
|
12586
12396
|
},
|
|
12587
|
-
resolver: zodResolver(schema)
|
|
12397
|
+
resolver: zodResolver(schema$1)
|
|
12588
12398
|
});
|
|
12589
12399
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12590
12400
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13034,9 +12844,199 @@ const Illustration = () => {
|
|
|
13034
12844
|
}
|
|
13035
12845
|
);
|
|
13036
12846
|
};
|
|
13037
|
-
const schema = objectType({
|
|
12847
|
+
const schema$1 = objectType({
|
|
13038
12848
|
customer_id: stringType().min(1)
|
|
13039
12849
|
});
|
|
12850
|
+
const BillingAddress = () => {
|
|
12851
|
+
const { id } = useParams();
|
|
12852
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12853
|
+
fields: "+billing_address"
|
|
12854
|
+
});
|
|
12855
|
+
if (isError) {
|
|
12856
|
+
throw error;
|
|
12857
|
+
}
|
|
12858
|
+
const isReady = !isPending && !!order;
|
|
12859
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12860
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12861
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
12862
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
12863
|
+
] }),
|
|
12864
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
12865
|
+
] });
|
|
12866
|
+
};
|
|
12867
|
+
const BillingAddressForm = ({ order }) => {
|
|
12868
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12869
|
+
const form = useForm({
|
|
12870
|
+
defaultValues: {
|
|
12871
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12872
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12873
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
12874
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12875
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12876
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
12877
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
12878
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12879
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12880
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
12881
|
+
},
|
|
12882
|
+
resolver: zodResolver(schema)
|
|
12883
|
+
});
|
|
12884
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12885
|
+
const { handleSuccess } = useRouteModal();
|
|
12886
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12887
|
+
await mutateAsync(
|
|
12888
|
+
{ billing_address: data },
|
|
12889
|
+
{
|
|
12890
|
+
onSuccess: () => {
|
|
12891
|
+
handleSuccess();
|
|
12892
|
+
},
|
|
12893
|
+
onError: (error) => {
|
|
12894
|
+
toast.error(error.message);
|
|
12895
|
+
}
|
|
12896
|
+
}
|
|
12897
|
+
);
|
|
12898
|
+
});
|
|
12899
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12900
|
+
KeyboundForm,
|
|
12901
|
+
{
|
|
12902
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12903
|
+
onSubmit,
|
|
12904
|
+
children: [
|
|
12905
|
+
/* @__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: [
|
|
12906
|
+
/* @__PURE__ */ jsx(
|
|
12907
|
+
Form$2.Field,
|
|
12908
|
+
{
|
|
12909
|
+
control: form.control,
|
|
12910
|
+
name: "country_code",
|
|
12911
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12912
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12913
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12914
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12915
|
+
] })
|
|
12916
|
+
}
|
|
12917
|
+
),
|
|
12918
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12919
|
+
/* @__PURE__ */ jsx(
|
|
12920
|
+
Form$2.Field,
|
|
12921
|
+
{
|
|
12922
|
+
control: form.control,
|
|
12923
|
+
name: "first_name",
|
|
12924
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12925
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12926
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12927
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12928
|
+
] })
|
|
12929
|
+
}
|
|
12930
|
+
),
|
|
12931
|
+
/* @__PURE__ */ jsx(
|
|
12932
|
+
Form$2.Field,
|
|
12933
|
+
{
|
|
12934
|
+
control: form.control,
|
|
12935
|
+
name: "last_name",
|
|
12936
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12937
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12938
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12939
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12940
|
+
] })
|
|
12941
|
+
}
|
|
12942
|
+
)
|
|
12943
|
+
] }),
|
|
12944
|
+
/* @__PURE__ */ jsx(
|
|
12945
|
+
Form$2.Field,
|
|
12946
|
+
{
|
|
12947
|
+
control: form.control,
|
|
12948
|
+
name: "company",
|
|
12949
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12950
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12951
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12952
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12953
|
+
] })
|
|
12954
|
+
}
|
|
12955
|
+
),
|
|
12956
|
+
/* @__PURE__ */ jsx(
|
|
12957
|
+
Form$2.Field,
|
|
12958
|
+
{
|
|
12959
|
+
control: form.control,
|
|
12960
|
+
name: "address_1",
|
|
12961
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12962
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12963
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12964
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12965
|
+
] })
|
|
12966
|
+
}
|
|
12967
|
+
),
|
|
12968
|
+
/* @__PURE__ */ jsx(
|
|
12969
|
+
Form$2.Field,
|
|
12970
|
+
{
|
|
12971
|
+
control: form.control,
|
|
12972
|
+
name: "address_2",
|
|
12973
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12974
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12975
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12976
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12977
|
+
] })
|
|
12978
|
+
}
|
|
12979
|
+
),
|
|
12980
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12981
|
+
/* @__PURE__ */ jsx(
|
|
12982
|
+
Form$2.Field,
|
|
12983
|
+
{
|
|
12984
|
+
control: form.control,
|
|
12985
|
+
name: "postal_code",
|
|
12986
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12987
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12988
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12989
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12990
|
+
] })
|
|
12991
|
+
}
|
|
12992
|
+
),
|
|
12993
|
+
/* @__PURE__ */ jsx(
|
|
12994
|
+
Form$2.Field,
|
|
12995
|
+
{
|
|
12996
|
+
control: form.control,
|
|
12997
|
+
name: "city",
|
|
12998
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12999
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
13000
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13001
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13002
|
+
] })
|
|
13003
|
+
}
|
|
13004
|
+
)
|
|
13005
|
+
] }),
|
|
13006
|
+
/* @__PURE__ */ jsx(
|
|
13007
|
+
Form$2.Field,
|
|
13008
|
+
{
|
|
13009
|
+
control: form.control,
|
|
13010
|
+
name: "province",
|
|
13011
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13012
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
13013
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13014
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13015
|
+
] })
|
|
13016
|
+
}
|
|
13017
|
+
),
|
|
13018
|
+
/* @__PURE__ */ jsx(
|
|
13019
|
+
Form$2.Field,
|
|
13020
|
+
{
|
|
13021
|
+
control: form.control,
|
|
13022
|
+
name: "phone",
|
|
13023
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13024
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
13025
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13026
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13027
|
+
] })
|
|
13028
|
+
}
|
|
13029
|
+
)
|
|
13030
|
+
] }) }),
|
|
13031
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13032
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13033
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13034
|
+
] }) })
|
|
13035
|
+
]
|
|
13036
|
+
}
|
|
13037
|
+
) });
|
|
13038
|
+
};
|
|
13039
|
+
const schema = addressSchema;
|
|
13040
13040
|
const widgetModule = { widgets: [] };
|
|
13041
13041
|
const routeModule = {
|
|
13042
13042
|
routes: [
|
|
@@ -13057,10 +13057,6 @@ const routeModule = {
|
|
|
13057
13057
|
handle,
|
|
13058
13058
|
loader,
|
|
13059
13059
|
children: [
|
|
13060
|
-
{
|
|
13061
|
-
Component: BillingAddress,
|
|
13062
|
-
path: "/draft-orders/:id/billing-address"
|
|
13063
|
-
},
|
|
13064
13060
|
{
|
|
13065
13061
|
Component: CustomItems,
|
|
13066
13062
|
path: "/draft-orders/:id/custom-items"
|
|
@@ -13073,14 +13069,14 @@ const routeModule = {
|
|
|
13073
13069
|
Component: Items,
|
|
13074
13070
|
path: "/draft-orders/:id/items"
|
|
13075
13071
|
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: Promotions,
|
|
13078
|
-
path: "/draft-orders/:id/promotions"
|
|
13079
|
-
},
|
|
13080
13072
|
{
|
|
13081
13073
|
Component: Metadata,
|
|
13082
13074
|
path: "/draft-orders/:id/metadata"
|
|
13083
13075
|
},
|
|
13076
|
+
{
|
|
13077
|
+
Component: Promotions,
|
|
13078
|
+
path: "/draft-orders/:id/promotions"
|
|
13079
|
+
},
|
|
13084
13080
|
{
|
|
13085
13081
|
Component: SalesChannel,
|
|
13086
13082
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13096,6 +13092,10 @@ const routeModule = {
|
|
|
13096
13092
|
{
|
|
13097
13093
|
Component: TransferOwnership,
|
|
13098
13094
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
|
+
},
|
|
13096
|
+
{
|
|
13097
|
+
Component: BillingAddress,
|
|
13098
|
+
path: "/draft-orders/:id/billing-address"
|
|
13099
13099
|
}
|
|
13100
13100
|
]
|
|
13101
13101
|
}
|