@medusajs/draft-order 2.10.4-preview-20250920090150 → 2.10.4-preview-20250920120200
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 +932 -932
- package/.medusa/server/src/admin/index.mjs +932 -932
- package/package.json +16 -16
|
@@ -11176,135 +11176,412 @@ function getHasUneditableRows(metadata) {
|
|
|
11176
11176
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11177
11177
|
);
|
|
11178
11178
|
}
|
|
11179
|
-
const
|
|
11180
|
-
|
|
11181
|
-
|
|
11179
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11180
|
+
const promotionsQueryKeys = {
|
|
11181
|
+
list: (query2) => [
|
|
11182
|
+
PROMOTION_QUERY_KEY,
|
|
11183
|
+
query2 ? query2 : void 0
|
|
11184
|
+
],
|
|
11185
|
+
detail: (id, query2) => [
|
|
11186
|
+
PROMOTION_QUERY_KEY,
|
|
11182
11187
|
id,
|
|
11188
|
+
query2 ? query2 : void 0
|
|
11189
|
+
]
|
|
11190
|
+
};
|
|
11191
|
+
const usePromotions = (query2, options) => {
|
|
11192
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
11193
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11194
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11195
|
+
...options
|
|
11196
|
+
});
|
|
11197
|
+
return { ...data, ...rest };
|
|
11198
|
+
};
|
|
11199
|
+
const Promotions = () => {
|
|
11200
|
+
const { id } = reactRouterDom.useParams();
|
|
11201
|
+
const {
|
|
11202
|
+
order: preview,
|
|
11203
|
+
isError: isPreviewError,
|
|
11204
|
+
error: previewError
|
|
11205
|
+
} = useOrderPreview(id, void 0);
|
|
11206
|
+
useInitiateOrderEdit({ preview });
|
|
11207
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11208
|
+
if (isPreviewError) {
|
|
11209
|
+
throw previewError;
|
|
11210
|
+
}
|
|
11211
|
+
const isReady = !!preview;
|
|
11212
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11213
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11214
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11215
|
+
] });
|
|
11216
|
+
};
|
|
11217
|
+
const PromotionForm = ({ preview }) => {
|
|
11218
|
+
const { items, shipping_methods } = preview;
|
|
11219
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11220
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11221
|
+
const { handleSuccess } = useRouteModal();
|
|
11222
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11223
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11224
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11183
11225
|
{
|
|
11184
|
-
|
|
11226
|
+
id: promoIds
|
|
11185
11227
|
},
|
|
11186
11228
|
{
|
|
11187
|
-
enabled: !!
|
|
11229
|
+
enabled: !!promoIds.length
|
|
11188
11230
|
}
|
|
11189
11231
|
);
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
|
|
11198
|
-
|
|
11199
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11200
|
-
] });
|
|
11201
|
-
};
|
|
11202
|
-
const SalesChannelForm = ({ order }) => {
|
|
11203
|
-
const form = reactHookForm.useForm({
|
|
11204
|
-
defaultValues: {
|
|
11205
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11232
|
+
const comboboxData = useComboboxData({
|
|
11233
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11234
|
+
queryFn: async (params) => {
|
|
11235
|
+
return await sdk.admin.promotion.list({
|
|
11236
|
+
...params,
|
|
11237
|
+
id: {
|
|
11238
|
+
$nin: promoIds
|
|
11239
|
+
}
|
|
11240
|
+
});
|
|
11206
11241
|
},
|
|
11207
|
-
|
|
11242
|
+
getOptions: (data) => {
|
|
11243
|
+
return data.promotions.map((promotion) => ({
|
|
11244
|
+
label: promotion.code,
|
|
11245
|
+
value: promotion.code
|
|
11246
|
+
}));
|
|
11247
|
+
}
|
|
11208
11248
|
});
|
|
11209
|
-
const
|
|
11210
|
-
|
|
11211
|
-
|
|
11212
|
-
|
|
11249
|
+
const add = async (value) => {
|
|
11250
|
+
if (!value) {
|
|
11251
|
+
return;
|
|
11252
|
+
}
|
|
11253
|
+
addPromotions(
|
|
11213
11254
|
{
|
|
11214
|
-
|
|
11255
|
+
promo_codes: [value]
|
|
11215
11256
|
},
|
|
11216
11257
|
{
|
|
11217
|
-
|
|
11218
|
-
ui.toast.
|
|
11219
|
-
|
|
11258
|
+
onError: (e) => {
|
|
11259
|
+
ui.toast.error(e.message);
|
|
11260
|
+
comboboxData.onSearchValueChange("");
|
|
11261
|
+
setComboboxValue("");
|
|
11220
11262
|
},
|
|
11221
|
-
|
|
11222
|
-
|
|
11263
|
+
onSuccess: () => {
|
|
11264
|
+
comboboxData.onSearchValueChange("");
|
|
11265
|
+
setComboboxValue("");
|
|
11223
11266
|
}
|
|
11224
11267
|
}
|
|
11225
11268
|
);
|
|
11226
|
-
}
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
]
|
|
11239
|
-
}
|
|
11240
|
-
) });
|
|
11241
|
-
};
|
|
11242
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11243
|
-
const salesChannels = useComboboxData({
|
|
11244
|
-
queryFn: async (params) => {
|
|
11245
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11246
|
-
},
|
|
11247
|
-
queryKey: ["sales-channels"],
|
|
11248
|
-
getOptions: (data) => {
|
|
11249
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11250
|
-
label: salesChannel.name,
|
|
11251
|
-
value: salesChannel.id
|
|
11252
|
-
}));
|
|
11253
|
-
},
|
|
11254
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11255
|
-
});
|
|
11256
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11257
|
-
Form$2.Field,
|
|
11258
|
-
{
|
|
11259
|
-
control,
|
|
11260
|
-
name: "sales_channel_id",
|
|
11261
|
-
render: ({ field }) => {
|
|
11262
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11263
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11264
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11265
|
-
Combobox,
|
|
11266
|
-
{
|
|
11267
|
-
options: salesChannels.options,
|
|
11268
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11269
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11270
|
-
searchValue: salesChannels.searchValue,
|
|
11271
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11272
|
-
placeholder: "Select sales channel",
|
|
11273
|
-
...field
|
|
11274
|
-
}
|
|
11275
|
-
) }),
|
|
11276
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11277
|
-
] });
|
|
11269
|
+
};
|
|
11270
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11271
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11272
|
+
const onSubmit = async () => {
|
|
11273
|
+
setIsSubmitting(true);
|
|
11274
|
+
let requestSucceeded = false;
|
|
11275
|
+
await requestOrderEdit(void 0, {
|
|
11276
|
+
onError: (e) => {
|
|
11277
|
+
ui.toast.error(e.message);
|
|
11278
|
+
},
|
|
11279
|
+
onSuccess: () => {
|
|
11280
|
+
requestSucceeded = true;
|
|
11278
11281
|
}
|
|
11282
|
+
});
|
|
11283
|
+
if (!requestSucceeded) {
|
|
11284
|
+
setIsSubmitting(false);
|
|
11285
|
+
return;
|
|
11279
11286
|
}
|
|
11280
|
-
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
|
|
11284
|
-
|
|
11285
|
-
|
|
11286
|
-
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
|
|
11287
|
+
await confirmOrderEdit(void 0, {
|
|
11288
|
+
onError: (e) => {
|
|
11289
|
+
ui.toast.error(e.message);
|
|
11290
|
+
},
|
|
11291
|
+
onSuccess: () => {
|
|
11292
|
+
handleSuccess();
|
|
11293
|
+
},
|
|
11294
|
+
onSettled: () => {
|
|
11295
|
+
setIsSubmitting(false);
|
|
11296
|
+
}
|
|
11297
|
+
});
|
|
11298
|
+
};
|
|
11290
11299
|
if (isError) {
|
|
11291
11300
|
throw error;
|
|
11292
11301
|
}
|
|
11293
|
-
|
|
11294
|
-
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
|
|
11299
|
-
|
|
11302
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11303
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11304
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11305
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11306
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11307
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11308
|
+
] }),
|
|
11309
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11310
|
+
Combobox,
|
|
11311
|
+
{
|
|
11312
|
+
id: "promotion-combobox",
|
|
11313
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11314
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11315
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11316
|
+
options: comboboxData.options,
|
|
11317
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11318
|
+
searchValue: comboboxData.searchValue,
|
|
11319
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11320
|
+
onChange: add,
|
|
11321
|
+
value: comboboxValue
|
|
11322
|
+
}
|
|
11323
|
+
)
|
|
11324
|
+
] }),
|
|
11325
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11326
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11327
|
+
PromotionItem,
|
|
11328
|
+
{
|
|
11329
|
+
promotion,
|
|
11330
|
+
orderId: preview.id,
|
|
11331
|
+
isLoading: isPending
|
|
11332
|
+
},
|
|
11333
|
+
promotion.id
|
|
11334
|
+
)) })
|
|
11335
|
+
] }) }),
|
|
11336
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11337
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11338
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11339
|
+
ui.Button,
|
|
11340
|
+
{
|
|
11341
|
+
size: "small",
|
|
11342
|
+
type: "submit",
|
|
11343
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11344
|
+
children: "Save"
|
|
11345
|
+
}
|
|
11346
|
+
)
|
|
11347
|
+
] }) })
|
|
11300
11348
|
] });
|
|
11301
11349
|
};
|
|
11302
|
-
const
|
|
11303
|
-
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
|
|
11350
|
+
const PromotionItem = ({
|
|
11351
|
+
promotion,
|
|
11352
|
+
orderId,
|
|
11353
|
+
isLoading
|
|
11354
|
+
}) => {
|
|
11355
|
+
var _a;
|
|
11356
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11357
|
+
const onRemove = async () => {
|
|
11358
|
+
removePromotions(
|
|
11359
|
+
{
|
|
11360
|
+
promo_codes: [promotion.code]
|
|
11361
|
+
},
|
|
11362
|
+
{
|
|
11363
|
+
onError: (e) => {
|
|
11364
|
+
ui.toast.error(e.message);
|
|
11365
|
+
}
|
|
11366
|
+
}
|
|
11367
|
+
);
|
|
11368
|
+
};
|
|
11369
|
+
const displayValue = getDisplayValue(promotion);
|
|
11370
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11371
|
+
"div",
|
|
11372
|
+
{
|
|
11373
|
+
className: ui.clx(
|
|
11374
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11375
|
+
{
|
|
11376
|
+
"animate-pulse": isLoading
|
|
11377
|
+
}
|
|
11378
|
+
),
|
|
11379
|
+
children: [
|
|
11380
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11381
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11382
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11383
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11384
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11385
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11386
|
+
] }),
|
|
11387
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11388
|
+
] })
|
|
11389
|
+
] }),
|
|
11390
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11391
|
+
ui.IconButton,
|
|
11392
|
+
{
|
|
11393
|
+
size: "small",
|
|
11394
|
+
type: "button",
|
|
11395
|
+
variant: "transparent",
|
|
11396
|
+
onClick: onRemove,
|
|
11397
|
+
isLoading: isPending || isLoading,
|
|
11398
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11399
|
+
}
|
|
11400
|
+
)
|
|
11401
|
+
]
|
|
11402
|
+
},
|
|
11403
|
+
promotion.id
|
|
11404
|
+
);
|
|
11405
|
+
};
|
|
11406
|
+
function getDisplayValue(promotion) {
|
|
11407
|
+
var _a, _b, _c, _d;
|
|
11408
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11409
|
+
if (!value) {
|
|
11410
|
+
return null;
|
|
11411
|
+
}
|
|
11412
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11413
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11414
|
+
if (!currency) {
|
|
11415
|
+
return null;
|
|
11416
|
+
}
|
|
11417
|
+
return getLocaleAmount(value, currency);
|
|
11418
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11419
|
+
return formatPercentage(value);
|
|
11420
|
+
}
|
|
11421
|
+
return null;
|
|
11422
|
+
}
|
|
11423
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11424
|
+
style: "percent",
|
|
11425
|
+
minimumFractionDigits: 2
|
|
11426
|
+
});
|
|
11427
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11428
|
+
let val = value || 0;
|
|
11429
|
+
if (!isPercentageValue) {
|
|
11430
|
+
val = val / 100;
|
|
11431
|
+
}
|
|
11432
|
+
return formatter.format(val);
|
|
11433
|
+
};
|
|
11434
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11435
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11436
|
+
for (const item of items) {
|
|
11437
|
+
if (item.adjustments) {
|
|
11438
|
+
for (const adjustment of item.adjustments) {
|
|
11439
|
+
if (adjustment.promotion_id) {
|
|
11440
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11441
|
+
}
|
|
11442
|
+
}
|
|
11443
|
+
}
|
|
11444
|
+
}
|
|
11445
|
+
for (const shippingMethod of shippingMethods) {
|
|
11446
|
+
if (shippingMethod.adjustments) {
|
|
11447
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11448
|
+
if (adjustment.promotion_id) {
|
|
11449
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
}
|
|
11453
|
+
}
|
|
11454
|
+
return Array.from(promotionIds);
|
|
11455
|
+
}
|
|
11456
|
+
const SalesChannel = () => {
|
|
11457
|
+
const { id } = reactRouterDom.useParams();
|
|
11458
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11459
|
+
id,
|
|
11460
|
+
{
|
|
11461
|
+
fields: "+sales_channel_id"
|
|
11462
|
+
},
|
|
11463
|
+
{
|
|
11464
|
+
enabled: !!id
|
|
11465
|
+
}
|
|
11466
|
+
);
|
|
11467
|
+
if (isError) {
|
|
11468
|
+
throw error;
|
|
11469
|
+
}
|
|
11470
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11471
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11472
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11473
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
11474
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11475
|
+
] }),
|
|
11476
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11477
|
+
] });
|
|
11478
|
+
};
|
|
11479
|
+
const SalesChannelForm = ({ order }) => {
|
|
11480
|
+
const form = reactHookForm.useForm({
|
|
11481
|
+
defaultValues: {
|
|
11482
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11483
|
+
},
|
|
11484
|
+
resolver: zod.zodResolver(schema$2)
|
|
11485
|
+
});
|
|
11486
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11487
|
+
const { handleSuccess } = useRouteModal();
|
|
11488
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11489
|
+
await mutateAsync(
|
|
11490
|
+
{
|
|
11491
|
+
sales_channel_id: data.sales_channel_id
|
|
11492
|
+
},
|
|
11493
|
+
{
|
|
11494
|
+
onSuccess: () => {
|
|
11495
|
+
ui.toast.success("Sales channel updated");
|
|
11496
|
+
handleSuccess();
|
|
11497
|
+
},
|
|
11498
|
+
onError: (error) => {
|
|
11499
|
+
ui.toast.error(error.message);
|
|
11500
|
+
}
|
|
11501
|
+
}
|
|
11502
|
+
);
|
|
11503
|
+
});
|
|
11504
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11505
|
+
KeyboundForm,
|
|
11506
|
+
{
|
|
11507
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11508
|
+
onSubmit,
|
|
11509
|
+
children: [
|
|
11510
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11511
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11512
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11513
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11514
|
+
] }) })
|
|
11515
|
+
]
|
|
11516
|
+
}
|
|
11517
|
+
) });
|
|
11518
|
+
};
|
|
11519
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11520
|
+
const salesChannels = useComboboxData({
|
|
11521
|
+
queryFn: async (params) => {
|
|
11522
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11523
|
+
},
|
|
11524
|
+
queryKey: ["sales-channels"],
|
|
11525
|
+
getOptions: (data) => {
|
|
11526
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11527
|
+
label: salesChannel.name,
|
|
11528
|
+
value: salesChannel.id
|
|
11529
|
+
}));
|
|
11530
|
+
},
|
|
11531
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11532
|
+
});
|
|
11533
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11534
|
+
Form$2.Field,
|
|
11535
|
+
{
|
|
11536
|
+
control,
|
|
11537
|
+
name: "sales_channel_id",
|
|
11538
|
+
render: ({ field }) => {
|
|
11539
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11540
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11541
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11542
|
+
Combobox,
|
|
11543
|
+
{
|
|
11544
|
+
options: salesChannels.options,
|
|
11545
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11546
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11547
|
+
searchValue: salesChannels.searchValue,
|
|
11548
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11549
|
+
placeholder: "Select sales channel",
|
|
11550
|
+
...field
|
|
11551
|
+
}
|
|
11552
|
+
) }),
|
|
11553
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11554
|
+
] });
|
|
11555
|
+
}
|
|
11556
|
+
}
|
|
11557
|
+
);
|
|
11558
|
+
};
|
|
11559
|
+
const schema$2 = objectType({
|
|
11560
|
+
sales_channel_id: stringType().min(1)
|
|
11561
|
+
});
|
|
11562
|
+
const ShippingAddress = () => {
|
|
11563
|
+
const { id } = reactRouterDom.useParams();
|
|
11564
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11565
|
+
fields: "+shipping_address"
|
|
11566
|
+
});
|
|
11567
|
+
if (isError) {
|
|
11568
|
+
throw error;
|
|
11569
|
+
}
|
|
11570
|
+
const isReady = !isPending && !!order;
|
|
11571
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11572
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11573
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
|
|
11574
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
11575
|
+
] }),
|
|
11576
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
|
|
11577
|
+
] });
|
|
11578
|
+
};
|
|
11579
|
+
const ShippingAddressForm = ({ order }) => {
|
|
11580
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
11581
|
+
const form = reactHookForm.useForm({
|
|
11582
|
+
defaultValues: {
|
|
11583
|
+
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
11584
|
+
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
11308
11585
|
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
11309
11586
|
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
11310
11587
|
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
@@ -11485,584 +11762,108 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11485
11762
|
) });
|
|
11486
11763
|
};
|
|
11487
11764
|
const schema$1 = addressSchema;
|
|
11488
|
-
const
|
|
11765
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11766
|
+
const Shipping = () => {
|
|
11767
|
+
var _a;
|
|
11489
11768
|
const { id } = reactRouterDom.useParams();
|
|
11490
|
-
const {
|
|
11491
|
-
fields: "
|
|
11769
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11770
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11492
11771
|
});
|
|
11772
|
+
const {
|
|
11773
|
+
order: preview,
|
|
11774
|
+
isPending: isPreviewPending,
|
|
11775
|
+
isError: isPreviewError,
|
|
11776
|
+
error: previewError
|
|
11777
|
+
} = useOrderPreview(id);
|
|
11778
|
+
useInitiateOrderEdit({ preview });
|
|
11779
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11493
11780
|
if (isError) {
|
|
11494
11781
|
throw error;
|
|
11495
11782
|
}
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11783
|
+
if (isPreviewError) {
|
|
11784
|
+
throw previewError;
|
|
11785
|
+
}
|
|
11786
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11787
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11788
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11789
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
11790
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
11791
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
11792
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11793
|
+
] }) }) }),
|
|
11794
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11795
|
+
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11796
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11797
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11798
|
+
] }) });
|
|
11504
11799
|
};
|
|
11505
|
-
const
|
|
11506
|
-
var _a
|
|
11507
|
-
const
|
|
11508
|
-
|
|
11509
|
-
|
|
11800
|
+
const ShippingForm = ({ preview, order }) => {
|
|
11801
|
+
var _a;
|
|
11802
|
+
const { setIsOpen } = useStackedModal();
|
|
11803
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11804
|
+
const [data, setData] = React.useState(null);
|
|
11805
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11806
|
+
const { shipping_options } = useShippingOptions(
|
|
11807
|
+
{
|
|
11808
|
+
id: appliedShippingOptionIds,
|
|
11809
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11510
11810
|
},
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11811
|
+
{
|
|
11812
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11813
|
+
}
|
|
11814
|
+
);
|
|
11815
|
+
const uniqueShippingProfiles = React.useMemo(() => {
|
|
11816
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
11817
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11818
|
+
profiles.set(profile.id, profile);
|
|
11819
|
+
});
|
|
11820
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11821
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11822
|
+
});
|
|
11823
|
+
return Array.from(profiles.values());
|
|
11824
|
+
}, [order.items, shipping_options]);
|
|
11514
11825
|
const { handleSuccess } = useRouteModal();
|
|
11515
|
-
const
|
|
11516
|
-
const
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
{
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
onError: (error) => {
|
|
11529
|
-
ui.toast.error(error.message);
|
|
11530
|
-
}
|
|
11826
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11827
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11828
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11829
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11830
|
+
const onSubmit = async () => {
|
|
11831
|
+
setIsSubmitting(true);
|
|
11832
|
+
let requestSucceeded = false;
|
|
11833
|
+
await requestOrderEdit(void 0, {
|
|
11834
|
+
onError: (e) => {
|
|
11835
|
+
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
11836
|
+
},
|
|
11837
|
+
onSuccess: () => {
|
|
11838
|
+
requestSucceeded = true;
|
|
11531
11839
|
}
|
|
11532
|
-
);
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
{
|
|
11537
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11538
|
-
onSubmit,
|
|
11539
|
-
children: [
|
|
11540
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
11541
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
|
|
11542
|
-
currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
|
|
11543
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11544
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
|
|
11545
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
|
|
11546
|
-
] }),
|
|
11547
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
|
|
11548
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
11549
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
|
|
11550
|
-
] })
|
|
11551
|
-
] }),
|
|
11552
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11553
|
-
CustomerField,
|
|
11554
|
-
{
|
|
11555
|
-
control: form.control,
|
|
11556
|
-
currentCustomerId: order.customer_id
|
|
11557
|
-
}
|
|
11558
|
-
)
|
|
11559
|
-
] }),
|
|
11560
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11561
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
|
|
11562
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11563
|
-
] }) })
|
|
11564
|
-
]
|
|
11840
|
+
});
|
|
11841
|
+
if (!requestSucceeded) {
|
|
11842
|
+
setIsSubmitting(false);
|
|
11843
|
+
return;
|
|
11565
11844
|
}
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11845
|
+
await confirmOrderEdit(void 0, {
|
|
11846
|
+
onError: (e) => {
|
|
11847
|
+
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11848
|
+
},
|
|
11849
|
+
onSuccess: () => {
|
|
11850
|
+
handleSuccess();
|
|
11851
|
+
},
|
|
11852
|
+
onSettled: () => {
|
|
11853
|
+
setIsSubmitting(false);
|
|
11854
|
+
}
|
|
11855
|
+
});
|
|
11856
|
+
};
|
|
11857
|
+
const onKeydown = React.useCallback(
|
|
11858
|
+
(e) => {
|
|
11859
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
11860
|
+
if (data || isSubmitting) {
|
|
11861
|
+
return;
|
|
11862
|
+
}
|
|
11863
|
+
onSubmit();
|
|
11864
|
+
}
|
|
11575
11865
|
},
|
|
11576
|
-
|
|
11577
|
-
getOptions: (data) => {
|
|
11578
|
-
return data.customers.map((customer) => {
|
|
11579
|
-
const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
|
|
11580
|
-
return {
|
|
11581
|
-
label: name ? `${name} (${customer.email})` : customer.email,
|
|
11582
|
-
value: customer.id
|
|
11583
|
-
};
|
|
11584
|
-
});
|
|
11585
|
-
}
|
|
11586
|
-
});
|
|
11587
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11588
|
-
Form$2.Field,
|
|
11589
|
-
{
|
|
11590
|
-
name: "customer_id",
|
|
11591
|
-
control,
|
|
11592
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
|
|
11593
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11594
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
|
|
11595
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
|
|
11596
|
-
] }),
|
|
11597
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11598
|
-
Combobox,
|
|
11599
|
-
{
|
|
11600
|
-
options: customers.options,
|
|
11601
|
-
fetchNextPage: customers.fetchNextPage,
|
|
11602
|
-
isFetchingNextPage: customers.isFetchingNextPage,
|
|
11603
|
-
searchValue: customers.searchValue,
|
|
11604
|
-
onSearchValueChange: customers.onSearchValueChange,
|
|
11605
|
-
placeholder: "Select customer",
|
|
11606
|
-
...field
|
|
11607
|
-
}
|
|
11608
|
-
) }),
|
|
11609
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11610
|
-
] })
|
|
11611
|
-
}
|
|
11612
|
-
);
|
|
11613
|
-
};
|
|
11614
|
-
const Illustration = () => {
|
|
11615
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11616
|
-
"svg",
|
|
11617
|
-
{
|
|
11618
|
-
width: "280",
|
|
11619
|
-
height: "180",
|
|
11620
|
-
viewBox: "0 0 280 180",
|
|
11621
|
-
fill: "none",
|
|
11622
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
11623
|
-
children: [
|
|
11624
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11625
|
-
"rect",
|
|
11626
|
-
{
|
|
11627
|
-
x: "0.00428286",
|
|
11628
|
-
y: "-0.742904",
|
|
11629
|
-
width: "33.5",
|
|
11630
|
-
height: "65.5",
|
|
11631
|
-
rx: "6.75",
|
|
11632
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
|
|
11633
|
-
fill: "#D4D4D8",
|
|
11634
|
-
stroke: "#52525B",
|
|
11635
|
-
strokeWidth: "1.5"
|
|
11636
|
-
}
|
|
11637
|
-
),
|
|
11638
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11639
|
-
"rect",
|
|
11640
|
-
{
|
|
11641
|
-
x: "0.00428286",
|
|
11642
|
-
y: "-0.742904",
|
|
11643
|
-
width: "33.5",
|
|
11644
|
-
height: "65.5",
|
|
11645
|
-
rx: "6.75",
|
|
11646
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
|
|
11647
|
-
fill: "white",
|
|
11648
|
-
stroke: "#52525B",
|
|
11649
|
-
strokeWidth: "1.5"
|
|
11650
|
-
}
|
|
11651
|
-
),
|
|
11652
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11653
|
-
"path",
|
|
11654
|
-
{
|
|
11655
|
-
d: "M180.579 107.142L179.126 107.959",
|
|
11656
|
-
stroke: "#52525B",
|
|
11657
|
-
strokeWidth: "1.5",
|
|
11658
|
-
strokeLinecap: "round",
|
|
11659
|
-
strokeLinejoin: "round"
|
|
11660
|
-
}
|
|
11661
|
-
),
|
|
11662
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11663
|
-
"path",
|
|
11664
|
-
{
|
|
11665
|
-
opacity: "0.88",
|
|
11666
|
-
d: "M182.305 109.546L180.257 109.534",
|
|
11667
|
-
stroke: "#52525B",
|
|
11668
|
-
strokeWidth: "1.5",
|
|
11669
|
-
strokeLinecap: "round",
|
|
11670
|
-
strokeLinejoin: "round"
|
|
11671
|
-
}
|
|
11672
|
-
),
|
|
11673
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11674
|
-
"path",
|
|
11675
|
-
{
|
|
11676
|
-
opacity: "0.75",
|
|
11677
|
-
d: "M180.551 111.93L179.108 111.096",
|
|
11678
|
-
stroke: "#52525B",
|
|
11679
|
-
strokeWidth: "1.5",
|
|
11680
|
-
strokeLinecap: "round",
|
|
11681
|
-
strokeLinejoin: "round"
|
|
11682
|
-
}
|
|
11683
|
-
),
|
|
11684
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11685
|
-
"path",
|
|
11686
|
-
{
|
|
11687
|
-
opacity: "0.63",
|
|
11688
|
-
d: "M176.347 112.897L176.354 111.73",
|
|
11689
|
-
stroke: "#52525B",
|
|
11690
|
-
strokeWidth: "1.5",
|
|
11691
|
-
strokeLinecap: "round",
|
|
11692
|
-
strokeLinejoin: "round"
|
|
11693
|
-
}
|
|
11694
|
-
),
|
|
11695
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11696
|
-
"path",
|
|
11697
|
-
{
|
|
11698
|
-
opacity: "0.5",
|
|
11699
|
-
d: "M172.153 111.881L173.606 111.064",
|
|
11700
|
-
stroke: "#52525B",
|
|
11701
|
-
strokeWidth: "1.5",
|
|
11702
|
-
strokeLinecap: "round",
|
|
11703
|
-
strokeLinejoin: "round"
|
|
11704
|
-
}
|
|
11705
|
-
),
|
|
11706
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11707
|
-
"path",
|
|
11708
|
-
{
|
|
11709
|
-
opacity: "0.38",
|
|
11710
|
-
d: "M170.428 109.478L172.476 109.489",
|
|
11711
|
-
stroke: "#52525B",
|
|
11712
|
-
strokeWidth: "1.5",
|
|
11713
|
-
strokeLinecap: "round",
|
|
11714
|
-
strokeLinejoin: "round"
|
|
11715
|
-
}
|
|
11716
|
-
),
|
|
11717
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11718
|
-
"path",
|
|
11719
|
-
{
|
|
11720
|
-
opacity: "0.25",
|
|
11721
|
-
d: "M172.181 107.094L173.624 107.928",
|
|
11722
|
-
stroke: "#52525B",
|
|
11723
|
-
strokeWidth: "1.5",
|
|
11724
|
-
strokeLinecap: "round",
|
|
11725
|
-
strokeLinejoin: "round"
|
|
11726
|
-
}
|
|
11727
|
-
),
|
|
11728
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11729
|
-
"path",
|
|
11730
|
-
{
|
|
11731
|
-
opacity: "0.13",
|
|
11732
|
-
d: "M176.386 106.126L176.379 107.294",
|
|
11733
|
-
stroke: "#52525B",
|
|
11734
|
-
strokeWidth: "1.5",
|
|
11735
|
-
strokeLinecap: "round",
|
|
11736
|
-
strokeLinejoin: "round"
|
|
11737
|
-
}
|
|
11738
|
-
),
|
|
11739
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11740
|
-
"rect",
|
|
11741
|
-
{
|
|
11742
|
-
width: "12",
|
|
11743
|
-
height: "3",
|
|
11744
|
-
rx: "1.5",
|
|
11745
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
|
|
11746
|
-
fill: "#D4D4D8"
|
|
11747
|
-
}
|
|
11748
|
-
),
|
|
11749
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11750
|
-
"rect",
|
|
11751
|
-
{
|
|
11752
|
-
x: "0.00428286",
|
|
11753
|
-
y: "-0.742904",
|
|
11754
|
-
width: "33.5",
|
|
11755
|
-
height: "65.5",
|
|
11756
|
-
rx: "6.75",
|
|
11757
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
|
|
11758
|
-
fill: "#D4D4D8",
|
|
11759
|
-
stroke: "#52525B",
|
|
11760
|
-
strokeWidth: "1.5"
|
|
11761
|
-
}
|
|
11762
|
-
),
|
|
11763
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11764
|
-
"rect",
|
|
11765
|
-
{
|
|
11766
|
-
x: "0.00428286",
|
|
11767
|
-
y: "-0.742904",
|
|
11768
|
-
width: "33.5",
|
|
11769
|
-
height: "65.5",
|
|
11770
|
-
rx: "6.75",
|
|
11771
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
|
|
11772
|
-
fill: "white",
|
|
11773
|
-
stroke: "#52525B",
|
|
11774
|
-
strokeWidth: "1.5"
|
|
11775
|
-
}
|
|
11776
|
-
),
|
|
11777
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11778
|
-
"rect",
|
|
11779
|
-
{
|
|
11780
|
-
width: "12",
|
|
11781
|
-
height: "3",
|
|
11782
|
-
rx: "1.5",
|
|
11783
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
|
|
11784
|
-
fill: "#D4D4D8"
|
|
11785
|
-
}
|
|
11786
|
-
),
|
|
11787
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11788
|
-
"rect",
|
|
11789
|
-
{
|
|
11790
|
-
width: "17",
|
|
11791
|
-
height: "3",
|
|
11792
|
-
rx: "1.5",
|
|
11793
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
|
|
11794
|
-
fill: "#D4D4D8"
|
|
11795
|
-
}
|
|
11796
|
-
),
|
|
11797
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11798
|
-
"rect",
|
|
11799
|
-
{
|
|
11800
|
-
width: "12",
|
|
11801
|
-
height: "3",
|
|
11802
|
-
rx: "1.5",
|
|
11803
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
|
|
11804
|
-
fill: "#D4D4D8"
|
|
11805
|
-
}
|
|
11806
|
-
),
|
|
11807
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11808
|
-
"path",
|
|
11809
|
-
{
|
|
11810
|
-
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",
|
|
11811
|
-
fill: "#A1A1AA"
|
|
11812
|
-
}
|
|
11813
|
-
),
|
|
11814
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11815
|
-
"rect",
|
|
11816
|
-
{
|
|
11817
|
-
width: "17",
|
|
11818
|
-
height: "3",
|
|
11819
|
-
rx: "1.5",
|
|
11820
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
|
|
11821
|
-
fill: "#A1A1AA"
|
|
11822
|
-
}
|
|
11823
|
-
),
|
|
11824
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11825
|
-
"rect",
|
|
11826
|
-
{
|
|
11827
|
-
width: "12",
|
|
11828
|
-
height: "3",
|
|
11829
|
-
rx: "1.5",
|
|
11830
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
11831
|
-
fill: "#A1A1AA"
|
|
11832
|
-
}
|
|
11833
|
-
),
|
|
11834
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11835
|
-
"path",
|
|
11836
|
-
{
|
|
11837
|
-
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",
|
|
11838
|
-
fill: "#52525B"
|
|
11839
|
-
}
|
|
11840
|
-
),
|
|
11841
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11842
|
-
"path",
|
|
11843
|
-
{
|
|
11844
|
-
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
11845
|
-
stroke: "#A1A1AA",
|
|
11846
|
-
strokeWidth: "1.5",
|
|
11847
|
-
strokeLinecap: "round",
|
|
11848
|
-
strokeLinejoin: "round"
|
|
11849
|
-
}
|
|
11850
|
-
) }),
|
|
11851
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11852
|
-
"path",
|
|
11853
|
-
{
|
|
11854
|
-
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
11855
|
-
stroke: "#A1A1AA",
|
|
11856
|
-
strokeWidth: "1.5",
|
|
11857
|
-
strokeLinecap: "round",
|
|
11858
|
-
strokeLinejoin: "round"
|
|
11859
|
-
}
|
|
11860
|
-
) }),
|
|
11861
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11862
|
-
"path",
|
|
11863
|
-
{
|
|
11864
|
-
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
11865
|
-
stroke: "#A1A1AA",
|
|
11866
|
-
strokeWidth: "1.5",
|
|
11867
|
-
strokeLinecap: "round",
|
|
11868
|
-
strokeLinejoin: "round"
|
|
11869
|
-
}
|
|
11870
|
-
) }),
|
|
11871
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11872
|
-
"path",
|
|
11873
|
-
{
|
|
11874
|
-
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
11875
|
-
stroke: "#A1A1AA",
|
|
11876
|
-
strokeWidth: "1.5",
|
|
11877
|
-
strokeLinecap: "round",
|
|
11878
|
-
strokeLinejoin: "round"
|
|
11879
|
-
}
|
|
11880
|
-
) }),
|
|
11881
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11882
|
-
"path",
|
|
11883
|
-
{
|
|
11884
|
-
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
11885
|
-
stroke: "#A1A1AA",
|
|
11886
|
-
strokeWidth: "1.5",
|
|
11887
|
-
strokeLinecap: "round",
|
|
11888
|
-
strokeLinejoin: "round"
|
|
11889
|
-
}
|
|
11890
|
-
) }),
|
|
11891
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11892
|
-
"path",
|
|
11893
|
-
{
|
|
11894
|
-
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
11895
|
-
stroke: "#A1A1AA",
|
|
11896
|
-
strokeWidth: "1.5",
|
|
11897
|
-
strokeLinecap: "round",
|
|
11898
|
-
strokeLinejoin: "round"
|
|
11899
|
-
}
|
|
11900
|
-
) }),
|
|
11901
|
-
/* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
11902
|
-
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11903
|
-
"rect",
|
|
11904
|
-
{
|
|
11905
|
-
width: "12",
|
|
11906
|
-
height: "12",
|
|
11907
|
-
fill: "white",
|
|
11908
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
11909
|
-
}
|
|
11910
|
-
) }),
|
|
11911
|
-
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11912
|
-
"rect",
|
|
11913
|
-
{
|
|
11914
|
-
width: "12",
|
|
11915
|
-
height: "12",
|
|
11916
|
-
fill: "white",
|
|
11917
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
11918
|
-
}
|
|
11919
|
-
) }),
|
|
11920
|
-
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11921
|
-
"rect",
|
|
11922
|
-
{
|
|
11923
|
-
width: "12",
|
|
11924
|
-
height: "12",
|
|
11925
|
-
fill: "white",
|
|
11926
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
11927
|
-
}
|
|
11928
|
-
) }),
|
|
11929
|
-
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11930
|
-
"rect",
|
|
11931
|
-
{
|
|
11932
|
-
width: "12",
|
|
11933
|
-
height: "12",
|
|
11934
|
-
fill: "white",
|
|
11935
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
11936
|
-
}
|
|
11937
|
-
) }),
|
|
11938
|
-
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11939
|
-
"rect",
|
|
11940
|
-
{
|
|
11941
|
-
width: "12",
|
|
11942
|
-
height: "12",
|
|
11943
|
-
fill: "white",
|
|
11944
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
11945
|
-
}
|
|
11946
|
-
) }),
|
|
11947
|
-
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11948
|
-
"rect",
|
|
11949
|
-
{
|
|
11950
|
-
width: "12",
|
|
11951
|
-
height: "12",
|
|
11952
|
-
fill: "white",
|
|
11953
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
11954
|
-
}
|
|
11955
|
-
) })
|
|
11956
|
-
] })
|
|
11957
|
-
]
|
|
11958
|
-
}
|
|
11959
|
-
);
|
|
11960
|
-
};
|
|
11961
|
-
const schema = objectType({
|
|
11962
|
-
customer_id: stringType().min(1)
|
|
11963
|
-
});
|
|
11964
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11965
|
-
const Shipping = () => {
|
|
11966
|
-
var _a;
|
|
11967
|
-
const { id } = reactRouterDom.useParams();
|
|
11968
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11969
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11970
|
-
});
|
|
11971
|
-
const {
|
|
11972
|
-
order: preview,
|
|
11973
|
-
isPending: isPreviewPending,
|
|
11974
|
-
isError: isPreviewError,
|
|
11975
|
-
error: previewError
|
|
11976
|
-
} = useOrderPreview(id);
|
|
11977
|
-
useInitiateOrderEdit({ preview });
|
|
11978
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11979
|
-
if (isError) {
|
|
11980
|
-
throw error;
|
|
11981
|
-
}
|
|
11982
|
-
if (isPreviewError) {
|
|
11983
|
-
throw previewError;
|
|
11984
|
-
}
|
|
11985
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11986
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11987
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11988
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
11989
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
11990
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
11991
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11992
|
-
] }) }) }),
|
|
11993
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11994
|
-
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11995
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11996
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11997
|
-
] }) });
|
|
11998
|
-
};
|
|
11999
|
-
const ShippingForm = ({ preview, order }) => {
|
|
12000
|
-
var _a;
|
|
12001
|
-
const { setIsOpen } = useStackedModal();
|
|
12002
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
12003
|
-
const [data, setData] = React.useState(null);
|
|
12004
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
12005
|
-
const { shipping_options } = useShippingOptions(
|
|
12006
|
-
{
|
|
12007
|
-
id: appliedShippingOptionIds,
|
|
12008
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
12009
|
-
},
|
|
12010
|
-
{
|
|
12011
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
12012
|
-
}
|
|
12013
|
-
);
|
|
12014
|
-
const uniqueShippingProfiles = React.useMemo(() => {
|
|
12015
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
12016
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
12017
|
-
profiles.set(profile.id, profile);
|
|
12018
|
-
});
|
|
12019
|
-
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
12020
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
12021
|
-
});
|
|
12022
|
-
return Array.from(profiles.values());
|
|
12023
|
-
}, [order.items, shipping_options]);
|
|
12024
|
-
const { handleSuccess } = useRouteModal();
|
|
12025
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12026
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
12027
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
12028
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
12029
|
-
const onSubmit = async () => {
|
|
12030
|
-
setIsSubmitting(true);
|
|
12031
|
-
let requestSucceeded = false;
|
|
12032
|
-
await requestOrderEdit(void 0, {
|
|
12033
|
-
onError: (e) => {
|
|
12034
|
-
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
12035
|
-
},
|
|
12036
|
-
onSuccess: () => {
|
|
12037
|
-
requestSucceeded = true;
|
|
12038
|
-
}
|
|
12039
|
-
});
|
|
12040
|
-
if (!requestSucceeded) {
|
|
12041
|
-
setIsSubmitting(false);
|
|
12042
|
-
return;
|
|
12043
|
-
}
|
|
12044
|
-
await confirmOrderEdit(void 0, {
|
|
12045
|
-
onError: (e) => {
|
|
12046
|
-
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
12047
|
-
},
|
|
12048
|
-
onSuccess: () => {
|
|
12049
|
-
handleSuccess();
|
|
12050
|
-
},
|
|
12051
|
-
onSettled: () => {
|
|
12052
|
-
setIsSubmitting(false);
|
|
12053
|
-
}
|
|
12054
|
-
});
|
|
12055
|
-
};
|
|
12056
|
-
const onKeydown = React.useCallback(
|
|
12057
|
-
(e) => {
|
|
12058
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
12059
|
-
if (data || isSubmitting) {
|
|
12060
|
-
return;
|
|
12061
|
-
}
|
|
12062
|
-
onSubmit();
|
|
12063
|
-
}
|
|
12064
|
-
},
|
|
12065
|
-
[data, isSubmitting, onSubmit]
|
|
11866
|
+
[data, isSubmitting, onSubmit]
|
|
12066
11867
|
);
|
|
12067
11868
|
React.useEffect(() => {
|
|
12068
11869
|
document.addEventListener("keydown", onKeydown);
|
|
@@ -12768,283 +12569,482 @@ const CustomAmountField = ({
|
|
|
12768
12569
|
}
|
|
12769
12570
|
);
|
|
12770
12571
|
};
|
|
12771
|
-
const
|
|
12772
|
-
const promotionsQueryKeys = {
|
|
12773
|
-
list: (query2) => [
|
|
12774
|
-
PROMOTION_QUERY_KEY,
|
|
12775
|
-
query2 ? query2 : void 0
|
|
12776
|
-
],
|
|
12777
|
-
detail: (id, query2) => [
|
|
12778
|
-
PROMOTION_QUERY_KEY,
|
|
12779
|
-
id,
|
|
12780
|
-
query2 ? query2 : void 0
|
|
12781
|
-
]
|
|
12782
|
-
};
|
|
12783
|
-
const usePromotions = (query2, options) => {
|
|
12784
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
12785
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
12786
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
12787
|
-
...options
|
|
12788
|
-
});
|
|
12789
|
-
return { ...data, ...rest };
|
|
12790
|
-
};
|
|
12791
|
-
const Promotions = () => {
|
|
12572
|
+
const TransferOwnership = () => {
|
|
12792
12573
|
const { id } = reactRouterDom.useParams();
|
|
12793
|
-
const {
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
useInitiateOrderEdit({ preview });
|
|
12799
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12800
|
-
if (isPreviewError) {
|
|
12801
|
-
throw previewError;
|
|
12574
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
12575
|
+
fields: "id,customer_id,customer.*"
|
|
12576
|
+
});
|
|
12577
|
+
if (isError) {
|
|
12578
|
+
throw error;
|
|
12802
12579
|
}
|
|
12803
|
-
const isReady = !!
|
|
12804
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, {
|
|
12805
|
-
/* @__PURE__ */ jsxRuntime.
|
|
12806
|
-
|
|
12580
|
+
const isReady = !isPending && !!draft_order;
|
|
12581
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12582
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12583
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
|
|
12584
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
|
|
12585
|
+
] }),
|
|
12586
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
|
|
12807
12587
|
] });
|
|
12808
12588
|
};
|
|
12809
|
-
const
|
|
12810
|
-
|
|
12811
|
-
const
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
12815
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
12816
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
12817
|
-
{
|
|
12818
|
-
id: promoIds
|
|
12589
|
+
const TransferOwnershipForm = ({ order }) => {
|
|
12590
|
+
var _a, _b;
|
|
12591
|
+
const form = reactHookForm.useForm({
|
|
12592
|
+
defaultValues: {
|
|
12593
|
+
customer_id: order.customer_id || ""
|
|
12819
12594
|
},
|
|
12595
|
+
resolver: zod.zodResolver(schema)
|
|
12596
|
+
});
|
|
12597
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12598
|
+
const { handleSuccess } = useRouteModal();
|
|
12599
|
+
const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
|
|
12600
|
+
const currentCustomer = order.customer ? {
|
|
12601
|
+
label: name ? `${name} (${order.customer.email})` : order.customer.email,
|
|
12602
|
+
value: order.customer.id
|
|
12603
|
+
} : null;
|
|
12604
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12605
|
+
await mutateAsync(
|
|
12606
|
+
{ customer_id: data.customer_id },
|
|
12607
|
+
{
|
|
12608
|
+
onSuccess: () => {
|
|
12609
|
+
ui.toast.success("Customer updated");
|
|
12610
|
+
handleSuccess();
|
|
12611
|
+
},
|
|
12612
|
+
onError: (error) => {
|
|
12613
|
+
ui.toast.error(error.message);
|
|
12614
|
+
}
|
|
12615
|
+
}
|
|
12616
|
+
);
|
|
12617
|
+
});
|
|
12618
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12619
|
+
KeyboundForm,
|
|
12820
12620
|
{
|
|
12821
|
-
|
|
12621
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12622
|
+
onSubmit,
|
|
12623
|
+
children: [
|
|
12624
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
12625
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
|
|
12626
|
+
currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
|
|
12627
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
12628
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
|
|
12629
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
|
|
12630
|
+
] }),
|
|
12631
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
|
|
12632
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
12633
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
|
|
12634
|
+
] })
|
|
12635
|
+
] }),
|
|
12636
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12637
|
+
CustomerField,
|
|
12638
|
+
{
|
|
12639
|
+
control: form.control,
|
|
12640
|
+
currentCustomerId: order.customer_id
|
|
12641
|
+
}
|
|
12642
|
+
)
|
|
12643
|
+
] }),
|
|
12644
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12645
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
|
|
12646
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12647
|
+
] }) })
|
|
12648
|
+
]
|
|
12822
12649
|
}
|
|
12823
|
-
);
|
|
12824
|
-
|
|
12825
|
-
|
|
12650
|
+
) });
|
|
12651
|
+
};
|
|
12652
|
+
const CustomerField = ({ control, currentCustomerId }) => {
|
|
12653
|
+
const customers = useComboboxData({
|
|
12826
12654
|
queryFn: async (params) => {
|
|
12827
|
-
return await sdk.admin.
|
|
12655
|
+
return await sdk.admin.customer.list({
|
|
12828
12656
|
...params,
|
|
12829
|
-
id: {
|
|
12830
|
-
$nin: promoIds
|
|
12831
|
-
}
|
|
12657
|
+
id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
|
|
12832
12658
|
});
|
|
12833
12659
|
},
|
|
12660
|
+
queryKey: ["customers"],
|
|
12834
12661
|
getOptions: (data) => {
|
|
12835
|
-
return data.
|
|
12836
|
-
|
|
12837
|
-
|
|
12838
|
-
|
|
12662
|
+
return data.customers.map((customer) => {
|
|
12663
|
+
const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
|
|
12664
|
+
return {
|
|
12665
|
+
label: name ? `${name} (${customer.email})` : customer.email,
|
|
12666
|
+
value: customer.id
|
|
12667
|
+
};
|
|
12668
|
+
});
|
|
12839
12669
|
}
|
|
12840
12670
|
});
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
{
|
|
12847
|
-
promo_codes: [value]
|
|
12848
|
-
},
|
|
12849
|
-
{
|
|
12850
|
-
onError: (e) => {
|
|
12851
|
-
ui.toast.error(e.message);
|
|
12852
|
-
comboboxData.onSearchValueChange("");
|
|
12853
|
-
setComboboxValue("");
|
|
12854
|
-
},
|
|
12855
|
-
onSuccess: () => {
|
|
12856
|
-
comboboxData.onSearchValueChange("");
|
|
12857
|
-
setComboboxValue("");
|
|
12858
|
-
}
|
|
12859
|
-
}
|
|
12860
|
-
);
|
|
12861
|
-
};
|
|
12862
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12863
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
12864
|
-
const onSubmit = async () => {
|
|
12865
|
-
setIsSubmitting(true);
|
|
12866
|
-
let requestSucceeded = false;
|
|
12867
|
-
await requestOrderEdit(void 0, {
|
|
12868
|
-
onError: (e) => {
|
|
12869
|
-
ui.toast.error(e.message);
|
|
12870
|
-
},
|
|
12871
|
-
onSuccess: () => {
|
|
12872
|
-
requestSucceeded = true;
|
|
12873
|
-
}
|
|
12874
|
-
});
|
|
12875
|
-
if (!requestSucceeded) {
|
|
12876
|
-
setIsSubmitting(false);
|
|
12877
|
-
return;
|
|
12878
|
-
}
|
|
12879
|
-
await confirmOrderEdit(void 0, {
|
|
12880
|
-
onError: (e) => {
|
|
12881
|
-
ui.toast.error(e.message);
|
|
12882
|
-
},
|
|
12883
|
-
onSuccess: () => {
|
|
12884
|
-
handleSuccess();
|
|
12885
|
-
},
|
|
12886
|
-
onSettled: () => {
|
|
12887
|
-
setIsSubmitting(false);
|
|
12888
|
-
}
|
|
12889
|
-
});
|
|
12890
|
-
};
|
|
12891
|
-
if (isError) {
|
|
12892
|
-
throw error;
|
|
12893
|
-
}
|
|
12894
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
12895
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
12896
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
12671
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12672
|
+
Form$2.Field,
|
|
12673
|
+
{
|
|
12674
|
+
name: "customer_id",
|
|
12675
|
+
control,
|
|
12676
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
|
|
12897
12677
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
12898
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12899
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12678
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
|
|
12679
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
|
|
12900
12680
|
] }),
|
|
12901
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12681
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12902
12682
|
Combobox,
|
|
12903
12683
|
{
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
isFetchingNextPage:
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
|
|
12684
|
+
options: customers.options,
|
|
12685
|
+
fetchNextPage: customers.fetchNextPage,
|
|
12686
|
+
isFetchingNextPage: customers.isFetchingNextPage,
|
|
12687
|
+
searchValue: customers.searchValue,
|
|
12688
|
+
onSearchValueChange: customers.onSearchValueChange,
|
|
12689
|
+
placeholder: "Select customer",
|
|
12690
|
+
...field
|
|
12691
|
+
}
|
|
12692
|
+
) }),
|
|
12693
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12694
|
+
] })
|
|
12695
|
+
}
|
|
12696
|
+
);
|
|
12697
|
+
};
|
|
12698
|
+
const Illustration = () => {
|
|
12699
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12700
|
+
"svg",
|
|
12701
|
+
{
|
|
12702
|
+
width: "280",
|
|
12703
|
+
height: "180",
|
|
12704
|
+
viewBox: "0 0 280 180",
|
|
12705
|
+
fill: "none",
|
|
12706
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
12707
|
+
children: [
|
|
12708
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12709
|
+
"rect",
|
|
12710
|
+
{
|
|
12711
|
+
x: "0.00428286",
|
|
12712
|
+
y: "-0.742904",
|
|
12713
|
+
width: "33.5",
|
|
12714
|
+
height: "65.5",
|
|
12715
|
+
rx: "6.75",
|
|
12716
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
|
|
12717
|
+
fill: "#D4D4D8",
|
|
12718
|
+
stroke: "#52525B",
|
|
12719
|
+
strokeWidth: "1.5"
|
|
12720
|
+
}
|
|
12721
|
+
),
|
|
12722
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12723
|
+
"rect",
|
|
12724
|
+
{
|
|
12725
|
+
x: "0.00428286",
|
|
12726
|
+
y: "-0.742904",
|
|
12727
|
+
width: "33.5",
|
|
12728
|
+
height: "65.5",
|
|
12729
|
+
rx: "6.75",
|
|
12730
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
|
|
12731
|
+
fill: "white",
|
|
12732
|
+
stroke: "#52525B",
|
|
12733
|
+
strokeWidth: "1.5"
|
|
12734
|
+
}
|
|
12735
|
+
),
|
|
12736
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12737
|
+
"path",
|
|
12738
|
+
{
|
|
12739
|
+
d: "M180.579 107.142L179.126 107.959",
|
|
12740
|
+
stroke: "#52525B",
|
|
12741
|
+
strokeWidth: "1.5",
|
|
12742
|
+
strokeLinecap: "round",
|
|
12743
|
+
strokeLinejoin: "round"
|
|
12744
|
+
}
|
|
12745
|
+
),
|
|
12746
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12747
|
+
"path",
|
|
12748
|
+
{
|
|
12749
|
+
opacity: "0.88",
|
|
12750
|
+
d: "M182.305 109.546L180.257 109.534",
|
|
12751
|
+
stroke: "#52525B",
|
|
12752
|
+
strokeWidth: "1.5",
|
|
12753
|
+
strokeLinecap: "round",
|
|
12754
|
+
strokeLinejoin: "round"
|
|
12755
|
+
}
|
|
12756
|
+
),
|
|
12757
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12758
|
+
"path",
|
|
12759
|
+
{
|
|
12760
|
+
opacity: "0.75",
|
|
12761
|
+
d: "M180.551 111.93L179.108 111.096",
|
|
12762
|
+
stroke: "#52525B",
|
|
12763
|
+
strokeWidth: "1.5",
|
|
12764
|
+
strokeLinecap: "round",
|
|
12765
|
+
strokeLinejoin: "round"
|
|
12766
|
+
}
|
|
12767
|
+
),
|
|
12768
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12769
|
+
"path",
|
|
12770
|
+
{
|
|
12771
|
+
opacity: "0.63",
|
|
12772
|
+
d: "M176.347 112.897L176.354 111.73",
|
|
12773
|
+
stroke: "#52525B",
|
|
12774
|
+
strokeWidth: "1.5",
|
|
12775
|
+
strokeLinecap: "round",
|
|
12776
|
+
strokeLinejoin: "round"
|
|
12777
|
+
}
|
|
12778
|
+
),
|
|
12779
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12780
|
+
"path",
|
|
12781
|
+
{
|
|
12782
|
+
opacity: "0.5",
|
|
12783
|
+
d: "M172.153 111.881L173.606 111.064",
|
|
12784
|
+
stroke: "#52525B",
|
|
12785
|
+
strokeWidth: "1.5",
|
|
12786
|
+
strokeLinecap: "round",
|
|
12787
|
+
strokeLinejoin: "round"
|
|
12788
|
+
}
|
|
12789
|
+
),
|
|
12790
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12791
|
+
"path",
|
|
12792
|
+
{
|
|
12793
|
+
opacity: "0.38",
|
|
12794
|
+
d: "M170.428 109.478L172.476 109.489",
|
|
12795
|
+
stroke: "#52525B",
|
|
12796
|
+
strokeWidth: "1.5",
|
|
12797
|
+
strokeLinecap: "round",
|
|
12798
|
+
strokeLinejoin: "round"
|
|
12799
|
+
}
|
|
12800
|
+
),
|
|
12801
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12802
|
+
"path",
|
|
12803
|
+
{
|
|
12804
|
+
opacity: "0.25",
|
|
12805
|
+
d: "M172.181 107.094L173.624 107.928",
|
|
12806
|
+
stroke: "#52525B",
|
|
12807
|
+
strokeWidth: "1.5",
|
|
12808
|
+
strokeLinecap: "round",
|
|
12809
|
+
strokeLinejoin: "round"
|
|
12810
|
+
}
|
|
12811
|
+
),
|
|
12812
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12813
|
+
"path",
|
|
12814
|
+
{
|
|
12815
|
+
opacity: "0.13",
|
|
12816
|
+
d: "M176.386 106.126L176.379 107.294",
|
|
12817
|
+
stroke: "#52525B",
|
|
12818
|
+
strokeWidth: "1.5",
|
|
12819
|
+
strokeLinecap: "round",
|
|
12820
|
+
strokeLinejoin: "round"
|
|
12821
|
+
}
|
|
12822
|
+
),
|
|
12823
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12824
|
+
"rect",
|
|
12825
|
+
{
|
|
12826
|
+
width: "12",
|
|
12827
|
+
height: "3",
|
|
12828
|
+
rx: "1.5",
|
|
12829
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
|
|
12830
|
+
fill: "#D4D4D8"
|
|
12831
|
+
}
|
|
12832
|
+
),
|
|
12833
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12834
|
+
"rect",
|
|
12835
|
+
{
|
|
12836
|
+
x: "0.00428286",
|
|
12837
|
+
y: "-0.742904",
|
|
12838
|
+
width: "33.5",
|
|
12839
|
+
height: "65.5",
|
|
12840
|
+
rx: "6.75",
|
|
12841
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
|
|
12842
|
+
fill: "#D4D4D8",
|
|
12843
|
+
stroke: "#52525B",
|
|
12844
|
+
strokeWidth: "1.5"
|
|
12845
|
+
}
|
|
12846
|
+
),
|
|
12847
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12848
|
+
"rect",
|
|
12849
|
+
{
|
|
12850
|
+
x: "0.00428286",
|
|
12851
|
+
y: "-0.742904",
|
|
12852
|
+
width: "33.5",
|
|
12853
|
+
height: "65.5",
|
|
12854
|
+
rx: "6.75",
|
|
12855
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
|
|
12856
|
+
fill: "white",
|
|
12857
|
+
stroke: "#52525B",
|
|
12858
|
+
strokeWidth: "1.5"
|
|
12859
|
+
}
|
|
12860
|
+
),
|
|
12861
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12862
|
+
"rect",
|
|
12863
|
+
{
|
|
12864
|
+
width: "12",
|
|
12865
|
+
height: "3",
|
|
12866
|
+
rx: "1.5",
|
|
12867
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
|
|
12868
|
+
fill: "#D4D4D8"
|
|
12869
|
+
}
|
|
12870
|
+
),
|
|
12871
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12872
|
+
"rect",
|
|
12873
|
+
{
|
|
12874
|
+
width: "17",
|
|
12875
|
+
height: "3",
|
|
12876
|
+
rx: "1.5",
|
|
12877
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
|
|
12878
|
+
fill: "#D4D4D8"
|
|
12879
|
+
}
|
|
12880
|
+
),
|
|
12881
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12882
|
+
"rect",
|
|
12883
|
+
{
|
|
12884
|
+
width: "12",
|
|
12885
|
+
height: "3",
|
|
12886
|
+
rx: "1.5",
|
|
12887
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
|
|
12888
|
+
fill: "#D4D4D8"
|
|
12889
|
+
}
|
|
12890
|
+
),
|
|
12891
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12892
|
+
"path",
|
|
12893
|
+
{
|
|
12894
|
+
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",
|
|
12895
|
+
fill: "#A1A1AA"
|
|
12896
|
+
}
|
|
12897
|
+
),
|
|
12898
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12899
|
+
"rect",
|
|
12900
|
+
{
|
|
12901
|
+
width: "17",
|
|
12902
|
+
height: "3",
|
|
12903
|
+
rx: "1.5",
|
|
12904
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
|
|
12905
|
+
fill: "#A1A1AA"
|
|
12906
|
+
}
|
|
12907
|
+
),
|
|
12908
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12909
|
+
"rect",
|
|
12910
|
+
{
|
|
12911
|
+
width: "12",
|
|
12912
|
+
height: "3",
|
|
12913
|
+
rx: "1.5",
|
|
12914
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
12915
|
+
fill: "#A1A1AA"
|
|
12916
|
+
}
|
|
12917
|
+
),
|
|
12918
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12919
|
+
"path",
|
|
12920
|
+
{
|
|
12921
|
+
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",
|
|
12922
|
+
fill: "#52525B"
|
|
12923
|
+
}
|
|
12924
|
+
),
|
|
12925
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12926
|
+
"path",
|
|
12927
|
+
{
|
|
12928
|
+
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
12929
|
+
stroke: "#A1A1AA",
|
|
12930
|
+
strokeWidth: "1.5",
|
|
12931
|
+
strokeLinecap: "round",
|
|
12932
|
+
strokeLinejoin: "round"
|
|
12933
|
+
}
|
|
12934
|
+
) }),
|
|
12935
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12936
|
+
"path",
|
|
12937
|
+
{
|
|
12938
|
+
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
12939
|
+
stroke: "#A1A1AA",
|
|
12940
|
+
strokeWidth: "1.5",
|
|
12941
|
+
strokeLinecap: "round",
|
|
12942
|
+
strokeLinejoin: "round"
|
|
12914
12943
|
}
|
|
12915
|
-
)
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
12919
|
-
PromotionItem,
|
|
12920
|
-
{
|
|
12921
|
-
promotion,
|
|
12922
|
-
orderId: preview.id,
|
|
12923
|
-
isLoading: isPending
|
|
12924
|
-
},
|
|
12925
|
-
promotion.id
|
|
12926
|
-
)) })
|
|
12927
|
-
] }) }),
|
|
12928
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12929
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12930
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12931
|
-
ui.Button,
|
|
12932
|
-
{
|
|
12933
|
-
size: "small",
|
|
12934
|
-
type: "submit",
|
|
12935
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
12936
|
-
children: "Save"
|
|
12937
|
-
}
|
|
12938
|
-
)
|
|
12939
|
-
] }) })
|
|
12940
|
-
] });
|
|
12941
|
-
};
|
|
12942
|
-
const PromotionItem = ({
|
|
12943
|
-
promotion,
|
|
12944
|
-
orderId,
|
|
12945
|
-
isLoading
|
|
12946
|
-
}) => {
|
|
12947
|
-
var _a;
|
|
12948
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
12949
|
-
const onRemove = async () => {
|
|
12950
|
-
removePromotions(
|
|
12951
|
-
{
|
|
12952
|
-
promo_codes: [promotion.code]
|
|
12953
|
-
},
|
|
12954
|
-
{
|
|
12955
|
-
onError: (e) => {
|
|
12956
|
-
ui.toast.error(e.message);
|
|
12957
|
-
}
|
|
12958
|
-
}
|
|
12959
|
-
);
|
|
12960
|
-
};
|
|
12961
|
-
const displayValue = getDisplayValue(promotion);
|
|
12962
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12963
|
-
"div",
|
|
12964
|
-
{
|
|
12965
|
-
className: ui.clx(
|
|
12966
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
12967
|
-
{
|
|
12968
|
-
"animate-pulse": isLoading
|
|
12969
|
-
}
|
|
12970
|
-
),
|
|
12971
|
-
children: [
|
|
12972
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
12973
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
12974
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
12975
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
12976
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
12977
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
12978
|
-
] }),
|
|
12979
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
12980
|
-
] })
|
|
12981
|
-
] }),
|
|
12982
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12983
|
-
ui.IconButton,
|
|
12944
|
+
) }),
|
|
12945
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12946
|
+
"path",
|
|
12984
12947
|
{
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
12948
|
+
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
12949
|
+
stroke: "#A1A1AA",
|
|
12950
|
+
strokeWidth: "1.5",
|
|
12951
|
+
strokeLinecap: "round",
|
|
12952
|
+
strokeLinejoin: "round"
|
|
12991
12953
|
}
|
|
12992
|
-
)
|
|
12954
|
+
) }),
|
|
12955
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12956
|
+
"path",
|
|
12957
|
+
{
|
|
12958
|
+
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
12959
|
+
stroke: "#A1A1AA",
|
|
12960
|
+
strokeWidth: "1.5",
|
|
12961
|
+
strokeLinecap: "round",
|
|
12962
|
+
strokeLinejoin: "round"
|
|
12963
|
+
}
|
|
12964
|
+
) }),
|
|
12965
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12966
|
+
"path",
|
|
12967
|
+
{
|
|
12968
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12969
|
+
stroke: "#A1A1AA",
|
|
12970
|
+
strokeWidth: "1.5",
|
|
12971
|
+
strokeLinecap: "round",
|
|
12972
|
+
strokeLinejoin: "round"
|
|
12973
|
+
}
|
|
12974
|
+
) }),
|
|
12975
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12976
|
+
"path",
|
|
12977
|
+
{
|
|
12978
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12979
|
+
stroke: "#A1A1AA",
|
|
12980
|
+
strokeWidth: "1.5",
|
|
12981
|
+
strokeLinecap: "round",
|
|
12982
|
+
strokeLinejoin: "round"
|
|
12983
|
+
}
|
|
12984
|
+
) }),
|
|
12985
|
+
/* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
12986
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12987
|
+
"rect",
|
|
12988
|
+
{
|
|
12989
|
+
width: "12",
|
|
12990
|
+
height: "12",
|
|
12991
|
+
fill: "white",
|
|
12992
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12993
|
+
}
|
|
12994
|
+
) }),
|
|
12995
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12996
|
+
"rect",
|
|
12997
|
+
{
|
|
12998
|
+
width: "12",
|
|
12999
|
+
height: "12",
|
|
13000
|
+
fill: "white",
|
|
13001
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
13002
|
+
}
|
|
13003
|
+
) }),
|
|
13004
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
13005
|
+
"rect",
|
|
13006
|
+
{
|
|
13007
|
+
width: "12",
|
|
13008
|
+
height: "12",
|
|
13009
|
+
fill: "white",
|
|
13010
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
13011
|
+
}
|
|
13012
|
+
) }),
|
|
13013
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
13014
|
+
"rect",
|
|
13015
|
+
{
|
|
13016
|
+
width: "12",
|
|
13017
|
+
height: "12",
|
|
13018
|
+
fill: "white",
|
|
13019
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
13020
|
+
}
|
|
13021
|
+
) }),
|
|
13022
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
13023
|
+
"rect",
|
|
13024
|
+
{
|
|
13025
|
+
width: "12",
|
|
13026
|
+
height: "12",
|
|
13027
|
+
fill: "white",
|
|
13028
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
13029
|
+
}
|
|
13030
|
+
) }),
|
|
13031
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
13032
|
+
"rect",
|
|
13033
|
+
{
|
|
13034
|
+
width: "12",
|
|
13035
|
+
height: "12",
|
|
13036
|
+
fill: "white",
|
|
13037
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
13038
|
+
}
|
|
13039
|
+
) })
|
|
13040
|
+
] })
|
|
12993
13041
|
]
|
|
12994
|
-
}
|
|
12995
|
-
promotion.id
|
|
13042
|
+
}
|
|
12996
13043
|
);
|
|
12997
13044
|
};
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
13001
|
-
if (!value) {
|
|
13002
|
-
return null;
|
|
13003
|
-
}
|
|
13004
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
13005
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
13006
|
-
if (!currency) {
|
|
13007
|
-
return null;
|
|
13008
|
-
}
|
|
13009
|
-
return getLocaleAmount(value, currency);
|
|
13010
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
13011
|
-
return formatPercentage(value);
|
|
13012
|
-
}
|
|
13013
|
-
return null;
|
|
13014
|
-
}
|
|
13015
|
-
const formatter = new Intl.NumberFormat([], {
|
|
13016
|
-
style: "percent",
|
|
13017
|
-
minimumFractionDigits: 2
|
|
13045
|
+
const schema = objectType({
|
|
13046
|
+
customer_id: stringType().min(1)
|
|
13018
13047
|
});
|
|
13019
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
13020
|
-
let val = value || 0;
|
|
13021
|
-
if (!isPercentageValue) {
|
|
13022
|
-
val = val / 100;
|
|
13023
|
-
}
|
|
13024
|
-
return formatter.format(val);
|
|
13025
|
-
};
|
|
13026
|
-
function getPromotionIds(items, shippingMethods) {
|
|
13027
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
13028
|
-
for (const item of items) {
|
|
13029
|
-
if (item.adjustments) {
|
|
13030
|
-
for (const adjustment of item.adjustments) {
|
|
13031
|
-
if (adjustment.promotion_id) {
|
|
13032
|
-
promotionIds.add(adjustment.promotion_id);
|
|
13033
|
-
}
|
|
13034
|
-
}
|
|
13035
|
-
}
|
|
13036
|
-
}
|
|
13037
|
-
for (const shippingMethod of shippingMethods) {
|
|
13038
|
-
if (shippingMethod.adjustments) {
|
|
13039
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
13040
|
-
if (adjustment.promotion_id) {
|
|
13041
|
-
promotionIds.add(adjustment.promotion_id);
|
|
13042
|
-
}
|
|
13043
|
-
}
|
|
13044
|
-
}
|
|
13045
|
-
}
|
|
13046
|
-
return Array.from(promotionIds);
|
|
13047
|
-
}
|
|
13048
13048
|
const widgetModule = { widgets: [] };
|
|
13049
13049
|
const routeModule = {
|
|
13050
13050
|
routes: [
|
|
@@ -13085,6 +13085,10 @@ const routeModule = {
|
|
|
13085
13085
|
Component: Metadata,
|
|
13086
13086
|
path: "/draft-orders/:id/metadata"
|
|
13087
13087
|
},
|
|
13088
|
+
{
|
|
13089
|
+
Component: Promotions,
|
|
13090
|
+
path: "/draft-orders/:id/promotions"
|
|
13091
|
+
},
|
|
13088
13092
|
{
|
|
13089
13093
|
Component: SalesChannel,
|
|
13090
13094
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13093,17 +13097,13 @@ const routeModule = {
|
|
|
13093
13097
|
Component: ShippingAddress,
|
|
13094
13098
|
path: "/draft-orders/:id/shipping-address"
|
|
13095
13099
|
},
|
|
13096
|
-
{
|
|
13097
|
-
Component: TransferOwnership,
|
|
13098
|
-
path: "/draft-orders/:id/transfer-ownership"
|
|
13099
|
-
},
|
|
13100
13100
|
{
|
|
13101
13101
|
Component: Shipping,
|
|
13102
13102
|
path: "/draft-orders/:id/shipping"
|
|
13103
13103
|
},
|
|
13104
13104
|
{
|
|
13105
|
-
Component:
|
|
13106
|
-
path: "/draft-orders/:id/
|
|
13105
|
+
Component: TransferOwnership,
|
|
13106
|
+
path: "/draft-orders/:id/transfer-ownership"
|
|
13107
13107
|
}
|
|
13108
13108
|
]
|
|
13109
13109
|
}
|