@medusajs/draft-order 2.11.4-preview-20251112090213 → 2.11.4-preview-20251112180139
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 +562 -562
- package/.medusa/server/src/admin/index.mjs +562 -562
- package/package.json +16 -16
|
@@ -8722,7 +8722,7 @@ const Contact = ({ order }) => {
|
|
|
8722
8722
|
children: phone
|
|
8723
8723
|
}
|
|
8724
8724
|
),
|
|
8725
|
-
/* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Copy, { content:
|
|
8725
|
+
/* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Copy, { content: phone, className: "text-ui-fg-muted" }) })
|
|
8726
8726
|
] })
|
|
8727
8727
|
] })
|
|
8728
8728
|
] });
|
|
@@ -9776,6 +9776,74 @@ const CustomItemsForm = () => {
|
|
|
9776
9776
|
const schema$4 = objectType({
|
|
9777
9777
|
email: stringType().email()
|
|
9778
9778
|
});
|
|
9779
|
+
const Email = () => {
|
|
9780
|
+
const { id } = useParams();
|
|
9781
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9782
|
+
fields: "+email"
|
|
9783
|
+
});
|
|
9784
|
+
if (isError) {
|
|
9785
|
+
throw error;
|
|
9786
|
+
}
|
|
9787
|
+
const isReady = !isPending && !!order;
|
|
9788
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9789
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9790
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
9791
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9792
|
+
] }),
|
|
9793
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
9794
|
+
] });
|
|
9795
|
+
};
|
|
9796
|
+
const EmailForm = ({ order }) => {
|
|
9797
|
+
const form = useForm({
|
|
9798
|
+
defaultValues: {
|
|
9799
|
+
email: order.email ?? ""
|
|
9800
|
+
},
|
|
9801
|
+
resolver: zodResolver(schema$3)
|
|
9802
|
+
});
|
|
9803
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9804
|
+
const { handleSuccess } = useRouteModal();
|
|
9805
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9806
|
+
await mutateAsync(
|
|
9807
|
+
{ email: data.email },
|
|
9808
|
+
{
|
|
9809
|
+
onSuccess: () => {
|
|
9810
|
+
handleSuccess();
|
|
9811
|
+
},
|
|
9812
|
+
onError: (error) => {
|
|
9813
|
+
toast.error(error.message);
|
|
9814
|
+
}
|
|
9815
|
+
}
|
|
9816
|
+
);
|
|
9817
|
+
});
|
|
9818
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9819
|
+
KeyboundForm,
|
|
9820
|
+
{
|
|
9821
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9822
|
+
onSubmit,
|
|
9823
|
+
children: [
|
|
9824
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
9825
|
+
Form$2.Field,
|
|
9826
|
+
{
|
|
9827
|
+
control: form.control,
|
|
9828
|
+
name: "email",
|
|
9829
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9830
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
9831
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9832
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9833
|
+
] })
|
|
9834
|
+
}
|
|
9835
|
+
) }),
|
|
9836
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9837
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9838
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9839
|
+
] }) })
|
|
9840
|
+
]
|
|
9841
|
+
}
|
|
9842
|
+
) });
|
|
9843
|
+
};
|
|
9844
|
+
const schema$3 = objectType({
|
|
9845
|
+
email: stringType().email()
|
|
9846
|
+
});
|
|
9779
9847
|
const NumberInput = forwardRef(
|
|
9780
9848
|
({
|
|
9781
9849
|
value,
|
|
@@ -11100,505 +11168,160 @@ function getHasUneditableRows(metadata) {
|
|
|
11100
11168
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11101
11169
|
);
|
|
11102
11170
|
}
|
|
11103
|
-
const
|
|
11104
|
-
const
|
|
11105
|
-
|
|
11106
|
-
PROMOTION_QUERY_KEY,
|
|
11107
|
-
query2 ? query2 : void 0
|
|
11108
|
-
],
|
|
11109
|
-
detail: (id, query2) => [
|
|
11110
|
-
PROMOTION_QUERY_KEY,
|
|
11171
|
+
const SalesChannel = () => {
|
|
11172
|
+
const { id } = useParams();
|
|
11173
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11111
11174
|
id,
|
|
11112
|
-
|
|
11113
|
-
|
|
11175
|
+
{
|
|
11176
|
+
fields: "+sales_channel_id"
|
|
11177
|
+
},
|
|
11178
|
+
{
|
|
11179
|
+
enabled: !!id
|
|
11180
|
+
}
|
|
11181
|
+
);
|
|
11182
|
+
if (isError) {
|
|
11183
|
+
throw error;
|
|
11184
|
+
}
|
|
11185
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11186
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11187
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11188
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11189
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11190
|
+
] }),
|
|
11191
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11192
|
+
] });
|
|
11114
11193
|
};
|
|
11115
|
-
const
|
|
11116
|
-
const
|
|
11117
|
-
|
|
11118
|
-
|
|
11119
|
-
|
|
11194
|
+
const SalesChannelForm = ({ order }) => {
|
|
11195
|
+
const form = useForm({
|
|
11196
|
+
defaultValues: {
|
|
11197
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11198
|
+
},
|
|
11199
|
+
resolver: zodResolver(schema$2)
|
|
11120
11200
|
});
|
|
11121
|
-
|
|
11201
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11202
|
+
const { handleSuccess } = useRouteModal();
|
|
11203
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11204
|
+
await mutateAsync(
|
|
11205
|
+
{
|
|
11206
|
+
sales_channel_id: data.sales_channel_id
|
|
11207
|
+
},
|
|
11208
|
+
{
|
|
11209
|
+
onSuccess: () => {
|
|
11210
|
+
toast.success("Sales channel updated");
|
|
11211
|
+
handleSuccess();
|
|
11212
|
+
},
|
|
11213
|
+
onError: (error) => {
|
|
11214
|
+
toast.error(error.message);
|
|
11215
|
+
}
|
|
11216
|
+
}
|
|
11217
|
+
);
|
|
11218
|
+
});
|
|
11219
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11220
|
+
KeyboundForm,
|
|
11221
|
+
{
|
|
11222
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11223
|
+
onSubmit,
|
|
11224
|
+
children: [
|
|
11225
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11226
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11227
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11228
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11229
|
+
] }) })
|
|
11230
|
+
]
|
|
11231
|
+
}
|
|
11232
|
+
) });
|
|
11122
11233
|
};
|
|
11123
|
-
const
|
|
11234
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11235
|
+
const salesChannels = useComboboxData({
|
|
11236
|
+
queryFn: async (params) => {
|
|
11237
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11238
|
+
},
|
|
11239
|
+
queryKey: ["sales-channels"],
|
|
11240
|
+
getOptions: (data) => {
|
|
11241
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11242
|
+
label: salesChannel.name,
|
|
11243
|
+
value: salesChannel.id
|
|
11244
|
+
}));
|
|
11245
|
+
},
|
|
11246
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11247
|
+
});
|
|
11248
|
+
return /* @__PURE__ */ jsx(
|
|
11249
|
+
Form$2.Field,
|
|
11250
|
+
{
|
|
11251
|
+
control,
|
|
11252
|
+
name: "sales_channel_id",
|
|
11253
|
+
render: ({ field }) => {
|
|
11254
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11255
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11256
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11257
|
+
Combobox,
|
|
11258
|
+
{
|
|
11259
|
+
options: salesChannels.options,
|
|
11260
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11261
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11262
|
+
searchValue: salesChannels.searchValue,
|
|
11263
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11264
|
+
placeholder: "Select sales channel",
|
|
11265
|
+
...field
|
|
11266
|
+
}
|
|
11267
|
+
) }),
|
|
11268
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11269
|
+
] });
|
|
11270
|
+
}
|
|
11271
|
+
}
|
|
11272
|
+
);
|
|
11273
|
+
};
|
|
11274
|
+
const schema$2 = objectType({
|
|
11275
|
+
sales_channel_id: stringType().min(1)
|
|
11276
|
+
});
|
|
11277
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11278
|
+
const Shipping = () => {
|
|
11279
|
+
var _a;
|
|
11124
11280
|
const { id } = useParams();
|
|
11281
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11282
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11283
|
+
});
|
|
11125
11284
|
const {
|
|
11126
11285
|
order: preview,
|
|
11286
|
+
isPending: isPreviewPending,
|
|
11127
11287
|
isError: isPreviewError,
|
|
11128
11288
|
error: previewError
|
|
11129
|
-
} = useOrderPreview(id
|
|
11289
|
+
} = useOrderPreview(id);
|
|
11130
11290
|
useInitiateOrderEdit({ preview });
|
|
11131
11291
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11292
|
+
if (isError) {
|
|
11293
|
+
throw error;
|
|
11294
|
+
}
|
|
11132
11295
|
if (isPreviewError) {
|
|
11133
11296
|
throw previewError;
|
|
11134
11297
|
}
|
|
11135
|
-
const
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11298
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11299
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11300
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11301
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11302
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
11303
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11304
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11305
|
+
] }) }) }),
|
|
11306
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11307
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11308
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11309
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11310
|
+
] }) });
|
|
11140
11311
|
};
|
|
11141
|
-
const
|
|
11142
|
-
|
|
11312
|
+
const ShippingForm = ({ preview, order }) => {
|
|
11313
|
+
var _a;
|
|
11314
|
+
const { setIsOpen } = useStackedModal();
|
|
11143
11315
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11144
|
-
const [
|
|
11145
|
-
const
|
|
11146
|
-
const {
|
|
11147
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11148
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
11316
|
+
const [data, setData] = useState(null);
|
|
11317
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11318
|
+
const { shipping_options } = useShippingOptions(
|
|
11149
11319
|
{
|
|
11150
|
-
id:
|
|
11320
|
+
id: appliedShippingOptionIds,
|
|
11321
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11151
11322
|
},
|
|
11152
11323
|
{
|
|
11153
|
-
enabled:
|
|
11154
|
-
}
|
|
11155
|
-
);
|
|
11156
|
-
const comboboxData = useComboboxData({
|
|
11157
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
11158
|
-
queryFn: async (params) => {
|
|
11159
|
-
return await sdk.admin.promotion.list({
|
|
11160
|
-
...params,
|
|
11161
|
-
id: {
|
|
11162
|
-
$nin: promoIds
|
|
11163
|
-
}
|
|
11164
|
-
});
|
|
11165
|
-
},
|
|
11166
|
-
getOptions: (data) => {
|
|
11167
|
-
return data.promotions.map((promotion) => ({
|
|
11168
|
-
label: promotion.code,
|
|
11169
|
-
value: promotion.code
|
|
11170
|
-
}));
|
|
11171
|
-
}
|
|
11172
|
-
});
|
|
11173
|
-
const add = async (value) => {
|
|
11174
|
-
if (!value) {
|
|
11175
|
-
return;
|
|
11176
|
-
}
|
|
11177
|
-
addPromotions(
|
|
11178
|
-
{
|
|
11179
|
-
promo_codes: [value]
|
|
11180
|
-
},
|
|
11181
|
-
{
|
|
11182
|
-
onError: (e) => {
|
|
11183
|
-
toast.error(e.message);
|
|
11184
|
-
comboboxData.onSearchValueChange("");
|
|
11185
|
-
setComboboxValue("");
|
|
11186
|
-
},
|
|
11187
|
-
onSuccess: () => {
|
|
11188
|
-
comboboxData.onSearchValueChange("");
|
|
11189
|
-
setComboboxValue("");
|
|
11190
|
-
}
|
|
11191
|
-
}
|
|
11192
|
-
);
|
|
11193
|
-
};
|
|
11194
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11195
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11196
|
-
const onSubmit = async () => {
|
|
11197
|
-
setIsSubmitting(true);
|
|
11198
|
-
let requestSucceeded = false;
|
|
11199
|
-
await requestOrderEdit(void 0, {
|
|
11200
|
-
onError: (e) => {
|
|
11201
|
-
toast.error(e.message);
|
|
11202
|
-
},
|
|
11203
|
-
onSuccess: () => {
|
|
11204
|
-
requestSucceeded = true;
|
|
11205
|
-
}
|
|
11206
|
-
});
|
|
11207
|
-
if (!requestSucceeded) {
|
|
11208
|
-
setIsSubmitting(false);
|
|
11209
|
-
return;
|
|
11210
|
-
}
|
|
11211
|
-
await confirmOrderEdit(void 0, {
|
|
11212
|
-
onError: (e) => {
|
|
11213
|
-
toast.error(e.message);
|
|
11214
|
-
},
|
|
11215
|
-
onSuccess: () => {
|
|
11216
|
-
handleSuccess();
|
|
11217
|
-
},
|
|
11218
|
-
onSettled: () => {
|
|
11219
|
-
setIsSubmitting(false);
|
|
11220
|
-
}
|
|
11221
|
-
});
|
|
11222
|
-
};
|
|
11223
|
-
if (isError) {
|
|
11224
|
-
throw error;
|
|
11225
|
-
}
|
|
11226
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11227
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11228
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11229
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11230
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11231
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11232
|
-
] }),
|
|
11233
|
-
/* @__PURE__ */ jsx(
|
|
11234
|
-
Combobox,
|
|
11235
|
-
{
|
|
11236
|
-
id: "promotion-combobox",
|
|
11237
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11238
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11239
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11240
|
-
options: comboboxData.options,
|
|
11241
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11242
|
-
searchValue: comboboxData.searchValue,
|
|
11243
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11244
|
-
onChange: add,
|
|
11245
|
-
value: comboboxValue
|
|
11246
|
-
}
|
|
11247
|
-
)
|
|
11248
|
-
] }),
|
|
11249
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11250
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11251
|
-
PromotionItem,
|
|
11252
|
-
{
|
|
11253
|
-
promotion,
|
|
11254
|
-
orderId: preview.id,
|
|
11255
|
-
isLoading: isPending
|
|
11256
|
-
},
|
|
11257
|
-
promotion.id
|
|
11258
|
-
)) })
|
|
11259
|
-
] }) }),
|
|
11260
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11261
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11262
|
-
/* @__PURE__ */ jsx(
|
|
11263
|
-
Button,
|
|
11264
|
-
{
|
|
11265
|
-
size: "small",
|
|
11266
|
-
type: "submit",
|
|
11267
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11268
|
-
children: "Save"
|
|
11269
|
-
}
|
|
11270
|
-
)
|
|
11271
|
-
] }) })
|
|
11272
|
-
] });
|
|
11273
|
-
};
|
|
11274
|
-
const PromotionItem = ({
|
|
11275
|
-
promotion,
|
|
11276
|
-
orderId,
|
|
11277
|
-
isLoading
|
|
11278
|
-
}) => {
|
|
11279
|
-
var _a;
|
|
11280
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11281
|
-
const onRemove = async () => {
|
|
11282
|
-
removePromotions(
|
|
11283
|
-
{
|
|
11284
|
-
promo_codes: [promotion.code]
|
|
11285
|
-
},
|
|
11286
|
-
{
|
|
11287
|
-
onError: (e) => {
|
|
11288
|
-
toast.error(e.message);
|
|
11289
|
-
}
|
|
11290
|
-
}
|
|
11291
|
-
);
|
|
11292
|
-
};
|
|
11293
|
-
const displayValue = getDisplayValue(promotion);
|
|
11294
|
-
return /* @__PURE__ */ jsxs(
|
|
11295
|
-
"div",
|
|
11296
|
-
{
|
|
11297
|
-
className: clx(
|
|
11298
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11299
|
-
{
|
|
11300
|
-
"animate-pulse": isLoading
|
|
11301
|
-
}
|
|
11302
|
-
),
|
|
11303
|
-
children: [
|
|
11304
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11305
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11306
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11307
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11308
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11309
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11310
|
-
] }),
|
|
11311
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11312
|
-
] })
|
|
11313
|
-
] }),
|
|
11314
|
-
/* @__PURE__ */ jsx(
|
|
11315
|
-
IconButton,
|
|
11316
|
-
{
|
|
11317
|
-
size: "small",
|
|
11318
|
-
type: "button",
|
|
11319
|
-
variant: "transparent",
|
|
11320
|
-
onClick: onRemove,
|
|
11321
|
-
isLoading: isPending || isLoading,
|
|
11322
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11323
|
-
}
|
|
11324
|
-
)
|
|
11325
|
-
]
|
|
11326
|
-
},
|
|
11327
|
-
promotion.id
|
|
11328
|
-
);
|
|
11329
|
-
};
|
|
11330
|
-
function getDisplayValue(promotion) {
|
|
11331
|
-
var _a, _b, _c, _d;
|
|
11332
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11333
|
-
if (!value) {
|
|
11334
|
-
return null;
|
|
11335
|
-
}
|
|
11336
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11337
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11338
|
-
if (!currency) {
|
|
11339
|
-
return null;
|
|
11340
|
-
}
|
|
11341
|
-
return getLocaleAmount(value, currency);
|
|
11342
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11343
|
-
return formatPercentage(value);
|
|
11344
|
-
}
|
|
11345
|
-
return null;
|
|
11346
|
-
}
|
|
11347
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11348
|
-
style: "percent",
|
|
11349
|
-
minimumFractionDigits: 2
|
|
11350
|
-
});
|
|
11351
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11352
|
-
let val = value || 0;
|
|
11353
|
-
if (!isPercentageValue) {
|
|
11354
|
-
val = val / 100;
|
|
11355
|
-
}
|
|
11356
|
-
return formatter.format(val);
|
|
11357
|
-
};
|
|
11358
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11359
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11360
|
-
for (const item of items) {
|
|
11361
|
-
if (item.adjustments) {
|
|
11362
|
-
for (const adjustment of item.adjustments) {
|
|
11363
|
-
if (adjustment.promotion_id) {
|
|
11364
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11365
|
-
}
|
|
11366
|
-
}
|
|
11367
|
-
}
|
|
11368
|
-
}
|
|
11369
|
-
for (const shippingMethod of shippingMethods) {
|
|
11370
|
-
if (shippingMethod.adjustments) {
|
|
11371
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11372
|
-
if (adjustment.promotion_id) {
|
|
11373
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11374
|
-
}
|
|
11375
|
-
}
|
|
11376
|
-
}
|
|
11377
|
-
}
|
|
11378
|
-
return Array.from(promotionIds);
|
|
11379
|
-
}
|
|
11380
|
-
const Email = () => {
|
|
11381
|
-
const { id } = useParams();
|
|
11382
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11383
|
-
fields: "+email"
|
|
11384
|
-
});
|
|
11385
|
-
if (isError) {
|
|
11386
|
-
throw error;
|
|
11387
|
-
}
|
|
11388
|
-
const isReady = !isPending && !!order;
|
|
11389
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11390
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11391
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
11392
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
11393
|
-
] }),
|
|
11394
|
-
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
11395
|
-
] });
|
|
11396
|
-
};
|
|
11397
|
-
const EmailForm = ({ order }) => {
|
|
11398
|
-
const form = useForm({
|
|
11399
|
-
defaultValues: {
|
|
11400
|
-
email: order.email ?? ""
|
|
11401
|
-
},
|
|
11402
|
-
resolver: zodResolver(schema$3)
|
|
11403
|
-
});
|
|
11404
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11405
|
-
const { handleSuccess } = useRouteModal();
|
|
11406
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11407
|
-
await mutateAsync(
|
|
11408
|
-
{ email: data.email },
|
|
11409
|
-
{
|
|
11410
|
-
onSuccess: () => {
|
|
11411
|
-
handleSuccess();
|
|
11412
|
-
},
|
|
11413
|
-
onError: (error) => {
|
|
11414
|
-
toast.error(error.message);
|
|
11415
|
-
}
|
|
11416
|
-
}
|
|
11417
|
-
);
|
|
11418
|
-
});
|
|
11419
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11420
|
-
KeyboundForm,
|
|
11421
|
-
{
|
|
11422
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11423
|
-
onSubmit,
|
|
11424
|
-
children: [
|
|
11425
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
11426
|
-
Form$2.Field,
|
|
11427
|
-
{
|
|
11428
|
-
control: form.control,
|
|
11429
|
-
name: "email",
|
|
11430
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11431
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
11432
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11433
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11434
|
-
] })
|
|
11435
|
-
}
|
|
11436
|
-
) }),
|
|
11437
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11438
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11439
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11440
|
-
] }) })
|
|
11441
|
-
]
|
|
11442
|
-
}
|
|
11443
|
-
) });
|
|
11444
|
-
};
|
|
11445
|
-
const schema$3 = objectType({
|
|
11446
|
-
email: stringType().email()
|
|
11447
|
-
});
|
|
11448
|
-
const SalesChannel = () => {
|
|
11449
|
-
const { id } = useParams();
|
|
11450
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11451
|
-
id,
|
|
11452
|
-
{
|
|
11453
|
-
fields: "+sales_channel_id"
|
|
11454
|
-
},
|
|
11455
|
-
{
|
|
11456
|
-
enabled: !!id
|
|
11457
|
-
}
|
|
11458
|
-
);
|
|
11459
|
-
if (isError) {
|
|
11460
|
-
throw error;
|
|
11461
|
-
}
|
|
11462
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
11463
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11464
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11465
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11466
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11467
|
-
] }),
|
|
11468
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11469
|
-
] });
|
|
11470
|
-
};
|
|
11471
|
-
const SalesChannelForm = ({ order }) => {
|
|
11472
|
-
const form = useForm({
|
|
11473
|
-
defaultValues: {
|
|
11474
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11475
|
-
},
|
|
11476
|
-
resolver: zodResolver(schema$2)
|
|
11477
|
-
});
|
|
11478
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11479
|
-
const { handleSuccess } = useRouteModal();
|
|
11480
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11481
|
-
await mutateAsync(
|
|
11482
|
-
{
|
|
11483
|
-
sales_channel_id: data.sales_channel_id
|
|
11484
|
-
},
|
|
11485
|
-
{
|
|
11486
|
-
onSuccess: () => {
|
|
11487
|
-
toast.success("Sales channel updated");
|
|
11488
|
-
handleSuccess();
|
|
11489
|
-
},
|
|
11490
|
-
onError: (error) => {
|
|
11491
|
-
toast.error(error.message);
|
|
11492
|
-
}
|
|
11493
|
-
}
|
|
11494
|
-
);
|
|
11495
|
-
});
|
|
11496
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11497
|
-
KeyboundForm,
|
|
11498
|
-
{
|
|
11499
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11500
|
-
onSubmit,
|
|
11501
|
-
children: [
|
|
11502
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11503
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11504
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11505
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11506
|
-
] }) })
|
|
11507
|
-
]
|
|
11508
|
-
}
|
|
11509
|
-
) });
|
|
11510
|
-
};
|
|
11511
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11512
|
-
const salesChannels = useComboboxData({
|
|
11513
|
-
queryFn: async (params) => {
|
|
11514
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11515
|
-
},
|
|
11516
|
-
queryKey: ["sales-channels"],
|
|
11517
|
-
getOptions: (data) => {
|
|
11518
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11519
|
-
label: salesChannel.name,
|
|
11520
|
-
value: salesChannel.id
|
|
11521
|
-
}));
|
|
11522
|
-
},
|
|
11523
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11524
|
-
});
|
|
11525
|
-
return /* @__PURE__ */ jsx(
|
|
11526
|
-
Form$2.Field,
|
|
11527
|
-
{
|
|
11528
|
-
control,
|
|
11529
|
-
name: "sales_channel_id",
|
|
11530
|
-
render: ({ field }) => {
|
|
11531
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11532
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11533
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11534
|
-
Combobox,
|
|
11535
|
-
{
|
|
11536
|
-
options: salesChannels.options,
|
|
11537
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11538
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11539
|
-
searchValue: salesChannels.searchValue,
|
|
11540
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11541
|
-
placeholder: "Select sales channel",
|
|
11542
|
-
...field
|
|
11543
|
-
}
|
|
11544
|
-
) }),
|
|
11545
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11546
|
-
] });
|
|
11547
|
-
}
|
|
11548
|
-
}
|
|
11549
|
-
);
|
|
11550
|
-
};
|
|
11551
|
-
const schema$2 = objectType({
|
|
11552
|
-
sales_channel_id: stringType().min(1)
|
|
11553
|
-
});
|
|
11554
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11555
|
-
const Shipping = () => {
|
|
11556
|
-
var _a;
|
|
11557
|
-
const { id } = useParams();
|
|
11558
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11559
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11560
|
-
});
|
|
11561
|
-
const {
|
|
11562
|
-
order: preview,
|
|
11563
|
-
isPending: isPreviewPending,
|
|
11564
|
-
isError: isPreviewError,
|
|
11565
|
-
error: previewError
|
|
11566
|
-
} = useOrderPreview(id);
|
|
11567
|
-
useInitiateOrderEdit({ preview });
|
|
11568
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11569
|
-
if (isError) {
|
|
11570
|
-
throw error;
|
|
11571
|
-
}
|
|
11572
|
-
if (isPreviewError) {
|
|
11573
|
-
throw previewError;
|
|
11574
|
-
}
|
|
11575
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11576
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11577
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11578
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11579
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
11580
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11581
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11582
|
-
] }) }) }),
|
|
11583
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11584
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11585
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11586
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11587
|
-
] }) });
|
|
11588
|
-
};
|
|
11589
|
-
const ShippingForm = ({ preview, order }) => {
|
|
11590
|
-
var _a;
|
|
11591
|
-
const { setIsOpen } = useStackedModal();
|
|
11592
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11593
|
-
const [data, setData] = useState(null);
|
|
11594
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11595
|
-
const { shipping_options } = useShippingOptions(
|
|
11596
|
-
{
|
|
11597
|
-
id: appliedShippingOptionIds,
|
|
11598
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11599
|
-
},
|
|
11600
|
-
{
|
|
11601
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
11324
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11602
11325
|
}
|
|
11603
11326
|
);
|
|
11604
11327
|
const uniqueShippingProfiles = useMemo(() => {
|
|
@@ -12957,86 +12680,363 @@ const Illustration = () => {
|
|
|
12957
12680
|
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12958
12681
|
"path",
|
|
12959
12682
|
{
|
|
12960
|
-
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12961
|
-
stroke: "#A1A1AA",
|
|
12962
|
-
strokeWidth: "1.5",
|
|
12963
|
-
strokeLinecap: "round",
|
|
12964
|
-
strokeLinejoin: "round"
|
|
12683
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12684
|
+
stroke: "#A1A1AA",
|
|
12685
|
+
strokeWidth: "1.5",
|
|
12686
|
+
strokeLinecap: "round",
|
|
12687
|
+
strokeLinejoin: "round"
|
|
12688
|
+
}
|
|
12689
|
+
) }),
|
|
12690
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12691
|
+
"path",
|
|
12692
|
+
{
|
|
12693
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12694
|
+
stroke: "#A1A1AA",
|
|
12695
|
+
strokeWidth: "1.5",
|
|
12696
|
+
strokeLinecap: "round",
|
|
12697
|
+
strokeLinejoin: "round"
|
|
12698
|
+
}
|
|
12699
|
+
) }),
|
|
12700
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12701
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12702
|
+
"rect",
|
|
12703
|
+
{
|
|
12704
|
+
width: "12",
|
|
12705
|
+
height: "12",
|
|
12706
|
+
fill: "white",
|
|
12707
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12708
|
+
}
|
|
12709
|
+
) }),
|
|
12710
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12711
|
+
"rect",
|
|
12712
|
+
{
|
|
12713
|
+
width: "12",
|
|
12714
|
+
height: "12",
|
|
12715
|
+
fill: "white",
|
|
12716
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12717
|
+
}
|
|
12718
|
+
) }),
|
|
12719
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12720
|
+
"rect",
|
|
12721
|
+
{
|
|
12722
|
+
width: "12",
|
|
12723
|
+
height: "12",
|
|
12724
|
+
fill: "white",
|
|
12725
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12726
|
+
}
|
|
12727
|
+
) }),
|
|
12728
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12729
|
+
"rect",
|
|
12730
|
+
{
|
|
12731
|
+
width: "12",
|
|
12732
|
+
height: "12",
|
|
12733
|
+
fill: "white",
|
|
12734
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
12735
|
+
}
|
|
12736
|
+
) }),
|
|
12737
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12738
|
+
"rect",
|
|
12739
|
+
{
|
|
12740
|
+
width: "12",
|
|
12741
|
+
height: "12",
|
|
12742
|
+
fill: "white",
|
|
12743
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
12744
|
+
}
|
|
12745
|
+
) }),
|
|
12746
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12747
|
+
"rect",
|
|
12748
|
+
{
|
|
12749
|
+
width: "12",
|
|
12750
|
+
height: "12",
|
|
12751
|
+
fill: "white",
|
|
12752
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12753
|
+
}
|
|
12754
|
+
) })
|
|
12755
|
+
] })
|
|
12756
|
+
]
|
|
12757
|
+
}
|
|
12758
|
+
);
|
|
12759
|
+
};
|
|
12760
|
+
const schema = objectType({
|
|
12761
|
+
customer_id: stringType().min(1)
|
|
12762
|
+
});
|
|
12763
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
12764
|
+
const promotionsQueryKeys = {
|
|
12765
|
+
list: (query2) => [
|
|
12766
|
+
PROMOTION_QUERY_KEY,
|
|
12767
|
+
query2 ? query2 : void 0
|
|
12768
|
+
],
|
|
12769
|
+
detail: (id, query2) => [
|
|
12770
|
+
PROMOTION_QUERY_KEY,
|
|
12771
|
+
id,
|
|
12772
|
+
query2 ? query2 : void 0
|
|
12773
|
+
]
|
|
12774
|
+
};
|
|
12775
|
+
const usePromotions = (query2, options) => {
|
|
12776
|
+
const { data, ...rest } = useQuery({
|
|
12777
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
12778
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
12779
|
+
...options
|
|
12780
|
+
});
|
|
12781
|
+
return { ...data, ...rest };
|
|
12782
|
+
};
|
|
12783
|
+
const Promotions = () => {
|
|
12784
|
+
const { id } = useParams();
|
|
12785
|
+
const {
|
|
12786
|
+
order: preview,
|
|
12787
|
+
isError: isPreviewError,
|
|
12788
|
+
error: previewError
|
|
12789
|
+
} = useOrderPreview(id, void 0);
|
|
12790
|
+
useInitiateOrderEdit({ preview });
|
|
12791
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12792
|
+
if (isPreviewError) {
|
|
12793
|
+
throw previewError;
|
|
12794
|
+
}
|
|
12795
|
+
const isReady = !!preview;
|
|
12796
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
12797
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
12798
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
12799
|
+
] });
|
|
12800
|
+
};
|
|
12801
|
+
const PromotionForm = ({ preview }) => {
|
|
12802
|
+
const { items, shipping_methods } = preview;
|
|
12803
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
12804
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
12805
|
+
const { handleSuccess } = useRouteModal();
|
|
12806
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
12807
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
12808
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
12809
|
+
{
|
|
12810
|
+
id: promoIds
|
|
12811
|
+
},
|
|
12812
|
+
{
|
|
12813
|
+
enabled: !!promoIds.length
|
|
12814
|
+
}
|
|
12815
|
+
);
|
|
12816
|
+
const comboboxData = useComboboxData({
|
|
12817
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
12818
|
+
queryFn: async (params) => {
|
|
12819
|
+
return await sdk.admin.promotion.list({
|
|
12820
|
+
...params,
|
|
12821
|
+
id: {
|
|
12822
|
+
$nin: promoIds
|
|
12823
|
+
}
|
|
12824
|
+
});
|
|
12825
|
+
},
|
|
12826
|
+
getOptions: (data) => {
|
|
12827
|
+
return data.promotions.map((promotion) => ({
|
|
12828
|
+
label: promotion.code,
|
|
12829
|
+
value: promotion.code
|
|
12830
|
+
}));
|
|
12831
|
+
}
|
|
12832
|
+
});
|
|
12833
|
+
const add = async (value) => {
|
|
12834
|
+
if (!value) {
|
|
12835
|
+
return;
|
|
12836
|
+
}
|
|
12837
|
+
addPromotions(
|
|
12838
|
+
{
|
|
12839
|
+
promo_codes: [value]
|
|
12840
|
+
},
|
|
12841
|
+
{
|
|
12842
|
+
onError: (e) => {
|
|
12843
|
+
toast.error(e.message);
|
|
12844
|
+
comboboxData.onSearchValueChange("");
|
|
12845
|
+
setComboboxValue("");
|
|
12846
|
+
},
|
|
12847
|
+
onSuccess: () => {
|
|
12848
|
+
comboboxData.onSearchValueChange("");
|
|
12849
|
+
setComboboxValue("");
|
|
12850
|
+
}
|
|
12851
|
+
}
|
|
12852
|
+
);
|
|
12853
|
+
};
|
|
12854
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12855
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
12856
|
+
const onSubmit = async () => {
|
|
12857
|
+
setIsSubmitting(true);
|
|
12858
|
+
let requestSucceeded = false;
|
|
12859
|
+
await requestOrderEdit(void 0, {
|
|
12860
|
+
onError: (e) => {
|
|
12861
|
+
toast.error(e.message);
|
|
12862
|
+
},
|
|
12863
|
+
onSuccess: () => {
|
|
12864
|
+
requestSucceeded = true;
|
|
12865
|
+
}
|
|
12866
|
+
});
|
|
12867
|
+
if (!requestSucceeded) {
|
|
12868
|
+
setIsSubmitting(false);
|
|
12869
|
+
return;
|
|
12870
|
+
}
|
|
12871
|
+
await confirmOrderEdit(void 0, {
|
|
12872
|
+
onError: (e) => {
|
|
12873
|
+
toast.error(e.message);
|
|
12874
|
+
},
|
|
12875
|
+
onSuccess: () => {
|
|
12876
|
+
handleSuccess();
|
|
12877
|
+
},
|
|
12878
|
+
onSettled: () => {
|
|
12879
|
+
setIsSubmitting(false);
|
|
12880
|
+
}
|
|
12881
|
+
});
|
|
12882
|
+
};
|
|
12883
|
+
if (isError) {
|
|
12884
|
+
throw error;
|
|
12885
|
+
}
|
|
12886
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
12887
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
12888
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
12889
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12890
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
12891
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
12892
|
+
] }),
|
|
12893
|
+
/* @__PURE__ */ jsx(
|
|
12894
|
+
Combobox,
|
|
12895
|
+
{
|
|
12896
|
+
id: "promotion-combobox",
|
|
12897
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
12898
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
12899
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
12900
|
+
options: comboboxData.options,
|
|
12901
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
12902
|
+
searchValue: comboboxData.searchValue,
|
|
12903
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
12904
|
+
onChange: add,
|
|
12905
|
+
value: comboboxValue
|
|
12965
12906
|
}
|
|
12966
|
-
)
|
|
12967
|
-
|
|
12968
|
-
|
|
12907
|
+
)
|
|
12908
|
+
] }),
|
|
12909
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12910
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
12911
|
+
PromotionItem,
|
|
12912
|
+
{
|
|
12913
|
+
promotion,
|
|
12914
|
+
orderId: preview.id,
|
|
12915
|
+
isLoading: isPending
|
|
12916
|
+
},
|
|
12917
|
+
promotion.id
|
|
12918
|
+
)) })
|
|
12919
|
+
] }) }),
|
|
12920
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12921
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12922
|
+
/* @__PURE__ */ jsx(
|
|
12923
|
+
Button,
|
|
12924
|
+
{
|
|
12925
|
+
size: "small",
|
|
12926
|
+
type: "submit",
|
|
12927
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
12928
|
+
children: "Save"
|
|
12929
|
+
}
|
|
12930
|
+
)
|
|
12931
|
+
] }) })
|
|
12932
|
+
] });
|
|
12933
|
+
};
|
|
12934
|
+
const PromotionItem = ({
|
|
12935
|
+
promotion,
|
|
12936
|
+
orderId,
|
|
12937
|
+
isLoading
|
|
12938
|
+
}) => {
|
|
12939
|
+
var _a;
|
|
12940
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
12941
|
+
const onRemove = async () => {
|
|
12942
|
+
removePromotions(
|
|
12943
|
+
{
|
|
12944
|
+
promo_codes: [promotion.code]
|
|
12945
|
+
},
|
|
12946
|
+
{
|
|
12947
|
+
onError: (e) => {
|
|
12948
|
+
toast.error(e.message);
|
|
12949
|
+
}
|
|
12950
|
+
}
|
|
12951
|
+
);
|
|
12952
|
+
};
|
|
12953
|
+
const displayValue = getDisplayValue(promotion);
|
|
12954
|
+
return /* @__PURE__ */ jsxs(
|
|
12955
|
+
"div",
|
|
12956
|
+
{
|
|
12957
|
+
className: clx(
|
|
12958
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
12959
|
+
{
|
|
12960
|
+
"animate-pulse": isLoading
|
|
12961
|
+
}
|
|
12962
|
+
),
|
|
12963
|
+
children: [
|
|
12964
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12965
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
12966
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
12967
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
12968
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
12969
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
12970
|
+
] }),
|
|
12971
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
12972
|
+
] })
|
|
12973
|
+
] }),
|
|
12974
|
+
/* @__PURE__ */ jsx(
|
|
12975
|
+
IconButton,
|
|
12969
12976
|
{
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12977
|
+
size: "small",
|
|
12978
|
+
type: "button",
|
|
12979
|
+
variant: "transparent",
|
|
12980
|
+
onClick: onRemove,
|
|
12981
|
+
isLoading: isPending || isLoading,
|
|
12982
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
12975
12983
|
}
|
|
12976
|
-
)
|
|
12977
|
-
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12978
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12979
|
-
"rect",
|
|
12980
|
-
{
|
|
12981
|
-
width: "12",
|
|
12982
|
-
height: "12",
|
|
12983
|
-
fill: "white",
|
|
12984
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12985
|
-
}
|
|
12986
|
-
) }),
|
|
12987
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12988
|
-
"rect",
|
|
12989
|
-
{
|
|
12990
|
-
width: "12",
|
|
12991
|
-
height: "12",
|
|
12992
|
-
fill: "white",
|
|
12993
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12994
|
-
}
|
|
12995
|
-
) }),
|
|
12996
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12997
|
-
"rect",
|
|
12998
|
-
{
|
|
12999
|
-
width: "12",
|
|
13000
|
-
height: "12",
|
|
13001
|
-
fill: "white",
|
|
13002
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
13003
|
-
}
|
|
13004
|
-
) }),
|
|
13005
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13006
|
-
"rect",
|
|
13007
|
-
{
|
|
13008
|
-
width: "12",
|
|
13009
|
-
height: "12",
|
|
13010
|
-
fill: "white",
|
|
13011
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
13012
|
-
}
|
|
13013
|
-
) }),
|
|
13014
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13015
|
-
"rect",
|
|
13016
|
-
{
|
|
13017
|
-
width: "12",
|
|
13018
|
-
height: "12",
|
|
13019
|
-
fill: "white",
|
|
13020
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
13021
|
-
}
|
|
13022
|
-
) }),
|
|
13023
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13024
|
-
"rect",
|
|
13025
|
-
{
|
|
13026
|
-
width: "12",
|
|
13027
|
-
height: "12",
|
|
13028
|
-
fill: "white",
|
|
13029
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
13030
|
-
}
|
|
13031
|
-
) })
|
|
13032
|
-
] })
|
|
12984
|
+
)
|
|
13033
12985
|
]
|
|
13034
|
-
}
|
|
12986
|
+
},
|
|
12987
|
+
promotion.id
|
|
13035
12988
|
);
|
|
13036
12989
|
};
|
|
13037
|
-
|
|
13038
|
-
|
|
12990
|
+
function getDisplayValue(promotion) {
|
|
12991
|
+
var _a, _b, _c, _d;
|
|
12992
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
12993
|
+
if (!value) {
|
|
12994
|
+
return null;
|
|
12995
|
+
}
|
|
12996
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
12997
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
12998
|
+
if (!currency) {
|
|
12999
|
+
return null;
|
|
13000
|
+
}
|
|
13001
|
+
return getLocaleAmount(value, currency);
|
|
13002
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
13003
|
+
return formatPercentage(value);
|
|
13004
|
+
}
|
|
13005
|
+
return null;
|
|
13006
|
+
}
|
|
13007
|
+
const formatter = new Intl.NumberFormat([], {
|
|
13008
|
+
style: "percent",
|
|
13009
|
+
minimumFractionDigits: 2
|
|
13039
13010
|
});
|
|
13011
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
13012
|
+
let val = value || 0;
|
|
13013
|
+
if (!isPercentageValue) {
|
|
13014
|
+
val = val / 100;
|
|
13015
|
+
}
|
|
13016
|
+
return formatter.format(val);
|
|
13017
|
+
};
|
|
13018
|
+
function getPromotionIds(items, shippingMethods) {
|
|
13019
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
13020
|
+
for (const item of items) {
|
|
13021
|
+
if (item.adjustments) {
|
|
13022
|
+
for (const adjustment of item.adjustments) {
|
|
13023
|
+
if (adjustment.promotion_id) {
|
|
13024
|
+
promotionIds.add(adjustment.promotion_id);
|
|
13025
|
+
}
|
|
13026
|
+
}
|
|
13027
|
+
}
|
|
13028
|
+
}
|
|
13029
|
+
for (const shippingMethod of shippingMethods) {
|
|
13030
|
+
if (shippingMethod.adjustments) {
|
|
13031
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
13032
|
+
if (adjustment.promotion_id) {
|
|
13033
|
+
promotionIds.add(adjustment.promotion_id);
|
|
13034
|
+
}
|
|
13035
|
+
}
|
|
13036
|
+
}
|
|
13037
|
+
}
|
|
13038
|
+
return Array.from(promotionIds);
|
|
13039
|
+
}
|
|
13040
13040
|
const widgetModule = { widgets: [] };
|
|
13041
13041
|
const routeModule = {
|
|
13042
13042
|
routes: [
|
|
@@ -13065,6 +13065,10 @@ const routeModule = {
|
|
|
13065
13065
|
Component: CustomItems,
|
|
13066
13066
|
path: "/draft-orders/:id/custom-items"
|
|
13067
13067
|
},
|
|
13068
|
+
{
|
|
13069
|
+
Component: Email,
|
|
13070
|
+
path: "/draft-orders/:id/email"
|
|
13071
|
+
},
|
|
13068
13072
|
{
|
|
13069
13073
|
Component: Items,
|
|
13070
13074
|
path: "/draft-orders/:id/items"
|
|
@@ -13073,14 +13077,6 @@ const routeModule = {
|
|
|
13073
13077
|
Component: Metadata,
|
|
13074
13078
|
path: "/draft-orders/:id/metadata"
|
|
13075
13079
|
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: Promotions,
|
|
13078
|
-
path: "/draft-orders/:id/promotions"
|
|
13079
|
-
},
|
|
13080
|
-
{
|
|
13081
|
-
Component: Email,
|
|
13082
|
-
path: "/draft-orders/:id/email"
|
|
13083
|
-
},
|
|
13084
13080
|
{
|
|
13085
13081
|
Component: SalesChannel,
|
|
13086
13082
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13096,6 +13092,10 @@ const routeModule = {
|
|
|
13096
13092
|
{
|
|
13097
13093
|
Component: TransferOwnership,
|
|
13098
13094
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
|
+
},
|
|
13096
|
+
{
|
|
13097
|
+
Component: Promotions,
|
|
13098
|
+
path: "/draft-orders/:id/promotions"
|
|
13099
13099
|
}
|
|
13100
13100
|
]
|
|
13101
13101
|
}
|