@medusajs/draft-order 2.11.4-preview-20251112180139 → 2.11.4-preview-20251113000307
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 +392 -392
- package/.medusa/server/src/admin/index.mjs +392 -392
- package/package.json +16 -16
|
@@ -11168,6 +11168,283 @@ function getHasUneditableRows(metadata) {
|
|
|
11168
11168
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11169
11169
|
);
|
|
11170
11170
|
}
|
|
11171
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11172
|
+
const promotionsQueryKeys = {
|
|
11173
|
+
list: (query2) => [
|
|
11174
|
+
PROMOTION_QUERY_KEY,
|
|
11175
|
+
query2 ? query2 : void 0
|
|
11176
|
+
],
|
|
11177
|
+
detail: (id, query2) => [
|
|
11178
|
+
PROMOTION_QUERY_KEY,
|
|
11179
|
+
id,
|
|
11180
|
+
query2 ? query2 : void 0
|
|
11181
|
+
]
|
|
11182
|
+
};
|
|
11183
|
+
const usePromotions = (query2, options) => {
|
|
11184
|
+
const { data, ...rest } = useQuery({
|
|
11185
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11186
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11187
|
+
...options
|
|
11188
|
+
});
|
|
11189
|
+
return { ...data, ...rest };
|
|
11190
|
+
};
|
|
11191
|
+
const Promotions = () => {
|
|
11192
|
+
const { id } = useParams();
|
|
11193
|
+
const {
|
|
11194
|
+
order: preview,
|
|
11195
|
+
isError: isPreviewError,
|
|
11196
|
+
error: previewError
|
|
11197
|
+
} = useOrderPreview(id, void 0);
|
|
11198
|
+
useInitiateOrderEdit({ preview });
|
|
11199
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11200
|
+
if (isPreviewError) {
|
|
11201
|
+
throw previewError;
|
|
11202
|
+
}
|
|
11203
|
+
const isReady = !!preview;
|
|
11204
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11205
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11206
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11207
|
+
] });
|
|
11208
|
+
};
|
|
11209
|
+
const PromotionForm = ({ preview }) => {
|
|
11210
|
+
const { items, shipping_methods } = preview;
|
|
11211
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11212
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
11213
|
+
const { handleSuccess } = useRouteModal();
|
|
11214
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11215
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11216
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11217
|
+
{
|
|
11218
|
+
id: promoIds
|
|
11219
|
+
},
|
|
11220
|
+
{
|
|
11221
|
+
enabled: !!promoIds.length
|
|
11222
|
+
}
|
|
11223
|
+
);
|
|
11224
|
+
const comboboxData = useComboboxData({
|
|
11225
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11226
|
+
queryFn: async (params) => {
|
|
11227
|
+
return await sdk.admin.promotion.list({
|
|
11228
|
+
...params,
|
|
11229
|
+
id: {
|
|
11230
|
+
$nin: promoIds
|
|
11231
|
+
}
|
|
11232
|
+
});
|
|
11233
|
+
},
|
|
11234
|
+
getOptions: (data) => {
|
|
11235
|
+
return data.promotions.map((promotion) => ({
|
|
11236
|
+
label: promotion.code,
|
|
11237
|
+
value: promotion.code
|
|
11238
|
+
}));
|
|
11239
|
+
}
|
|
11240
|
+
});
|
|
11241
|
+
const add = async (value) => {
|
|
11242
|
+
if (!value) {
|
|
11243
|
+
return;
|
|
11244
|
+
}
|
|
11245
|
+
addPromotions(
|
|
11246
|
+
{
|
|
11247
|
+
promo_codes: [value]
|
|
11248
|
+
},
|
|
11249
|
+
{
|
|
11250
|
+
onError: (e) => {
|
|
11251
|
+
toast.error(e.message);
|
|
11252
|
+
comboboxData.onSearchValueChange("");
|
|
11253
|
+
setComboboxValue("");
|
|
11254
|
+
},
|
|
11255
|
+
onSuccess: () => {
|
|
11256
|
+
comboboxData.onSearchValueChange("");
|
|
11257
|
+
setComboboxValue("");
|
|
11258
|
+
}
|
|
11259
|
+
}
|
|
11260
|
+
);
|
|
11261
|
+
};
|
|
11262
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11263
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11264
|
+
const onSubmit = async () => {
|
|
11265
|
+
setIsSubmitting(true);
|
|
11266
|
+
let requestSucceeded = false;
|
|
11267
|
+
await requestOrderEdit(void 0, {
|
|
11268
|
+
onError: (e) => {
|
|
11269
|
+
toast.error(e.message);
|
|
11270
|
+
},
|
|
11271
|
+
onSuccess: () => {
|
|
11272
|
+
requestSucceeded = true;
|
|
11273
|
+
}
|
|
11274
|
+
});
|
|
11275
|
+
if (!requestSucceeded) {
|
|
11276
|
+
setIsSubmitting(false);
|
|
11277
|
+
return;
|
|
11278
|
+
}
|
|
11279
|
+
await confirmOrderEdit(void 0, {
|
|
11280
|
+
onError: (e) => {
|
|
11281
|
+
toast.error(e.message);
|
|
11282
|
+
},
|
|
11283
|
+
onSuccess: () => {
|
|
11284
|
+
handleSuccess();
|
|
11285
|
+
},
|
|
11286
|
+
onSettled: () => {
|
|
11287
|
+
setIsSubmitting(false);
|
|
11288
|
+
}
|
|
11289
|
+
});
|
|
11290
|
+
};
|
|
11291
|
+
if (isError) {
|
|
11292
|
+
throw error;
|
|
11293
|
+
}
|
|
11294
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11295
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11296
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11297
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11298
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11299
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11300
|
+
] }),
|
|
11301
|
+
/* @__PURE__ */ jsx(
|
|
11302
|
+
Combobox,
|
|
11303
|
+
{
|
|
11304
|
+
id: "promotion-combobox",
|
|
11305
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11306
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11307
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11308
|
+
options: comboboxData.options,
|
|
11309
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11310
|
+
searchValue: comboboxData.searchValue,
|
|
11311
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11312
|
+
onChange: add,
|
|
11313
|
+
value: comboboxValue
|
|
11314
|
+
}
|
|
11315
|
+
)
|
|
11316
|
+
] }),
|
|
11317
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11318
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11319
|
+
PromotionItem,
|
|
11320
|
+
{
|
|
11321
|
+
promotion,
|
|
11322
|
+
orderId: preview.id,
|
|
11323
|
+
isLoading: isPending
|
|
11324
|
+
},
|
|
11325
|
+
promotion.id
|
|
11326
|
+
)) })
|
|
11327
|
+
] }) }),
|
|
11328
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11329
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11330
|
+
/* @__PURE__ */ jsx(
|
|
11331
|
+
Button,
|
|
11332
|
+
{
|
|
11333
|
+
size: "small",
|
|
11334
|
+
type: "submit",
|
|
11335
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11336
|
+
children: "Save"
|
|
11337
|
+
}
|
|
11338
|
+
)
|
|
11339
|
+
] }) })
|
|
11340
|
+
] });
|
|
11341
|
+
};
|
|
11342
|
+
const PromotionItem = ({
|
|
11343
|
+
promotion,
|
|
11344
|
+
orderId,
|
|
11345
|
+
isLoading
|
|
11346
|
+
}) => {
|
|
11347
|
+
var _a;
|
|
11348
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11349
|
+
const onRemove = async () => {
|
|
11350
|
+
removePromotions(
|
|
11351
|
+
{
|
|
11352
|
+
promo_codes: [promotion.code]
|
|
11353
|
+
},
|
|
11354
|
+
{
|
|
11355
|
+
onError: (e) => {
|
|
11356
|
+
toast.error(e.message);
|
|
11357
|
+
}
|
|
11358
|
+
}
|
|
11359
|
+
);
|
|
11360
|
+
};
|
|
11361
|
+
const displayValue = getDisplayValue(promotion);
|
|
11362
|
+
return /* @__PURE__ */ jsxs(
|
|
11363
|
+
"div",
|
|
11364
|
+
{
|
|
11365
|
+
className: clx(
|
|
11366
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11367
|
+
{
|
|
11368
|
+
"animate-pulse": isLoading
|
|
11369
|
+
}
|
|
11370
|
+
),
|
|
11371
|
+
children: [
|
|
11372
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11373
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11374
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11375
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11376
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11377
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11378
|
+
] }),
|
|
11379
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11380
|
+
] })
|
|
11381
|
+
] }),
|
|
11382
|
+
/* @__PURE__ */ jsx(
|
|
11383
|
+
IconButton,
|
|
11384
|
+
{
|
|
11385
|
+
size: "small",
|
|
11386
|
+
type: "button",
|
|
11387
|
+
variant: "transparent",
|
|
11388
|
+
onClick: onRemove,
|
|
11389
|
+
isLoading: isPending || isLoading,
|
|
11390
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11391
|
+
}
|
|
11392
|
+
)
|
|
11393
|
+
]
|
|
11394
|
+
},
|
|
11395
|
+
promotion.id
|
|
11396
|
+
);
|
|
11397
|
+
};
|
|
11398
|
+
function getDisplayValue(promotion) {
|
|
11399
|
+
var _a, _b, _c, _d;
|
|
11400
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11401
|
+
if (!value) {
|
|
11402
|
+
return null;
|
|
11403
|
+
}
|
|
11404
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11405
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11406
|
+
if (!currency) {
|
|
11407
|
+
return null;
|
|
11408
|
+
}
|
|
11409
|
+
return getLocaleAmount(value, currency);
|
|
11410
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11411
|
+
return formatPercentage(value);
|
|
11412
|
+
}
|
|
11413
|
+
return null;
|
|
11414
|
+
}
|
|
11415
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11416
|
+
style: "percent",
|
|
11417
|
+
minimumFractionDigits: 2
|
|
11418
|
+
});
|
|
11419
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11420
|
+
let val = value || 0;
|
|
11421
|
+
if (!isPercentageValue) {
|
|
11422
|
+
val = val / 100;
|
|
11423
|
+
}
|
|
11424
|
+
return formatter.format(val);
|
|
11425
|
+
};
|
|
11426
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11427
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11428
|
+
for (const item of items) {
|
|
11429
|
+
if (item.adjustments) {
|
|
11430
|
+
for (const adjustment of item.adjustments) {
|
|
11431
|
+
if (adjustment.promotion_id) {
|
|
11432
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11433
|
+
}
|
|
11434
|
+
}
|
|
11435
|
+
}
|
|
11436
|
+
}
|
|
11437
|
+
for (const shippingMethod of shippingMethods) {
|
|
11438
|
+
if (shippingMethod.adjustments) {
|
|
11439
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11440
|
+
if (adjustment.promotion_id) {
|
|
11441
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11442
|
+
}
|
|
11443
|
+
}
|
|
11444
|
+
}
|
|
11445
|
+
}
|
|
11446
|
+
return Array.from(promotionIds);
|
|
11447
|
+
}
|
|
11171
11448
|
const SalesChannel = () => {
|
|
11172
11449
|
const { id } = useParams();
|
|
11173
11450
|
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
@@ -12641,402 +12918,125 @@ const Illustration = () => {
|
|
|
12641
12918
|
"path",
|
|
12642
12919
|
{
|
|
12643
12920
|
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
12644
|
-
stroke: "#A1A1AA",
|
|
12645
|
-
strokeWidth: "1.5",
|
|
12646
|
-
strokeLinecap: "round",
|
|
12647
|
-
strokeLinejoin: "round"
|
|
12648
|
-
}
|
|
12649
|
-
) }),
|
|
12650
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12651
|
-
"path",
|
|
12652
|
-
{
|
|
12653
|
-
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
12654
|
-
stroke: "#A1A1AA",
|
|
12655
|
-
strokeWidth: "1.5",
|
|
12656
|
-
strokeLinecap: "round",
|
|
12657
|
-
strokeLinejoin: "round"
|
|
12658
|
-
}
|
|
12659
|
-
) }),
|
|
12660
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12661
|
-
"path",
|
|
12662
|
-
{
|
|
12663
|
-
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
12664
|
-
stroke: "#A1A1AA",
|
|
12665
|
-
strokeWidth: "1.5",
|
|
12666
|
-
strokeLinecap: "round",
|
|
12667
|
-
strokeLinejoin: "round"
|
|
12668
|
-
}
|
|
12669
|
-
) }),
|
|
12670
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12671
|
-
"path",
|
|
12672
|
-
{
|
|
12673
|
-
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
12674
|
-
stroke: "#A1A1AA",
|
|
12675
|
-
strokeWidth: "1.5",
|
|
12676
|
-
strokeLinecap: "round",
|
|
12677
|
-
strokeLinejoin: "round"
|
|
12678
|
-
}
|
|
12679
|
-
) }),
|
|
12680
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12681
|
-
"path",
|
|
12682
|
-
{
|
|
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,
|
|
12921
|
+
stroke: "#A1A1AA",
|
|
12922
|
+
strokeWidth: "1.5",
|
|
12923
|
+
strokeLinecap: "round",
|
|
12924
|
+
strokeLinejoin: "round"
|
|
12925
|
+
}
|
|
12926
|
+
) }),
|
|
12927
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12928
|
+
"path",
|
|
12895
12929
|
{
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
12902
|
-
searchValue: comboboxData.searchValue,
|
|
12903
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
12904
|
-
onChange: add,
|
|
12905
|
-
value: comboboxValue
|
|
12930
|
+
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
12931
|
+
stroke: "#A1A1AA",
|
|
12932
|
+
strokeWidth: "1.5",
|
|
12933
|
+
strokeLinecap: "round",
|
|
12934
|
+
strokeLinejoin: "round"
|
|
12906
12935
|
}
|
|
12907
|
-
)
|
|
12908
|
-
|
|
12909
|
-
|
|
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,
|
|
12936
|
+
) }),
|
|
12937
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12938
|
+
"path",
|
|
12976
12939
|
{
|
|
12977
|
-
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
12940
|
+
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
12941
|
+
stroke: "#A1A1AA",
|
|
12942
|
+
strokeWidth: "1.5",
|
|
12943
|
+
strokeLinecap: "round",
|
|
12944
|
+
strokeLinejoin: "round"
|
|
12983
12945
|
}
|
|
12984
|
-
)
|
|
12946
|
+
) }),
|
|
12947
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12948
|
+
"path",
|
|
12949
|
+
{
|
|
12950
|
+
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
12951
|
+
stroke: "#A1A1AA",
|
|
12952
|
+
strokeWidth: "1.5",
|
|
12953
|
+
strokeLinecap: "round",
|
|
12954
|
+
strokeLinejoin: "round"
|
|
12955
|
+
}
|
|
12956
|
+
) }),
|
|
12957
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12958
|
+
"path",
|
|
12959
|
+
{
|
|
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"
|
|
12965
|
+
}
|
|
12966
|
+
) }),
|
|
12967
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12968
|
+
"path",
|
|
12969
|
+
{
|
|
12970
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12971
|
+
stroke: "#A1A1AA",
|
|
12972
|
+
strokeWidth: "1.5",
|
|
12973
|
+
strokeLinecap: "round",
|
|
12974
|
+
strokeLinejoin: "round"
|
|
12975
|
+
}
|
|
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
|
+
] })
|
|
12985
13033
|
]
|
|
12986
|
-
}
|
|
12987
|
-
promotion.id
|
|
13034
|
+
}
|
|
12988
13035
|
);
|
|
12989
13036
|
};
|
|
12990
|
-
|
|
12991
|
-
|
|
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
|
|
13037
|
+
const schema = objectType({
|
|
13038
|
+
customer_id: stringType().min(1)
|
|
13010
13039
|
});
|
|
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: [
|
|
@@ -13077,6 +13077,10 @@ const routeModule = {
|
|
|
13077
13077
|
Component: Metadata,
|
|
13078
13078
|
path: "/draft-orders/:id/metadata"
|
|
13079
13079
|
},
|
|
13080
|
+
{
|
|
13081
|
+
Component: Promotions,
|
|
13082
|
+
path: "/draft-orders/:id/promotions"
|
|
13083
|
+
},
|
|
13080
13084
|
{
|
|
13081
13085
|
Component: SalesChannel,
|
|
13082
13086
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13092,10 +13096,6 @@ const routeModule = {
|
|
|
13092
13096
|
{
|
|
13093
13097
|
Component: TransferOwnership,
|
|
13094
13098
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
|
-
},
|
|
13096
|
-
{
|
|
13097
|
-
Component: Promotions,
|
|
13098
|
-
path: "/draft-orders/:id/promotions"
|
|
13099
13099
|
}
|
|
13100
13100
|
]
|
|
13101
13101
|
}
|