@medusajs/draft-order 2.11.2 → 2.11.3-preview-20251031150158
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 +706 -706
- package/.medusa/server/src/admin/index.mjs +706 -706
- package/package.json +24 -22
|
@@ -9654,196 +9654,6 @@ const EmailForm = ({ order }) => {
|
|
|
9654
9654
|
const schema$4 = objectType({
|
|
9655
9655
|
email: stringType().email()
|
|
9656
9656
|
});
|
|
9657
|
-
const BillingAddress = () => {
|
|
9658
|
-
const { id } = useParams();
|
|
9659
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
9660
|
-
fields: "+billing_address"
|
|
9661
|
-
});
|
|
9662
|
-
if (isError) {
|
|
9663
|
-
throw error;
|
|
9664
|
-
}
|
|
9665
|
-
const isReady = !isPending && !!order;
|
|
9666
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9667
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9668
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
9669
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9670
|
-
] }),
|
|
9671
|
-
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
9672
|
-
] });
|
|
9673
|
-
};
|
|
9674
|
-
const BillingAddressForm = ({ order }) => {
|
|
9675
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9676
|
-
const form = useForm({
|
|
9677
|
-
defaultValues: {
|
|
9678
|
-
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9679
|
-
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9680
|
-
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9681
|
-
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9682
|
-
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9683
|
-
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9684
|
-
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9685
|
-
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9686
|
-
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9687
|
-
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9688
|
-
},
|
|
9689
|
-
resolver: zodResolver(schema$3)
|
|
9690
|
-
});
|
|
9691
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9692
|
-
const { handleSuccess } = useRouteModal();
|
|
9693
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9694
|
-
await mutateAsync(
|
|
9695
|
-
{ billing_address: data },
|
|
9696
|
-
{
|
|
9697
|
-
onSuccess: () => {
|
|
9698
|
-
handleSuccess();
|
|
9699
|
-
},
|
|
9700
|
-
onError: (error) => {
|
|
9701
|
-
toast.error(error.message);
|
|
9702
|
-
}
|
|
9703
|
-
}
|
|
9704
|
-
);
|
|
9705
|
-
});
|
|
9706
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9707
|
-
KeyboundForm,
|
|
9708
|
-
{
|
|
9709
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
9710
|
-
onSubmit,
|
|
9711
|
-
children: [
|
|
9712
|
-
/* @__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: [
|
|
9713
|
-
/* @__PURE__ */ jsx(
|
|
9714
|
-
Form$2.Field,
|
|
9715
|
-
{
|
|
9716
|
-
control: form.control,
|
|
9717
|
-
name: "country_code",
|
|
9718
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9719
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
9720
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
9721
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9722
|
-
] })
|
|
9723
|
-
}
|
|
9724
|
-
),
|
|
9725
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9726
|
-
/* @__PURE__ */ jsx(
|
|
9727
|
-
Form$2.Field,
|
|
9728
|
-
{
|
|
9729
|
-
control: form.control,
|
|
9730
|
-
name: "first_name",
|
|
9731
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9732
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
9733
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9734
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9735
|
-
] })
|
|
9736
|
-
}
|
|
9737
|
-
),
|
|
9738
|
-
/* @__PURE__ */ jsx(
|
|
9739
|
-
Form$2.Field,
|
|
9740
|
-
{
|
|
9741
|
-
control: form.control,
|
|
9742
|
-
name: "last_name",
|
|
9743
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9744
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
9745
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9746
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9747
|
-
] })
|
|
9748
|
-
}
|
|
9749
|
-
)
|
|
9750
|
-
] }),
|
|
9751
|
-
/* @__PURE__ */ jsx(
|
|
9752
|
-
Form$2.Field,
|
|
9753
|
-
{
|
|
9754
|
-
control: form.control,
|
|
9755
|
-
name: "company",
|
|
9756
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9757
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9758
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9759
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9760
|
-
] })
|
|
9761
|
-
}
|
|
9762
|
-
),
|
|
9763
|
-
/* @__PURE__ */ jsx(
|
|
9764
|
-
Form$2.Field,
|
|
9765
|
-
{
|
|
9766
|
-
control: form.control,
|
|
9767
|
-
name: "address_1",
|
|
9768
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9769
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
9770
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9771
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9772
|
-
] })
|
|
9773
|
-
}
|
|
9774
|
-
),
|
|
9775
|
-
/* @__PURE__ */ jsx(
|
|
9776
|
-
Form$2.Field,
|
|
9777
|
-
{
|
|
9778
|
-
control: form.control,
|
|
9779
|
-
name: "address_2",
|
|
9780
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9781
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9782
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9783
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9784
|
-
] })
|
|
9785
|
-
}
|
|
9786
|
-
),
|
|
9787
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9788
|
-
/* @__PURE__ */ jsx(
|
|
9789
|
-
Form$2.Field,
|
|
9790
|
-
{
|
|
9791
|
-
control: form.control,
|
|
9792
|
-
name: "postal_code",
|
|
9793
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9794
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
9795
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9796
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9797
|
-
] })
|
|
9798
|
-
}
|
|
9799
|
-
),
|
|
9800
|
-
/* @__PURE__ */ jsx(
|
|
9801
|
-
Form$2.Field,
|
|
9802
|
-
{
|
|
9803
|
-
control: form.control,
|
|
9804
|
-
name: "city",
|
|
9805
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9806
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
9807
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9808
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9809
|
-
] })
|
|
9810
|
-
}
|
|
9811
|
-
)
|
|
9812
|
-
] }),
|
|
9813
|
-
/* @__PURE__ */ jsx(
|
|
9814
|
-
Form$2.Field,
|
|
9815
|
-
{
|
|
9816
|
-
control: form.control,
|
|
9817
|
-
name: "province",
|
|
9818
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9819
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9820
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9821
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9822
|
-
] })
|
|
9823
|
-
}
|
|
9824
|
-
),
|
|
9825
|
-
/* @__PURE__ */ jsx(
|
|
9826
|
-
Form$2.Field,
|
|
9827
|
-
{
|
|
9828
|
-
control: form.control,
|
|
9829
|
-
name: "phone",
|
|
9830
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9831
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9832
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9833
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9834
|
-
] })
|
|
9835
|
-
}
|
|
9836
|
-
)
|
|
9837
|
-
] }) }),
|
|
9838
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9839
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9840
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9841
|
-
] }) })
|
|
9842
|
-
]
|
|
9843
|
-
}
|
|
9844
|
-
) });
|
|
9845
|
-
};
|
|
9846
|
-
const schema$3 = addressSchema;
|
|
9847
9657
|
const NumberInput = forwardRef(
|
|
9848
9658
|
({
|
|
9849
9659
|
value,
|
|
@@ -11168,35 +10978,312 @@ function getHasUneditableRows(metadata) {
|
|
|
11168
10978
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11169
10979
|
);
|
|
11170
10980
|
}
|
|
11171
|
-
const
|
|
11172
|
-
|
|
11173
|
-
|
|
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,
|
|
11174
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(
|
|
11175
11027
|
{
|
|
11176
|
-
|
|
11028
|
+
id: promoIds
|
|
11177
11029
|
},
|
|
11178
11030
|
{
|
|
11179
|
-
enabled: !!
|
|
11031
|
+
enabled: !!promoIds.length
|
|
11180
11032
|
}
|
|
11181
11033
|
);
|
|
11182
|
-
|
|
11183
|
-
|
|
11184
|
-
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
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
|
+
}
|
|
11253
|
+
}
|
|
11254
|
+
}
|
|
11255
|
+
}
|
|
11256
|
+
return Array.from(promotionIds);
|
|
11257
|
+
}
|
|
11258
|
+
const SalesChannel = () => {
|
|
11259
|
+
const { id } = useParams();
|
|
11260
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11261
|
+
id,
|
|
11262
|
+
{
|
|
11263
|
+
fields: "+sales_channel_id"
|
|
11264
|
+
},
|
|
11265
|
+
{
|
|
11266
|
+
enabled: !!id
|
|
11267
|
+
}
|
|
11268
|
+
);
|
|
11269
|
+
if (isError) {
|
|
11270
|
+
throw error;
|
|
11271
|
+
}
|
|
11272
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11273
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11274
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11275
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11276
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11277
|
+
] }),
|
|
11278
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11279
|
+
] });
|
|
11280
|
+
};
|
|
11281
|
+
const SalesChannelForm = ({ order }) => {
|
|
11282
|
+
const form = useForm({
|
|
11283
|
+
defaultValues: {
|
|
11197
11284
|
sales_channel_id: order.sales_channel_id || ""
|
|
11198
11285
|
},
|
|
11199
|
-
resolver: zodResolver(schema$
|
|
11286
|
+
resolver: zodResolver(schema$3)
|
|
11200
11287
|
});
|
|
11201
11288
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11202
11289
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11271,12 +11358,215 @@ const SalesChannelField = ({ control, order }) => {
|
|
|
11271
11358
|
}
|
|
11272
11359
|
);
|
|
11273
11360
|
};
|
|
11274
|
-
const schema$
|
|
11361
|
+
const schema$3 = objectType({
|
|
11275
11362
|
sales_channel_id: stringType().min(1)
|
|
11276
11363
|
});
|
|
11277
|
-
const
|
|
11278
|
-
const
|
|
11279
|
-
|
|
11364
|
+
const ShippingAddress = () => {
|
|
11365
|
+
const { id } = useParams();
|
|
11366
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11367
|
+
fields: "+shipping_address"
|
|
11368
|
+
});
|
|
11369
|
+
if (isError) {
|
|
11370
|
+
throw error;
|
|
11371
|
+
}
|
|
11372
|
+
const isReady = !isPending && !!order;
|
|
11373
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11374
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11375
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
|
|
11376
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
11377
|
+
] }),
|
|
11378
|
+
isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
|
|
11379
|
+
] });
|
|
11380
|
+
};
|
|
11381
|
+
const ShippingAddressForm = ({ order }) => {
|
|
11382
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
11383
|
+
const form = useForm({
|
|
11384
|
+
defaultValues: {
|
|
11385
|
+
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
11386
|
+
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
11387
|
+
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
11388
|
+
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
11389
|
+
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
11390
|
+
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
11391
|
+
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
11392
|
+
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
11393
|
+
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11394
|
+
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
11395
|
+
},
|
|
11396
|
+
resolver: zodResolver(schema$2)
|
|
11397
|
+
});
|
|
11398
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11399
|
+
const { handleSuccess } = useRouteModal();
|
|
11400
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11401
|
+
await mutateAsync(
|
|
11402
|
+
{
|
|
11403
|
+
shipping_address: {
|
|
11404
|
+
first_name: data.first_name,
|
|
11405
|
+
last_name: data.last_name,
|
|
11406
|
+
company: data.company,
|
|
11407
|
+
address_1: data.address_1,
|
|
11408
|
+
address_2: data.address_2,
|
|
11409
|
+
city: data.city,
|
|
11410
|
+
province: data.province,
|
|
11411
|
+
country_code: data.country_code,
|
|
11412
|
+
postal_code: data.postal_code,
|
|
11413
|
+
phone: data.phone
|
|
11414
|
+
}
|
|
11415
|
+
},
|
|
11416
|
+
{
|
|
11417
|
+
onSuccess: () => {
|
|
11418
|
+
handleSuccess();
|
|
11419
|
+
},
|
|
11420
|
+
onError: (error) => {
|
|
11421
|
+
toast.error(error.message);
|
|
11422
|
+
}
|
|
11423
|
+
}
|
|
11424
|
+
);
|
|
11425
|
+
});
|
|
11426
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11427
|
+
KeyboundForm,
|
|
11428
|
+
{
|
|
11429
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11430
|
+
onSubmit,
|
|
11431
|
+
children: [
|
|
11432
|
+
/* @__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: [
|
|
11433
|
+
/* @__PURE__ */ jsx(
|
|
11434
|
+
Form$2.Field,
|
|
11435
|
+
{
|
|
11436
|
+
control: form.control,
|
|
11437
|
+
name: "country_code",
|
|
11438
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11439
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
11440
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
11441
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11442
|
+
] })
|
|
11443
|
+
}
|
|
11444
|
+
),
|
|
11445
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11446
|
+
/* @__PURE__ */ jsx(
|
|
11447
|
+
Form$2.Field,
|
|
11448
|
+
{
|
|
11449
|
+
control: form.control,
|
|
11450
|
+
name: "first_name",
|
|
11451
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11452
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
11453
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11454
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11455
|
+
] })
|
|
11456
|
+
}
|
|
11457
|
+
),
|
|
11458
|
+
/* @__PURE__ */ jsx(
|
|
11459
|
+
Form$2.Field,
|
|
11460
|
+
{
|
|
11461
|
+
control: form.control,
|
|
11462
|
+
name: "last_name",
|
|
11463
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11464
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
11465
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11466
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11467
|
+
] })
|
|
11468
|
+
}
|
|
11469
|
+
)
|
|
11470
|
+
] }),
|
|
11471
|
+
/* @__PURE__ */ jsx(
|
|
11472
|
+
Form$2.Field,
|
|
11473
|
+
{
|
|
11474
|
+
control: form.control,
|
|
11475
|
+
name: "company",
|
|
11476
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11477
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
11478
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11479
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11480
|
+
] })
|
|
11481
|
+
}
|
|
11482
|
+
),
|
|
11483
|
+
/* @__PURE__ */ jsx(
|
|
11484
|
+
Form$2.Field,
|
|
11485
|
+
{
|
|
11486
|
+
control: form.control,
|
|
11487
|
+
name: "address_1",
|
|
11488
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11489
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
11490
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11491
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11492
|
+
] })
|
|
11493
|
+
}
|
|
11494
|
+
),
|
|
11495
|
+
/* @__PURE__ */ jsx(
|
|
11496
|
+
Form$2.Field,
|
|
11497
|
+
{
|
|
11498
|
+
control: form.control,
|
|
11499
|
+
name: "address_2",
|
|
11500
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11501
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
11502
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11503
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11504
|
+
] })
|
|
11505
|
+
}
|
|
11506
|
+
),
|
|
11507
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11508
|
+
/* @__PURE__ */ jsx(
|
|
11509
|
+
Form$2.Field,
|
|
11510
|
+
{
|
|
11511
|
+
control: form.control,
|
|
11512
|
+
name: "postal_code",
|
|
11513
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11514
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
11515
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11516
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11517
|
+
] })
|
|
11518
|
+
}
|
|
11519
|
+
),
|
|
11520
|
+
/* @__PURE__ */ jsx(
|
|
11521
|
+
Form$2.Field,
|
|
11522
|
+
{
|
|
11523
|
+
control: form.control,
|
|
11524
|
+
name: "city",
|
|
11525
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11526
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
11527
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11528
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11529
|
+
] })
|
|
11530
|
+
}
|
|
11531
|
+
)
|
|
11532
|
+
] }),
|
|
11533
|
+
/* @__PURE__ */ jsx(
|
|
11534
|
+
Form$2.Field,
|
|
11535
|
+
{
|
|
11536
|
+
control: form.control,
|
|
11537
|
+
name: "province",
|
|
11538
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11539
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
11540
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11541
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11542
|
+
] })
|
|
11543
|
+
}
|
|
11544
|
+
),
|
|
11545
|
+
/* @__PURE__ */ jsx(
|
|
11546
|
+
Form$2.Field,
|
|
11547
|
+
{
|
|
11548
|
+
control: form.control,
|
|
11549
|
+
name: "phone",
|
|
11550
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11551
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
11552
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11553
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11554
|
+
] })
|
|
11555
|
+
}
|
|
11556
|
+
)
|
|
11557
|
+
] }) }),
|
|
11558
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11559
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11560
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11561
|
+
] }) })
|
|
11562
|
+
]
|
|
11563
|
+
}
|
|
11564
|
+
) });
|
|
11565
|
+
};
|
|
11566
|
+
const schema$2 = addressSchema;
|
|
11567
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11568
|
+
const Shipping = () => {
|
|
11569
|
+
var _a;
|
|
11280
11570
|
const { id } = useParams();
|
|
11281
11571
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
11282
11572
|
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
@@ -12081,247 +12371,44 @@ const CustomAmountField = ({
|
|
|
12081
12371
|
}
|
|
12082
12372
|
);
|
|
12083
12373
|
};
|
|
12084
|
-
const
|
|
12374
|
+
const TransferOwnership = () => {
|
|
12085
12375
|
const { id } = useParams();
|
|
12086
|
-
const {
|
|
12087
|
-
fields: "
|
|
12376
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
12377
|
+
fields: "id,customer_id,customer.*"
|
|
12088
12378
|
});
|
|
12089
12379
|
if (isError) {
|
|
12090
12380
|
throw error;
|
|
12091
12381
|
}
|
|
12092
|
-
const isReady = !isPending && !!
|
|
12382
|
+
const isReady = !isPending && !!draft_order;
|
|
12093
12383
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12094
12384
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12095
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
12096
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
12385
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
|
|
12386
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
|
|
12097
12387
|
] }),
|
|
12098
|
-
isReady && /* @__PURE__ */ jsx(
|
|
12388
|
+
isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
|
|
12099
12389
|
] });
|
|
12100
12390
|
};
|
|
12101
|
-
const
|
|
12102
|
-
var _a, _b
|
|
12391
|
+
const TransferOwnershipForm = ({ order }) => {
|
|
12392
|
+
var _a, _b;
|
|
12103
12393
|
const form = useForm({
|
|
12104
12394
|
defaultValues: {
|
|
12105
|
-
|
|
12106
|
-
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12107
|
-
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
12108
|
-
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12109
|
-
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12110
|
-
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
12111
|
-
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
12112
|
-
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12113
|
-
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12114
|
-
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12395
|
+
customer_id: order.customer_id || ""
|
|
12115
12396
|
},
|
|
12116
12397
|
resolver: zodResolver(schema$1)
|
|
12117
12398
|
});
|
|
12118
12399
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12119
12400
|
const { handleSuccess } = useRouteModal();
|
|
12401
|
+
const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
|
|
12402
|
+
const currentCustomer = order.customer ? {
|
|
12403
|
+
label: name ? `${name} (${order.customer.email})` : order.customer.email,
|
|
12404
|
+
value: order.customer.id
|
|
12405
|
+
} : null;
|
|
12120
12406
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
12121
12407
|
await mutateAsync(
|
|
12122
|
-
{
|
|
12123
|
-
shipping_address: {
|
|
12124
|
-
first_name: data.first_name,
|
|
12125
|
-
last_name: data.last_name,
|
|
12126
|
-
company: data.company,
|
|
12127
|
-
address_1: data.address_1,
|
|
12128
|
-
address_2: data.address_2,
|
|
12129
|
-
city: data.city,
|
|
12130
|
-
province: data.province,
|
|
12131
|
-
country_code: data.country_code,
|
|
12132
|
-
postal_code: data.postal_code,
|
|
12133
|
-
phone: data.phone
|
|
12134
|
-
}
|
|
12135
|
-
},
|
|
12408
|
+
{ customer_id: data.customer_id },
|
|
12136
12409
|
{
|
|
12137
12410
|
onSuccess: () => {
|
|
12138
|
-
|
|
12139
|
-
},
|
|
12140
|
-
onError: (error) => {
|
|
12141
|
-
toast.error(error.message);
|
|
12142
|
-
}
|
|
12143
|
-
}
|
|
12144
|
-
);
|
|
12145
|
-
});
|
|
12146
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12147
|
-
KeyboundForm,
|
|
12148
|
-
{
|
|
12149
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12150
|
-
onSubmit,
|
|
12151
|
-
children: [
|
|
12152
|
-
/* @__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: [
|
|
12153
|
-
/* @__PURE__ */ jsx(
|
|
12154
|
-
Form$2.Field,
|
|
12155
|
-
{
|
|
12156
|
-
control: form.control,
|
|
12157
|
-
name: "country_code",
|
|
12158
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12159
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12160
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12161
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12162
|
-
] })
|
|
12163
|
-
}
|
|
12164
|
-
),
|
|
12165
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12166
|
-
/* @__PURE__ */ jsx(
|
|
12167
|
-
Form$2.Field,
|
|
12168
|
-
{
|
|
12169
|
-
control: form.control,
|
|
12170
|
-
name: "first_name",
|
|
12171
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12172
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12173
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12174
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12175
|
-
] })
|
|
12176
|
-
}
|
|
12177
|
-
),
|
|
12178
|
-
/* @__PURE__ */ jsx(
|
|
12179
|
-
Form$2.Field,
|
|
12180
|
-
{
|
|
12181
|
-
control: form.control,
|
|
12182
|
-
name: "last_name",
|
|
12183
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12184
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12185
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12186
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12187
|
-
] })
|
|
12188
|
-
}
|
|
12189
|
-
)
|
|
12190
|
-
] }),
|
|
12191
|
-
/* @__PURE__ */ jsx(
|
|
12192
|
-
Form$2.Field,
|
|
12193
|
-
{
|
|
12194
|
-
control: form.control,
|
|
12195
|
-
name: "company",
|
|
12196
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12197
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12198
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12199
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12200
|
-
] })
|
|
12201
|
-
}
|
|
12202
|
-
),
|
|
12203
|
-
/* @__PURE__ */ jsx(
|
|
12204
|
-
Form$2.Field,
|
|
12205
|
-
{
|
|
12206
|
-
control: form.control,
|
|
12207
|
-
name: "address_1",
|
|
12208
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12209
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12210
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12211
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12212
|
-
] })
|
|
12213
|
-
}
|
|
12214
|
-
),
|
|
12215
|
-
/* @__PURE__ */ jsx(
|
|
12216
|
-
Form$2.Field,
|
|
12217
|
-
{
|
|
12218
|
-
control: form.control,
|
|
12219
|
-
name: "address_2",
|
|
12220
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12221
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12222
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12223
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12224
|
-
] })
|
|
12225
|
-
}
|
|
12226
|
-
),
|
|
12227
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12228
|
-
/* @__PURE__ */ jsx(
|
|
12229
|
-
Form$2.Field,
|
|
12230
|
-
{
|
|
12231
|
-
control: form.control,
|
|
12232
|
-
name: "postal_code",
|
|
12233
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12234
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12235
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12236
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12237
|
-
] })
|
|
12238
|
-
}
|
|
12239
|
-
),
|
|
12240
|
-
/* @__PURE__ */ jsx(
|
|
12241
|
-
Form$2.Field,
|
|
12242
|
-
{
|
|
12243
|
-
control: form.control,
|
|
12244
|
-
name: "city",
|
|
12245
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12246
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12247
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12248
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12249
|
-
] })
|
|
12250
|
-
}
|
|
12251
|
-
)
|
|
12252
|
-
] }),
|
|
12253
|
-
/* @__PURE__ */ jsx(
|
|
12254
|
-
Form$2.Field,
|
|
12255
|
-
{
|
|
12256
|
-
control: form.control,
|
|
12257
|
-
name: "province",
|
|
12258
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12259
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
12260
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12261
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12262
|
-
] })
|
|
12263
|
-
}
|
|
12264
|
-
),
|
|
12265
|
-
/* @__PURE__ */ jsx(
|
|
12266
|
-
Form$2.Field,
|
|
12267
|
-
{
|
|
12268
|
-
control: form.control,
|
|
12269
|
-
name: "phone",
|
|
12270
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12271
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
12272
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12273
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12274
|
-
] })
|
|
12275
|
-
}
|
|
12276
|
-
)
|
|
12277
|
-
] }) }),
|
|
12278
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12279
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12280
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12281
|
-
] }) })
|
|
12282
|
-
]
|
|
12283
|
-
}
|
|
12284
|
-
) });
|
|
12285
|
-
};
|
|
12286
|
-
const schema$1 = addressSchema;
|
|
12287
|
-
const TransferOwnership = () => {
|
|
12288
|
-
const { id } = useParams();
|
|
12289
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
12290
|
-
fields: "id,customer_id,customer.*"
|
|
12291
|
-
});
|
|
12292
|
-
if (isError) {
|
|
12293
|
-
throw error;
|
|
12294
|
-
}
|
|
12295
|
-
const isReady = !isPending && !!draft_order;
|
|
12296
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12297
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12298
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
|
|
12299
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
|
|
12300
|
-
] }),
|
|
12301
|
-
isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
|
|
12302
|
-
] });
|
|
12303
|
-
};
|
|
12304
|
-
const TransferOwnershipForm = ({ order }) => {
|
|
12305
|
-
var _a, _b;
|
|
12306
|
-
const form = useForm({
|
|
12307
|
-
defaultValues: {
|
|
12308
|
-
customer_id: order.customer_id || ""
|
|
12309
|
-
},
|
|
12310
|
-
resolver: zodResolver(schema)
|
|
12311
|
-
});
|
|
12312
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12313
|
-
const { handleSuccess } = useRouteModal();
|
|
12314
|
-
const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
|
|
12315
|
-
const currentCustomer = order.customer ? {
|
|
12316
|
-
label: name ? `${name} (${order.customer.email})` : order.customer.email,
|
|
12317
|
-
value: order.customer.id
|
|
12318
|
-
} : null;
|
|
12319
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12320
|
-
await mutateAsync(
|
|
12321
|
-
{ customer_id: data.customer_id },
|
|
12322
|
-
{
|
|
12323
|
-
onSuccess: () => {
|
|
12324
|
-
toast.success("Customer updated");
|
|
12411
|
+
toast.success("Customer updated");
|
|
12325
12412
|
handleSuccess();
|
|
12326
12413
|
},
|
|
12327
12414
|
onError: (error) => {
|
|
@@ -12757,286 +12844,199 @@ const Illustration = () => {
|
|
|
12757
12844
|
}
|
|
12758
12845
|
);
|
|
12759
12846
|
};
|
|
12760
|
-
const schema = objectType({
|
|
12847
|
+
const schema$1 = objectType({
|
|
12761
12848
|
customer_id: stringType().min(1)
|
|
12762
12849
|
});
|
|
12763
|
-
const
|
|
12764
|
-
const promotionsQueryKeys = {
|
|
12765
|
-
list: (query2) => [
|
|
12766
|
-
PROMOTION_QUERY_KEY,
|
|
12767
|
-
query2 ? query2 : void 0
|
|
12768
|
-
],
|
|
12769
|
-
detail: (id, query2) => [
|
|
12770
|
-
PROMOTION_QUERY_KEY,
|
|
12771
|
-
id,
|
|
12772
|
-
query2 ? query2 : void 0
|
|
12773
|
-
]
|
|
12774
|
-
};
|
|
12775
|
-
const usePromotions = (query2, options) => {
|
|
12776
|
-
const { data, ...rest } = useQuery({
|
|
12777
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
12778
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
12779
|
-
...options
|
|
12780
|
-
});
|
|
12781
|
-
return { ...data, ...rest };
|
|
12782
|
-
};
|
|
12783
|
-
const Promotions = () => {
|
|
12850
|
+
const BillingAddress = () => {
|
|
12784
12851
|
const { id } = useParams();
|
|
12785
|
-
const {
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
useInitiateOrderEdit({ preview });
|
|
12791
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12792
|
-
if (isPreviewError) {
|
|
12793
|
-
throw previewError;
|
|
12852
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12853
|
+
fields: "+billing_address"
|
|
12854
|
+
});
|
|
12855
|
+
if (isError) {
|
|
12856
|
+
throw error;
|
|
12794
12857
|
}
|
|
12795
|
-
const isReady = !!
|
|
12796
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, {
|
|
12797
|
-
/* @__PURE__ */
|
|
12798
|
-
|
|
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 })
|
|
12799
12865
|
] });
|
|
12800
12866
|
};
|
|
12801
|
-
const
|
|
12802
|
-
|
|
12803
|
-
const
|
|
12804
|
-
|
|
12805
|
-
|
|
12806
|
-
|
|
12807
|
-
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
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) ?? ""
|
|
12811
12881
|
},
|
|
12812
|
-
|
|
12813
|
-
enabled: !!promoIds.length
|
|
12814
|
-
}
|
|
12815
|
-
);
|
|
12816
|
-
const comboboxData = useComboboxData({
|
|
12817
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
12818
|
-
queryFn: async (params) => {
|
|
12819
|
-
return await sdk.admin.promotion.list({
|
|
12820
|
-
...params,
|
|
12821
|
-
id: {
|
|
12822
|
-
$nin: promoIds
|
|
12823
|
-
}
|
|
12824
|
-
});
|
|
12825
|
-
},
|
|
12826
|
-
getOptions: (data) => {
|
|
12827
|
-
return data.promotions.map((promotion) => ({
|
|
12828
|
-
label: promotion.code,
|
|
12829
|
-
value: promotion.code
|
|
12830
|
-
}));
|
|
12831
|
-
}
|
|
12882
|
+
resolver: zodResolver(schema)
|
|
12832
12883
|
});
|
|
12833
|
-
const
|
|
12834
|
-
|
|
12835
|
-
|
|
12836
|
-
|
|
12837
|
-
|
|
12838
|
-
{
|
|
12839
|
-
promo_codes: [value]
|
|
12840
|
-
},
|
|
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 },
|
|
12841
12889
|
{
|
|
12842
|
-
onError: (e) => {
|
|
12843
|
-
toast.error(e.message);
|
|
12844
|
-
comboboxData.onSearchValueChange("");
|
|
12845
|
-
setComboboxValue("");
|
|
12846
|
-
},
|
|
12847
12890
|
onSuccess: () => {
|
|
12848
|
-
|
|
12849
|
-
setComboboxValue("");
|
|
12850
|
-
}
|
|
12851
|
-
}
|
|
12852
|
-
);
|
|
12853
|
-
};
|
|
12854
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12855
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
12856
|
-
const onSubmit = async () => {
|
|
12857
|
-
setIsSubmitting(true);
|
|
12858
|
-
let requestSucceeded = false;
|
|
12859
|
-
await requestOrderEdit(void 0, {
|
|
12860
|
-
onError: (e) => {
|
|
12861
|
-
toast.error(e.message);
|
|
12862
|
-
},
|
|
12863
|
-
onSuccess: () => {
|
|
12864
|
-
requestSucceeded = true;
|
|
12865
|
-
}
|
|
12866
|
-
});
|
|
12867
|
-
if (!requestSucceeded) {
|
|
12868
|
-
setIsSubmitting(false);
|
|
12869
|
-
return;
|
|
12870
|
-
}
|
|
12871
|
-
await confirmOrderEdit(void 0, {
|
|
12872
|
-
onError: (e) => {
|
|
12873
|
-
toast.error(e.message);
|
|
12874
|
-
},
|
|
12875
|
-
onSuccess: () => {
|
|
12876
|
-
handleSuccess();
|
|
12877
|
-
},
|
|
12878
|
-
onSettled: () => {
|
|
12879
|
-
setIsSubmitting(false);
|
|
12880
|
-
}
|
|
12881
|
-
});
|
|
12882
|
-
};
|
|
12883
|
-
if (isError) {
|
|
12884
|
-
throw error;
|
|
12885
|
-
}
|
|
12886
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
12887
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
12888
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
12889
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12890
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
12891
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
12892
|
-
] }),
|
|
12893
|
-
/* @__PURE__ */ jsx(
|
|
12894
|
-
Combobox,
|
|
12895
|
-
{
|
|
12896
|
-
id: "promotion-combobox",
|
|
12897
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
12898
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
12899
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
12900
|
-
options: comboboxData.options,
|
|
12901
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
12902
|
-
searchValue: comboboxData.searchValue,
|
|
12903
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
12904
|
-
onChange: add,
|
|
12905
|
-
value: comboboxValue
|
|
12906
|
-
}
|
|
12907
|
-
)
|
|
12908
|
-
] }),
|
|
12909
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12910
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
12911
|
-
PromotionItem,
|
|
12912
|
-
{
|
|
12913
|
-
promotion,
|
|
12914
|
-
orderId: preview.id,
|
|
12915
|
-
isLoading: isPending
|
|
12891
|
+
handleSuccess();
|
|
12916
12892
|
},
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
] }) }),
|
|
12920
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12921
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12922
|
-
/* @__PURE__ */ jsx(
|
|
12923
|
-
Button,
|
|
12924
|
-
{
|
|
12925
|
-
size: "small",
|
|
12926
|
-
type: "submit",
|
|
12927
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
12928
|
-
children: "Save"
|
|
12929
|
-
}
|
|
12930
|
-
)
|
|
12931
|
-
] }) })
|
|
12932
|
-
] });
|
|
12933
|
-
};
|
|
12934
|
-
const PromotionItem = ({
|
|
12935
|
-
promotion,
|
|
12936
|
-
orderId,
|
|
12937
|
-
isLoading
|
|
12938
|
-
}) => {
|
|
12939
|
-
var _a;
|
|
12940
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
12941
|
-
const onRemove = async () => {
|
|
12942
|
-
removePromotions(
|
|
12943
|
-
{
|
|
12944
|
-
promo_codes: [promotion.code]
|
|
12945
|
-
},
|
|
12946
|
-
{
|
|
12947
|
-
onError: (e) => {
|
|
12948
|
-
toast.error(e.message);
|
|
12893
|
+
onError: (error) => {
|
|
12894
|
+
toast.error(error.message);
|
|
12949
12895
|
}
|
|
12950
12896
|
}
|
|
12951
12897
|
);
|
|
12952
|
-
};
|
|
12953
|
-
|
|
12954
|
-
|
|
12955
|
-
"div",
|
|
12898
|
+
});
|
|
12899
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12900
|
+
KeyboundForm,
|
|
12956
12901
|
{
|
|
12957
|
-
className:
|
|
12958
|
-
|
|
12959
|
-
{
|
|
12960
|
-
"animate-pulse": isLoading
|
|
12961
|
-
}
|
|
12962
|
-
),
|
|
12902
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12903
|
+
onSubmit,
|
|
12963
12904
|
children: [
|
|
12964
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
12965
|
-
/* @__PURE__ */ jsx(
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12975
|
-
|
|
12976
|
-
|
|
12977
|
-
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
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
|
+
] }) })
|
|
12985
13035
|
]
|
|
12986
|
-
},
|
|
12987
|
-
promotion.id
|
|
12988
|
-
);
|
|
12989
|
-
};
|
|
12990
|
-
function getDisplayValue(promotion) {
|
|
12991
|
-
var _a, _b, _c, _d;
|
|
12992
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
12993
|
-
if (!value) {
|
|
12994
|
-
return null;
|
|
12995
|
-
}
|
|
12996
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
12997
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
12998
|
-
if (!currency) {
|
|
12999
|
-
return null;
|
|
13000
13036
|
}
|
|
13001
|
-
|
|
13002
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
13003
|
-
return formatPercentage(value);
|
|
13004
|
-
}
|
|
13005
|
-
return null;
|
|
13006
|
-
}
|
|
13007
|
-
const formatter = new Intl.NumberFormat([], {
|
|
13008
|
-
style: "percent",
|
|
13009
|
-
minimumFractionDigits: 2
|
|
13010
|
-
});
|
|
13011
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
13012
|
-
let val = value || 0;
|
|
13013
|
-
if (!isPercentageValue) {
|
|
13014
|
-
val = val / 100;
|
|
13015
|
-
}
|
|
13016
|
-
return formatter.format(val);
|
|
13037
|
+
) });
|
|
13017
13038
|
};
|
|
13018
|
-
|
|
13019
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
13020
|
-
for (const item of items) {
|
|
13021
|
-
if (item.adjustments) {
|
|
13022
|
-
for (const adjustment of item.adjustments) {
|
|
13023
|
-
if (adjustment.promotion_id) {
|
|
13024
|
-
promotionIds.add(adjustment.promotion_id);
|
|
13025
|
-
}
|
|
13026
|
-
}
|
|
13027
|
-
}
|
|
13028
|
-
}
|
|
13029
|
-
for (const shippingMethod of shippingMethods) {
|
|
13030
|
-
if (shippingMethod.adjustments) {
|
|
13031
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
13032
|
-
if (adjustment.promotion_id) {
|
|
13033
|
-
promotionIds.add(adjustment.promotion_id);
|
|
13034
|
-
}
|
|
13035
|
-
}
|
|
13036
|
-
}
|
|
13037
|
-
}
|
|
13038
|
-
return Array.from(promotionIds);
|
|
13039
|
-
}
|
|
13039
|
+
const schema = addressSchema;
|
|
13040
13040
|
const widgetModule = { widgets: [] };
|
|
13041
13041
|
const routeModule = {
|
|
13042
13042
|
routes: [
|
|
@@ -13065,10 +13065,6 @@ const routeModule = {
|
|
|
13065
13065
|
Component: Email,
|
|
13066
13066
|
path: "/draft-orders/:id/email"
|
|
13067
13067
|
},
|
|
13068
|
-
{
|
|
13069
|
-
Component: BillingAddress,
|
|
13070
|
-
path: "/draft-orders/:id/billing-address"
|
|
13071
|
-
},
|
|
13072
13068
|
{
|
|
13073
13069
|
Component: Items,
|
|
13074
13070
|
path: "/draft-orders/:id/items"
|
|
@@ -13078,24 +13074,28 @@ const routeModule = {
|
|
|
13078
13074
|
path: "/draft-orders/:id/metadata"
|
|
13079
13075
|
},
|
|
13080
13076
|
{
|
|
13081
|
-
Component:
|
|
13082
|
-
path: "/draft-orders/:id/
|
|
13077
|
+
Component: Promotions,
|
|
13078
|
+
path: "/draft-orders/:id/promotions"
|
|
13083
13079
|
},
|
|
13084
13080
|
{
|
|
13085
|
-
Component:
|
|
13086
|
-
path: "/draft-orders/:id/
|
|
13081
|
+
Component: SalesChannel,
|
|
13082
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13087
13083
|
},
|
|
13088
13084
|
{
|
|
13089
13085
|
Component: ShippingAddress,
|
|
13090
13086
|
path: "/draft-orders/:id/shipping-address"
|
|
13091
13087
|
},
|
|
13088
|
+
{
|
|
13089
|
+
Component: Shipping,
|
|
13090
|
+
path: "/draft-orders/:id/shipping"
|
|
13091
|
+
},
|
|
13092
13092
|
{
|
|
13093
13093
|
Component: TransferOwnership,
|
|
13094
13094
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
13095
|
},
|
|
13096
13096
|
{
|
|
13097
|
-
Component:
|
|
13098
|
-
path: "/draft-orders/:id/
|
|
13097
|
+
Component: BillingAddress,
|
|
13098
|
+
path: "/draft-orders/:id/billing-address"
|
|
13099
13099
|
}
|
|
13100
13100
|
]
|
|
13101
13101
|
}
|