@medusajs/draft-order 2.22.0 → 2.22.1-snapshot-20261025213551
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 +414 -414
- package/.medusa/server/src/admin/index.mjs +414 -414
- package/package.json +18 -18
|
@@ -5983,6 +5983,95 @@ const ID = () => {
|
|
|
5983
5983
|
}
|
|
5984
5984
|
);
|
|
5985
5985
|
};
|
|
5986
|
+
const CustomItems = () => {
|
|
5987
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
5988
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
5989
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
5990
|
+
] });
|
|
5991
|
+
};
|
|
5992
|
+
const CustomItemsForm = () => {
|
|
5993
|
+
const form = reactHookForm.useForm({
|
|
5994
|
+
resolver: zod$1.zodResolver(schema$5)
|
|
5995
|
+
});
|
|
5996
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
5997
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
5998
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
5999
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6000
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
6001
|
+
] }) })
|
|
6002
|
+
] }) });
|
|
6003
|
+
};
|
|
6004
|
+
const schema$5 = zod.z.object({
|
|
6005
|
+
email: zod.z.string().email()
|
|
6006
|
+
});
|
|
6007
|
+
const Email = () => {
|
|
6008
|
+
const { id } = reactRouterDom.useParams();
|
|
6009
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
6010
|
+
fields: "+email"
|
|
6011
|
+
});
|
|
6012
|
+
if (isError) {
|
|
6013
|
+
throw error;
|
|
6014
|
+
}
|
|
6015
|
+
const isReady = !isPending && !!order;
|
|
6016
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
6017
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
6018
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
6019
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
6020
|
+
] }),
|
|
6021
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
6022
|
+
] });
|
|
6023
|
+
};
|
|
6024
|
+
const EmailForm = ({ order }) => {
|
|
6025
|
+
const form = reactHookForm.useForm({
|
|
6026
|
+
defaultValues: {
|
|
6027
|
+
email: order.email ?? ""
|
|
6028
|
+
},
|
|
6029
|
+
resolver: zod$1.zodResolver(schema$4)
|
|
6030
|
+
});
|
|
6031
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
6032
|
+
const { handleSuccess } = useRouteModal();
|
|
6033
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
6034
|
+
await mutateAsync(
|
|
6035
|
+
{ email: data.email },
|
|
6036
|
+
{
|
|
6037
|
+
onSuccess: () => {
|
|
6038
|
+
handleSuccess();
|
|
6039
|
+
},
|
|
6040
|
+
onError: (error) => {
|
|
6041
|
+
ui.toast.error(error.message);
|
|
6042
|
+
}
|
|
6043
|
+
}
|
|
6044
|
+
);
|
|
6045
|
+
});
|
|
6046
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6047
|
+
KeyboundForm,
|
|
6048
|
+
{
|
|
6049
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
6050
|
+
onSubmit,
|
|
6051
|
+
children: [
|
|
6052
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6053
|
+
Form$2.Field,
|
|
6054
|
+
{
|
|
6055
|
+
control: form.control,
|
|
6056
|
+
name: "email",
|
|
6057
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
6058
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
6059
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
6060
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
6061
|
+
] })
|
|
6062
|
+
}
|
|
6063
|
+
) }),
|
|
6064
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
6065
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6066
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
6067
|
+
] }) })
|
|
6068
|
+
]
|
|
6069
|
+
}
|
|
6070
|
+
) });
|
|
6071
|
+
};
|
|
6072
|
+
const schema$4 = zod.z.object({
|
|
6073
|
+
email: zod.z.string().email()
|
|
6074
|
+
});
|
|
5986
6075
|
const BillingAddress = () => {
|
|
5987
6076
|
const { id } = reactRouterDom.useParams();
|
|
5988
6077
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -6014,7 +6103,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
6014
6103
|
postal_code: order.billing_address?.postal_code ?? "",
|
|
6015
6104
|
phone: order.billing_address?.phone ?? ""
|
|
6016
6105
|
},
|
|
6017
|
-
resolver: zod$1.zodResolver(schema$
|
|
6106
|
+
resolver: zod$1.zodResolver(schema$3)
|
|
6018
6107
|
});
|
|
6019
6108
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
6020
6109
|
const { handleSuccess } = useRouteModal();
|
|
@@ -6171,75 +6260,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
6171
6260
|
}
|
|
6172
6261
|
) });
|
|
6173
6262
|
};
|
|
6174
|
-
const schema$
|
|
6175
|
-
const Email = () => {
|
|
6176
|
-
const { id } = reactRouterDom.useParams();
|
|
6177
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
6178
|
-
fields: "+email"
|
|
6179
|
-
});
|
|
6180
|
-
if (isError) {
|
|
6181
|
-
throw error;
|
|
6182
|
-
}
|
|
6183
|
-
const isReady = !isPending && !!order;
|
|
6184
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
6185
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
6186
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
6187
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
6188
|
-
] }),
|
|
6189
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
6190
|
-
] });
|
|
6191
|
-
};
|
|
6192
|
-
const EmailForm = ({ order }) => {
|
|
6193
|
-
const form = reactHookForm.useForm({
|
|
6194
|
-
defaultValues: {
|
|
6195
|
-
email: order.email ?? ""
|
|
6196
|
-
},
|
|
6197
|
-
resolver: zod$1.zodResolver(schema$4)
|
|
6198
|
-
});
|
|
6199
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
6200
|
-
const { handleSuccess } = useRouteModal();
|
|
6201
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
6202
|
-
await mutateAsync(
|
|
6203
|
-
{ email: data.email },
|
|
6204
|
-
{
|
|
6205
|
-
onSuccess: () => {
|
|
6206
|
-
handleSuccess();
|
|
6207
|
-
},
|
|
6208
|
-
onError: (error) => {
|
|
6209
|
-
ui.toast.error(error.message);
|
|
6210
|
-
}
|
|
6211
|
-
}
|
|
6212
|
-
);
|
|
6213
|
-
});
|
|
6214
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6215
|
-
KeyboundForm,
|
|
6216
|
-
{
|
|
6217
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
6218
|
-
onSubmit,
|
|
6219
|
-
children: [
|
|
6220
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6221
|
-
Form$2.Field,
|
|
6222
|
-
{
|
|
6223
|
-
control: form.control,
|
|
6224
|
-
name: "email",
|
|
6225
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
6226
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
6227
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
6228
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
6229
|
-
] })
|
|
6230
|
-
}
|
|
6231
|
-
) }),
|
|
6232
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
6233
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6234
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
6235
|
-
] }) })
|
|
6236
|
-
]
|
|
6237
|
-
}
|
|
6238
|
-
) });
|
|
6239
|
-
};
|
|
6240
|
-
const schema$4 = zod.z.object({
|
|
6241
|
-
email: zod.z.string().email()
|
|
6242
|
-
});
|
|
6263
|
+
const schema$3 = addressSchema;
|
|
6243
6264
|
const NumberInput = React.forwardRef(
|
|
6244
6265
|
({
|
|
6245
6266
|
value,
|
|
@@ -7259,27 +7280,6 @@ const customItemSchema = zod.z.object({
|
|
|
7259
7280
|
quantity: zod.z.number(),
|
|
7260
7281
|
unit_price: zod.z.union([zod.z.number(), zod.z.string()])
|
|
7261
7282
|
});
|
|
7262
|
-
const CustomItems = () => {
|
|
7263
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7264
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
7265
|
-
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
7266
|
-
] });
|
|
7267
|
-
};
|
|
7268
|
-
const CustomItemsForm = () => {
|
|
7269
|
-
const form = reactHookForm.useForm({
|
|
7270
|
-
resolver: zod$1.zodResolver(schema$3)
|
|
7271
|
-
});
|
|
7272
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
7273
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
7274
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7275
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7276
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
7277
|
-
] }) })
|
|
7278
|
-
] }) });
|
|
7279
|
-
};
|
|
7280
|
-
const schema$3 = zod.z.object({
|
|
7281
|
-
email: zod.z.string().email()
|
|
7282
|
-
});
|
|
7283
7283
|
const InlineTip = React.forwardRef(
|
|
7284
7284
|
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
7285
7285
|
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
@@ -7630,308 +7630,33 @@ function getHasUneditableRows(metadata) {
|
|
|
7630
7630
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
7631
7631
|
);
|
|
7632
7632
|
}
|
|
7633
|
-
const
|
|
7634
|
-
const promotionsQueryKeys = {
|
|
7635
|
-
list: (query2) => [
|
|
7636
|
-
PROMOTION_QUERY_KEY,
|
|
7637
|
-
query2 ? query2 : void 0
|
|
7638
|
-
],
|
|
7639
|
-
detail: (id, query2) => [
|
|
7640
|
-
PROMOTION_QUERY_KEY,
|
|
7641
|
-
id,
|
|
7642
|
-
query2 ? query2 : void 0
|
|
7643
|
-
]
|
|
7644
|
-
};
|
|
7645
|
-
const usePromotions = (query2, options) => {
|
|
7646
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
7647
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
7648
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
7649
|
-
...options
|
|
7650
|
-
});
|
|
7651
|
-
return { ...data, ...rest };
|
|
7652
|
-
};
|
|
7653
|
-
const Promotions = () => {
|
|
7633
|
+
const SalesChannel = () => {
|
|
7654
7634
|
const { id } = reactRouterDom.useParams();
|
|
7655
|
-
const {
|
|
7656
|
-
|
|
7657
|
-
isError: isPreviewError,
|
|
7658
|
-
error: previewError
|
|
7659
|
-
} = useOrderPreview(id, void 0);
|
|
7660
|
-
useInitiateOrderEdit({ preview });
|
|
7661
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
7662
|
-
if (isPreviewError) {
|
|
7663
|
-
throw previewError;
|
|
7664
|
-
}
|
|
7665
|
-
const isReady = !!preview;
|
|
7666
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
7667
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
7668
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
7669
|
-
] });
|
|
7670
|
-
};
|
|
7671
|
-
const PromotionForm = ({ preview }) => {
|
|
7672
|
-
const { items, shipping_methods } = preview;
|
|
7673
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
7674
|
-
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
7675
|
-
const { handleSuccess } = useRouteModal();
|
|
7676
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
7677
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
7678
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
7635
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
7636
|
+
id,
|
|
7679
7637
|
{
|
|
7680
|
-
|
|
7638
|
+
fields: "+sales_channel_id"
|
|
7681
7639
|
},
|
|
7682
7640
|
{
|
|
7683
|
-
enabled: !!
|
|
7641
|
+
enabled: !!id
|
|
7684
7642
|
}
|
|
7685
7643
|
);
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
}
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
});
|
|
7703
|
-
const add = async (value) => {
|
|
7704
|
-
if (!value) {
|
|
7705
|
-
return;
|
|
7706
|
-
}
|
|
7707
|
-
addPromotions(
|
|
7708
|
-
{
|
|
7709
|
-
promo_codes: [value]
|
|
7710
|
-
},
|
|
7711
|
-
{
|
|
7712
|
-
onError: (e) => {
|
|
7713
|
-
ui.toast.error(e.message);
|
|
7714
|
-
comboboxData.onSearchValueChange("");
|
|
7715
|
-
setComboboxValue("");
|
|
7716
|
-
},
|
|
7717
|
-
onSuccess: () => {
|
|
7718
|
-
comboboxData.onSearchValueChange("");
|
|
7719
|
-
setComboboxValue("");
|
|
7720
|
-
}
|
|
7721
|
-
}
|
|
7722
|
-
);
|
|
7723
|
-
};
|
|
7724
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
7725
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
7726
|
-
const onSubmit = async () => {
|
|
7727
|
-
setIsSubmitting(true);
|
|
7728
|
-
let requestSucceeded = false;
|
|
7729
|
-
await requestOrderEdit(void 0, {
|
|
7730
|
-
onError: (e) => {
|
|
7731
|
-
ui.toast.error(e.message);
|
|
7732
|
-
},
|
|
7733
|
-
onSuccess: () => {
|
|
7734
|
-
requestSucceeded = true;
|
|
7735
|
-
}
|
|
7736
|
-
});
|
|
7737
|
-
if (!requestSucceeded) {
|
|
7738
|
-
setIsSubmitting(false);
|
|
7739
|
-
return;
|
|
7740
|
-
}
|
|
7741
|
-
await confirmOrderEdit(void 0, {
|
|
7742
|
-
onError: (e) => {
|
|
7743
|
-
ui.toast.error(e.message);
|
|
7744
|
-
},
|
|
7745
|
-
onSuccess: () => {
|
|
7746
|
-
handleSuccess();
|
|
7747
|
-
},
|
|
7748
|
-
onSettled: () => {
|
|
7749
|
-
setIsSubmitting(false);
|
|
7750
|
-
}
|
|
7751
|
-
});
|
|
7752
|
-
};
|
|
7753
|
-
if (isError) {
|
|
7754
|
-
throw error;
|
|
7755
|
-
}
|
|
7756
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
7757
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
7758
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
7759
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
7760
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
7761
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
7762
|
-
] }),
|
|
7763
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7764
|
-
Combobox,
|
|
7765
|
-
{
|
|
7766
|
-
id: "promotion-combobox",
|
|
7767
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
7768
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
7769
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
7770
|
-
options: comboboxData.options,
|
|
7771
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
7772
|
-
searchValue: comboboxData.searchValue,
|
|
7773
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
7774
|
-
onChange: add,
|
|
7775
|
-
value: comboboxValue
|
|
7776
|
-
}
|
|
7777
|
-
)
|
|
7778
|
-
] }),
|
|
7779
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
7780
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
7781
|
-
PromotionItem,
|
|
7782
|
-
{
|
|
7783
|
-
promotion,
|
|
7784
|
-
orderId: preview.id,
|
|
7785
|
-
isLoading: isPending
|
|
7786
|
-
},
|
|
7787
|
-
promotion.id
|
|
7788
|
-
)) })
|
|
7789
|
-
] }) }),
|
|
7790
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7791
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7792
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7793
|
-
ui.Button,
|
|
7794
|
-
{
|
|
7795
|
-
size: "small",
|
|
7796
|
-
type: "submit",
|
|
7797
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
7798
|
-
children: "Save"
|
|
7799
|
-
}
|
|
7800
|
-
)
|
|
7801
|
-
] }) })
|
|
7802
|
-
] });
|
|
7803
|
-
};
|
|
7804
|
-
const PromotionItem = ({
|
|
7805
|
-
promotion,
|
|
7806
|
-
orderId,
|
|
7807
|
-
isLoading
|
|
7808
|
-
}) => {
|
|
7809
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
7810
|
-
const onRemove = async () => {
|
|
7811
|
-
removePromotions(
|
|
7812
|
-
{
|
|
7813
|
-
promo_codes: [promotion.code]
|
|
7814
|
-
},
|
|
7815
|
-
{
|
|
7816
|
-
onError: (e) => {
|
|
7817
|
-
ui.toast.error(e.message);
|
|
7818
|
-
}
|
|
7819
|
-
}
|
|
7820
|
-
);
|
|
7821
|
-
};
|
|
7822
|
-
const displayValue = getDisplayValue(promotion);
|
|
7823
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7824
|
-
"div",
|
|
7825
|
-
{
|
|
7826
|
-
className: ui.clx(
|
|
7827
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
7828
|
-
{
|
|
7829
|
-
"animate-pulse": isLoading
|
|
7830
|
-
}
|
|
7831
|
-
),
|
|
7832
|
-
children: [
|
|
7833
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7834
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
7835
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
7836
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
7837
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
7838
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
7839
|
-
] }),
|
|
7840
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
7841
|
-
] })
|
|
7842
|
-
] }),
|
|
7843
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7844
|
-
ui.IconButton,
|
|
7845
|
-
{
|
|
7846
|
-
size: "small",
|
|
7847
|
-
type: "button",
|
|
7848
|
-
variant: "transparent",
|
|
7849
|
-
onClick: onRemove,
|
|
7850
|
-
isLoading: isPending || isLoading,
|
|
7851
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
7852
|
-
}
|
|
7853
|
-
)
|
|
7854
|
-
]
|
|
7855
|
-
},
|
|
7856
|
-
promotion.id
|
|
7857
|
-
);
|
|
7858
|
-
};
|
|
7859
|
-
function getDisplayValue(promotion) {
|
|
7860
|
-
const value = promotion.application_method?.value;
|
|
7861
|
-
if (!value) {
|
|
7862
|
-
return null;
|
|
7863
|
-
}
|
|
7864
|
-
if (promotion.application_method?.type === "fixed") {
|
|
7865
|
-
const currency = promotion.application_method?.currency_code;
|
|
7866
|
-
if (!currency) {
|
|
7867
|
-
return null;
|
|
7868
|
-
}
|
|
7869
|
-
return getLocaleAmount(value, currency);
|
|
7870
|
-
} else if (promotion.application_method?.type === "percentage") {
|
|
7871
|
-
return formatPercentage(value);
|
|
7872
|
-
}
|
|
7873
|
-
return null;
|
|
7874
|
-
}
|
|
7875
|
-
const formatter = new Intl.NumberFormat([], {
|
|
7876
|
-
style: "percent",
|
|
7877
|
-
minimumFractionDigits: 2
|
|
7878
|
-
});
|
|
7879
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
7880
|
-
let val = value || 0;
|
|
7881
|
-
if (!isPercentageValue) {
|
|
7882
|
-
val = val / 100;
|
|
7883
|
-
}
|
|
7884
|
-
return formatter.format(val);
|
|
7885
|
-
};
|
|
7886
|
-
function getPromotionIds(items, shippingMethods) {
|
|
7887
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
7888
|
-
for (const item of items) {
|
|
7889
|
-
if (item.adjustments) {
|
|
7890
|
-
for (const adjustment of item.adjustments) {
|
|
7891
|
-
if (adjustment.promotion_id) {
|
|
7892
|
-
promotionIds.add(adjustment.promotion_id);
|
|
7893
|
-
}
|
|
7894
|
-
}
|
|
7895
|
-
}
|
|
7896
|
-
}
|
|
7897
|
-
for (const shippingMethod of shippingMethods) {
|
|
7898
|
-
if (shippingMethod.adjustments) {
|
|
7899
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
7900
|
-
if (adjustment.promotion_id) {
|
|
7901
|
-
promotionIds.add(adjustment.promotion_id);
|
|
7902
|
-
}
|
|
7903
|
-
}
|
|
7904
|
-
}
|
|
7905
|
-
}
|
|
7906
|
-
return Array.from(promotionIds);
|
|
7907
|
-
}
|
|
7908
|
-
const SalesChannel = () => {
|
|
7909
|
-
const { id } = reactRouterDom.useParams();
|
|
7910
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
7911
|
-
id,
|
|
7912
|
-
{
|
|
7913
|
-
fields: "+sales_channel_id"
|
|
7914
|
-
},
|
|
7915
|
-
{
|
|
7916
|
-
enabled: !!id
|
|
7917
|
-
}
|
|
7918
|
-
);
|
|
7919
|
-
if (isError) {
|
|
7920
|
-
throw error;
|
|
7921
|
-
}
|
|
7922
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
7923
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7924
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
7925
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
7926
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
7927
|
-
] }),
|
|
7928
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
7929
|
-
] });
|
|
7930
|
-
};
|
|
7931
|
-
const SalesChannelForm = ({ order }) => {
|
|
7932
|
-
const form = reactHookForm.useForm({
|
|
7933
|
-
defaultValues: {
|
|
7934
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
7644
|
+
if (isError) {
|
|
7645
|
+
throw error;
|
|
7646
|
+
}
|
|
7647
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
7648
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7649
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
7650
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
7651
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
7652
|
+
] }),
|
|
7653
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
7654
|
+
] });
|
|
7655
|
+
};
|
|
7656
|
+
const SalesChannelForm = ({ order }) => {
|
|
7657
|
+
const form = reactHookForm.useForm({
|
|
7658
|
+
defaultValues: {
|
|
7659
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
7935
7660
|
},
|
|
7936
7661
|
resolver: zod$1.zodResolver(schema$2)
|
|
7937
7662
|
});
|
|
@@ -9484,50 +9209,321 @@ const Illustration = () => {
|
|
|
9484
9209
|
const schema = zod.z.object({
|
|
9485
9210
|
customer_id: zod.z.string().min(1)
|
|
9486
9211
|
});
|
|
9487
|
-
const
|
|
9488
|
-
const
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9212
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
9213
|
+
const promotionsQueryKeys = {
|
|
9214
|
+
list: (query2) => [
|
|
9215
|
+
PROMOTION_QUERY_KEY,
|
|
9216
|
+
query2 ? query2 : void 0
|
|
9217
|
+
],
|
|
9218
|
+
detail: (id, query2) => [
|
|
9219
|
+
PROMOTION_QUERY_KEY,
|
|
9220
|
+
id,
|
|
9221
|
+
query2 ? query2 : void 0
|
|
9222
|
+
]
|
|
9223
|
+
};
|
|
9224
|
+
const usePromotions = (query2, options) => {
|
|
9225
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
9226
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
9227
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
9228
|
+
...options
|
|
9229
|
+
});
|
|
9230
|
+
return { ...data, ...rest };
|
|
9231
|
+
};
|
|
9232
|
+
const Promotions = () => {
|
|
9233
|
+
const { id } = reactRouterDom.useParams();
|
|
9234
|
+
const {
|
|
9235
|
+
order: preview,
|
|
9236
|
+
isError: isPreviewError,
|
|
9237
|
+
error: previewError
|
|
9238
|
+
} = useOrderPreview(id, void 0);
|
|
9239
|
+
useInitiateOrderEdit({ preview });
|
|
9240
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
9241
|
+
if (isPreviewError) {
|
|
9242
|
+
throw previewError;
|
|
9243
|
+
}
|
|
9244
|
+
const isReady = !!preview;
|
|
9245
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
9246
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
9247
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
9248
|
+
] });
|
|
9249
|
+
};
|
|
9250
|
+
const PromotionForm = ({ preview }) => {
|
|
9251
|
+
const { items, shipping_methods } = preview;
|
|
9252
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
9253
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
9254
|
+
const { handleSuccess } = useRouteModal();
|
|
9255
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
9256
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
9257
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
9258
|
+
{
|
|
9259
|
+
id: promoIds
|
|
9260
|
+
},
|
|
9261
|
+
{
|
|
9262
|
+
enabled: !!promoIds.length
|
|
9263
|
+
}
|
|
9264
|
+
);
|
|
9265
|
+
const comboboxData = useComboboxData({
|
|
9266
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
9267
|
+
queryFn: async (params) => {
|
|
9268
|
+
return await sdk.admin.promotion.list({
|
|
9269
|
+
...params,
|
|
9270
|
+
id: {
|
|
9271
|
+
$nin: promoIds
|
|
9272
|
+
}
|
|
9273
|
+
});
|
|
9274
|
+
},
|
|
9275
|
+
getOptions: (data) => {
|
|
9276
|
+
return data.promotions.map((promotion) => ({
|
|
9277
|
+
label: promotion.code,
|
|
9278
|
+
value: promotion.code
|
|
9279
|
+
}));
|
|
9280
|
+
}
|
|
9281
|
+
});
|
|
9282
|
+
const add = async (value) => {
|
|
9283
|
+
if (!value) {
|
|
9284
|
+
return;
|
|
9285
|
+
}
|
|
9286
|
+
addPromotions(
|
|
9287
|
+
{
|
|
9288
|
+
promo_codes: [value]
|
|
9289
|
+
},
|
|
9290
|
+
{
|
|
9291
|
+
onError: (e) => {
|
|
9292
|
+
ui.toast.error(e.message);
|
|
9293
|
+
comboboxData.onSearchValueChange("");
|
|
9294
|
+
setComboboxValue("");
|
|
9295
|
+
},
|
|
9296
|
+
onSuccess: () => {
|
|
9297
|
+
comboboxData.onSearchValueChange("");
|
|
9298
|
+
setComboboxValue("");
|
|
9299
|
+
}
|
|
9300
|
+
}
|
|
9301
|
+
);
|
|
9302
|
+
};
|
|
9303
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
9304
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
9305
|
+
const onSubmit = async () => {
|
|
9306
|
+
setIsSubmitting(true);
|
|
9307
|
+
let requestSucceeded = false;
|
|
9308
|
+
await requestOrderEdit(void 0, {
|
|
9309
|
+
onError: (e) => {
|
|
9310
|
+
ui.toast.error(e.message);
|
|
9311
|
+
},
|
|
9312
|
+
onSuccess: () => {
|
|
9313
|
+
requestSucceeded = true;
|
|
9314
|
+
}
|
|
9315
|
+
});
|
|
9316
|
+
if (!requestSucceeded) {
|
|
9317
|
+
setIsSubmitting(false);
|
|
9318
|
+
return;
|
|
9319
|
+
}
|
|
9320
|
+
await confirmOrderEdit(void 0, {
|
|
9321
|
+
onError: (e) => {
|
|
9322
|
+
ui.toast.error(e.message);
|
|
9323
|
+
},
|
|
9324
|
+
onSuccess: () => {
|
|
9325
|
+
handleSuccess();
|
|
9326
|
+
},
|
|
9327
|
+
onSettled: () => {
|
|
9328
|
+
setIsSubmitting(false);
|
|
9329
|
+
}
|
|
9330
|
+
});
|
|
9331
|
+
};
|
|
9332
|
+
if (isError) {
|
|
9333
|
+
throw error;
|
|
9334
|
+
}
|
|
9335
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
9336
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
9337
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
9338
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
9339
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
9340
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
9341
|
+
] }),
|
|
9342
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9343
|
+
Combobox,
|
|
9344
|
+
{
|
|
9345
|
+
id: "promotion-combobox",
|
|
9346
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
9347
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
9348
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
9349
|
+
options: comboboxData.options,
|
|
9350
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
9351
|
+
searchValue: comboboxData.searchValue,
|
|
9352
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
9353
|
+
onChange: add,
|
|
9354
|
+
value: comboboxValue
|
|
9355
|
+
}
|
|
9356
|
+
)
|
|
9357
|
+
] }),
|
|
9358
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
9359
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
9360
|
+
PromotionItem,
|
|
9361
|
+
{
|
|
9362
|
+
promotion,
|
|
9363
|
+
orderId: preview.id,
|
|
9364
|
+
isLoading: isPending
|
|
9365
|
+
},
|
|
9366
|
+
promotion.id
|
|
9367
|
+
)) })
|
|
9368
|
+
] }) }),
|
|
9369
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9370
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9371
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9372
|
+
ui.Button,
|
|
9373
|
+
{
|
|
9374
|
+
size: "small",
|
|
9375
|
+
type: "submit",
|
|
9376
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
9377
|
+
children: "Save"
|
|
9378
|
+
}
|
|
9379
|
+
)
|
|
9380
|
+
] }) })
|
|
9381
|
+
] });
|
|
9382
|
+
};
|
|
9383
|
+
const PromotionItem = ({
|
|
9384
|
+
promotion,
|
|
9385
|
+
orderId,
|
|
9386
|
+
isLoading
|
|
9387
|
+
}) => {
|
|
9388
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
9389
|
+
const onRemove = async () => {
|
|
9390
|
+
removePromotions(
|
|
9391
|
+
{
|
|
9392
|
+
promo_codes: [promotion.code]
|
|
9393
|
+
},
|
|
9394
|
+
{
|
|
9395
|
+
onError: (e) => {
|
|
9396
|
+
ui.toast.error(e.message);
|
|
9397
|
+
}
|
|
9398
|
+
}
|
|
9399
|
+
);
|
|
9400
|
+
};
|
|
9401
|
+
const displayValue = getDisplayValue(promotion);
|
|
9402
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9403
|
+
"div",
|
|
9404
|
+
{
|
|
9405
|
+
className: ui.clx(
|
|
9406
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
9407
|
+
{
|
|
9408
|
+
"animate-pulse": isLoading
|
|
9409
|
+
}
|
|
9410
|
+
),
|
|
9411
|
+
children: [
|
|
9412
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
9413
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
9414
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
9415
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
9416
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
9417
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
9418
|
+
] }),
|
|
9419
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
9420
|
+
] })
|
|
9421
|
+
] }),
|
|
9422
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9423
|
+
ui.IconButton,
|
|
9424
|
+
{
|
|
9425
|
+
size: "small",
|
|
9426
|
+
type: "button",
|
|
9427
|
+
variant: "transparent",
|
|
9428
|
+
onClick: onRemove,
|
|
9429
|
+
isLoading: isPending || isLoading,
|
|
9430
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
9431
|
+
}
|
|
9432
|
+
)
|
|
9433
|
+
]
|
|
9434
|
+
},
|
|
9435
|
+
promotion.id
|
|
9436
|
+
);
|
|
9437
|
+
};
|
|
9438
|
+
function getDisplayValue(promotion) {
|
|
9439
|
+
const value = promotion.application_method?.value;
|
|
9440
|
+
if (!value) {
|
|
9441
|
+
return null;
|
|
9442
|
+
}
|
|
9443
|
+
if (promotion.application_method?.type === "fixed") {
|
|
9444
|
+
const currency = promotion.application_method?.currency_code;
|
|
9445
|
+
if (!currency) {
|
|
9446
|
+
return null;
|
|
9447
|
+
}
|
|
9448
|
+
return getLocaleAmount(value, currency);
|
|
9449
|
+
} else if (promotion.application_method?.type === "percentage") {
|
|
9450
|
+
return formatPercentage(value);
|
|
9451
|
+
}
|
|
9452
|
+
return null;
|
|
9453
|
+
}
|
|
9454
|
+
const formatter = new Intl.NumberFormat([], {
|
|
9455
|
+
style: "percent",
|
|
9456
|
+
minimumFractionDigits: 2
|
|
9457
|
+
});
|
|
9458
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
9459
|
+
let val = value || 0;
|
|
9460
|
+
if (!isPercentageValue) {
|
|
9461
|
+
val = val / 100;
|
|
9462
|
+
}
|
|
9463
|
+
return formatter.format(val);
|
|
9464
|
+
};
|
|
9465
|
+
function getPromotionIds(items, shippingMethods) {
|
|
9466
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
9467
|
+
for (const item of items) {
|
|
9468
|
+
if (item.adjustments) {
|
|
9469
|
+
for (const adjustment of item.adjustments) {
|
|
9470
|
+
if (adjustment.promotion_id) {
|
|
9471
|
+
promotionIds.add(adjustment.promotion_id);
|
|
9472
|
+
}
|
|
9473
|
+
}
|
|
9474
|
+
}
|
|
9475
|
+
}
|
|
9476
|
+
for (const shippingMethod of shippingMethods) {
|
|
9477
|
+
if (shippingMethod.adjustments) {
|
|
9478
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
9479
|
+
if (adjustment.promotion_id) {
|
|
9480
|
+
promotionIds.add(adjustment.promotion_id);
|
|
9481
|
+
}
|
|
9482
|
+
}
|
|
9483
|
+
}
|
|
9484
|
+
}
|
|
9485
|
+
return Array.from(promotionIds);
|
|
9486
|
+
}
|
|
9487
|
+
const widgetModule = { widgets: [] };
|
|
9488
|
+
const routeModule = {
|
|
9489
|
+
routes: [
|
|
9490
|
+
{
|
|
9491
|
+
Component: List,
|
|
9492
|
+
path: "/draft-orders",
|
|
9493
|
+
handle: { label: config.label, translationNs: config.translationNs, ...handle$1 },
|
|
9494
|
+
children: [
|
|
9495
|
+
{
|
|
9496
|
+
Component: Create,
|
|
9497
|
+
path: "/draft-orders/create"
|
|
9498
|
+
}
|
|
9499
|
+
]
|
|
9500
|
+
},
|
|
9501
|
+
{
|
|
9502
|
+
Component: ID,
|
|
9503
|
+
path: "/draft-orders/:id",
|
|
9504
9504
|
handle,
|
|
9505
9505
|
loader,
|
|
9506
9506
|
children: [
|
|
9507
9507
|
{
|
|
9508
|
-
Component:
|
|
9509
|
-
path: "/draft-orders/:id/
|
|
9508
|
+
Component: CustomItems,
|
|
9509
|
+
path: "/draft-orders/:id/custom-items"
|
|
9510
9510
|
},
|
|
9511
9511
|
{
|
|
9512
9512
|
Component: Email,
|
|
9513
9513
|
path: "/draft-orders/:id/email"
|
|
9514
9514
|
},
|
|
9515
9515
|
{
|
|
9516
|
-
Component:
|
|
9517
|
-
path: "/draft-orders/:id/
|
|
9516
|
+
Component: BillingAddress,
|
|
9517
|
+
path: "/draft-orders/:id/billing-address"
|
|
9518
9518
|
},
|
|
9519
9519
|
{
|
|
9520
|
-
Component:
|
|
9521
|
-
path: "/draft-orders/:id/
|
|
9520
|
+
Component: Items,
|
|
9521
|
+
path: "/draft-orders/:id/items"
|
|
9522
9522
|
},
|
|
9523
9523
|
{
|
|
9524
9524
|
Component: Metadata,
|
|
9525
9525
|
path: "/draft-orders/:id/metadata"
|
|
9526
9526
|
},
|
|
9527
|
-
{
|
|
9528
|
-
Component: Promotions,
|
|
9529
|
-
path: "/draft-orders/:id/promotions"
|
|
9530
|
-
},
|
|
9531
9527
|
{
|
|
9532
9528
|
Component: SalesChannel,
|
|
9533
9529
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -9543,6 +9539,10 @@ const routeModule = {
|
|
|
9543
9539
|
{
|
|
9544
9540
|
Component: TransferOwnership,
|
|
9545
9541
|
path: "/draft-orders/:id/transfer-ownership"
|
|
9542
|
+
},
|
|
9543
|
+
{
|
|
9544
|
+
Component: Promotions,
|
|
9545
|
+
path: "/draft-orders/:id/promotions"
|
|
9546
9546
|
}
|
|
9547
9547
|
]
|
|
9548
9548
|
}
|