@medusajs/draft-order 2.11.3 → 2.11.4-snapshot-20251105174837
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 +778 -778
- package/.medusa/server/src/admin/index.mjs +778 -778
- package/package.json +16 -16
|
@@ -11164,77 +11164,105 @@ function getHasUneditableRows(metadata) {
|
|
|
11164
11164
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11165
11165
|
);
|
|
11166
11166
|
}
|
|
11167
|
-
const
|
|
11168
|
-
const
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
|
|
11167
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11168
|
+
const promotionsQueryKeys = {
|
|
11169
|
+
list: (query2) => [
|
|
11170
|
+
PROMOTION_QUERY_KEY,
|
|
11171
|
+
query2 ? query2 : void 0
|
|
11172
|
+
],
|
|
11173
|
+
detail: (id, query2) => [
|
|
11174
|
+
PROMOTION_QUERY_KEY,
|
|
11175
|
+
id,
|
|
11176
|
+
query2 ? query2 : void 0
|
|
11177
|
+
]
|
|
11178
|
+
};
|
|
11179
|
+
const usePromotions = (query2, options) => {
|
|
11180
|
+
const { data, ...rest } = useQuery({
|
|
11181
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11182
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11183
|
+
...options
|
|
11173
11184
|
});
|
|
11185
|
+
return { ...data, ...rest };
|
|
11186
|
+
};
|
|
11187
|
+
const Promotions = () => {
|
|
11188
|
+
const { id } = useParams();
|
|
11174
11189
|
const {
|
|
11175
11190
|
order: preview,
|
|
11176
|
-
isPending: isPreviewPending,
|
|
11177
11191
|
isError: isPreviewError,
|
|
11178
11192
|
error: previewError
|
|
11179
|
-
} = useOrderPreview(id);
|
|
11193
|
+
} = useOrderPreview(id, void 0);
|
|
11180
11194
|
useInitiateOrderEdit({ preview });
|
|
11181
11195
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11182
|
-
if (isError) {
|
|
11183
|
-
throw error;
|
|
11184
|
-
}
|
|
11185
11196
|
if (isPreviewError) {
|
|
11186
11197
|
throw previewError;
|
|
11187
11198
|
}
|
|
11188
|
-
const
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
/* @__PURE__ */ jsx(
|
|
11192
|
-
|
|
11193
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11194
|
-
/* @__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." }) })
|
|
11195
|
-
] }) }) }),
|
|
11196
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11197
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11198
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11199
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11200
|
-
] }) });
|
|
11199
|
+
const isReady = !!preview;
|
|
11200
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11201
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11202
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11203
|
+
] });
|
|
11201
11204
|
};
|
|
11202
|
-
const
|
|
11203
|
-
|
|
11204
|
-
const { setIsOpen } = useStackedModal();
|
|
11205
|
+
const PromotionForm = ({ preview }) => {
|
|
11206
|
+
const { items, shipping_methods } = preview;
|
|
11205
11207
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11206
|
-
const [
|
|
11207
|
-
const
|
|
11208
|
-
const {
|
|
11208
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
11209
|
+
const { handleSuccess } = useRouteModal();
|
|
11210
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11211
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11212
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11209
11213
|
{
|
|
11210
|
-
id:
|
|
11211
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11214
|
+
id: promoIds
|
|
11212
11215
|
},
|
|
11213
11216
|
{
|
|
11214
|
-
enabled:
|
|
11217
|
+
enabled: !!promoIds.length
|
|
11215
11218
|
}
|
|
11216
11219
|
);
|
|
11217
|
-
const
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11220
|
+
const comboboxData = useComboboxData({
|
|
11221
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11222
|
+
queryFn: async (params) => {
|
|
11223
|
+
return await sdk.admin.promotion.list({
|
|
11224
|
+
...params,
|
|
11225
|
+
id: {
|
|
11226
|
+
$nin: promoIds
|
|
11227
|
+
}
|
|
11228
|
+
});
|
|
11229
|
+
},
|
|
11230
|
+
getOptions: (data) => {
|
|
11231
|
+
return data.promotions.map((promotion) => ({
|
|
11232
|
+
label: promotion.code,
|
|
11233
|
+
value: promotion.code
|
|
11234
|
+
}));
|
|
11235
|
+
}
|
|
11236
|
+
});
|
|
11237
|
+
const add = async (value) => {
|
|
11238
|
+
if (!value) {
|
|
11239
|
+
return;
|
|
11240
|
+
}
|
|
11241
|
+
addPromotions(
|
|
11242
|
+
{
|
|
11243
|
+
promo_codes: [value]
|
|
11244
|
+
},
|
|
11245
|
+
{
|
|
11246
|
+
onError: (e) => {
|
|
11247
|
+
toast.error(e.message);
|
|
11248
|
+
comboboxData.onSearchValueChange("");
|
|
11249
|
+
setComboboxValue("");
|
|
11250
|
+
},
|
|
11251
|
+
onSuccess: () => {
|
|
11252
|
+
comboboxData.onSearchValueChange("");
|
|
11253
|
+
setComboboxValue("");
|
|
11254
|
+
}
|
|
11255
|
+
}
|
|
11256
|
+
);
|
|
11257
|
+
};
|
|
11228
11258
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11229
|
-
const { mutateAsync: requestOrderEdit } =
|
|
11230
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11231
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11259
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11232
11260
|
const onSubmit = async () => {
|
|
11233
11261
|
setIsSubmitting(true);
|
|
11234
11262
|
let requestSucceeded = false;
|
|
11235
11263
|
await requestOrderEdit(void 0, {
|
|
11236
11264
|
onError: (e) => {
|
|
11237
|
-
toast.error(
|
|
11265
|
+
toast.error(e.message);
|
|
11238
11266
|
},
|
|
11239
11267
|
onSuccess: () => {
|
|
11240
11268
|
requestSucceeded = true;
|
|
@@ -11246,7 +11274,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11246
11274
|
}
|
|
11247
11275
|
await confirmOrderEdit(void 0, {
|
|
11248
11276
|
onError: (e) => {
|
|
11249
|
-
toast.error(
|
|
11277
|
+
toast.error(e.message);
|
|
11250
11278
|
},
|
|
11251
11279
|
onSuccess: () => {
|
|
11252
11280
|
handleSuccess();
|
|
@@ -11256,53 +11284,408 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11256
11284
|
}
|
|
11257
11285
|
});
|
|
11258
11286
|
};
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
|
|
11287
|
+
if (isError) {
|
|
11288
|
+
throw error;
|
|
11289
|
+
}
|
|
11290
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11291
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11292
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11293
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11294
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11295
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11296
|
+
] }),
|
|
11297
|
+
/* @__PURE__ */ jsx(
|
|
11298
|
+
Combobox,
|
|
11299
|
+
{
|
|
11300
|
+
id: "promotion-combobox",
|
|
11301
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11302
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11303
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11304
|
+
options: comboboxData.options,
|
|
11305
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11306
|
+
searchValue: comboboxData.searchValue,
|
|
11307
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11308
|
+
onChange: add,
|
|
11309
|
+
value: comboboxValue
|
|
11310
|
+
}
|
|
11311
|
+
)
|
|
11312
|
+
] }),
|
|
11313
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11314
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11315
|
+
PromotionItem,
|
|
11316
|
+
{
|
|
11317
|
+
promotion,
|
|
11318
|
+
orderId: preview.id,
|
|
11319
|
+
isLoading: isPending
|
|
11320
|
+
},
|
|
11321
|
+
promotion.id
|
|
11322
|
+
)) })
|
|
11323
|
+
] }) }),
|
|
11324
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11325
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11326
|
+
/* @__PURE__ */ jsx(
|
|
11327
|
+
Button,
|
|
11328
|
+
{
|
|
11329
|
+
size: "small",
|
|
11330
|
+
type: "submit",
|
|
11331
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11332
|
+
children: "Save"
|
|
11333
|
+
}
|
|
11334
|
+
)
|
|
11335
|
+
] }) })
|
|
11336
|
+
] });
|
|
11337
|
+
};
|
|
11338
|
+
const PromotionItem = ({
|
|
11339
|
+
promotion,
|
|
11340
|
+
orderId,
|
|
11341
|
+
isLoading
|
|
11342
|
+
}) => {
|
|
11343
|
+
var _a;
|
|
11344
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11345
|
+
const onRemove = async () => {
|
|
11346
|
+
removePromotions(
|
|
11347
|
+
{
|
|
11348
|
+
promo_codes: [promotion.code]
|
|
11349
|
+
},
|
|
11350
|
+
{
|
|
11351
|
+
onError: (e) => {
|
|
11352
|
+
toast.error(e.message);
|
|
11264
11353
|
}
|
|
11265
|
-
onSubmit();
|
|
11266
11354
|
}
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
);
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
|
|
11274
|
-
|
|
11275
|
-
|
|
11276
|
-
|
|
11277
|
-
|
|
11278
|
-
|
|
11279
|
-
|
|
11355
|
+
);
|
|
11356
|
+
};
|
|
11357
|
+
const displayValue = getDisplayValue(promotion);
|
|
11358
|
+
return /* @__PURE__ */ jsxs(
|
|
11359
|
+
"div",
|
|
11360
|
+
{
|
|
11361
|
+
className: clx(
|
|
11362
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11363
|
+
{
|
|
11364
|
+
"animate-pulse": isLoading
|
|
11365
|
+
}
|
|
11366
|
+
),
|
|
11367
|
+
children: [
|
|
11280
11368
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
11281
|
-
/* @__PURE__ */ jsx(
|
|
11282
|
-
/* @__PURE__ */
|
|
11369
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11370
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11371
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11372
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11373
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11374
|
+
] }),
|
|
11375
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11376
|
+
] })
|
|
11283
11377
|
] }),
|
|
11284
|
-
/* @__PURE__ */ jsx(
|
|
11285
|
-
|
|
11286
|
-
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11294
|
-
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
|
|
11299
|
-
|
|
11300
|
-
|
|
11301
|
-
|
|
11302
|
-
|
|
11303
|
-
|
|
11304
|
-
|
|
11305
|
-
|
|
11378
|
+
/* @__PURE__ */ jsx(
|
|
11379
|
+
IconButton,
|
|
11380
|
+
{
|
|
11381
|
+
size: "small",
|
|
11382
|
+
type: "button",
|
|
11383
|
+
variant: "transparent",
|
|
11384
|
+
onClick: onRemove,
|
|
11385
|
+
isLoading: isPending || isLoading,
|
|
11386
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11387
|
+
}
|
|
11388
|
+
)
|
|
11389
|
+
]
|
|
11390
|
+
},
|
|
11391
|
+
promotion.id
|
|
11392
|
+
);
|
|
11393
|
+
};
|
|
11394
|
+
function getDisplayValue(promotion) {
|
|
11395
|
+
var _a, _b, _c, _d;
|
|
11396
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11397
|
+
if (!value) {
|
|
11398
|
+
return null;
|
|
11399
|
+
}
|
|
11400
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11401
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11402
|
+
if (!currency) {
|
|
11403
|
+
return null;
|
|
11404
|
+
}
|
|
11405
|
+
return getLocaleAmount(value, currency);
|
|
11406
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11407
|
+
return formatPercentage(value);
|
|
11408
|
+
}
|
|
11409
|
+
return null;
|
|
11410
|
+
}
|
|
11411
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11412
|
+
style: "percent",
|
|
11413
|
+
minimumFractionDigits: 2
|
|
11414
|
+
});
|
|
11415
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11416
|
+
let val = value || 0;
|
|
11417
|
+
if (!isPercentageValue) {
|
|
11418
|
+
val = val / 100;
|
|
11419
|
+
}
|
|
11420
|
+
return formatter.format(val);
|
|
11421
|
+
};
|
|
11422
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11423
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11424
|
+
for (const item of items) {
|
|
11425
|
+
if (item.adjustments) {
|
|
11426
|
+
for (const adjustment of item.adjustments) {
|
|
11427
|
+
if (adjustment.promotion_id) {
|
|
11428
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11429
|
+
}
|
|
11430
|
+
}
|
|
11431
|
+
}
|
|
11432
|
+
}
|
|
11433
|
+
for (const shippingMethod of shippingMethods) {
|
|
11434
|
+
if (shippingMethod.adjustments) {
|
|
11435
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11436
|
+
if (adjustment.promotion_id) {
|
|
11437
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11438
|
+
}
|
|
11439
|
+
}
|
|
11440
|
+
}
|
|
11441
|
+
}
|
|
11442
|
+
return Array.from(promotionIds);
|
|
11443
|
+
}
|
|
11444
|
+
const SalesChannel = () => {
|
|
11445
|
+
const { id } = useParams();
|
|
11446
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11447
|
+
id,
|
|
11448
|
+
{
|
|
11449
|
+
fields: "+sales_channel_id"
|
|
11450
|
+
},
|
|
11451
|
+
{
|
|
11452
|
+
enabled: !!id
|
|
11453
|
+
}
|
|
11454
|
+
);
|
|
11455
|
+
if (isError) {
|
|
11456
|
+
throw error;
|
|
11457
|
+
}
|
|
11458
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11459
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11460
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11461
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11462
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11463
|
+
] }),
|
|
11464
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11465
|
+
] });
|
|
11466
|
+
};
|
|
11467
|
+
const SalesChannelForm = ({ order }) => {
|
|
11468
|
+
const form = useForm({
|
|
11469
|
+
defaultValues: {
|
|
11470
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11471
|
+
},
|
|
11472
|
+
resolver: zodResolver(schema$2)
|
|
11473
|
+
});
|
|
11474
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11475
|
+
const { handleSuccess } = useRouteModal();
|
|
11476
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11477
|
+
await mutateAsync(
|
|
11478
|
+
{
|
|
11479
|
+
sales_channel_id: data.sales_channel_id
|
|
11480
|
+
},
|
|
11481
|
+
{
|
|
11482
|
+
onSuccess: () => {
|
|
11483
|
+
toast.success("Sales channel updated");
|
|
11484
|
+
handleSuccess();
|
|
11485
|
+
},
|
|
11486
|
+
onError: (error) => {
|
|
11487
|
+
toast.error(error.message);
|
|
11488
|
+
}
|
|
11489
|
+
}
|
|
11490
|
+
);
|
|
11491
|
+
});
|
|
11492
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11493
|
+
KeyboundForm,
|
|
11494
|
+
{
|
|
11495
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11496
|
+
onSubmit,
|
|
11497
|
+
children: [
|
|
11498
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11499
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11500
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11501
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11502
|
+
] }) })
|
|
11503
|
+
]
|
|
11504
|
+
}
|
|
11505
|
+
) });
|
|
11506
|
+
};
|
|
11507
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11508
|
+
const salesChannels = useComboboxData({
|
|
11509
|
+
queryFn: async (params) => {
|
|
11510
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11511
|
+
},
|
|
11512
|
+
queryKey: ["sales-channels"],
|
|
11513
|
+
getOptions: (data) => {
|
|
11514
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11515
|
+
label: salesChannel.name,
|
|
11516
|
+
value: salesChannel.id
|
|
11517
|
+
}));
|
|
11518
|
+
},
|
|
11519
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11520
|
+
});
|
|
11521
|
+
return /* @__PURE__ */ jsx(
|
|
11522
|
+
Form$2.Field,
|
|
11523
|
+
{
|
|
11524
|
+
control,
|
|
11525
|
+
name: "sales_channel_id",
|
|
11526
|
+
render: ({ field }) => {
|
|
11527
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11528
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11529
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11530
|
+
Combobox,
|
|
11531
|
+
{
|
|
11532
|
+
options: salesChannels.options,
|
|
11533
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11534
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11535
|
+
searchValue: salesChannels.searchValue,
|
|
11536
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11537
|
+
placeholder: "Select sales channel",
|
|
11538
|
+
...field
|
|
11539
|
+
}
|
|
11540
|
+
) }),
|
|
11541
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11542
|
+
] });
|
|
11543
|
+
}
|
|
11544
|
+
}
|
|
11545
|
+
);
|
|
11546
|
+
};
|
|
11547
|
+
const schema$2 = objectType({
|
|
11548
|
+
sales_channel_id: stringType().min(1)
|
|
11549
|
+
});
|
|
11550
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11551
|
+
const Shipping = () => {
|
|
11552
|
+
var _a;
|
|
11553
|
+
const { id } = useParams();
|
|
11554
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11555
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11556
|
+
});
|
|
11557
|
+
const {
|
|
11558
|
+
order: preview,
|
|
11559
|
+
isPending: isPreviewPending,
|
|
11560
|
+
isError: isPreviewError,
|
|
11561
|
+
error: previewError
|
|
11562
|
+
} = useOrderPreview(id);
|
|
11563
|
+
useInitiateOrderEdit({ preview });
|
|
11564
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11565
|
+
if (isError) {
|
|
11566
|
+
throw error;
|
|
11567
|
+
}
|
|
11568
|
+
if (isPreviewError) {
|
|
11569
|
+
throw previewError;
|
|
11570
|
+
}
|
|
11571
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11572
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11573
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11574
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11575
|
+
/* @__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: [
|
|
11576
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11577
|
+
/* @__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." }) })
|
|
11578
|
+
] }) }) }),
|
|
11579
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11580
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11581
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11582
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11583
|
+
] }) });
|
|
11584
|
+
};
|
|
11585
|
+
const ShippingForm = ({ preview, order }) => {
|
|
11586
|
+
var _a;
|
|
11587
|
+
const { setIsOpen } = useStackedModal();
|
|
11588
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11589
|
+
const [data, setData] = useState(null);
|
|
11590
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11591
|
+
const { shipping_options } = useShippingOptions(
|
|
11592
|
+
{
|
|
11593
|
+
id: appliedShippingOptionIds,
|
|
11594
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11595
|
+
},
|
|
11596
|
+
{
|
|
11597
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11598
|
+
}
|
|
11599
|
+
);
|
|
11600
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
11601
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
11602
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11603
|
+
profiles.set(profile.id, profile);
|
|
11604
|
+
});
|
|
11605
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11606
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11607
|
+
});
|
|
11608
|
+
return Array.from(profiles.values());
|
|
11609
|
+
}, [order.items, shipping_options]);
|
|
11610
|
+
const { handleSuccess } = useRouteModal();
|
|
11611
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11612
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11613
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11614
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11615
|
+
const onSubmit = async () => {
|
|
11616
|
+
setIsSubmitting(true);
|
|
11617
|
+
let requestSucceeded = false;
|
|
11618
|
+
await requestOrderEdit(void 0, {
|
|
11619
|
+
onError: (e) => {
|
|
11620
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11621
|
+
},
|
|
11622
|
+
onSuccess: () => {
|
|
11623
|
+
requestSucceeded = true;
|
|
11624
|
+
}
|
|
11625
|
+
});
|
|
11626
|
+
if (!requestSucceeded) {
|
|
11627
|
+
setIsSubmitting(false);
|
|
11628
|
+
return;
|
|
11629
|
+
}
|
|
11630
|
+
await confirmOrderEdit(void 0, {
|
|
11631
|
+
onError: (e) => {
|
|
11632
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11633
|
+
},
|
|
11634
|
+
onSuccess: () => {
|
|
11635
|
+
handleSuccess();
|
|
11636
|
+
},
|
|
11637
|
+
onSettled: () => {
|
|
11638
|
+
setIsSubmitting(false);
|
|
11639
|
+
}
|
|
11640
|
+
});
|
|
11641
|
+
};
|
|
11642
|
+
const onKeydown = useCallback(
|
|
11643
|
+
(e) => {
|
|
11644
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
11645
|
+
if (data || isSubmitting) {
|
|
11646
|
+
return;
|
|
11647
|
+
}
|
|
11648
|
+
onSubmit();
|
|
11649
|
+
}
|
|
11650
|
+
},
|
|
11651
|
+
[data, isSubmitting, onSubmit]
|
|
11652
|
+
);
|
|
11653
|
+
useEffect(() => {
|
|
11654
|
+
document.addEventListener("keydown", onKeydown);
|
|
11655
|
+
return () => {
|
|
11656
|
+
document.removeEventListener("keydown", onKeydown);
|
|
11657
|
+
};
|
|
11658
|
+
}, [onKeydown]);
|
|
11659
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
11660
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11661
|
+
/* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11662
|
+
/* @__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: [
|
|
11663
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11664
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11665
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
|
|
11666
|
+
] }),
|
|
11667
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11668
|
+
/* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
11669
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
|
|
11670
|
+
/* @__PURE__ */ jsx(
|
|
11671
|
+
Text,
|
|
11672
|
+
{
|
|
11673
|
+
size: "xsmall",
|
|
11674
|
+
weight: "plus",
|
|
11675
|
+
className: "text-ui-fg-muted",
|
|
11676
|
+
children: "Shipping profile"
|
|
11677
|
+
}
|
|
11678
|
+
),
|
|
11679
|
+
/* @__PURE__ */ jsx(
|
|
11680
|
+
Text,
|
|
11681
|
+
{
|
|
11682
|
+
size: "xsmall",
|
|
11683
|
+
weight: "plus",
|
|
11684
|
+
className: "text-ui-fg-muted",
|
|
11685
|
+
children: "Action"
|
|
11686
|
+
}
|
|
11687
|
+
)
|
|
11688
|
+
] }),
|
|
11306
11689
|
/* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
|
|
11307
11690
|
var _a2, _b, _c, _d, _e, _f, _g;
|
|
11308
11691
|
const items = getItemsWithShippingProfile(
|
|
@@ -11994,7 +12377,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
11994
12377
|
defaultValues: {
|
|
11995
12378
|
customer_id: order.customer_id || ""
|
|
11996
12379
|
},
|
|
11997
|
-
resolver: zodResolver(schema$
|
|
12380
|
+
resolver: zodResolver(schema$1)
|
|
11998
12381
|
});
|
|
11999
12382
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12000
12383
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12113,722 +12496,339 @@ const Illustration = () => {
|
|
|
12113
12496
|
x: "0.00428286",
|
|
12114
12497
|
y: "-0.742904",
|
|
12115
12498
|
width: "33.5",
|
|
12116
|
-
height: "65.5",
|
|
12117
|
-
rx: "6.75",
|
|
12118
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
|
|
12119
|
-
fill: "#D4D4D8",
|
|
12120
|
-
stroke: "#52525B",
|
|
12121
|
-
strokeWidth: "1.5"
|
|
12122
|
-
}
|
|
12123
|
-
),
|
|
12124
|
-
/* @__PURE__ */ jsx(
|
|
12125
|
-
"rect",
|
|
12126
|
-
{
|
|
12127
|
-
x: "0.00428286",
|
|
12128
|
-
y: "-0.742904",
|
|
12129
|
-
width: "33.5",
|
|
12130
|
-
height: "65.5",
|
|
12131
|
-
rx: "6.75",
|
|
12132
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
|
|
12133
|
-
fill: "white",
|
|
12134
|
-
stroke: "#52525B",
|
|
12135
|
-
strokeWidth: "1.5"
|
|
12136
|
-
}
|
|
12137
|
-
),
|
|
12138
|
-
/* @__PURE__ */ jsx(
|
|
12139
|
-
"path",
|
|
12140
|
-
{
|
|
12141
|
-
d: "M180.579 107.142L179.126 107.959",
|
|
12142
|
-
stroke: "#52525B",
|
|
12143
|
-
strokeWidth: "1.5",
|
|
12144
|
-
strokeLinecap: "round",
|
|
12145
|
-
strokeLinejoin: "round"
|
|
12146
|
-
}
|
|
12147
|
-
),
|
|
12148
|
-
/* @__PURE__ */ jsx(
|
|
12149
|
-
"path",
|
|
12150
|
-
{
|
|
12151
|
-
opacity: "0.88",
|
|
12152
|
-
d: "M182.305 109.546L180.257 109.534",
|
|
12153
|
-
stroke: "#52525B",
|
|
12154
|
-
strokeWidth: "1.5",
|
|
12155
|
-
strokeLinecap: "round",
|
|
12156
|
-
strokeLinejoin: "round"
|
|
12157
|
-
}
|
|
12158
|
-
),
|
|
12159
|
-
/* @__PURE__ */ jsx(
|
|
12160
|
-
"path",
|
|
12161
|
-
{
|
|
12162
|
-
opacity: "0.75",
|
|
12163
|
-
d: "M180.551 111.93L179.108 111.096",
|
|
12164
|
-
stroke: "#52525B",
|
|
12165
|
-
strokeWidth: "1.5",
|
|
12166
|
-
strokeLinecap: "round",
|
|
12167
|
-
strokeLinejoin: "round"
|
|
12168
|
-
}
|
|
12169
|
-
),
|
|
12170
|
-
/* @__PURE__ */ jsx(
|
|
12171
|
-
"path",
|
|
12172
|
-
{
|
|
12173
|
-
opacity: "0.63",
|
|
12174
|
-
d: "M176.347 112.897L176.354 111.73",
|
|
12175
|
-
stroke: "#52525B",
|
|
12176
|
-
strokeWidth: "1.5",
|
|
12177
|
-
strokeLinecap: "round",
|
|
12178
|
-
strokeLinejoin: "round"
|
|
12179
|
-
}
|
|
12180
|
-
),
|
|
12181
|
-
/* @__PURE__ */ jsx(
|
|
12182
|
-
"path",
|
|
12183
|
-
{
|
|
12184
|
-
opacity: "0.5",
|
|
12185
|
-
d: "M172.153 111.881L173.606 111.064",
|
|
12186
|
-
stroke: "#52525B",
|
|
12187
|
-
strokeWidth: "1.5",
|
|
12188
|
-
strokeLinecap: "round",
|
|
12189
|
-
strokeLinejoin: "round"
|
|
12190
|
-
}
|
|
12191
|
-
),
|
|
12192
|
-
/* @__PURE__ */ jsx(
|
|
12193
|
-
"path",
|
|
12194
|
-
{
|
|
12195
|
-
opacity: "0.38",
|
|
12196
|
-
d: "M170.428 109.478L172.476 109.489",
|
|
12197
|
-
stroke: "#52525B",
|
|
12198
|
-
strokeWidth: "1.5",
|
|
12199
|
-
strokeLinecap: "round",
|
|
12200
|
-
strokeLinejoin: "round"
|
|
12201
|
-
}
|
|
12202
|
-
),
|
|
12203
|
-
/* @__PURE__ */ jsx(
|
|
12204
|
-
"path",
|
|
12205
|
-
{
|
|
12206
|
-
opacity: "0.25",
|
|
12207
|
-
d: "M172.181 107.094L173.624 107.928",
|
|
12208
|
-
stroke: "#52525B",
|
|
12209
|
-
strokeWidth: "1.5",
|
|
12210
|
-
strokeLinecap: "round",
|
|
12211
|
-
strokeLinejoin: "round"
|
|
12212
|
-
}
|
|
12213
|
-
),
|
|
12214
|
-
/* @__PURE__ */ jsx(
|
|
12215
|
-
"path",
|
|
12216
|
-
{
|
|
12217
|
-
opacity: "0.13",
|
|
12218
|
-
d: "M176.386 106.126L176.379 107.294",
|
|
12219
|
-
stroke: "#52525B",
|
|
12220
|
-
strokeWidth: "1.5",
|
|
12221
|
-
strokeLinecap: "round",
|
|
12222
|
-
strokeLinejoin: "round"
|
|
12223
|
-
}
|
|
12224
|
-
),
|
|
12225
|
-
/* @__PURE__ */ jsx(
|
|
12226
|
-
"rect",
|
|
12227
|
-
{
|
|
12228
|
-
width: "12",
|
|
12229
|
-
height: "3",
|
|
12230
|
-
rx: "1.5",
|
|
12231
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
|
|
12232
|
-
fill: "#D4D4D8"
|
|
12233
|
-
}
|
|
12234
|
-
),
|
|
12235
|
-
/* @__PURE__ */ jsx(
|
|
12236
|
-
"rect",
|
|
12237
|
-
{
|
|
12238
|
-
x: "0.00428286",
|
|
12239
|
-
y: "-0.742904",
|
|
12240
|
-
width: "33.5",
|
|
12241
|
-
height: "65.5",
|
|
12242
|
-
rx: "6.75",
|
|
12243
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
|
|
12244
|
-
fill: "#D4D4D8",
|
|
12245
|
-
stroke: "#52525B",
|
|
12246
|
-
strokeWidth: "1.5"
|
|
12247
|
-
}
|
|
12248
|
-
),
|
|
12249
|
-
/* @__PURE__ */ jsx(
|
|
12250
|
-
"rect",
|
|
12251
|
-
{
|
|
12252
|
-
x: "0.00428286",
|
|
12253
|
-
y: "-0.742904",
|
|
12254
|
-
width: "33.5",
|
|
12255
|
-
height: "65.5",
|
|
12256
|
-
rx: "6.75",
|
|
12257
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
|
|
12258
|
-
fill: "white",
|
|
12259
|
-
stroke: "#52525B",
|
|
12260
|
-
strokeWidth: "1.5"
|
|
12261
|
-
}
|
|
12262
|
-
),
|
|
12263
|
-
/* @__PURE__ */ jsx(
|
|
12264
|
-
"rect",
|
|
12265
|
-
{
|
|
12266
|
-
width: "12",
|
|
12267
|
-
height: "3",
|
|
12268
|
-
rx: "1.5",
|
|
12269
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
|
|
12270
|
-
fill: "#D4D4D8"
|
|
12271
|
-
}
|
|
12272
|
-
),
|
|
12273
|
-
/* @__PURE__ */ jsx(
|
|
12274
|
-
"rect",
|
|
12275
|
-
{
|
|
12276
|
-
width: "17",
|
|
12277
|
-
height: "3",
|
|
12278
|
-
rx: "1.5",
|
|
12279
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
|
|
12280
|
-
fill: "#D4D4D8"
|
|
12281
|
-
}
|
|
12282
|
-
),
|
|
12283
|
-
/* @__PURE__ */ jsx(
|
|
12284
|
-
"rect",
|
|
12285
|
-
{
|
|
12286
|
-
width: "12",
|
|
12287
|
-
height: "3",
|
|
12288
|
-
rx: "1.5",
|
|
12289
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
|
|
12290
|
-
fill: "#D4D4D8"
|
|
12291
|
-
}
|
|
12292
|
-
),
|
|
12293
|
-
/* @__PURE__ */ jsx(
|
|
12294
|
-
"path",
|
|
12295
|
-
{
|
|
12296
|
-
d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
|
|
12297
|
-
fill: "#A1A1AA"
|
|
12298
|
-
}
|
|
12299
|
-
),
|
|
12300
|
-
/* @__PURE__ */ jsx(
|
|
12301
|
-
"rect",
|
|
12302
|
-
{
|
|
12303
|
-
width: "17",
|
|
12304
|
-
height: "3",
|
|
12305
|
-
rx: "1.5",
|
|
12306
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
|
|
12307
|
-
fill: "#A1A1AA"
|
|
12308
|
-
}
|
|
12309
|
-
),
|
|
12310
|
-
/* @__PURE__ */ jsx(
|
|
12311
|
-
"rect",
|
|
12312
|
-
{
|
|
12313
|
-
width: "12",
|
|
12314
|
-
height: "3",
|
|
12315
|
-
rx: "1.5",
|
|
12316
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
12317
|
-
fill: "#A1A1AA"
|
|
12318
|
-
}
|
|
12319
|
-
),
|
|
12320
|
-
/* @__PURE__ */ jsx(
|
|
12321
|
-
"path",
|
|
12322
|
-
{
|
|
12323
|
-
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
12324
|
-
fill: "#52525B"
|
|
12325
|
-
}
|
|
12326
|
-
),
|
|
12327
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12328
|
-
"path",
|
|
12329
|
-
{
|
|
12330
|
-
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
12331
|
-
stroke: "#A1A1AA",
|
|
12332
|
-
strokeWidth: "1.5",
|
|
12333
|
-
strokeLinecap: "round",
|
|
12334
|
-
strokeLinejoin: "round"
|
|
12499
|
+
height: "65.5",
|
|
12500
|
+
rx: "6.75",
|
|
12501
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
|
|
12502
|
+
fill: "#D4D4D8",
|
|
12503
|
+
stroke: "#52525B",
|
|
12504
|
+
strokeWidth: "1.5"
|
|
12335
12505
|
}
|
|
12336
|
-
)
|
|
12337
|
-
/* @__PURE__ */ jsx(
|
|
12338
|
-
"
|
|
12506
|
+
),
|
|
12507
|
+
/* @__PURE__ */ jsx(
|
|
12508
|
+
"rect",
|
|
12339
12509
|
{
|
|
12340
|
-
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12344
|
-
|
|
12510
|
+
x: "0.00428286",
|
|
12511
|
+
y: "-0.742904",
|
|
12512
|
+
width: "33.5",
|
|
12513
|
+
height: "65.5",
|
|
12514
|
+
rx: "6.75",
|
|
12515
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
|
|
12516
|
+
fill: "white",
|
|
12517
|
+
stroke: "#52525B",
|
|
12518
|
+
strokeWidth: "1.5"
|
|
12345
12519
|
}
|
|
12346
|
-
)
|
|
12347
|
-
/* @__PURE__ */ jsx(
|
|
12520
|
+
),
|
|
12521
|
+
/* @__PURE__ */ jsx(
|
|
12348
12522
|
"path",
|
|
12349
12523
|
{
|
|
12350
|
-
d: "
|
|
12351
|
-
stroke: "#
|
|
12524
|
+
d: "M180.579 107.142L179.126 107.959",
|
|
12525
|
+
stroke: "#52525B",
|
|
12352
12526
|
strokeWidth: "1.5",
|
|
12353
12527
|
strokeLinecap: "round",
|
|
12354
12528
|
strokeLinejoin: "round"
|
|
12355
12529
|
}
|
|
12356
|
-
)
|
|
12357
|
-
/* @__PURE__ */ jsx(
|
|
12530
|
+
),
|
|
12531
|
+
/* @__PURE__ */ jsx(
|
|
12358
12532
|
"path",
|
|
12359
12533
|
{
|
|
12360
|
-
|
|
12361
|
-
|
|
12534
|
+
opacity: "0.88",
|
|
12535
|
+
d: "M182.305 109.546L180.257 109.534",
|
|
12536
|
+
stroke: "#52525B",
|
|
12362
12537
|
strokeWidth: "1.5",
|
|
12363
12538
|
strokeLinecap: "round",
|
|
12364
12539
|
strokeLinejoin: "round"
|
|
12365
12540
|
}
|
|
12366
|
-
)
|
|
12367
|
-
/* @__PURE__ */ jsx(
|
|
12541
|
+
),
|
|
12542
|
+
/* @__PURE__ */ jsx(
|
|
12368
12543
|
"path",
|
|
12369
12544
|
{
|
|
12370
|
-
|
|
12371
|
-
|
|
12545
|
+
opacity: "0.75",
|
|
12546
|
+
d: "M180.551 111.93L179.108 111.096",
|
|
12547
|
+
stroke: "#52525B",
|
|
12372
12548
|
strokeWidth: "1.5",
|
|
12373
12549
|
strokeLinecap: "round",
|
|
12374
12550
|
strokeLinejoin: "round"
|
|
12375
12551
|
}
|
|
12376
|
-
)
|
|
12377
|
-
/* @__PURE__ */ jsx(
|
|
12552
|
+
),
|
|
12553
|
+
/* @__PURE__ */ jsx(
|
|
12378
12554
|
"path",
|
|
12379
12555
|
{
|
|
12380
|
-
|
|
12381
|
-
|
|
12556
|
+
opacity: "0.63",
|
|
12557
|
+
d: "M176.347 112.897L176.354 111.73",
|
|
12558
|
+
stroke: "#52525B",
|
|
12382
12559
|
strokeWidth: "1.5",
|
|
12383
12560
|
strokeLinecap: "round",
|
|
12384
12561
|
strokeLinejoin: "round"
|
|
12385
|
-
}
|
|
12386
|
-
)
|
|
12387
|
-
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12388
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12389
|
-
"rect",
|
|
12390
|
-
{
|
|
12391
|
-
width: "12",
|
|
12392
|
-
height: "12",
|
|
12393
|
-
fill: "white",
|
|
12394
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12395
|
-
}
|
|
12396
|
-
) }),
|
|
12397
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12398
|
-
"rect",
|
|
12399
|
-
{
|
|
12400
|
-
width: "12",
|
|
12401
|
-
height: "12",
|
|
12402
|
-
fill: "white",
|
|
12403
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12404
|
-
}
|
|
12405
|
-
) }),
|
|
12406
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12407
|
-
"rect",
|
|
12408
|
-
{
|
|
12409
|
-
width: "12",
|
|
12410
|
-
height: "12",
|
|
12411
|
-
fill: "white",
|
|
12412
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12413
|
-
}
|
|
12414
|
-
) }),
|
|
12415
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12416
|
-
"rect",
|
|
12417
|
-
{
|
|
12418
|
-
width: "12",
|
|
12419
|
-
height: "12",
|
|
12420
|
-
fill: "white",
|
|
12421
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
12422
|
-
}
|
|
12423
|
-
) }),
|
|
12424
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12425
|
-
"rect",
|
|
12426
|
-
{
|
|
12427
|
-
width: "12",
|
|
12428
|
-
height: "12",
|
|
12429
|
-
fill: "white",
|
|
12430
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
12431
|
-
}
|
|
12432
|
-
) }),
|
|
12433
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12434
|
-
"rect",
|
|
12435
|
-
{
|
|
12436
|
-
width: "12",
|
|
12437
|
-
height: "12",
|
|
12438
|
-
fill: "white",
|
|
12439
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12440
|
-
}
|
|
12441
|
-
) })
|
|
12442
|
-
] })
|
|
12443
|
-
]
|
|
12444
|
-
}
|
|
12445
|
-
);
|
|
12446
|
-
};
|
|
12447
|
-
const schema$2 = objectType({
|
|
12448
|
-
customer_id: stringType().min(1)
|
|
12449
|
-
});
|
|
12450
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
12451
|
-
const promotionsQueryKeys = {
|
|
12452
|
-
list: (query2) => [
|
|
12453
|
-
PROMOTION_QUERY_KEY,
|
|
12454
|
-
query2 ? query2 : void 0
|
|
12455
|
-
],
|
|
12456
|
-
detail: (id, query2) => [
|
|
12457
|
-
PROMOTION_QUERY_KEY,
|
|
12458
|
-
id,
|
|
12459
|
-
query2 ? query2 : void 0
|
|
12460
|
-
]
|
|
12461
|
-
};
|
|
12462
|
-
const usePromotions = (query2, options) => {
|
|
12463
|
-
const { data, ...rest } = useQuery({
|
|
12464
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
12465
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
12466
|
-
...options
|
|
12467
|
-
});
|
|
12468
|
-
return { ...data, ...rest };
|
|
12469
|
-
};
|
|
12470
|
-
const Promotions = () => {
|
|
12471
|
-
const { id } = useParams();
|
|
12472
|
-
const {
|
|
12473
|
-
order: preview,
|
|
12474
|
-
isError: isPreviewError,
|
|
12475
|
-
error: previewError
|
|
12476
|
-
} = useOrderPreview(id, void 0);
|
|
12477
|
-
useInitiateOrderEdit({ preview });
|
|
12478
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12479
|
-
if (isPreviewError) {
|
|
12480
|
-
throw previewError;
|
|
12481
|
-
}
|
|
12482
|
-
const isReady = !!preview;
|
|
12483
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
12484
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
12485
|
-
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
12486
|
-
] });
|
|
12487
|
-
};
|
|
12488
|
-
const PromotionForm = ({ preview }) => {
|
|
12489
|
-
const { items, shipping_methods } = preview;
|
|
12490
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
12491
|
-
const [comboboxValue, setComboboxValue] = useState("");
|
|
12492
|
-
const { handleSuccess } = useRouteModal();
|
|
12493
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
12494
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
12495
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
12496
|
-
{
|
|
12497
|
-
id: promoIds
|
|
12498
|
-
},
|
|
12499
|
-
{
|
|
12500
|
-
enabled: !!promoIds.length
|
|
12501
|
-
}
|
|
12502
|
-
);
|
|
12503
|
-
const comboboxData = useComboboxData({
|
|
12504
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
12505
|
-
queryFn: async (params) => {
|
|
12506
|
-
return await sdk.admin.promotion.list({
|
|
12507
|
-
...params,
|
|
12508
|
-
id: {
|
|
12509
|
-
$nin: promoIds
|
|
12510
|
-
}
|
|
12511
|
-
});
|
|
12512
|
-
},
|
|
12513
|
-
getOptions: (data) => {
|
|
12514
|
-
return data.promotions.map((promotion) => ({
|
|
12515
|
-
label: promotion.code,
|
|
12516
|
-
value: promotion.code
|
|
12517
|
-
}));
|
|
12518
|
-
}
|
|
12519
|
-
});
|
|
12520
|
-
const add = async (value) => {
|
|
12521
|
-
if (!value) {
|
|
12522
|
-
return;
|
|
12523
|
-
}
|
|
12524
|
-
addPromotions(
|
|
12525
|
-
{
|
|
12526
|
-
promo_codes: [value]
|
|
12527
|
-
},
|
|
12528
|
-
{
|
|
12529
|
-
onError: (e) => {
|
|
12530
|
-
toast.error(e.message);
|
|
12531
|
-
comboboxData.onSearchValueChange("");
|
|
12532
|
-
setComboboxValue("");
|
|
12533
|
-
},
|
|
12534
|
-
onSuccess: () => {
|
|
12535
|
-
comboboxData.onSearchValueChange("");
|
|
12536
|
-
setComboboxValue("");
|
|
12537
|
-
}
|
|
12538
|
-
}
|
|
12539
|
-
);
|
|
12540
|
-
};
|
|
12541
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12542
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
12543
|
-
const onSubmit = async () => {
|
|
12544
|
-
setIsSubmitting(true);
|
|
12545
|
-
let requestSucceeded = false;
|
|
12546
|
-
await requestOrderEdit(void 0, {
|
|
12547
|
-
onError: (e) => {
|
|
12548
|
-
toast.error(e.message);
|
|
12549
|
-
},
|
|
12550
|
-
onSuccess: () => {
|
|
12551
|
-
requestSucceeded = true;
|
|
12552
|
-
}
|
|
12553
|
-
});
|
|
12554
|
-
if (!requestSucceeded) {
|
|
12555
|
-
setIsSubmitting(false);
|
|
12556
|
-
return;
|
|
12557
|
-
}
|
|
12558
|
-
await confirmOrderEdit(void 0, {
|
|
12559
|
-
onError: (e) => {
|
|
12560
|
-
toast.error(e.message);
|
|
12561
|
-
},
|
|
12562
|
-
onSuccess: () => {
|
|
12563
|
-
handleSuccess();
|
|
12564
|
-
},
|
|
12565
|
-
onSettled: () => {
|
|
12566
|
-
setIsSubmitting(false);
|
|
12567
|
-
}
|
|
12568
|
-
});
|
|
12569
|
-
};
|
|
12570
|
-
if (isError) {
|
|
12571
|
-
throw error;
|
|
12572
|
-
}
|
|
12573
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
12574
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
12575
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
12576
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12577
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
12578
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
12579
|
-
] }),
|
|
12562
|
+
}
|
|
12563
|
+
),
|
|
12580
12564
|
/* @__PURE__ */ jsx(
|
|
12581
|
-
|
|
12565
|
+
"path",
|
|
12582
12566
|
{
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
searchValue: comboboxData.searchValue,
|
|
12590
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
12591
|
-
onChange: add,
|
|
12592
|
-
value: comboboxValue
|
|
12567
|
+
opacity: "0.5",
|
|
12568
|
+
d: "M172.153 111.881L173.606 111.064",
|
|
12569
|
+
stroke: "#52525B",
|
|
12570
|
+
strokeWidth: "1.5",
|
|
12571
|
+
strokeLinecap: "round",
|
|
12572
|
+
strokeLinejoin: "round"
|
|
12593
12573
|
}
|
|
12594
|
-
)
|
|
12595
|
-
] }),
|
|
12596
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12597
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
12598
|
-
PromotionItem,
|
|
12599
|
-
{
|
|
12600
|
-
promotion,
|
|
12601
|
-
orderId: preview.id,
|
|
12602
|
-
isLoading: isPending
|
|
12603
|
-
},
|
|
12604
|
-
promotion.id
|
|
12605
|
-
)) })
|
|
12606
|
-
] }) }),
|
|
12607
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12608
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12609
|
-
/* @__PURE__ */ jsx(
|
|
12610
|
-
Button,
|
|
12611
|
-
{
|
|
12612
|
-
size: "small",
|
|
12613
|
-
type: "submit",
|
|
12614
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
12615
|
-
children: "Save"
|
|
12616
|
-
}
|
|
12617
|
-
)
|
|
12618
|
-
] }) })
|
|
12619
|
-
] });
|
|
12620
|
-
};
|
|
12621
|
-
const PromotionItem = ({
|
|
12622
|
-
promotion,
|
|
12623
|
-
orderId,
|
|
12624
|
-
isLoading
|
|
12625
|
-
}) => {
|
|
12626
|
-
var _a;
|
|
12627
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
12628
|
-
const onRemove = async () => {
|
|
12629
|
-
removePromotions(
|
|
12630
|
-
{
|
|
12631
|
-
promo_codes: [promotion.code]
|
|
12632
|
-
},
|
|
12633
|
-
{
|
|
12634
|
-
onError: (e) => {
|
|
12635
|
-
toast.error(e.message);
|
|
12636
|
-
}
|
|
12637
|
-
}
|
|
12638
|
-
);
|
|
12639
|
-
};
|
|
12640
|
-
const displayValue = getDisplayValue(promotion);
|
|
12641
|
-
return /* @__PURE__ */ jsxs(
|
|
12642
|
-
"div",
|
|
12643
|
-
{
|
|
12644
|
-
className: clx(
|
|
12645
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
12646
|
-
{
|
|
12647
|
-
"animate-pulse": isLoading
|
|
12648
|
-
}
|
|
12649
|
-
),
|
|
12650
|
-
children: [
|
|
12651
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
12652
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
12653
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
12654
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
12655
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
12656
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
12657
|
-
] }),
|
|
12658
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
12659
|
-
] })
|
|
12660
|
-
] }),
|
|
12574
|
+
),
|
|
12661
12575
|
/* @__PURE__ */ jsx(
|
|
12662
|
-
|
|
12576
|
+
"path",
|
|
12577
|
+
{
|
|
12578
|
+
opacity: "0.38",
|
|
12579
|
+
d: "M170.428 109.478L172.476 109.489",
|
|
12580
|
+
stroke: "#52525B",
|
|
12581
|
+
strokeWidth: "1.5",
|
|
12582
|
+
strokeLinecap: "round",
|
|
12583
|
+
strokeLinejoin: "round"
|
|
12584
|
+
}
|
|
12585
|
+
),
|
|
12586
|
+
/* @__PURE__ */ jsx(
|
|
12587
|
+
"path",
|
|
12588
|
+
{
|
|
12589
|
+
opacity: "0.25",
|
|
12590
|
+
d: "M172.181 107.094L173.624 107.928",
|
|
12591
|
+
stroke: "#52525B",
|
|
12592
|
+
strokeWidth: "1.5",
|
|
12593
|
+
strokeLinecap: "round",
|
|
12594
|
+
strokeLinejoin: "round"
|
|
12595
|
+
}
|
|
12596
|
+
),
|
|
12597
|
+
/* @__PURE__ */ jsx(
|
|
12598
|
+
"path",
|
|
12599
|
+
{
|
|
12600
|
+
opacity: "0.13",
|
|
12601
|
+
d: "M176.386 106.126L176.379 107.294",
|
|
12602
|
+
stroke: "#52525B",
|
|
12603
|
+
strokeWidth: "1.5",
|
|
12604
|
+
strokeLinecap: "round",
|
|
12605
|
+
strokeLinejoin: "round"
|
|
12606
|
+
}
|
|
12607
|
+
),
|
|
12608
|
+
/* @__PURE__ */ jsx(
|
|
12609
|
+
"rect",
|
|
12610
|
+
{
|
|
12611
|
+
width: "12",
|
|
12612
|
+
height: "3",
|
|
12613
|
+
rx: "1.5",
|
|
12614
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
|
|
12615
|
+
fill: "#D4D4D8"
|
|
12616
|
+
}
|
|
12617
|
+
),
|
|
12618
|
+
/* @__PURE__ */ jsx(
|
|
12619
|
+
"rect",
|
|
12620
|
+
{
|
|
12621
|
+
x: "0.00428286",
|
|
12622
|
+
y: "-0.742904",
|
|
12623
|
+
width: "33.5",
|
|
12624
|
+
height: "65.5",
|
|
12625
|
+
rx: "6.75",
|
|
12626
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
|
|
12627
|
+
fill: "#D4D4D8",
|
|
12628
|
+
stroke: "#52525B",
|
|
12629
|
+
strokeWidth: "1.5"
|
|
12630
|
+
}
|
|
12631
|
+
),
|
|
12632
|
+
/* @__PURE__ */ jsx(
|
|
12633
|
+
"rect",
|
|
12634
|
+
{
|
|
12635
|
+
x: "0.00428286",
|
|
12636
|
+
y: "-0.742904",
|
|
12637
|
+
width: "33.5",
|
|
12638
|
+
height: "65.5",
|
|
12639
|
+
rx: "6.75",
|
|
12640
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
|
|
12641
|
+
fill: "white",
|
|
12642
|
+
stroke: "#52525B",
|
|
12643
|
+
strokeWidth: "1.5"
|
|
12644
|
+
}
|
|
12645
|
+
),
|
|
12646
|
+
/* @__PURE__ */ jsx(
|
|
12647
|
+
"rect",
|
|
12648
|
+
{
|
|
12649
|
+
width: "12",
|
|
12650
|
+
height: "3",
|
|
12651
|
+
rx: "1.5",
|
|
12652
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
|
|
12653
|
+
fill: "#D4D4D8"
|
|
12654
|
+
}
|
|
12655
|
+
),
|
|
12656
|
+
/* @__PURE__ */ jsx(
|
|
12657
|
+
"rect",
|
|
12658
|
+
{
|
|
12659
|
+
width: "17",
|
|
12660
|
+
height: "3",
|
|
12661
|
+
rx: "1.5",
|
|
12662
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
|
|
12663
|
+
fill: "#D4D4D8"
|
|
12664
|
+
}
|
|
12665
|
+
),
|
|
12666
|
+
/* @__PURE__ */ jsx(
|
|
12667
|
+
"rect",
|
|
12668
|
+
{
|
|
12669
|
+
width: "12",
|
|
12670
|
+
height: "3",
|
|
12671
|
+
rx: "1.5",
|
|
12672
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
|
|
12673
|
+
fill: "#D4D4D8"
|
|
12674
|
+
}
|
|
12675
|
+
),
|
|
12676
|
+
/* @__PURE__ */ jsx(
|
|
12677
|
+
"path",
|
|
12678
|
+
{
|
|
12679
|
+
d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
|
|
12680
|
+
fill: "#A1A1AA"
|
|
12681
|
+
}
|
|
12682
|
+
),
|
|
12683
|
+
/* @__PURE__ */ jsx(
|
|
12684
|
+
"rect",
|
|
12685
|
+
{
|
|
12686
|
+
width: "17",
|
|
12687
|
+
height: "3",
|
|
12688
|
+
rx: "1.5",
|
|
12689
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
|
|
12690
|
+
fill: "#A1A1AA"
|
|
12691
|
+
}
|
|
12692
|
+
),
|
|
12693
|
+
/* @__PURE__ */ jsx(
|
|
12694
|
+
"rect",
|
|
12695
|
+
{
|
|
12696
|
+
width: "12",
|
|
12697
|
+
height: "3",
|
|
12698
|
+
rx: "1.5",
|
|
12699
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
12700
|
+
fill: "#A1A1AA"
|
|
12701
|
+
}
|
|
12702
|
+
),
|
|
12703
|
+
/* @__PURE__ */ jsx(
|
|
12704
|
+
"path",
|
|
12705
|
+
{
|
|
12706
|
+
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
12707
|
+
fill: "#52525B"
|
|
12708
|
+
}
|
|
12709
|
+
),
|
|
12710
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12711
|
+
"path",
|
|
12712
|
+
{
|
|
12713
|
+
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
12714
|
+
stroke: "#A1A1AA",
|
|
12715
|
+
strokeWidth: "1.5",
|
|
12716
|
+
strokeLinecap: "round",
|
|
12717
|
+
strokeLinejoin: "round"
|
|
12718
|
+
}
|
|
12719
|
+
) }),
|
|
12720
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12721
|
+
"path",
|
|
12722
|
+
{
|
|
12723
|
+
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
12724
|
+
stroke: "#A1A1AA",
|
|
12725
|
+
strokeWidth: "1.5",
|
|
12726
|
+
strokeLinecap: "round",
|
|
12727
|
+
strokeLinejoin: "round"
|
|
12728
|
+
}
|
|
12729
|
+
) }),
|
|
12730
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12731
|
+
"path",
|
|
12732
|
+
{
|
|
12733
|
+
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
12734
|
+
stroke: "#A1A1AA",
|
|
12735
|
+
strokeWidth: "1.5",
|
|
12736
|
+
strokeLinecap: "round",
|
|
12737
|
+
strokeLinejoin: "round"
|
|
12738
|
+
}
|
|
12739
|
+
) }),
|
|
12740
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12741
|
+
"path",
|
|
12742
|
+
{
|
|
12743
|
+
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
12744
|
+
stroke: "#A1A1AA",
|
|
12745
|
+
strokeWidth: "1.5",
|
|
12746
|
+
strokeLinecap: "round",
|
|
12747
|
+
strokeLinejoin: "round"
|
|
12748
|
+
}
|
|
12749
|
+
) }),
|
|
12750
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12751
|
+
"path",
|
|
12663
12752
|
{
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
|
|
12668
|
-
|
|
12669
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
12753
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12754
|
+
stroke: "#A1A1AA",
|
|
12755
|
+
strokeWidth: "1.5",
|
|
12756
|
+
strokeLinecap: "round",
|
|
12757
|
+
strokeLinejoin: "round"
|
|
12670
12758
|
}
|
|
12671
|
-
)
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
12679
|
-
|
|
12680
|
-
|
|
12681
|
-
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
if (!currency) {
|
|
12686
|
-
return null;
|
|
12687
|
-
}
|
|
12688
|
-
return getLocaleAmount(value, currency);
|
|
12689
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
12690
|
-
return formatPercentage(value);
|
|
12691
|
-
}
|
|
12692
|
-
return null;
|
|
12693
|
-
}
|
|
12694
|
-
const formatter = new Intl.NumberFormat([], {
|
|
12695
|
-
style: "percent",
|
|
12696
|
-
minimumFractionDigits: 2
|
|
12697
|
-
});
|
|
12698
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
12699
|
-
let val = value || 0;
|
|
12700
|
-
if (!isPercentageValue) {
|
|
12701
|
-
val = val / 100;
|
|
12702
|
-
}
|
|
12703
|
-
return formatter.format(val);
|
|
12704
|
-
};
|
|
12705
|
-
function getPromotionIds(items, shippingMethods) {
|
|
12706
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
12707
|
-
for (const item of items) {
|
|
12708
|
-
if (item.adjustments) {
|
|
12709
|
-
for (const adjustment of item.adjustments) {
|
|
12710
|
-
if (adjustment.promotion_id) {
|
|
12711
|
-
promotionIds.add(adjustment.promotion_id);
|
|
12712
|
-
}
|
|
12713
|
-
}
|
|
12714
|
-
}
|
|
12715
|
-
}
|
|
12716
|
-
for (const shippingMethod of shippingMethods) {
|
|
12717
|
-
if (shippingMethod.adjustments) {
|
|
12718
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
12719
|
-
if (adjustment.promotion_id) {
|
|
12720
|
-
promotionIds.add(adjustment.promotion_id);
|
|
12721
|
-
}
|
|
12722
|
-
}
|
|
12723
|
-
}
|
|
12724
|
-
}
|
|
12725
|
-
return Array.from(promotionIds);
|
|
12726
|
-
}
|
|
12727
|
-
const SalesChannel = () => {
|
|
12728
|
-
const { id } = useParams();
|
|
12729
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12730
|
-
id,
|
|
12731
|
-
{
|
|
12732
|
-
fields: "+sales_channel_id"
|
|
12733
|
-
},
|
|
12734
|
-
{
|
|
12735
|
-
enabled: !!id
|
|
12736
|
-
}
|
|
12737
|
-
);
|
|
12738
|
-
if (isError) {
|
|
12739
|
-
throw error;
|
|
12740
|
-
}
|
|
12741
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
12742
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12743
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12744
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
12745
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12746
|
-
] }),
|
|
12747
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
12748
|
-
] });
|
|
12749
|
-
};
|
|
12750
|
-
const SalesChannelForm = ({ order }) => {
|
|
12751
|
-
const form = useForm({
|
|
12752
|
-
defaultValues: {
|
|
12753
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
12754
|
-
},
|
|
12755
|
-
resolver: zodResolver(schema$1)
|
|
12756
|
-
});
|
|
12757
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12758
|
-
const { handleSuccess } = useRouteModal();
|
|
12759
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12760
|
-
await mutateAsync(
|
|
12761
|
-
{
|
|
12762
|
-
sales_channel_id: data.sales_channel_id
|
|
12763
|
-
},
|
|
12764
|
-
{
|
|
12765
|
-
onSuccess: () => {
|
|
12766
|
-
toast.success("Sales channel updated");
|
|
12767
|
-
handleSuccess();
|
|
12768
|
-
},
|
|
12769
|
-
onError: (error) => {
|
|
12770
|
-
toast.error(error.message);
|
|
12771
|
-
}
|
|
12772
|
-
}
|
|
12773
|
-
);
|
|
12774
|
-
});
|
|
12775
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12776
|
-
KeyboundForm,
|
|
12777
|
-
{
|
|
12778
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12779
|
-
onSubmit,
|
|
12780
|
-
children: [
|
|
12781
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12782
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12783
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12784
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12785
|
-
] }) })
|
|
12786
|
-
]
|
|
12787
|
-
}
|
|
12788
|
-
) });
|
|
12789
|
-
};
|
|
12790
|
-
const SalesChannelField = ({ control, order }) => {
|
|
12791
|
-
const salesChannels = useComboboxData({
|
|
12792
|
-
queryFn: async (params) => {
|
|
12793
|
-
return await sdk.admin.salesChannel.list(params);
|
|
12794
|
-
},
|
|
12795
|
-
queryKey: ["sales-channels"],
|
|
12796
|
-
getOptions: (data) => {
|
|
12797
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
12798
|
-
label: salesChannel.name,
|
|
12799
|
-
value: salesChannel.id
|
|
12800
|
-
}));
|
|
12801
|
-
},
|
|
12802
|
-
defaultValue: order.sales_channel_id || void 0
|
|
12803
|
-
});
|
|
12804
|
-
return /* @__PURE__ */ jsx(
|
|
12805
|
-
Form$2.Field,
|
|
12806
|
-
{
|
|
12807
|
-
control,
|
|
12808
|
-
name: "sales_channel_id",
|
|
12809
|
-
render: ({ field }) => {
|
|
12810
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12811
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12812
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12813
|
-
Combobox,
|
|
12759
|
+
) }),
|
|
12760
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12761
|
+
"path",
|
|
12762
|
+
{
|
|
12763
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12764
|
+
stroke: "#A1A1AA",
|
|
12765
|
+
strokeWidth: "1.5",
|
|
12766
|
+
strokeLinecap: "round",
|
|
12767
|
+
strokeLinejoin: "round"
|
|
12768
|
+
}
|
|
12769
|
+
) }),
|
|
12770
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12771
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12772
|
+
"rect",
|
|
12814
12773
|
{
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12820
|
-
placeholder: "Select sales channel",
|
|
12821
|
-
...field
|
|
12774
|
+
width: "12",
|
|
12775
|
+
height: "12",
|
|
12776
|
+
fill: "white",
|
|
12777
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12822
12778
|
}
|
|
12823
12779
|
) }),
|
|
12824
|
-
/* @__PURE__ */ jsx(
|
|
12825
|
-
|
|
12826
|
-
|
|
12780
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12781
|
+
"rect",
|
|
12782
|
+
{
|
|
12783
|
+
width: "12",
|
|
12784
|
+
height: "12",
|
|
12785
|
+
fill: "white",
|
|
12786
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12787
|
+
}
|
|
12788
|
+
) }),
|
|
12789
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12790
|
+
"rect",
|
|
12791
|
+
{
|
|
12792
|
+
width: "12",
|
|
12793
|
+
height: "12",
|
|
12794
|
+
fill: "white",
|
|
12795
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12796
|
+
}
|
|
12797
|
+
) }),
|
|
12798
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12799
|
+
"rect",
|
|
12800
|
+
{
|
|
12801
|
+
width: "12",
|
|
12802
|
+
height: "12",
|
|
12803
|
+
fill: "white",
|
|
12804
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
12805
|
+
}
|
|
12806
|
+
) }),
|
|
12807
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12808
|
+
"rect",
|
|
12809
|
+
{
|
|
12810
|
+
width: "12",
|
|
12811
|
+
height: "12",
|
|
12812
|
+
fill: "white",
|
|
12813
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
12814
|
+
}
|
|
12815
|
+
) }),
|
|
12816
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12817
|
+
"rect",
|
|
12818
|
+
{
|
|
12819
|
+
width: "12",
|
|
12820
|
+
height: "12",
|
|
12821
|
+
fill: "white",
|
|
12822
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12823
|
+
}
|
|
12824
|
+
) })
|
|
12825
|
+
] })
|
|
12826
|
+
]
|
|
12827
12827
|
}
|
|
12828
12828
|
);
|
|
12829
12829
|
};
|
|
12830
12830
|
const schema$1 = objectType({
|
|
12831
|
-
|
|
12831
|
+
customer_id: stringType().min(1)
|
|
12832
12832
|
});
|
|
12833
12833
|
const ShippingAddress = () => {
|
|
12834
12834
|
const { id } = useParams();
|
|
@@ -13073,14 +13073,6 @@ const routeModule = {
|
|
|
13073
13073
|
Component: Metadata,
|
|
13074
13074
|
path: "/draft-orders/:id/metadata"
|
|
13075
13075
|
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: Shipping,
|
|
13078
|
-
path: "/draft-orders/:id/shipping"
|
|
13079
|
-
},
|
|
13080
|
-
{
|
|
13081
|
-
Component: TransferOwnership,
|
|
13082
|
-
path: "/draft-orders/:id/transfer-ownership"
|
|
13083
|
-
},
|
|
13084
13076
|
{
|
|
13085
13077
|
Component: Promotions,
|
|
13086
13078
|
path: "/draft-orders/:id/promotions"
|
|
@@ -13089,6 +13081,14 @@ const routeModule = {
|
|
|
13089
13081
|
Component: SalesChannel,
|
|
13090
13082
|
path: "/draft-orders/:id/sales-channel"
|
|
13091
13083
|
},
|
|
13084
|
+
{
|
|
13085
|
+
Component: Shipping,
|
|
13086
|
+
path: "/draft-orders/:id/shipping"
|
|
13087
|
+
},
|
|
13088
|
+
{
|
|
13089
|
+
Component: TransferOwnership,
|
|
13090
|
+
path: "/draft-orders/:id/transfer-ownership"
|
|
13091
|
+
},
|
|
13092
13092
|
{
|
|
13093
13093
|
Component: ShippingAddress,
|
|
13094
13094
|
path: "/draft-orders/:id/shipping-address"
|