@medusajs/draft-order 2.10.0-snapshot-20250827070327 → 2.10.0-snapshot-20250827144020
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 +473 -473
- package/.medusa/server/src/admin/index.mjs +473 -473
- package/package.json +18 -18
|
@@ -9554,6 +9554,196 @@ const ID = () => {
|
|
|
9554
9554
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9555
9555
|
] });
|
|
9556
9556
|
};
|
|
9557
|
+
const BillingAddress = () => {
|
|
9558
|
+
const { id } = useParams();
|
|
9559
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9560
|
+
fields: "+billing_address"
|
|
9561
|
+
});
|
|
9562
|
+
if (isError) {
|
|
9563
|
+
throw error;
|
|
9564
|
+
}
|
|
9565
|
+
const isReady = !isPending && !!order;
|
|
9566
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9567
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9568
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
9569
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9570
|
+
] }),
|
|
9571
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
9572
|
+
] });
|
|
9573
|
+
};
|
|
9574
|
+
const BillingAddressForm = ({ order }) => {
|
|
9575
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9576
|
+
const form = useForm({
|
|
9577
|
+
defaultValues: {
|
|
9578
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9579
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9580
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9581
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9582
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9583
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9584
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9585
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9586
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9587
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9588
|
+
},
|
|
9589
|
+
resolver: zodResolver(schema$5)
|
|
9590
|
+
});
|
|
9591
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9592
|
+
const { handleSuccess } = useRouteModal();
|
|
9593
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9594
|
+
await mutateAsync(
|
|
9595
|
+
{ billing_address: data },
|
|
9596
|
+
{
|
|
9597
|
+
onSuccess: () => {
|
|
9598
|
+
handleSuccess();
|
|
9599
|
+
},
|
|
9600
|
+
onError: (error) => {
|
|
9601
|
+
toast.error(error.message);
|
|
9602
|
+
}
|
|
9603
|
+
}
|
|
9604
|
+
);
|
|
9605
|
+
});
|
|
9606
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9607
|
+
KeyboundForm,
|
|
9608
|
+
{
|
|
9609
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9610
|
+
onSubmit,
|
|
9611
|
+
children: [
|
|
9612
|
+
/* @__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: [
|
|
9613
|
+
/* @__PURE__ */ jsx(
|
|
9614
|
+
Form$2.Field,
|
|
9615
|
+
{
|
|
9616
|
+
control: form.control,
|
|
9617
|
+
name: "country_code",
|
|
9618
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9619
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
9620
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
9621
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9622
|
+
] })
|
|
9623
|
+
}
|
|
9624
|
+
),
|
|
9625
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9626
|
+
/* @__PURE__ */ jsx(
|
|
9627
|
+
Form$2.Field,
|
|
9628
|
+
{
|
|
9629
|
+
control: form.control,
|
|
9630
|
+
name: "first_name",
|
|
9631
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9632
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
9633
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9634
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9635
|
+
] })
|
|
9636
|
+
}
|
|
9637
|
+
),
|
|
9638
|
+
/* @__PURE__ */ jsx(
|
|
9639
|
+
Form$2.Field,
|
|
9640
|
+
{
|
|
9641
|
+
control: form.control,
|
|
9642
|
+
name: "last_name",
|
|
9643
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9644
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
9645
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9646
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9647
|
+
] })
|
|
9648
|
+
}
|
|
9649
|
+
)
|
|
9650
|
+
] }),
|
|
9651
|
+
/* @__PURE__ */ jsx(
|
|
9652
|
+
Form$2.Field,
|
|
9653
|
+
{
|
|
9654
|
+
control: form.control,
|
|
9655
|
+
name: "company",
|
|
9656
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9657
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9658
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9659
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9660
|
+
] })
|
|
9661
|
+
}
|
|
9662
|
+
),
|
|
9663
|
+
/* @__PURE__ */ jsx(
|
|
9664
|
+
Form$2.Field,
|
|
9665
|
+
{
|
|
9666
|
+
control: form.control,
|
|
9667
|
+
name: "address_1",
|
|
9668
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9669
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
9670
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9671
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9672
|
+
] })
|
|
9673
|
+
}
|
|
9674
|
+
),
|
|
9675
|
+
/* @__PURE__ */ jsx(
|
|
9676
|
+
Form$2.Field,
|
|
9677
|
+
{
|
|
9678
|
+
control: form.control,
|
|
9679
|
+
name: "address_2",
|
|
9680
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9681
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9682
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9683
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9684
|
+
] })
|
|
9685
|
+
}
|
|
9686
|
+
),
|
|
9687
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9688
|
+
/* @__PURE__ */ jsx(
|
|
9689
|
+
Form$2.Field,
|
|
9690
|
+
{
|
|
9691
|
+
control: form.control,
|
|
9692
|
+
name: "postal_code",
|
|
9693
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9694
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
9695
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9696
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9697
|
+
] })
|
|
9698
|
+
}
|
|
9699
|
+
),
|
|
9700
|
+
/* @__PURE__ */ jsx(
|
|
9701
|
+
Form$2.Field,
|
|
9702
|
+
{
|
|
9703
|
+
control: form.control,
|
|
9704
|
+
name: "city",
|
|
9705
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9706
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
9707
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9708
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9709
|
+
] })
|
|
9710
|
+
}
|
|
9711
|
+
)
|
|
9712
|
+
] }),
|
|
9713
|
+
/* @__PURE__ */ jsx(
|
|
9714
|
+
Form$2.Field,
|
|
9715
|
+
{
|
|
9716
|
+
control: form.control,
|
|
9717
|
+
name: "province",
|
|
9718
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9719
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9720
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9721
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9722
|
+
] })
|
|
9723
|
+
}
|
|
9724
|
+
),
|
|
9725
|
+
/* @__PURE__ */ jsx(
|
|
9726
|
+
Form$2.Field,
|
|
9727
|
+
{
|
|
9728
|
+
control: form.control,
|
|
9729
|
+
name: "phone",
|
|
9730
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9731
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9732
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9733
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9734
|
+
] })
|
|
9735
|
+
}
|
|
9736
|
+
)
|
|
9737
|
+
] }) }),
|
|
9738
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9739
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9740
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9741
|
+
] }) })
|
|
9742
|
+
]
|
|
9743
|
+
}
|
|
9744
|
+
) });
|
|
9745
|
+
};
|
|
9746
|
+
const schema$5 = addressSchema;
|
|
9557
9747
|
const CustomItems = () => {
|
|
9558
9748
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9559
9749
|
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
@@ -9562,7 +9752,7 @@ const CustomItems = () => {
|
|
|
9562
9752
|
};
|
|
9563
9753
|
const CustomItemsForm = () => {
|
|
9564
9754
|
const form = useForm({
|
|
9565
|
-
resolver: zodResolver(schema$
|
|
9755
|
+
resolver: zodResolver(schema$4)
|
|
9566
9756
|
});
|
|
9567
9757
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9568
9758
|
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
@@ -9572,46 +9762,114 @@ const CustomItemsForm = () => {
|
|
|
9572
9762
|
] }) })
|
|
9573
9763
|
] }) });
|
|
9574
9764
|
};
|
|
9575
|
-
const schema$
|
|
9765
|
+
const schema$4 = objectType({
|
|
9576
9766
|
email: stringType().email()
|
|
9577
9767
|
});
|
|
9578
|
-
const
|
|
9579
|
-
(
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
}
|
|
9607
|
-
};
|
|
9608
|
-
return /* @__PURE__ */ jsxs(
|
|
9609
|
-
"div",
|
|
9768
|
+
const Email = () => {
|
|
9769
|
+
const { id } = useParams();
|
|
9770
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9771
|
+
fields: "+email"
|
|
9772
|
+
});
|
|
9773
|
+
if (isError) {
|
|
9774
|
+
throw error;
|
|
9775
|
+
}
|
|
9776
|
+
const isReady = !isPending && !!order;
|
|
9777
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9778
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9779
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
9780
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9781
|
+
] }),
|
|
9782
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
9783
|
+
] });
|
|
9784
|
+
};
|
|
9785
|
+
const EmailForm = ({ order }) => {
|
|
9786
|
+
const form = useForm({
|
|
9787
|
+
defaultValues: {
|
|
9788
|
+
email: order.email ?? ""
|
|
9789
|
+
},
|
|
9790
|
+
resolver: zodResolver(schema$3)
|
|
9791
|
+
});
|
|
9792
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9793
|
+
const { handleSuccess } = useRouteModal();
|
|
9794
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9795
|
+
await mutateAsync(
|
|
9796
|
+
{ email: data.email },
|
|
9610
9797
|
{
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9798
|
+
onSuccess: () => {
|
|
9799
|
+
handleSuccess();
|
|
9800
|
+
},
|
|
9801
|
+
onError: (error) => {
|
|
9802
|
+
toast.error(error.message);
|
|
9803
|
+
}
|
|
9804
|
+
}
|
|
9805
|
+
);
|
|
9806
|
+
});
|
|
9807
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9808
|
+
KeyboundForm,
|
|
9809
|
+
{
|
|
9810
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9811
|
+
onSubmit,
|
|
9812
|
+
children: [
|
|
9813
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
9814
|
+
Form$2.Field,
|
|
9815
|
+
{
|
|
9816
|
+
control: form.control,
|
|
9817
|
+
name: "email",
|
|
9818
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9819
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
9820
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9821
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9822
|
+
] })
|
|
9823
|
+
}
|
|
9824
|
+
) }),
|
|
9825
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9826
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9827
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9828
|
+
] }) })
|
|
9829
|
+
]
|
|
9830
|
+
}
|
|
9831
|
+
) });
|
|
9832
|
+
};
|
|
9833
|
+
const schema$3 = objectType({
|
|
9834
|
+
email: stringType().email()
|
|
9835
|
+
});
|
|
9836
|
+
const NumberInput = forwardRef(
|
|
9837
|
+
({
|
|
9838
|
+
value,
|
|
9839
|
+
onChange,
|
|
9840
|
+
size = "base",
|
|
9841
|
+
min = 0,
|
|
9842
|
+
max = 100,
|
|
9843
|
+
step = 1,
|
|
9844
|
+
className,
|
|
9845
|
+
disabled,
|
|
9846
|
+
...props
|
|
9847
|
+
}, ref) => {
|
|
9848
|
+
const handleChange = (event) => {
|
|
9849
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
9850
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
9851
|
+
onChange(newValue);
|
|
9852
|
+
}
|
|
9853
|
+
};
|
|
9854
|
+
const handleIncrement = () => {
|
|
9855
|
+
const newValue = value + step;
|
|
9856
|
+
if (max === void 0 || newValue <= max) {
|
|
9857
|
+
onChange(newValue);
|
|
9858
|
+
}
|
|
9859
|
+
};
|
|
9860
|
+
const handleDecrement = () => {
|
|
9861
|
+
const newValue = value - step;
|
|
9862
|
+
if (min === void 0 || newValue >= min) {
|
|
9863
|
+
onChange(newValue);
|
|
9864
|
+
}
|
|
9865
|
+
};
|
|
9866
|
+
return /* @__PURE__ */ jsxs(
|
|
9867
|
+
"div",
|
|
9868
|
+
{
|
|
9869
|
+
className: clx(
|
|
9870
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
9871
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
9872
|
+
{
|
|
9615
9873
|
"h-7": size === "small",
|
|
9616
9874
|
"h-8": size === "base"
|
|
9617
9875
|
},
|
|
@@ -11010,362 +11268,172 @@ const PromotionForm = ({ preview }) => {
|
|
|
11010
11268
|
await confirmOrderEdit(void 0, {
|
|
11011
11269
|
onError: (e) => {
|
|
11012
11270
|
toast.error(e.message);
|
|
11013
|
-
},
|
|
11014
|
-
onSuccess: () => {
|
|
11015
|
-
handleSuccess();
|
|
11016
|
-
},
|
|
11017
|
-
onSettled: () => {
|
|
11018
|
-
setIsSubmitting(false);
|
|
11019
|
-
}
|
|
11020
|
-
});
|
|
11021
|
-
};
|
|
11022
|
-
if (isError) {
|
|
11023
|
-
throw error;
|
|
11024
|
-
}
|
|
11025
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11026
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11027
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11028
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11029
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11030
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11031
|
-
] }),
|
|
11032
|
-
/* @__PURE__ */ jsx(
|
|
11033
|
-
Combobox,
|
|
11034
|
-
{
|
|
11035
|
-
id: "promotion-combobox",
|
|
11036
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11037
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11038
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11039
|
-
options: comboboxData.options,
|
|
11040
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11041
|
-
searchValue: comboboxData.searchValue,
|
|
11042
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11043
|
-
onChange: add,
|
|
11044
|
-
value: comboboxValue
|
|
11045
|
-
}
|
|
11046
|
-
)
|
|
11047
|
-
] }),
|
|
11048
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11049
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11050
|
-
PromotionItem,
|
|
11051
|
-
{
|
|
11052
|
-
promotion,
|
|
11053
|
-
orderId: preview.id,
|
|
11054
|
-
isLoading: isPending
|
|
11055
|
-
},
|
|
11056
|
-
promotion.id
|
|
11057
|
-
)) })
|
|
11058
|
-
] }) }),
|
|
11059
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11060
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11061
|
-
/* @__PURE__ */ jsx(
|
|
11062
|
-
Button,
|
|
11063
|
-
{
|
|
11064
|
-
size: "small",
|
|
11065
|
-
type: "submit",
|
|
11066
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11067
|
-
children: "Save"
|
|
11068
|
-
}
|
|
11069
|
-
)
|
|
11070
|
-
] }) })
|
|
11071
|
-
] });
|
|
11072
|
-
};
|
|
11073
|
-
const PromotionItem = ({
|
|
11074
|
-
promotion,
|
|
11075
|
-
orderId,
|
|
11076
|
-
isLoading
|
|
11077
|
-
}) => {
|
|
11078
|
-
var _a;
|
|
11079
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11080
|
-
const onRemove = async () => {
|
|
11081
|
-
removePromotions(
|
|
11082
|
-
{
|
|
11083
|
-
promo_codes: [promotion.code]
|
|
11084
|
-
},
|
|
11085
|
-
{
|
|
11086
|
-
onError: (e) => {
|
|
11087
|
-
toast.error(e.message);
|
|
11088
|
-
}
|
|
11089
|
-
}
|
|
11090
|
-
);
|
|
11091
|
-
};
|
|
11092
|
-
const displayValue = getDisplayValue(promotion);
|
|
11093
|
-
return /* @__PURE__ */ jsxs(
|
|
11094
|
-
"div",
|
|
11095
|
-
{
|
|
11096
|
-
className: clx(
|
|
11097
|
-
"px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
|
|
11098
|
-
{
|
|
11099
|
-
"animate-pulse": isLoading
|
|
11100
|
-
}
|
|
11101
|
-
),
|
|
11102
|
-
children: [
|
|
11103
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11104
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11105
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
|
|
11106
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11107
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11108
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11109
|
-
] }),
|
|
11110
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11111
|
-
] })
|
|
11112
|
-
] }),
|
|
11113
|
-
/* @__PURE__ */ jsx(
|
|
11114
|
-
IconButton,
|
|
11115
|
-
{
|
|
11116
|
-
size: "small",
|
|
11117
|
-
type: "button",
|
|
11118
|
-
variant: "transparent",
|
|
11119
|
-
onClick: onRemove,
|
|
11120
|
-
isLoading: isPending || isLoading,
|
|
11121
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11122
|
-
}
|
|
11123
|
-
)
|
|
11124
|
-
]
|
|
11125
|
-
},
|
|
11126
|
-
promotion.id
|
|
11127
|
-
);
|
|
11128
|
-
};
|
|
11129
|
-
function getDisplayValue(promotion) {
|
|
11130
|
-
var _a, _b, _c, _d;
|
|
11131
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11132
|
-
if (!value) {
|
|
11133
|
-
return null;
|
|
11134
|
-
}
|
|
11135
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11136
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11137
|
-
if (!currency) {
|
|
11138
|
-
return null;
|
|
11139
|
-
}
|
|
11140
|
-
return getLocaleAmount(value, currency);
|
|
11141
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11142
|
-
return formatPercentage(value);
|
|
11143
|
-
}
|
|
11144
|
-
return null;
|
|
11145
|
-
}
|
|
11146
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11147
|
-
style: "percent",
|
|
11148
|
-
minimumFractionDigits: 2
|
|
11149
|
-
});
|
|
11150
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11151
|
-
let val = value || 0;
|
|
11152
|
-
if (!isPercentageValue) {
|
|
11153
|
-
val = val / 100;
|
|
11154
|
-
}
|
|
11155
|
-
return formatter.format(val);
|
|
11156
|
-
};
|
|
11157
|
-
function getPromotionCodes(items, shippingMethods) {
|
|
11158
|
-
const codes = /* @__PURE__ */ new Set();
|
|
11159
|
-
for (const item of items) {
|
|
11160
|
-
if (item.adjustments) {
|
|
11161
|
-
for (const adjustment of item.adjustments) {
|
|
11162
|
-
if (adjustment.code) {
|
|
11163
|
-
codes.add(adjustment.code);
|
|
11164
|
-
}
|
|
11165
|
-
}
|
|
11166
|
-
}
|
|
11167
|
-
}
|
|
11168
|
-
for (const shippingMethod of shippingMethods) {
|
|
11169
|
-
if (shippingMethod.adjustments) {
|
|
11170
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11171
|
-
if (adjustment.code) {
|
|
11172
|
-
codes.add(adjustment.code);
|
|
11173
|
-
}
|
|
11174
|
-
}
|
|
11175
|
-
}
|
|
11176
|
-
}
|
|
11177
|
-
return Array.from(codes);
|
|
11178
|
-
}
|
|
11179
|
-
const BillingAddress = () => {
|
|
11180
|
-
const { id } = useParams();
|
|
11181
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11182
|
-
fields: "+billing_address"
|
|
11183
|
-
});
|
|
11184
|
-
if (isError) {
|
|
11185
|
-
throw error;
|
|
11186
|
-
}
|
|
11187
|
-
const isReady = !isPending && !!order;
|
|
11188
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11189
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11190
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
11191
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
11192
|
-
] }),
|
|
11193
|
-
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
11194
|
-
] });
|
|
11195
|
-
};
|
|
11196
|
-
const BillingAddressForm = ({ order }) => {
|
|
11197
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
11198
|
-
const form = useForm({
|
|
11199
|
-
defaultValues: {
|
|
11200
|
-
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
11201
|
-
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
11202
|
-
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
11203
|
-
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
11204
|
-
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
11205
|
-
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
11206
|
-
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
11207
|
-
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
11208
|
-
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11209
|
-
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
11210
|
-
},
|
|
11211
|
-
resolver: zodResolver(schema$4)
|
|
11212
|
-
});
|
|
11213
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11214
|
-
const { handleSuccess } = useRouteModal();
|
|
11215
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11216
|
-
await mutateAsync(
|
|
11217
|
-
{ billing_address: data },
|
|
11218
|
-
{
|
|
11219
|
-
onSuccess: () => {
|
|
11220
|
-
handleSuccess();
|
|
11221
|
-
},
|
|
11222
|
-
onError: (error) => {
|
|
11223
|
-
toast.error(error.message);
|
|
11224
|
-
}
|
|
11225
|
-
}
|
|
11226
|
-
);
|
|
11227
|
-
});
|
|
11228
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11229
|
-
KeyboundForm,
|
|
11230
|
-
{
|
|
11231
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11232
|
-
onSubmit,
|
|
11233
|
-
children: [
|
|
11234
|
-
/* @__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: [
|
|
11235
|
-
/* @__PURE__ */ jsx(
|
|
11236
|
-
Form$2.Field,
|
|
11237
|
-
{
|
|
11238
|
-
control: form.control,
|
|
11239
|
-
name: "country_code",
|
|
11240
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11241
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
11242
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
11243
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11244
|
-
] })
|
|
11245
|
-
}
|
|
11246
|
-
),
|
|
11247
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11248
|
-
/* @__PURE__ */ jsx(
|
|
11249
|
-
Form$2.Field,
|
|
11250
|
-
{
|
|
11251
|
-
control: form.control,
|
|
11252
|
-
name: "first_name",
|
|
11253
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11254
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
11255
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11256
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11257
|
-
] })
|
|
11258
|
-
}
|
|
11259
|
-
),
|
|
11260
|
-
/* @__PURE__ */ jsx(
|
|
11261
|
-
Form$2.Field,
|
|
11262
|
-
{
|
|
11263
|
-
control: form.control,
|
|
11264
|
-
name: "last_name",
|
|
11265
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11266
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
11267
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11268
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11269
|
-
] })
|
|
11270
|
-
}
|
|
11271
|
-
)
|
|
11272
|
-
] }),
|
|
11273
|
-
/* @__PURE__ */ jsx(
|
|
11274
|
-
Form$2.Field,
|
|
11275
|
-
{
|
|
11276
|
-
control: form.control,
|
|
11277
|
-
name: "company",
|
|
11278
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11279
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
11280
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11281
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11282
|
-
] })
|
|
11283
|
-
}
|
|
11284
|
-
),
|
|
11285
|
-
/* @__PURE__ */ jsx(
|
|
11286
|
-
Form$2.Field,
|
|
11287
|
-
{
|
|
11288
|
-
control: form.control,
|
|
11289
|
-
name: "address_1",
|
|
11290
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11291
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
11292
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11293
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11294
|
-
] })
|
|
11295
|
-
}
|
|
11296
|
-
),
|
|
11297
|
-
/* @__PURE__ */ jsx(
|
|
11298
|
-
Form$2.Field,
|
|
11299
|
-
{
|
|
11300
|
-
control: form.control,
|
|
11301
|
-
name: "address_2",
|
|
11302
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11303
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
11304
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11305
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11306
|
-
] })
|
|
11307
|
-
}
|
|
11308
|
-
),
|
|
11309
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11310
|
-
/* @__PURE__ */ jsx(
|
|
11311
|
-
Form$2.Field,
|
|
11312
|
-
{
|
|
11313
|
-
control: form.control,
|
|
11314
|
-
name: "postal_code",
|
|
11315
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11316
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
11317
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11318
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11319
|
-
] })
|
|
11320
|
-
}
|
|
11321
|
-
),
|
|
11322
|
-
/* @__PURE__ */ jsx(
|
|
11323
|
-
Form$2.Field,
|
|
11324
|
-
{
|
|
11325
|
-
control: form.control,
|
|
11326
|
-
name: "city",
|
|
11327
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11328
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
11329
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11330
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11331
|
-
] })
|
|
11332
|
-
}
|
|
11333
|
-
)
|
|
11334
|
-
] }),
|
|
11335
|
-
/* @__PURE__ */ jsx(
|
|
11336
|
-
Form$2.Field,
|
|
11337
|
-
{
|
|
11338
|
-
control: form.control,
|
|
11339
|
-
name: "province",
|
|
11340
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11341
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
11342
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11343
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11344
|
-
] })
|
|
11345
|
-
}
|
|
11346
|
-
),
|
|
11347
|
-
/* @__PURE__ */ jsx(
|
|
11348
|
-
Form$2.Field,
|
|
11349
|
-
{
|
|
11350
|
-
control: form.control,
|
|
11351
|
-
name: "phone",
|
|
11352
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11353
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
11354
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11355
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11356
|
-
] })
|
|
11357
|
-
}
|
|
11358
|
-
)
|
|
11359
|
-
] }) }),
|
|
11360
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11361
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11362
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11363
|
-
] }) })
|
|
11271
|
+
},
|
|
11272
|
+
onSuccess: () => {
|
|
11273
|
+
handleSuccess();
|
|
11274
|
+
},
|
|
11275
|
+
onSettled: () => {
|
|
11276
|
+
setIsSubmitting(false);
|
|
11277
|
+
}
|
|
11278
|
+
});
|
|
11279
|
+
};
|
|
11280
|
+
if (isError) {
|
|
11281
|
+
throw error;
|
|
11282
|
+
}
|
|
11283
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11284
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11285
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11286
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11287
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11288
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11289
|
+
] }),
|
|
11290
|
+
/* @__PURE__ */ jsx(
|
|
11291
|
+
Combobox,
|
|
11292
|
+
{
|
|
11293
|
+
id: "promotion-combobox",
|
|
11294
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11295
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11296
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11297
|
+
options: comboboxData.options,
|
|
11298
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11299
|
+
searchValue: comboboxData.searchValue,
|
|
11300
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11301
|
+
onChange: add,
|
|
11302
|
+
value: comboboxValue
|
|
11303
|
+
}
|
|
11304
|
+
)
|
|
11305
|
+
] }),
|
|
11306
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11307
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11308
|
+
PromotionItem,
|
|
11309
|
+
{
|
|
11310
|
+
promotion,
|
|
11311
|
+
orderId: preview.id,
|
|
11312
|
+
isLoading: isPending
|
|
11313
|
+
},
|
|
11314
|
+
promotion.id
|
|
11315
|
+
)) })
|
|
11316
|
+
] }) }),
|
|
11317
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11318
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11319
|
+
/* @__PURE__ */ jsx(
|
|
11320
|
+
Button,
|
|
11321
|
+
{
|
|
11322
|
+
size: "small",
|
|
11323
|
+
type: "submit",
|
|
11324
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11325
|
+
children: "Save"
|
|
11326
|
+
}
|
|
11327
|
+
)
|
|
11328
|
+
] }) })
|
|
11329
|
+
] });
|
|
11330
|
+
};
|
|
11331
|
+
const PromotionItem = ({
|
|
11332
|
+
promotion,
|
|
11333
|
+
orderId,
|
|
11334
|
+
isLoading
|
|
11335
|
+
}) => {
|
|
11336
|
+
var _a;
|
|
11337
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11338
|
+
const onRemove = async () => {
|
|
11339
|
+
removePromotions(
|
|
11340
|
+
{
|
|
11341
|
+
promo_codes: [promotion.code]
|
|
11342
|
+
},
|
|
11343
|
+
{
|
|
11344
|
+
onError: (e) => {
|
|
11345
|
+
toast.error(e.message);
|
|
11346
|
+
}
|
|
11347
|
+
}
|
|
11348
|
+
);
|
|
11349
|
+
};
|
|
11350
|
+
const displayValue = getDisplayValue(promotion);
|
|
11351
|
+
return /* @__PURE__ */ jsxs(
|
|
11352
|
+
"div",
|
|
11353
|
+
{
|
|
11354
|
+
className: clx(
|
|
11355
|
+
"px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
|
|
11356
|
+
{
|
|
11357
|
+
"animate-pulse": isLoading
|
|
11358
|
+
}
|
|
11359
|
+
),
|
|
11360
|
+
children: [
|
|
11361
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11362
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11363
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
|
|
11364
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11365
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11366
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11367
|
+
] }),
|
|
11368
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11369
|
+
] })
|
|
11370
|
+
] }),
|
|
11371
|
+
/* @__PURE__ */ jsx(
|
|
11372
|
+
IconButton,
|
|
11373
|
+
{
|
|
11374
|
+
size: "small",
|
|
11375
|
+
type: "button",
|
|
11376
|
+
variant: "transparent",
|
|
11377
|
+
onClick: onRemove,
|
|
11378
|
+
isLoading: isPending || isLoading,
|
|
11379
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11380
|
+
}
|
|
11381
|
+
)
|
|
11364
11382
|
]
|
|
11383
|
+
},
|
|
11384
|
+
promotion.id
|
|
11385
|
+
);
|
|
11386
|
+
};
|
|
11387
|
+
function getDisplayValue(promotion) {
|
|
11388
|
+
var _a, _b, _c, _d;
|
|
11389
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11390
|
+
if (!value) {
|
|
11391
|
+
return null;
|
|
11392
|
+
}
|
|
11393
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11394
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11395
|
+
if (!currency) {
|
|
11396
|
+
return null;
|
|
11365
11397
|
}
|
|
11366
|
-
|
|
11398
|
+
return getLocaleAmount(value, currency);
|
|
11399
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11400
|
+
return formatPercentage(value);
|
|
11401
|
+
}
|
|
11402
|
+
return null;
|
|
11403
|
+
}
|
|
11404
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11405
|
+
style: "percent",
|
|
11406
|
+
minimumFractionDigits: 2
|
|
11407
|
+
});
|
|
11408
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11409
|
+
let val = value || 0;
|
|
11410
|
+
if (!isPercentageValue) {
|
|
11411
|
+
val = val / 100;
|
|
11412
|
+
}
|
|
11413
|
+
return formatter.format(val);
|
|
11367
11414
|
};
|
|
11368
|
-
|
|
11415
|
+
function getPromotionCodes(items, shippingMethods) {
|
|
11416
|
+
const codes = /* @__PURE__ */ new Set();
|
|
11417
|
+
for (const item of items) {
|
|
11418
|
+
if (item.adjustments) {
|
|
11419
|
+
for (const adjustment of item.adjustments) {
|
|
11420
|
+
if (adjustment.code) {
|
|
11421
|
+
codes.add(adjustment.code);
|
|
11422
|
+
}
|
|
11423
|
+
}
|
|
11424
|
+
}
|
|
11425
|
+
}
|
|
11426
|
+
for (const shippingMethod of shippingMethods) {
|
|
11427
|
+
if (shippingMethod.adjustments) {
|
|
11428
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11429
|
+
if (adjustment.code) {
|
|
11430
|
+
codes.add(adjustment.code);
|
|
11431
|
+
}
|
|
11432
|
+
}
|
|
11433
|
+
}
|
|
11434
|
+
}
|
|
11435
|
+
return Array.from(codes);
|
|
11436
|
+
}
|
|
11369
11437
|
const SalesChannel = () => {
|
|
11370
11438
|
const { id } = useParams();
|
|
11371
11439
|
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
@@ -11394,7 +11462,7 @@ const SalesChannelForm = ({ order }) => {
|
|
|
11394
11462
|
defaultValues: {
|
|
11395
11463
|
sales_channel_id: order.sales_channel_id || ""
|
|
11396
11464
|
},
|
|
11397
|
-
resolver: zodResolver(schema$
|
|
11465
|
+
resolver: zodResolver(schema$2)
|
|
11398
11466
|
});
|
|
11399
11467
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11400
11468
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11469,7 +11537,7 @@ const SalesChannelField = ({ control, order }) => {
|
|
|
11469
11537
|
}
|
|
11470
11538
|
);
|
|
11471
11539
|
};
|
|
11472
|
-
const schema$
|
|
11540
|
+
const schema$2 = objectType({
|
|
11473
11541
|
sales_channel_id: stringType().min(1)
|
|
11474
11542
|
});
|
|
11475
11543
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
@@ -12311,7 +12379,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12311
12379
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12312
12380
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12313
12381
|
},
|
|
12314
|
-
resolver: zodResolver(schema$
|
|
12382
|
+
resolver: zodResolver(schema$1)
|
|
12315
12383
|
});
|
|
12316
12384
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12317
12385
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12481,7 +12549,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12481
12549
|
}
|
|
12482
12550
|
) });
|
|
12483
12551
|
};
|
|
12484
|
-
const schema$
|
|
12552
|
+
const schema$1 = addressSchema;
|
|
12485
12553
|
const TransferOwnership = () => {
|
|
12486
12554
|
const { id } = useParams();
|
|
12487
12555
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12505,7 +12573,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12505
12573
|
defaultValues: {
|
|
12506
12574
|
customer_id: order.customer_id || ""
|
|
12507
12575
|
},
|
|
12508
|
-
resolver: zodResolver(schema
|
|
12576
|
+
resolver: zodResolver(schema)
|
|
12509
12577
|
});
|
|
12510
12578
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12511
12579
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12955,76 +13023,8 @@ const Illustration = () => {
|
|
|
12955
13023
|
}
|
|
12956
13024
|
);
|
|
12957
13025
|
};
|
|
12958
|
-
const schema$1 = objectType({
|
|
12959
|
-
customer_id: stringType().min(1)
|
|
12960
|
-
});
|
|
12961
|
-
const Email = () => {
|
|
12962
|
-
const { id } = useParams();
|
|
12963
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
12964
|
-
fields: "+email"
|
|
12965
|
-
});
|
|
12966
|
-
if (isError) {
|
|
12967
|
-
throw error;
|
|
12968
|
-
}
|
|
12969
|
-
const isReady = !isPending && !!order;
|
|
12970
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12971
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12972
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
12973
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
12974
|
-
] }),
|
|
12975
|
-
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
12976
|
-
] });
|
|
12977
|
-
};
|
|
12978
|
-
const EmailForm = ({ order }) => {
|
|
12979
|
-
const form = useForm({
|
|
12980
|
-
defaultValues: {
|
|
12981
|
-
email: order.email ?? ""
|
|
12982
|
-
},
|
|
12983
|
-
resolver: zodResolver(schema)
|
|
12984
|
-
});
|
|
12985
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12986
|
-
const { handleSuccess } = useRouteModal();
|
|
12987
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12988
|
-
await mutateAsync(
|
|
12989
|
-
{ email: data.email },
|
|
12990
|
-
{
|
|
12991
|
-
onSuccess: () => {
|
|
12992
|
-
handleSuccess();
|
|
12993
|
-
},
|
|
12994
|
-
onError: (error) => {
|
|
12995
|
-
toast.error(error.message);
|
|
12996
|
-
}
|
|
12997
|
-
}
|
|
12998
|
-
);
|
|
12999
|
-
});
|
|
13000
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
13001
|
-
KeyboundForm,
|
|
13002
|
-
{
|
|
13003
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
13004
|
-
onSubmit,
|
|
13005
|
-
children: [
|
|
13006
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
13007
|
-
Form$2.Field,
|
|
13008
|
-
{
|
|
13009
|
-
control: form.control,
|
|
13010
|
-
name: "email",
|
|
13011
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13012
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
13013
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13014
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13015
|
-
] })
|
|
13016
|
-
}
|
|
13017
|
-
) }),
|
|
13018
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13019
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13020
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13021
|
-
] }) })
|
|
13022
|
-
]
|
|
13023
|
-
}
|
|
13024
|
-
) });
|
|
13025
|
-
};
|
|
13026
13026
|
const schema = objectType({
|
|
13027
|
-
|
|
13027
|
+
customer_id: stringType().min(1)
|
|
13028
13028
|
});
|
|
13029
13029
|
const widgetModule = { widgets: [] };
|
|
13030
13030
|
const routeModule = {
|
|
@@ -13046,10 +13046,18 @@ const routeModule = {
|
|
|
13046
13046
|
handle,
|
|
13047
13047
|
loader,
|
|
13048
13048
|
children: [
|
|
13049
|
+
{
|
|
13050
|
+
Component: BillingAddress,
|
|
13051
|
+
path: "/draft-orders/:id/billing-address"
|
|
13052
|
+
},
|
|
13049
13053
|
{
|
|
13050
13054
|
Component: CustomItems,
|
|
13051
13055
|
path: "/draft-orders/:id/custom-items"
|
|
13052
13056
|
},
|
|
13057
|
+
{
|
|
13058
|
+
Component: Email,
|
|
13059
|
+
path: "/draft-orders/:id/email"
|
|
13060
|
+
},
|
|
13053
13061
|
{
|
|
13054
13062
|
Component: Items,
|
|
13055
13063
|
path: "/draft-orders/:id/items"
|
|
@@ -13062,10 +13070,6 @@ const routeModule = {
|
|
|
13062
13070
|
Component: Promotions,
|
|
13063
13071
|
path: "/draft-orders/:id/promotions"
|
|
13064
13072
|
},
|
|
13065
|
-
{
|
|
13066
|
-
Component: BillingAddress,
|
|
13067
|
-
path: "/draft-orders/:id/billing-address"
|
|
13068
|
-
},
|
|
13069
13073
|
{
|
|
13070
13074
|
Component: SalesChannel,
|
|
13071
13075
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13081,10 +13085,6 @@ const routeModule = {
|
|
|
13081
13085
|
{
|
|
13082
13086
|
Component: TransferOwnership,
|
|
13083
13087
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13084
|
-
},
|
|
13085
|
-
{
|
|
13086
|
-
Component: Email,
|
|
13087
|
-
path: "/draft-orders/:id/email"
|
|
13088
13088
|
}
|
|
13089
13089
|
]
|
|
13090
13090
|
}
|