@medusajs/draft-order 2.22.2-preview-20261029142542 → 2.22.2
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 +421 -421
- package/.medusa/server/src/admin/index.mjs +421 -421
- package/package.json +18 -18
|
@@ -6193,6 +6193,74 @@ const CustomItemsForm = () => {
|
|
|
6193
6193
|
const schema$4 = zod.z.object({
|
|
6194
6194
|
email: zod.z.string().email()
|
|
6195
6195
|
});
|
|
6196
|
+
const Email = () => {
|
|
6197
|
+
const { id } = reactRouterDom.useParams();
|
|
6198
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
6199
|
+
fields: "+email"
|
|
6200
|
+
});
|
|
6201
|
+
if (isError) {
|
|
6202
|
+
throw error;
|
|
6203
|
+
}
|
|
6204
|
+
const isReady = !isPending && !!order;
|
|
6205
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
6206
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
6207
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
6208
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
6209
|
+
] }),
|
|
6210
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
6211
|
+
] });
|
|
6212
|
+
};
|
|
6213
|
+
const EmailForm = ({ order }) => {
|
|
6214
|
+
const form = reactHookForm.useForm({
|
|
6215
|
+
defaultValues: {
|
|
6216
|
+
email: order.email ?? ""
|
|
6217
|
+
},
|
|
6218
|
+
resolver: zod$1.zodResolver(schema$3)
|
|
6219
|
+
});
|
|
6220
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
6221
|
+
const { handleSuccess } = useRouteModal();
|
|
6222
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
6223
|
+
await mutateAsync(
|
|
6224
|
+
{ email: data.email },
|
|
6225
|
+
{
|
|
6226
|
+
onSuccess: () => {
|
|
6227
|
+
handleSuccess();
|
|
6228
|
+
},
|
|
6229
|
+
onError: (error) => {
|
|
6230
|
+
ui.toast.error(error.message);
|
|
6231
|
+
}
|
|
6232
|
+
}
|
|
6233
|
+
);
|
|
6234
|
+
});
|
|
6235
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6236
|
+
KeyboundForm,
|
|
6237
|
+
{
|
|
6238
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
6239
|
+
onSubmit,
|
|
6240
|
+
children: [
|
|
6241
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6242
|
+
Form$2.Field,
|
|
6243
|
+
{
|
|
6244
|
+
control: form.control,
|
|
6245
|
+
name: "email",
|
|
6246
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
6247
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
6248
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
6249
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
6250
|
+
] })
|
|
6251
|
+
}
|
|
6252
|
+
) }),
|
|
6253
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
6254
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6255
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
6256
|
+
] }) })
|
|
6257
|
+
]
|
|
6258
|
+
}
|
|
6259
|
+
) });
|
|
6260
|
+
};
|
|
6261
|
+
const schema$3 = zod.z.object({
|
|
6262
|
+
email: zod.z.string().email()
|
|
6263
|
+
});
|
|
6196
6264
|
const NumberInput = React.forwardRef(
|
|
6197
6265
|
({
|
|
6198
6266
|
value,
|
|
@@ -7212,74 +7280,6 @@ const customItemSchema = zod.z.object({
|
|
|
7212
7280
|
quantity: zod.z.number(),
|
|
7213
7281
|
unit_price: zod.z.union([zod.z.number(), zod.z.string()])
|
|
7214
7282
|
});
|
|
7215
|
-
const Email = () => {
|
|
7216
|
-
const { id } = reactRouterDom.useParams();
|
|
7217
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
7218
|
-
fields: "+email"
|
|
7219
|
-
});
|
|
7220
|
-
if (isError) {
|
|
7221
|
-
throw error;
|
|
7222
|
-
}
|
|
7223
|
-
const isReady = !isPending && !!order;
|
|
7224
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7225
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
7226
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
7227
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
7228
|
-
] }),
|
|
7229
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
7230
|
-
] });
|
|
7231
|
-
};
|
|
7232
|
-
const EmailForm = ({ order }) => {
|
|
7233
|
-
const form = reactHookForm.useForm({
|
|
7234
|
-
defaultValues: {
|
|
7235
|
-
email: order.email ?? ""
|
|
7236
|
-
},
|
|
7237
|
-
resolver: zod$1.zodResolver(schema$3)
|
|
7238
|
-
});
|
|
7239
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
7240
|
-
const { handleSuccess } = useRouteModal();
|
|
7241
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
7242
|
-
await mutateAsync(
|
|
7243
|
-
{ email: data.email },
|
|
7244
|
-
{
|
|
7245
|
-
onSuccess: () => {
|
|
7246
|
-
handleSuccess();
|
|
7247
|
-
},
|
|
7248
|
-
onError: (error) => {
|
|
7249
|
-
ui.toast.error(error.message);
|
|
7250
|
-
}
|
|
7251
|
-
}
|
|
7252
|
-
);
|
|
7253
|
-
});
|
|
7254
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7255
|
-
KeyboundForm,
|
|
7256
|
-
{
|
|
7257
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
7258
|
-
onSubmit,
|
|
7259
|
-
children: [
|
|
7260
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7261
|
-
Form$2.Field,
|
|
7262
|
-
{
|
|
7263
|
-
control: form.control,
|
|
7264
|
-
name: "email",
|
|
7265
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
7266
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
7267
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
7268
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
7269
|
-
] })
|
|
7270
|
-
}
|
|
7271
|
-
) }),
|
|
7272
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7273
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7274
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7275
|
-
] }) })
|
|
7276
|
-
]
|
|
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,112 +7630,281 @@ function getHasUneditableRows(metadata) {
|
|
|
7630
7630
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
7631
7631
|
);
|
|
7632
7632
|
}
|
|
7633
|
-
const
|
|
7634
|
-
|
|
7635
|
-
|
|
7633
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
7634
|
+
const promotionsQueryKeys = {
|
|
7635
|
+
list: (query2) => [
|
|
7636
|
+
PROMOTION_QUERY_KEY,
|
|
7637
|
+
query2 ? query2 : void 0
|
|
7638
|
+
],
|
|
7639
|
+
detail: (id, query2) => [
|
|
7640
|
+
PROMOTION_QUERY_KEY,
|
|
7636
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 = () => {
|
|
7654
|
+
const { id } = reactRouterDom.useParams();
|
|
7655
|
+
const {
|
|
7656
|
+
order: preview,
|
|
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(
|
|
7637
7679
|
{
|
|
7638
|
-
|
|
7680
|
+
id: promoIds
|
|
7639
7681
|
},
|
|
7640
7682
|
{
|
|
7641
|
-
enabled: !!
|
|
7683
|
+
enabled: !!promoIds.length
|
|
7642
7684
|
}
|
|
7643
7685
|
);
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
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 || ""
|
|
7686
|
+
const comboboxData = useComboboxData({
|
|
7687
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
7688
|
+
queryFn: async (params) => {
|
|
7689
|
+
return await sdk.admin.promotion.list({
|
|
7690
|
+
...params,
|
|
7691
|
+
id: {
|
|
7692
|
+
$nin: promoIds
|
|
7693
|
+
}
|
|
7694
|
+
});
|
|
7660
7695
|
},
|
|
7661
|
-
|
|
7696
|
+
getOptions: (data) => {
|
|
7697
|
+
return data.promotions.map((promotion) => ({
|
|
7698
|
+
label: promotion.code,
|
|
7699
|
+
value: promotion.code
|
|
7700
|
+
}));
|
|
7701
|
+
}
|
|
7662
7702
|
});
|
|
7663
|
-
const
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7703
|
+
const add = async (value) => {
|
|
7704
|
+
if (!value) {
|
|
7705
|
+
return;
|
|
7706
|
+
}
|
|
7707
|
+
addPromotions(
|
|
7667
7708
|
{
|
|
7668
|
-
|
|
7709
|
+
promo_codes: [value]
|
|
7669
7710
|
},
|
|
7670
7711
|
{
|
|
7671
|
-
|
|
7672
|
-
ui.toast.
|
|
7673
|
-
|
|
7712
|
+
onError: (e) => {
|
|
7713
|
+
ui.toast.error(e.message);
|
|
7714
|
+
comboboxData.onSearchValueChange("");
|
|
7715
|
+
setComboboxValue("");
|
|
7674
7716
|
},
|
|
7675
|
-
|
|
7676
|
-
|
|
7717
|
+
onSuccess: () => {
|
|
7718
|
+
comboboxData.onSearchValueChange("");
|
|
7719
|
+
setComboboxValue("");
|
|
7677
7720
|
}
|
|
7678
7721
|
}
|
|
7679
7722
|
);
|
|
7680
|
-
}
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
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;
|
|
7693
7740
|
}
|
|
7694
|
-
|
|
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
|
+
] });
|
|
7695
7803
|
};
|
|
7696
|
-
const
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
}
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
Form$2.Field,
|
|
7712
|
-
{
|
|
7713
|
-
control,
|
|
7714
|
-
name: "sales_channel_id",
|
|
7715
|
-
render: ({ field }) => {
|
|
7716
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
7717
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
7718
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7719
|
-
Combobox,
|
|
7720
|
-
{
|
|
7721
|
-
options: salesChannels.options,
|
|
7722
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
7723
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
7724
|
-
searchValue: salesChannels.searchValue,
|
|
7725
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
7726
|
-
placeholder: "Select sales channel",
|
|
7727
|
-
...field
|
|
7728
|
-
}
|
|
7729
|
-
) }),
|
|
7730
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
7731
|
-
] });
|
|
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
|
+
}
|
|
7732
7819
|
}
|
|
7733
|
-
|
|
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
|
|
7734
7857
|
);
|
|
7735
7858
|
};
|
|
7736
|
-
|
|
7737
|
-
|
|
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
|
|
7738
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
|
+
}
|
|
7739
7908
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
7740
7909
|
const Shipping = () => {
|
|
7741
7910
|
const { id } = reactRouterDom.useParams();
|
|
@@ -8561,7 +8730,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
8561
8730
|
postal_code: order.shipping_address?.postal_code ?? "",
|
|
8562
8731
|
phone: order.shipping_address?.phone ?? ""
|
|
8563
8732
|
},
|
|
8564
|
-
resolver: zod$1.zodResolver(schema$
|
|
8733
|
+
resolver: zod$1.zodResolver(schema$2)
|
|
8565
8734
|
});
|
|
8566
8735
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
8567
8736
|
const { handleSuccess } = useRouteModal();
|
|
@@ -8731,7 +8900,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
8731
8900
|
}
|
|
8732
8901
|
) });
|
|
8733
8902
|
};
|
|
8734
|
-
const schema$
|
|
8903
|
+
const schema$2 = addressSchema;
|
|
8735
8904
|
const TransferOwnership = () => {
|
|
8736
8905
|
const { id } = reactRouterDom.useParams();
|
|
8737
8906
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -8754,7 +8923,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
8754
8923
|
defaultValues: {
|
|
8755
8924
|
customer_id: order.customer_id || ""
|
|
8756
8925
|
},
|
|
8757
|
-
resolver: zod$1.zodResolver(schema)
|
|
8926
|
+
resolver: zod$1.zodResolver(schema$1)
|
|
8758
8927
|
});
|
|
8759
8928
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
8760
8929
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9206,284 +9375,115 @@ const Illustration = () => {
|
|
|
9206
9375
|
}
|
|
9207
9376
|
);
|
|
9208
9377
|
};
|
|
9209
|
-
const schema = zod.z.object({
|
|
9378
|
+
const schema$1 = zod.z.object({
|
|
9210
9379
|
customer_id: zod.z.string().min(1)
|
|
9211
9380
|
});
|
|
9212
|
-
const
|
|
9213
|
-
const
|
|
9214
|
-
|
|
9215
|
-
PROMOTION_QUERY_KEY,
|
|
9216
|
-
query2 ? query2 : void 0
|
|
9217
|
-
],
|
|
9218
|
-
detail: (id, query2) => [
|
|
9219
|
-
PROMOTION_QUERY_KEY,
|
|
9381
|
+
const SalesChannel = () => {
|
|
9382
|
+
const { id } = reactRouterDom.useParams();
|
|
9383
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
9220
9384
|
id,
|
|
9221
|
-
|
|
9222
|
-
|
|
9385
|
+
{
|
|
9386
|
+
fields: "+sales_channel_id"
|
|
9387
|
+
},
|
|
9388
|
+
{
|
|
9389
|
+
enabled: !!id
|
|
9390
|
+
}
|
|
9391
|
+
);
|
|
9392
|
+
if (isError) {
|
|
9393
|
+
throw error;
|
|
9394
|
+
}
|
|
9395
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
9396
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9397
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9398
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
9399
|
+
/* @__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" }) })
|
|
9400
|
+
] }),
|
|
9401
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
9402
|
+
] });
|
|
9223
9403
|
};
|
|
9224
|
-
const
|
|
9225
|
-
const
|
|
9226
|
-
|
|
9227
|
-
|
|
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
|
-
});
|
|
9404
|
+
const SalesChannelForm = ({ order }) => {
|
|
9405
|
+
const form = reactHookForm.useForm({
|
|
9406
|
+
defaultValues: {
|
|
9407
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
9274
9408
|
},
|
|
9275
|
-
|
|
9276
|
-
return data.promotions.map((promotion) => ({
|
|
9277
|
-
label: promotion.code,
|
|
9278
|
-
value: promotion.code
|
|
9279
|
-
}));
|
|
9280
|
-
}
|
|
9409
|
+
resolver: zod$1.zodResolver(schema)
|
|
9281
9410
|
});
|
|
9282
|
-
const
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
addPromotions(
|
|
9411
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9412
|
+
const { handleSuccess } = useRouteModal();
|
|
9413
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9414
|
+
await mutateAsync(
|
|
9287
9415
|
{
|
|
9288
|
-
|
|
9416
|
+
sales_channel_id: data.sales_channel_id
|
|
9289
9417
|
},
|
|
9290
9418
|
{
|
|
9291
|
-
onError: (e) => {
|
|
9292
|
-
ui.toast.error(e.message);
|
|
9293
|
-
comboboxData.onSearchValueChange("");
|
|
9294
|
-
setComboboxValue("");
|
|
9295
|
-
},
|
|
9296
9419
|
onSuccess: () => {
|
|
9297
|
-
|
|
9298
|
-
|
|
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
|
|
9420
|
+
ui.toast.success("Sales channel updated");
|
|
9421
|
+
handleSuccess();
|
|
9365
9422
|
},
|
|
9366
|
-
|
|
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);
|
|
9423
|
+
onError: (error) => {
|
|
9424
|
+
ui.toast.error(error.message);
|
|
9397
9425
|
}
|
|
9398
9426
|
}
|
|
9399
9427
|
);
|
|
9400
|
-
};
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
"div",
|
|
9428
|
+
});
|
|
9429
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9430
|
+
KeyboundForm,
|
|
9404
9431
|
{
|
|
9405
|
-
className:
|
|
9406
|
-
|
|
9407
|
-
{
|
|
9408
|
-
"animate-pulse": isLoading
|
|
9409
|
-
}
|
|
9410
|
-
),
|
|
9432
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9433
|
+
onSubmit,
|
|
9411
9434
|
children: [
|
|
9412
|
-
/* @__PURE__ */ jsxRuntime.
|
|
9413
|
-
|
|
9414
|
-
/* @__PURE__ */ jsxRuntime.
|
|
9415
|
-
|
|
9416
|
-
|
|
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
|
-
)
|
|
9435
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
9436
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9437
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9438
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9439
|
+
] }) })
|
|
9433
9440
|
]
|
|
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
9441
|
}
|
|
9448
|
-
|
|
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);
|
|
9442
|
+
) });
|
|
9464
9443
|
};
|
|
9465
|
-
|
|
9466
|
-
const
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9444
|
+
const SalesChannelField = ({ control, order }) => {
|
|
9445
|
+
const salesChannels = useComboboxData({
|
|
9446
|
+
queryFn: async (params) => {
|
|
9447
|
+
return await sdk.admin.salesChannel.list(params);
|
|
9448
|
+
},
|
|
9449
|
+
queryKey: ["sales-channels"],
|
|
9450
|
+
getOptions: (data) => {
|
|
9451
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
9452
|
+
label: salesChannel.name,
|
|
9453
|
+
value: salesChannel.id
|
|
9454
|
+
}));
|
|
9455
|
+
},
|
|
9456
|
+
defaultValue: order.sales_channel_id || void 0
|
|
9457
|
+
});
|
|
9458
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9459
|
+
Form$2.Field,
|
|
9460
|
+
{
|
|
9461
|
+
control,
|
|
9462
|
+
name: "sales_channel_id",
|
|
9463
|
+
render: ({ field }) => {
|
|
9464
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9465
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
9466
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9467
|
+
Combobox,
|
|
9468
|
+
{
|
|
9469
|
+
options: salesChannels.options,
|
|
9470
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
9471
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
9472
|
+
searchValue: salesChannels.searchValue,
|
|
9473
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
9474
|
+
placeholder: "Select sales channel",
|
|
9475
|
+
...field
|
|
9476
|
+
}
|
|
9477
|
+
) }),
|
|
9478
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9479
|
+
] });
|
|
9482
9480
|
}
|
|
9483
9481
|
}
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9482
|
+
);
|
|
9483
|
+
};
|
|
9484
|
+
const schema = zod.z.object({
|
|
9485
|
+
sales_channel_id: zod.z.string().min(1)
|
|
9486
|
+
});
|
|
9487
9487
|
const widgetModule = { widgets: [] };
|
|
9488
9488
|
const routeModule = {
|
|
9489
9489
|
routes: [
|
|
@@ -9512,21 +9512,21 @@ const routeModule = {
|
|
|
9512
9512
|
Component: CustomItems,
|
|
9513
9513
|
path: "/draft-orders/:id/custom-items"
|
|
9514
9514
|
},
|
|
9515
|
-
{
|
|
9516
|
-
Component: Items,
|
|
9517
|
-
path: "/draft-orders/:id/items"
|
|
9518
|
-
},
|
|
9519
9515
|
{
|
|
9520
9516
|
Component: Email,
|
|
9521
9517
|
path: "/draft-orders/:id/email"
|
|
9522
9518
|
},
|
|
9519
|
+
{
|
|
9520
|
+
Component: Items,
|
|
9521
|
+
path: "/draft-orders/:id/items"
|
|
9522
|
+
},
|
|
9523
9523
|
{
|
|
9524
9524
|
Component: Metadata,
|
|
9525
9525
|
path: "/draft-orders/:id/metadata"
|
|
9526
9526
|
},
|
|
9527
9527
|
{
|
|
9528
|
-
Component:
|
|
9529
|
-
path: "/draft-orders/:id/
|
|
9528
|
+
Component: Promotions,
|
|
9529
|
+
path: "/draft-orders/:id/promotions"
|
|
9530
9530
|
},
|
|
9531
9531
|
{
|
|
9532
9532
|
Component: Shipping,
|
|
@@ -9541,8 +9541,8 @@ const routeModule = {
|
|
|
9541
9541
|
path: "/draft-orders/:id/transfer-ownership"
|
|
9542
9542
|
},
|
|
9543
9543
|
{
|
|
9544
|
-
Component:
|
|
9545
|
-
path: "/draft-orders/:id/
|
|
9544
|
+
Component: SalesChannel,
|
|
9545
|
+
path: "/draft-orders/:id/sales-channel"
|
|
9546
9546
|
}
|
|
9547
9547
|
]
|
|
9548
9548
|
}
|