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