@medusajs/draft-order 2.15.0 → 2.15.1-preview-20260511150319
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 +615 -615
- package/.medusa/server/src/admin/index.mjs +615 -615
- package/package.json +16 -16
|
@@ -9899,27 +9899,6 @@ const ID = () => {
|
|
|
9899
9899
|
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
|
|
9900
9900
|
] });
|
|
9901
9901
|
};
|
|
9902
|
-
const CustomItems = () => {
|
|
9903
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9904
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9905
|
-
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9906
|
-
] });
|
|
9907
|
-
};
|
|
9908
|
-
const CustomItemsForm = () => {
|
|
9909
|
-
const form = reactHookForm.useForm({
|
|
9910
|
-
resolver: zod.zodResolver(schema$5)
|
|
9911
|
-
});
|
|
9912
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9913
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9914
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9915
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9916
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9917
|
-
] }) })
|
|
9918
|
-
] }) });
|
|
9919
|
-
};
|
|
9920
|
-
const schema$5 = object({
|
|
9921
|
-
email: string().email()
|
|
9922
|
-
});
|
|
9923
9902
|
const BillingAddress = () => {
|
|
9924
9903
|
const { id } = reactRouterDom.useParams();
|
|
9925
9904
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9952,7 +9931,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9952
9931
|
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9953
9932
|
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9954
9933
|
},
|
|
9955
|
-
resolver: zod.zodResolver(schema$
|
|
9934
|
+
resolver: zod.zodResolver(schema$5)
|
|
9956
9935
|
});
|
|
9957
9936
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9958
9937
|
const { handleSuccess } = useRouteModal();
|
|
@@ -10109,7 +10088,96 @@ const BillingAddressForm = ({ order }) => {
|
|
|
10109
10088
|
}
|
|
10110
10089
|
) });
|
|
10111
10090
|
};
|
|
10112
|
-
const schema$
|
|
10091
|
+
const schema$5 = addressSchema;
|
|
10092
|
+
const Email = () => {
|
|
10093
|
+
const { id } = reactRouterDom.useParams();
|
|
10094
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10095
|
+
fields: "+email"
|
|
10096
|
+
});
|
|
10097
|
+
if (isError) {
|
|
10098
|
+
throw error;
|
|
10099
|
+
}
|
|
10100
|
+
const isReady = !isPending && !!order;
|
|
10101
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10102
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
10103
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
10104
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
10105
|
+
] }),
|
|
10106
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
10107
|
+
] });
|
|
10108
|
+
};
|
|
10109
|
+
const EmailForm = ({ order }) => {
|
|
10110
|
+
const form = reactHookForm.useForm({
|
|
10111
|
+
defaultValues: {
|
|
10112
|
+
email: order.email ?? ""
|
|
10113
|
+
},
|
|
10114
|
+
resolver: zod.zodResolver(schema$4)
|
|
10115
|
+
});
|
|
10116
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10117
|
+
const { handleSuccess } = useRouteModal();
|
|
10118
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10119
|
+
await mutateAsync(
|
|
10120
|
+
{ email: data.email },
|
|
10121
|
+
{
|
|
10122
|
+
onSuccess: () => {
|
|
10123
|
+
handleSuccess();
|
|
10124
|
+
},
|
|
10125
|
+
onError: (error) => {
|
|
10126
|
+
ui.toast.error(error.message);
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
10129
|
+
);
|
|
10130
|
+
});
|
|
10131
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10132
|
+
KeyboundForm,
|
|
10133
|
+
{
|
|
10134
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10135
|
+
onSubmit,
|
|
10136
|
+
children: [
|
|
10137
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10138
|
+
Form$2.Field,
|
|
10139
|
+
{
|
|
10140
|
+
control: form.control,
|
|
10141
|
+
name: "email",
|
|
10142
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
10143
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
10144
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
10145
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
10146
|
+
] })
|
|
10147
|
+
}
|
|
10148
|
+
) }),
|
|
10149
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10150
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10151
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10152
|
+
] }) })
|
|
10153
|
+
]
|
|
10154
|
+
}
|
|
10155
|
+
) });
|
|
10156
|
+
};
|
|
10157
|
+
const schema$4 = object({
|
|
10158
|
+
email: string().email()
|
|
10159
|
+
});
|
|
10160
|
+
const CustomItems = () => {
|
|
10161
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10162
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
10163
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
10164
|
+
] });
|
|
10165
|
+
};
|
|
10166
|
+
const CustomItemsForm = () => {
|
|
10167
|
+
const form = reactHookForm.useForm({
|
|
10168
|
+
resolver: zod.zodResolver(schema$3)
|
|
10169
|
+
});
|
|
10170
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
10171
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
10172
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10173
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10174
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
10175
|
+
] }) })
|
|
10176
|
+
] }) });
|
|
10177
|
+
};
|
|
10178
|
+
const schema$3 = object({
|
|
10179
|
+
email: string().email()
|
|
10180
|
+
});
|
|
10113
10181
|
const NumberInput = React.forwardRef(
|
|
10114
10182
|
({
|
|
10115
10183
|
value,
|
|
@@ -11084,74 +11152,6 @@ const customItemSchema = object({
|
|
|
11084
11152
|
quantity: number(),
|
|
11085
11153
|
unit_price: union([number(), string()])
|
|
11086
11154
|
});
|
|
11087
|
-
const Email = () => {
|
|
11088
|
-
const { id } = reactRouterDom.useParams();
|
|
11089
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11090
|
-
fields: "+email"
|
|
11091
|
-
});
|
|
11092
|
-
if (isError) {
|
|
11093
|
-
throw error;
|
|
11094
|
-
}
|
|
11095
|
-
const isReady = !isPending && !!order;
|
|
11096
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11097
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11098
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
11099
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
11100
|
-
] }),
|
|
11101
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
11102
|
-
] });
|
|
11103
|
-
};
|
|
11104
|
-
const EmailForm = ({ order }) => {
|
|
11105
|
-
const form = reactHookForm.useForm({
|
|
11106
|
-
defaultValues: {
|
|
11107
|
-
email: order.email ?? ""
|
|
11108
|
-
},
|
|
11109
|
-
resolver: zod.zodResolver(schema$3)
|
|
11110
|
-
});
|
|
11111
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11112
|
-
const { handleSuccess } = useRouteModal();
|
|
11113
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11114
|
-
await mutateAsync(
|
|
11115
|
-
{ email: data.email },
|
|
11116
|
-
{
|
|
11117
|
-
onSuccess: () => {
|
|
11118
|
-
handleSuccess();
|
|
11119
|
-
},
|
|
11120
|
-
onError: (error) => {
|
|
11121
|
-
ui.toast.error(error.message);
|
|
11122
|
-
}
|
|
11123
|
-
}
|
|
11124
|
-
);
|
|
11125
|
-
});
|
|
11126
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11127
|
-
KeyboundForm,
|
|
11128
|
-
{
|
|
11129
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11130
|
-
onSubmit,
|
|
11131
|
-
children: [
|
|
11132
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11133
|
-
Form$2.Field,
|
|
11134
|
-
{
|
|
11135
|
-
control: form.control,
|
|
11136
|
-
name: "email",
|
|
11137
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11138
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
11139
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
11140
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11141
|
-
] })
|
|
11142
|
-
}
|
|
11143
|
-
) }),
|
|
11144
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11145
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11146
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11147
|
-
] }) })
|
|
11148
|
-
]
|
|
11149
|
-
}
|
|
11150
|
-
) });
|
|
11151
|
-
};
|
|
11152
|
-
const schema$3 = object({
|
|
11153
|
-
email: string().email()
|
|
11154
|
-
});
|
|
11155
11155
|
const InlineTip = React.forwardRef(
|
|
11156
11156
|
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11157
11157
|
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
@@ -11502,65 +11502,448 @@ function getHasUneditableRows(metadata) {
|
|
|
11502
11502
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11503
11503
|
);
|
|
11504
11504
|
}
|
|
11505
|
-
const
|
|
11506
|
-
const
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11505
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11506
|
+
const promotionsQueryKeys = {
|
|
11507
|
+
list: (query2) => [
|
|
11508
|
+
PROMOTION_QUERY_KEY,
|
|
11509
|
+
query2 ? query2 : void 0
|
|
11510
|
+
],
|
|
11511
|
+
detail: (id, query2) => [
|
|
11512
|
+
PROMOTION_QUERY_KEY,
|
|
11513
|
+
id,
|
|
11514
|
+
query2 ? query2 : void 0
|
|
11515
|
+
]
|
|
11516
|
+
};
|
|
11517
|
+
const usePromotions = (query2, options) => {
|
|
11518
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
11519
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11520
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11521
|
+
...options
|
|
11511
11522
|
});
|
|
11523
|
+
return { ...data, ...rest };
|
|
11524
|
+
};
|
|
11525
|
+
const Promotions = () => {
|
|
11526
|
+
const { id } = reactRouterDom.useParams();
|
|
11512
11527
|
const {
|
|
11513
11528
|
order: preview,
|
|
11514
|
-
isPending: isPreviewPending,
|
|
11515
11529
|
isError: isPreviewError,
|
|
11516
11530
|
error: previewError
|
|
11517
|
-
} = useOrderPreview(id);
|
|
11531
|
+
} = useOrderPreview(id, void 0);
|
|
11518
11532
|
useInitiateOrderEdit({ preview });
|
|
11519
11533
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11520
|
-
if (isError) {
|
|
11521
|
-
throw error;
|
|
11522
|
-
}
|
|
11523
11534
|
if (isPreviewError) {
|
|
11524
11535
|
throw previewError;
|
|
11525
11536
|
}
|
|
11526
|
-
const
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11530
|
-
|
|
11531
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
11532
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11533
|
-
] }) }) }),
|
|
11534
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11535
|
-
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11536
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11537
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11538
|
-
] }) });
|
|
11537
|
+
const isReady = !!preview;
|
|
11538
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11539
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11540
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11541
|
+
] });
|
|
11539
11542
|
};
|
|
11540
|
-
const
|
|
11541
|
-
|
|
11542
|
-
const { setIsOpen } = useStackedModal();
|
|
11543
|
+
const PromotionForm = ({ preview }) => {
|
|
11544
|
+
const { items, shipping_methods } = preview;
|
|
11543
11545
|
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11544
|
-
const [
|
|
11545
|
-
const
|
|
11546
|
-
const {
|
|
11546
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11547
|
+
const { handleSuccess } = useRouteModal();
|
|
11548
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11549
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11550
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11547
11551
|
{
|
|
11548
|
-
id:
|
|
11549
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11552
|
+
id: promoIds
|
|
11550
11553
|
},
|
|
11551
11554
|
{
|
|
11552
|
-
enabled:
|
|
11555
|
+
enabled: !!promoIds.length
|
|
11553
11556
|
}
|
|
11554
11557
|
);
|
|
11555
|
-
const
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11560
|
-
|
|
11561
|
-
|
|
11562
|
-
|
|
11563
|
-
|
|
11558
|
+
const comboboxData = useComboboxData({
|
|
11559
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11560
|
+
queryFn: async (params) => {
|
|
11561
|
+
return await sdk.admin.promotion.list({
|
|
11562
|
+
...params,
|
|
11563
|
+
id: {
|
|
11564
|
+
$nin: promoIds
|
|
11565
|
+
}
|
|
11566
|
+
});
|
|
11567
|
+
},
|
|
11568
|
+
getOptions: (data) => {
|
|
11569
|
+
return data.promotions.map((promotion) => ({
|
|
11570
|
+
label: promotion.code,
|
|
11571
|
+
value: promotion.code
|
|
11572
|
+
}));
|
|
11573
|
+
}
|
|
11574
|
+
});
|
|
11575
|
+
const add = async (value) => {
|
|
11576
|
+
if (!value) {
|
|
11577
|
+
return;
|
|
11578
|
+
}
|
|
11579
|
+
addPromotions(
|
|
11580
|
+
{
|
|
11581
|
+
promo_codes: [value]
|
|
11582
|
+
},
|
|
11583
|
+
{
|
|
11584
|
+
onError: (e) => {
|
|
11585
|
+
ui.toast.error(e.message);
|
|
11586
|
+
comboboxData.onSearchValueChange("");
|
|
11587
|
+
setComboboxValue("");
|
|
11588
|
+
},
|
|
11589
|
+
onSuccess: () => {
|
|
11590
|
+
comboboxData.onSearchValueChange("");
|
|
11591
|
+
setComboboxValue("");
|
|
11592
|
+
}
|
|
11593
|
+
}
|
|
11594
|
+
);
|
|
11595
|
+
};
|
|
11596
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11597
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11598
|
+
const onSubmit = async () => {
|
|
11599
|
+
setIsSubmitting(true);
|
|
11600
|
+
let requestSucceeded = false;
|
|
11601
|
+
await requestOrderEdit(void 0, {
|
|
11602
|
+
onError: (e) => {
|
|
11603
|
+
ui.toast.error(e.message);
|
|
11604
|
+
},
|
|
11605
|
+
onSuccess: () => {
|
|
11606
|
+
requestSucceeded = true;
|
|
11607
|
+
}
|
|
11608
|
+
});
|
|
11609
|
+
if (!requestSucceeded) {
|
|
11610
|
+
setIsSubmitting(false);
|
|
11611
|
+
return;
|
|
11612
|
+
}
|
|
11613
|
+
await confirmOrderEdit(void 0, {
|
|
11614
|
+
onError: (e) => {
|
|
11615
|
+
ui.toast.error(e.message);
|
|
11616
|
+
},
|
|
11617
|
+
onSuccess: () => {
|
|
11618
|
+
handleSuccess();
|
|
11619
|
+
},
|
|
11620
|
+
onSettled: () => {
|
|
11621
|
+
setIsSubmitting(false);
|
|
11622
|
+
}
|
|
11623
|
+
});
|
|
11624
|
+
};
|
|
11625
|
+
if (isError) {
|
|
11626
|
+
throw error;
|
|
11627
|
+
}
|
|
11628
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11629
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11630
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11631
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11632
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11633
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11634
|
+
] }),
|
|
11635
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11636
|
+
Combobox,
|
|
11637
|
+
{
|
|
11638
|
+
id: "promotion-combobox",
|
|
11639
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11640
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11641
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11642
|
+
options: comboboxData.options,
|
|
11643
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11644
|
+
searchValue: comboboxData.searchValue,
|
|
11645
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11646
|
+
onChange: add,
|
|
11647
|
+
value: comboboxValue
|
|
11648
|
+
}
|
|
11649
|
+
)
|
|
11650
|
+
] }),
|
|
11651
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11652
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11653
|
+
PromotionItem,
|
|
11654
|
+
{
|
|
11655
|
+
promotion,
|
|
11656
|
+
orderId: preview.id,
|
|
11657
|
+
isLoading: isPending
|
|
11658
|
+
},
|
|
11659
|
+
promotion.id
|
|
11660
|
+
)) })
|
|
11661
|
+
] }) }),
|
|
11662
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11663
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11664
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11665
|
+
ui.Button,
|
|
11666
|
+
{
|
|
11667
|
+
size: "small",
|
|
11668
|
+
type: "submit",
|
|
11669
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11670
|
+
children: "Save"
|
|
11671
|
+
}
|
|
11672
|
+
)
|
|
11673
|
+
] }) })
|
|
11674
|
+
] });
|
|
11675
|
+
};
|
|
11676
|
+
const PromotionItem = ({
|
|
11677
|
+
promotion,
|
|
11678
|
+
orderId,
|
|
11679
|
+
isLoading
|
|
11680
|
+
}) => {
|
|
11681
|
+
var _a2;
|
|
11682
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11683
|
+
const onRemove = async () => {
|
|
11684
|
+
removePromotions(
|
|
11685
|
+
{
|
|
11686
|
+
promo_codes: [promotion.code]
|
|
11687
|
+
},
|
|
11688
|
+
{
|
|
11689
|
+
onError: (e) => {
|
|
11690
|
+
ui.toast.error(e.message);
|
|
11691
|
+
}
|
|
11692
|
+
}
|
|
11693
|
+
);
|
|
11694
|
+
};
|
|
11695
|
+
const displayValue = getDisplayValue(promotion);
|
|
11696
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11697
|
+
"div",
|
|
11698
|
+
{
|
|
11699
|
+
className: ui.clx(
|
|
11700
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11701
|
+
{
|
|
11702
|
+
"animate-pulse": isLoading
|
|
11703
|
+
}
|
|
11704
|
+
),
|
|
11705
|
+
children: [
|
|
11706
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11707
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11708
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11709
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11710
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11711
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11712
|
+
] }),
|
|
11713
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a2 = promotion.application_method) == null ? void 0 : _a2.allocation })
|
|
11714
|
+
] })
|
|
11715
|
+
] }),
|
|
11716
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11717
|
+
ui.IconButton,
|
|
11718
|
+
{
|
|
11719
|
+
size: "small",
|
|
11720
|
+
type: "button",
|
|
11721
|
+
variant: "transparent",
|
|
11722
|
+
onClick: onRemove,
|
|
11723
|
+
isLoading: isPending || isLoading,
|
|
11724
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11725
|
+
}
|
|
11726
|
+
)
|
|
11727
|
+
]
|
|
11728
|
+
},
|
|
11729
|
+
promotion.id
|
|
11730
|
+
);
|
|
11731
|
+
};
|
|
11732
|
+
function getDisplayValue(promotion) {
|
|
11733
|
+
var _a2, _b, _c, _d;
|
|
11734
|
+
const value = (_a2 = promotion.application_method) == null ? void 0 : _a2.value;
|
|
11735
|
+
if (!value) {
|
|
11736
|
+
return null;
|
|
11737
|
+
}
|
|
11738
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11739
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11740
|
+
if (!currency) {
|
|
11741
|
+
return null;
|
|
11742
|
+
}
|
|
11743
|
+
return getLocaleAmount(value, currency);
|
|
11744
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11745
|
+
return formatPercentage(value);
|
|
11746
|
+
}
|
|
11747
|
+
return null;
|
|
11748
|
+
}
|
|
11749
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11750
|
+
style: "percent",
|
|
11751
|
+
minimumFractionDigits: 2
|
|
11752
|
+
});
|
|
11753
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11754
|
+
let val = value || 0;
|
|
11755
|
+
if (!isPercentageValue) {
|
|
11756
|
+
val = val / 100;
|
|
11757
|
+
}
|
|
11758
|
+
return formatter.format(val);
|
|
11759
|
+
};
|
|
11760
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11761
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11762
|
+
for (const item of items) {
|
|
11763
|
+
if (item.adjustments) {
|
|
11764
|
+
for (const adjustment of item.adjustments) {
|
|
11765
|
+
if (adjustment.promotion_id) {
|
|
11766
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11767
|
+
}
|
|
11768
|
+
}
|
|
11769
|
+
}
|
|
11770
|
+
}
|
|
11771
|
+
for (const shippingMethod of shippingMethods) {
|
|
11772
|
+
if (shippingMethod.adjustments) {
|
|
11773
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11774
|
+
if (adjustment.promotion_id) {
|
|
11775
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11776
|
+
}
|
|
11777
|
+
}
|
|
11778
|
+
}
|
|
11779
|
+
}
|
|
11780
|
+
return Array.from(promotionIds);
|
|
11781
|
+
}
|
|
11782
|
+
const SalesChannel = () => {
|
|
11783
|
+
const { id } = reactRouterDom.useParams();
|
|
11784
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11785
|
+
id,
|
|
11786
|
+
{
|
|
11787
|
+
fields: "+sales_channel_id"
|
|
11788
|
+
},
|
|
11789
|
+
{
|
|
11790
|
+
enabled: !!id
|
|
11791
|
+
}
|
|
11792
|
+
);
|
|
11793
|
+
if (isError) {
|
|
11794
|
+
throw error;
|
|
11795
|
+
}
|
|
11796
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11797
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11798
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11799
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
11800
|
+
/* @__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" }) })
|
|
11801
|
+
] }),
|
|
11802
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11803
|
+
] });
|
|
11804
|
+
};
|
|
11805
|
+
const SalesChannelForm = ({ order }) => {
|
|
11806
|
+
const form = reactHookForm.useForm({
|
|
11807
|
+
defaultValues: {
|
|
11808
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11809
|
+
},
|
|
11810
|
+
resolver: zod.zodResolver(schema$2)
|
|
11811
|
+
});
|
|
11812
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11813
|
+
const { handleSuccess } = useRouteModal();
|
|
11814
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11815
|
+
await mutateAsync(
|
|
11816
|
+
{
|
|
11817
|
+
sales_channel_id: data.sales_channel_id
|
|
11818
|
+
},
|
|
11819
|
+
{
|
|
11820
|
+
onSuccess: () => {
|
|
11821
|
+
ui.toast.success("Sales channel updated");
|
|
11822
|
+
handleSuccess();
|
|
11823
|
+
},
|
|
11824
|
+
onError: (error) => {
|
|
11825
|
+
ui.toast.error(error.message);
|
|
11826
|
+
}
|
|
11827
|
+
}
|
|
11828
|
+
);
|
|
11829
|
+
});
|
|
11830
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11831
|
+
KeyboundForm,
|
|
11832
|
+
{
|
|
11833
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11834
|
+
onSubmit,
|
|
11835
|
+
children: [
|
|
11836
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11837
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11838
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11839
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11840
|
+
] }) })
|
|
11841
|
+
]
|
|
11842
|
+
}
|
|
11843
|
+
) });
|
|
11844
|
+
};
|
|
11845
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11846
|
+
const salesChannels = useComboboxData({
|
|
11847
|
+
queryFn: async (params) => {
|
|
11848
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11849
|
+
},
|
|
11850
|
+
queryKey: ["sales-channels"],
|
|
11851
|
+
getOptions: (data) => {
|
|
11852
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11853
|
+
label: salesChannel.name,
|
|
11854
|
+
value: salesChannel.id
|
|
11855
|
+
}));
|
|
11856
|
+
},
|
|
11857
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11858
|
+
});
|
|
11859
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11860
|
+
Form$2.Field,
|
|
11861
|
+
{
|
|
11862
|
+
control,
|
|
11863
|
+
name: "sales_channel_id",
|
|
11864
|
+
render: ({ field }) => {
|
|
11865
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11866
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11867
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11868
|
+
Combobox,
|
|
11869
|
+
{
|
|
11870
|
+
options: salesChannels.options,
|
|
11871
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11872
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11873
|
+
searchValue: salesChannels.searchValue,
|
|
11874
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11875
|
+
placeholder: "Select sales channel",
|
|
11876
|
+
...field
|
|
11877
|
+
}
|
|
11878
|
+
) }),
|
|
11879
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11880
|
+
] });
|
|
11881
|
+
}
|
|
11882
|
+
}
|
|
11883
|
+
);
|
|
11884
|
+
};
|
|
11885
|
+
const schema$2 = object({
|
|
11886
|
+
sales_channel_id: string().min(1)
|
|
11887
|
+
});
|
|
11888
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11889
|
+
const Shipping = () => {
|
|
11890
|
+
var _a2;
|
|
11891
|
+
const { id } = reactRouterDom.useParams();
|
|
11892
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11893
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11894
|
+
});
|
|
11895
|
+
const {
|
|
11896
|
+
order: preview,
|
|
11897
|
+
isPending: isPreviewPending,
|
|
11898
|
+
isError: isPreviewError,
|
|
11899
|
+
error: previewError
|
|
11900
|
+
} = useOrderPreview(id);
|
|
11901
|
+
useInitiateOrderEdit({ preview });
|
|
11902
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11903
|
+
if (isError) {
|
|
11904
|
+
throw error;
|
|
11905
|
+
}
|
|
11906
|
+
if (isPreviewError) {
|
|
11907
|
+
throw previewError;
|
|
11908
|
+
}
|
|
11909
|
+
const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
|
|
11910
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11911
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11912
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
11913
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
11914
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
11915
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11916
|
+
] }) }) }),
|
|
11917
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11918
|
+
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11919
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11920
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11921
|
+
] }) });
|
|
11922
|
+
};
|
|
11923
|
+
const ShippingForm = ({ preview, order }) => {
|
|
11924
|
+
var _a2;
|
|
11925
|
+
const { setIsOpen } = useStackedModal();
|
|
11926
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11927
|
+
const [data, setData] = React.useState(null);
|
|
11928
|
+
const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11929
|
+
const { shipping_options } = useShippingOptions(
|
|
11930
|
+
{
|
|
11931
|
+
id: appliedShippingOptionIds,
|
|
11932
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11933
|
+
},
|
|
11934
|
+
{
|
|
11935
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11936
|
+
}
|
|
11937
|
+
);
|
|
11938
|
+
const uniqueShippingProfiles = React.useMemo(() => {
|
|
11939
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
11940
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11941
|
+
profiles.set(profile.id, profile);
|
|
11942
|
+
});
|
|
11943
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11944
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11945
|
+
});
|
|
11946
|
+
return Array.from(profiles.values());
|
|
11564
11947
|
}, [order.items, shipping_options]);
|
|
11565
11948
|
const { handleSuccess } = useRouteModal();
|
|
11566
11949
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
@@ -12341,7 +12724,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12341
12724
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12342
12725
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12343
12726
|
},
|
|
12344
|
-
resolver: zod.zodResolver(schema$
|
|
12727
|
+
resolver: zod.zodResolver(schema$1)
|
|
12345
12728
|
});
|
|
12346
12729
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12347
12730
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12384,70 +12767,8 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12384
12767
|
control: form.control,
|
|
12385
12768
|
name: "country_code",
|
|
12386
12769
|
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12387
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
|
|
12388
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
|
|
12389
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12390
|
-
] })
|
|
12391
|
-
}
|
|
12392
|
-
),
|
|
12393
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12394
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12395
|
-
Form$2.Field,
|
|
12396
|
-
{
|
|
12397
|
-
control: form.control,
|
|
12398
|
-
name: "first_name",
|
|
12399
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12400
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
|
|
12401
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12402
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12403
|
-
] })
|
|
12404
|
-
}
|
|
12405
|
-
),
|
|
12406
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12407
|
-
Form$2.Field,
|
|
12408
|
-
{
|
|
12409
|
-
control: form.control,
|
|
12410
|
-
name: "last_name",
|
|
12411
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12412
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
|
|
12413
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12414
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12415
|
-
] })
|
|
12416
|
-
}
|
|
12417
|
-
)
|
|
12418
|
-
] }),
|
|
12419
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12420
|
-
Form$2.Field,
|
|
12421
|
-
{
|
|
12422
|
-
control: form.control,
|
|
12423
|
-
name: "company",
|
|
12424
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12425
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12426
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12427
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12428
|
-
] })
|
|
12429
|
-
}
|
|
12430
|
-
),
|
|
12431
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12432
|
-
Form$2.Field,
|
|
12433
|
-
{
|
|
12434
|
-
control: form.control,
|
|
12435
|
-
name: "address_1",
|
|
12436
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12437
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
|
|
12438
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12439
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12440
|
-
] })
|
|
12441
|
-
}
|
|
12442
|
-
),
|
|
12443
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12444
|
-
Form$2.Field,
|
|
12445
|
-
{
|
|
12446
|
-
control: form.control,
|
|
12447
|
-
name: "address_2",
|
|
12448
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12449
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12450
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12770
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
|
|
12771
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
|
|
12451
12772
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12452
12773
|
] })
|
|
12453
12774
|
}
|
|
@@ -12457,9 +12778,9 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12457
12778
|
Form$2.Field,
|
|
12458
12779
|
{
|
|
12459
12780
|
control: form.control,
|
|
12460
|
-
name: "
|
|
12781
|
+
name: "first_name",
|
|
12461
12782
|
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12462
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "
|
|
12783
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
|
|
12463
12784
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12464
12785
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12465
12786
|
] })
|
|
@@ -12469,9 +12790,9 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12469
12790
|
Form$2.Field,
|
|
12470
12791
|
{
|
|
12471
12792
|
control: form.control,
|
|
12472
|
-
name: "
|
|
12793
|
+
name: "last_name",
|
|
12473
12794
|
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12474
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "
|
|
12795
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
|
|
12475
12796
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12476
12797
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12477
12798
|
] })
|
|
@@ -12482,9 +12803,9 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12482
12803
|
Form$2.Field,
|
|
12483
12804
|
{
|
|
12484
12805
|
control: form.control,
|
|
12485
|
-
name: "
|
|
12806
|
+
name: "company",
|
|
12486
12807
|
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12487
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "
|
|
12808
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12488
12809
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12489
12810
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12490
12811
|
] })
|
|
@@ -12494,301 +12815,86 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12494
12815
|
Form$2.Field,
|
|
12495
12816
|
{
|
|
12496
12817
|
control: form.control,
|
|
12497
|
-
name: "
|
|
12818
|
+
name: "address_1",
|
|
12498
12819
|
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12499
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, {
|
|
12820
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
|
|
12500
12821
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12501
12822
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12502
12823
|
] })
|
|
12503
12824
|
}
|
|
12504
|
-
)
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
}
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
}
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
}
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
|
|
12556
|
-
|
|
12557
|
-
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
|
|
12566
|
-
|
|
12567
|
-
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
...params,
|
|
12573
|
-
id: {
|
|
12574
|
-
$nin: promoIds
|
|
12575
|
-
}
|
|
12576
|
-
});
|
|
12577
|
-
},
|
|
12578
|
-
getOptions: (data) => {
|
|
12579
|
-
return data.promotions.map((promotion) => ({
|
|
12580
|
-
label: promotion.code,
|
|
12581
|
-
value: promotion.code
|
|
12582
|
-
}));
|
|
12583
|
-
}
|
|
12584
|
-
});
|
|
12585
|
-
const add = async (value) => {
|
|
12586
|
-
if (!value) {
|
|
12587
|
-
return;
|
|
12588
|
-
}
|
|
12589
|
-
addPromotions(
|
|
12590
|
-
{
|
|
12591
|
-
promo_codes: [value]
|
|
12592
|
-
},
|
|
12593
|
-
{
|
|
12594
|
-
onError: (e) => {
|
|
12595
|
-
ui.toast.error(e.message);
|
|
12596
|
-
comboboxData.onSearchValueChange("");
|
|
12597
|
-
setComboboxValue("");
|
|
12598
|
-
},
|
|
12599
|
-
onSuccess: () => {
|
|
12600
|
-
comboboxData.onSearchValueChange("");
|
|
12601
|
-
setComboboxValue("");
|
|
12602
|
-
}
|
|
12603
|
-
}
|
|
12604
|
-
);
|
|
12605
|
-
};
|
|
12606
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12607
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
12608
|
-
const onSubmit = async () => {
|
|
12609
|
-
setIsSubmitting(true);
|
|
12610
|
-
let requestSucceeded = false;
|
|
12611
|
-
await requestOrderEdit(void 0, {
|
|
12612
|
-
onError: (e) => {
|
|
12613
|
-
ui.toast.error(e.message);
|
|
12614
|
-
},
|
|
12615
|
-
onSuccess: () => {
|
|
12616
|
-
requestSucceeded = true;
|
|
12617
|
-
}
|
|
12618
|
-
});
|
|
12619
|
-
if (!requestSucceeded) {
|
|
12620
|
-
setIsSubmitting(false);
|
|
12621
|
-
return;
|
|
12622
|
-
}
|
|
12623
|
-
await confirmOrderEdit(void 0, {
|
|
12624
|
-
onError: (e) => {
|
|
12625
|
-
ui.toast.error(e.message);
|
|
12626
|
-
},
|
|
12627
|
-
onSuccess: () => {
|
|
12628
|
-
handleSuccess();
|
|
12629
|
-
},
|
|
12630
|
-
onSettled: () => {
|
|
12631
|
-
setIsSubmitting(false);
|
|
12632
|
-
}
|
|
12633
|
-
});
|
|
12634
|
-
};
|
|
12635
|
-
if (isError) {
|
|
12636
|
-
throw error;
|
|
12637
|
-
}
|
|
12638
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
12639
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
12640
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
12641
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
12642
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
12643
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
12644
|
-
] }),
|
|
12645
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12646
|
-
Combobox,
|
|
12647
|
-
{
|
|
12648
|
-
id: "promotion-combobox",
|
|
12649
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
12650
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
12651
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
12652
|
-
options: comboboxData.options,
|
|
12653
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
12654
|
-
searchValue: comboboxData.searchValue,
|
|
12655
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
12656
|
-
onChange: add,
|
|
12657
|
-
value: comboboxValue
|
|
12658
|
-
}
|
|
12659
|
-
)
|
|
12660
|
-
] }),
|
|
12661
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
12662
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
12663
|
-
PromotionItem,
|
|
12664
|
-
{
|
|
12665
|
-
promotion,
|
|
12666
|
-
orderId: preview.id,
|
|
12667
|
-
isLoading: isPending
|
|
12668
|
-
},
|
|
12669
|
-
promotion.id
|
|
12670
|
-
)) })
|
|
12671
|
-
] }) }),
|
|
12672
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12673
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12674
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12675
|
-
ui.Button,
|
|
12676
|
-
{
|
|
12677
|
-
size: "small",
|
|
12678
|
-
type: "submit",
|
|
12679
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
12680
|
-
children: "Save"
|
|
12681
|
-
}
|
|
12682
|
-
)
|
|
12683
|
-
] }) })
|
|
12684
|
-
] });
|
|
12685
|
-
};
|
|
12686
|
-
const PromotionItem = ({
|
|
12687
|
-
promotion,
|
|
12688
|
-
orderId,
|
|
12689
|
-
isLoading
|
|
12690
|
-
}) => {
|
|
12691
|
-
var _a2;
|
|
12692
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
12693
|
-
const onRemove = async () => {
|
|
12694
|
-
removePromotions(
|
|
12695
|
-
{
|
|
12696
|
-
promo_codes: [promotion.code]
|
|
12697
|
-
},
|
|
12698
|
-
{
|
|
12699
|
-
onError: (e) => {
|
|
12700
|
-
ui.toast.error(e.message);
|
|
12701
|
-
}
|
|
12702
|
-
}
|
|
12703
|
-
);
|
|
12704
|
-
};
|
|
12705
|
-
const displayValue = getDisplayValue(promotion);
|
|
12706
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12707
|
-
"div",
|
|
12708
|
-
{
|
|
12709
|
-
className: ui.clx(
|
|
12710
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
12711
|
-
{
|
|
12712
|
-
"animate-pulse": isLoading
|
|
12713
|
-
}
|
|
12714
|
-
),
|
|
12715
|
-
children: [
|
|
12716
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
12717
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
12718
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
12719
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
12720
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
12721
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
12722
|
-
] }),
|
|
12723
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a2 = promotion.application_method) == null ? void 0 : _a2.allocation })
|
|
12724
|
-
] })
|
|
12725
|
-
] }),
|
|
12726
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12727
|
-
ui.IconButton,
|
|
12728
|
-
{
|
|
12729
|
-
size: "small",
|
|
12730
|
-
type: "button",
|
|
12731
|
-
variant: "transparent",
|
|
12732
|
-
onClick: onRemove,
|
|
12733
|
-
isLoading: isPending || isLoading,
|
|
12734
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
12735
|
-
}
|
|
12736
|
-
)
|
|
12825
|
+
),
|
|
12826
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12827
|
+
Form$2.Field,
|
|
12828
|
+
{
|
|
12829
|
+
control: form.control,
|
|
12830
|
+
name: "address_2",
|
|
12831
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12832
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12833
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12834
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12835
|
+
] })
|
|
12836
|
+
}
|
|
12837
|
+
),
|
|
12838
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12839
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12840
|
+
Form$2.Field,
|
|
12841
|
+
{
|
|
12842
|
+
control: form.control,
|
|
12843
|
+
name: "postal_code",
|
|
12844
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12845
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
|
|
12846
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12847
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12848
|
+
] })
|
|
12849
|
+
}
|
|
12850
|
+
),
|
|
12851
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12852
|
+
Form$2.Field,
|
|
12853
|
+
{
|
|
12854
|
+
control: form.control,
|
|
12855
|
+
name: "city",
|
|
12856
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12857
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
|
|
12858
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12859
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12860
|
+
] })
|
|
12861
|
+
}
|
|
12862
|
+
)
|
|
12863
|
+
] }),
|
|
12864
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12865
|
+
Form$2.Field,
|
|
12866
|
+
{
|
|
12867
|
+
control: form.control,
|
|
12868
|
+
name: "province",
|
|
12869
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12870
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
12871
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12872
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12873
|
+
] })
|
|
12874
|
+
}
|
|
12875
|
+
),
|
|
12876
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12877
|
+
Form$2.Field,
|
|
12878
|
+
{
|
|
12879
|
+
control: form.control,
|
|
12880
|
+
name: "phone",
|
|
12881
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12882
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
12883
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12884
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12885
|
+
] })
|
|
12886
|
+
}
|
|
12887
|
+
)
|
|
12888
|
+
] }) }),
|
|
12889
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12890
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12891
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12892
|
+
] }) })
|
|
12737
12893
|
]
|
|
12738
|
-
},
|
|
12739
|
-
promotion.id
|
|
12740
|
-
);
|
|
12741
|
-
};
|
|
12742
|
-
function getDisplayValue(promotion) {
|
|
12743
|
-
var _a2, _b, _c, _d;
|
|
12744
|
-
const value = (_a2 = promotion.application_method) == null ? void 0 : _a2.value;
|
|
12745
|
-
if (!value) {
|
|
12746
|
-
return null;
|
|
12747
|
-
}
|
|
12748
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
12749
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
12750
|
-
if (!currency) {
|
|
12751
|
-
return null;
|
|
12752
12894
|
}
|
|
12753
|
-
|
|
12754
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
12755
|
-
return formatPercentage(value);
|
|
12756
|
-
}
|
|
12757
|
-
return null;
|
|
12758
|
-
}
|
|
12759
|
-
const formatter = new Intl.NumberFormat([], {
|
|
12760
|
-
style: "percent",
|
|
12761
|
-
minimumFractionDigits: 2
|
|
12762
|
-
});
|
|
12763
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
12764
|
-
let val = value || 0;
|
|
12765
|
-
if (!isPercentageValue) {
|
|
12766
|
-
val = val / 100;
|
|
12767
|
-
}
|
|
12768
|
-
return formatter.format(val);
|
|
12895
|
+
) });
|
|
12769
12896
|
};
|
|
12770
|
-
|
|
12771
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
12772
|
-
for (const item of items) {
|
|
12773
|
-
if (item.adjustments) {
|
|
12774
|
-
for (const adjustment of item.adjustments) {
|
|
12775
|
-
if (adjustment.promotion_id) {
|
|
12776
|
-
promotionIds.add(adjustment.promotion_id);
|
|
12777
|
-
}
|
|
12778
|
-
}
|
|
12779
|
-
}
|
|
12780
|
-
}
|
|
12781
|
-
for (const shippingMethod of shippingMethods) {
|
|
12782
|
-
if (shippingMethod.adjustments) {
|
|
12783
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
12784
|
-
if (adjustment.promotion_id) {
|
|
12785
|
-
promotionIds.add(adjustment.promotion_id);
|
|
12786
|
-
}
|
|
12787
|
-
}
|
|
12788
|
-
}
|
|
12789
|
-
}
|
|
12790
|
-
return Array.from(promotionIds);
|
|
12791
|
-
}
|
|
12897
|
+
const schema$1 = addressSchema;
|
|
12792
12898
|
const TransferOwnership = () => {
|
|
12793
12899
|
const { id } = reactRouterDom.useParams();
|
|
12794
12900
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12812,7 +12918,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12812
12918
|
defaultValues: {
|
|
12813
12919
|
customer_id: order.customer_id || ""
|
|
12814
12920
|
},
|
|
12815
|
-
resolver: zod.zodResolver(schema
|
|
12921
|
+
resolver: zod.zodResolver(schema)
|
|
12816
12922
|
});
|
|
12817
12923
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12818
12924
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13262,114 +13368,8 @@ const Illustration = () => {
|
|
|
13262
13368
|
}
|
|
13263
13369
|
);
|
|
13264
13370
|
};
|
|
13265
|
-
const schema$1 = object({
|
|
13266
|
-
customer_id: string().min(1)
|
|
13267
|
-
});
|
|
13268
|
-
const SalesChannel = () => {
|
|
13269
|
-
const { id } = reactRouterDom.useParams();
|
|
13270
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
13271
|
-
id,
|
|
13272
|
-
{
|
|
13273
|
-
fields: "+sales_channel_id"
|
|
13274
|
-
},
|
|
13275
|
-
{
|
|
13276
|
-
enabled: !!id
|
|
13277
|
-
}
|
|
13278
|
-
);
|
|
13279
|
-
if (isError) {
|
|
13280
|
-
throw error;
|
|
13281
|
-
}
|
|
13282
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
13283
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
13284
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
13285
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
13286
|
-
/* @__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" }) })
|
|
13287
|
-
] }),
|
|
13288
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
13289
|
-
] });
|
|
13290
|
-
};
|
|
13291
|
-
const SalesChannelForm = ({ order }) => {
|
|
13292
|
-
const form = reactHookForm.useForm({
|
|
13293
|
-
defaultValues: {
|
|
13294
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
13295
|
-
},
|
|
13296
|
-
resolver: zod.zodResolver(schema)
|
|
13297
|
-
});
|
|
13298
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
13299
|
-
const { handleSuccess } = useRouteModal();
|
|
13300
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
13301
|
-
await mutateAsync(
|
|
13302
|
-
{
|
|
13303
|
-
sales_channel_id: data.sales_channel_id
|
|
13304
|
-
},
|
|
13305
|
-
{
|
|
13306
|
-
onSuccess: () => {
|
|
13307
|
-
ui.toast.success("Sales channel updated");
|
|
13308
|
-
handleSuccess();
|
|
13309
|
-
},
|
|
13310
|
-
onError: (error) => {
|
|
13311
|
-
ui.toast.error(error.message);
|
|
13312
|
-
}
|
|
13313
|
-
}
|
|
13314
|
-
);
|
|
13315
|
-
});
|
|
13316
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
13317
|
-
KeyboundForm,
|
|
13318
|
-
{
|
|
13319
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
13320
|
-
onSubmit,
|
|
13321
|
-
children: [
|
|
13322
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
13323
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13324
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13325
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13326
|
-
] }) })
|
|
13327
|
-
]
|
|
13328
|
-
}
|
|
13329
|
-
) });
|
|
13330
|
-
};
|
|
13331
|
-
const SalesChannelField = ({ control, order }) => {
|
|
13332
|
-
const salesChannels = useComboboxData({
|
|
13333
|
-
queryFn: async (params) => {
|
|
13334
|
-
return await sdk.admin.salesChannel.list(params);
|
|
13335
|
-
},
|
|
13336
|
-
queryKey: ["sales-channels"],
|
|
13337
|
-
getOptions: (data) => {
|
|
13338
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
13339
|
-
label: salesChannel.name,
|
|
13340
|
-
value: salesChannel.id
|
|
13341
|
-
}));
|
|
13342
|
-
},
|
|
13343
|
-
defaultValue: order.sales_channel_id || void 0
|
|
13344
|
-
});
|
|
13345
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
13346
|
-
Form$2.Field,
|
|
13347
|
-
{
|
|
13348
|
-
control,
|
|
13349
|
-
name: "sales_channel_id",
|
|
13350
|
-
render: ({ field }) => {
|
|
13351
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
13352
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
13353
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
13354
|
-
Combobox,
|
|
13355
|
-
{
|
|
13356
|
-
options: salesChannels.options,
|
|
13357
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
13358
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
13359
|
-
searchValue: salesChannels.searchValue,
|
|
13360
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
13361
|
-
placeholder: "Select sales channel",
|
|
13362
|
-
...field
|
|
13363
|
-
}
|
|
13364
|
-
) }),
|
|
13365
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
13366
|
-
] });
|
|
13367
|
-
}
|
|
13368
|
-
}
|
|
13369
|
-
);
|
|
13370
|
-
};
|
|
13371
13371
|
const schema = object({
|
|
13372
|
-
|
|
13372
|
+
customer_id: string().min(1)
|
|
13373
13373
|
});
|
|
13374
13374
|
const widgetModule = { widgets: [] };
|
|
13375
13375
|
const routeModule = {
|
|
@@ -13391,26 +13391,34 @@ const routeModule = {
|
|
|
13391
13391
|
handle,
|
|
13392
13392
|
loader,
|
|
13393
13393
|
children: [
|
|
13394
|
-
{
|
|
13395
|
-
Component: CustomItems,
|
|
13396
|
-
path: "/draft-orders/:id/custom-items"
|
|
13397
|
-
},
|
|
13398
13394
|
{
|
|
13399
13395
|
Component: BillingAddress,
|
|
13400
13396
|
path: "/draft-orders/:id/billing-address"
|
|
13401
13397
|
},
|
|
13402
|
-
{
|
|
13403
|
-
Component: Items,
|
|
13404
|
-
path: "/draft-orders/:id/items"
|
|
13405
|
-
},
|
|
13406
13398
|
{
|
|
13407
13399
|
Component: Email,
|
|
13408
13400
|
path: "/draft-orders/:id/email"
|
|
13409
13401
|
},
|
|
13402
|
+
{
|
|
13403
|
+
Component: CustomItems,
|
|
13404
|
+
path: "/draft-orders/:id/custom-items"
|
|
13405
|
+
},
|
|
13406
|
+
{
|
|
13407
|
+
Component: Items,
|
|
13408
|
+
path: "/draft-orders/:id/items"
|
|
13409
|
+
},
|
|
13410
13410
|
{
|
|
13411
13411
|
Component: Metadata,
|
|
13412
13412
|
path: "/draft-orders/:id/metadata"
|
|
13413
13413
|
},
|
|
13414
|
+
{
|
|
13415
|
+
Component: Promotions,
|
|
13416
|
+
path: "/draft-orders/:id/promotions"
|
|
13417
|
+
},
|
|
13418
|
+
{
|
|
13419
|
+
Component: SalesChannel,
|
|
13420
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13421
|
+
},
|
|
13414
13422
|
{
|
|
13415
13423
|
Component: Shipping,
|
|
13416
13424
|
path: "/draft-orders/:id/shipping"
|
|
@@ -13419,17 +13427,9 @@ const routeModule = {
|
|
|
13419
13427
|
Component: ShippingAddress,
|
|
13420
13428
|
path: "/draft-orders/:id/shipping-address"
|
|
13421
13429
|
},
|
|
13422
|
-
{
|
|
13423
|
-
Component: Promotions,
|
|
13424
|
-
path: "/draft-orders/:id/promotions"
|
|
13425
|
-
},
|
|
13426
13430
|
{
|
|
13427
13431
|
Component: TransferOwnership,
|
|
13428
13432
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13429
|
-
},
|
|
13430
|
-
{
|
|
13431
|
-
Component: SalesChannel,
|
|
13432
|
-
path: "/draft-orders/:id/sales-channel"
|
|
13433
13433
|
}
|
|
13434
13434
|
]
|
|
13435
13435
|
}
|