@medusajs/draft-order 2.21.1 → 2.21.2-preview-20260925133948
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 +808 -808
- package/.medusa/server/src/admin/index.mjs +808 -808
- package/package.json +18 -18
|
@@ -3025,7 +3025,7 @@ const LoadingState = () => {
|
|
|
3025
3025
|
};
|
|
3026
3026
|
const CustomerInfo = ({ customer }) => {
|
|
3027
3027
|
const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
|
|
3028
|
-
const fallback = name ? name[0] : customer.email[0];
|
|
3028
|
+
const fallback = name ? name[0] : customer.email?.[0] || "-";
|
|
3029
3029
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 flex-1", children: [
|
|
3030
3030
|
/* @__PURE__ */ jsx(Avatar, { size: "small", fallback, className: "w-6 h-6" }),
|
|
3031
3031
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1 overflow-hidden", children: [
|
|
@@ -7269,88 +7269,46 @@ const customItemSchema = z.object({
|
|
|
7269
7269
|
quantity: z.number(),
|
|
7270
7270
|
unit_price: z.union([z.number(), z.string()])
|
|
7271
7271
|
});
|
|
7272
|
-
const
|
|
7273
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
7274
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
7275
|
-
return /* @__PURE__ */ jsxs(
|
|
7276
|
-
"div",
|
|
7277
|
-
{
|
|
7278
|
-
ref,
|
|
7279
|
-
className: clx(
|
|
7280
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
7281
|
-
className
|
|
7282
|
-
),
|
|
7283
|
-
...props,
|
|
7284
|
-
children: [
|
|
7285
|
-
/* @__PURE__ */ jsx(
|
|
7286
|
-
"div",
|
|
7287
|
-
{
|
|
7288
|
-
role: "presentation",
|
|
7289
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
7290
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
7291
|
-
})
|
|
7292
|
-
}
|
|
7293
|
-
),
|
|
7294
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
7295
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
7296
|
-
labelValue,
|
|
7297
|
-
":"
|
|
7298
|
-
] }),
|
|
7299
|
-
" ",
|
|
7300
|
-
children
|
|
7301
|
-
] })
|
|
7302
|
-
]
|
|
7303
|
-
}
|
|
7304
|
-
);
|
|
7305
|
-
}
|
|
7306
|
-
);
|
|
7307
|
-
InlineTip.displayName = "InlineTip";
|
|
7308
|
-
const MetadataFieldSchema = z.object({
|
|
7309
|
-
key: z.string(),
|
|
7310
|
-
disabled: z.boolean().optional(),
|
|
7311
|
-
value: z.any()
|
|
7312
|
-
});
|
|
7313
|
-
const MetadataSchema = z.object({
|
|
7314
|
-
metadata: z.array(MetadataFieldSchema)
|
|
7315
|
-
});
|
|
7316
|
-
const Metadata = () => {
|
|
7272
|
+
const SalesChannel = () => {
|
|
7317
7273
|
const { id } = useParams();
|
|
7318
|
-
const {
|
|
7319
|
-
|
|
7320
|
-
|
|
7274
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
7275
|
+
id,
|
|
7276
|
+
{
|
|
7277
|
+
fields: "+sales_channel_id"
|
|
7278
|
+
},
|
|
7279
|
+
{
|
|
7280
|
+
enabled: !!id
|
|
7281
|
+
}
|
|
7282
|
+
);
|
|
7321
7283
|
if (isError) {
|
|
7322
7284
|
throw error;
|
|
7323
7285
|
}
|
|
7324
|
-
const
|
|
7286
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
7325
7287
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
7326
7288
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
7327
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
7328
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
7289
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
7290
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
7329
7291
|
] }),
|
|
7330
|
-
|
|
7292
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
7331
7293
|
] });
|
|
7332
7294
|
};
|
|
7333
|
-
const
|
|
7334
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
7335
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
7336
|
-
const { handleSuccess } = useRouteModal();
|
|
7337
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
7338
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
7295
|
+
const SalesChannelForm = ({ order }) => {
|
|
7339
7296
|
const form = useForm({
|
|
7340
7297
|
defaultValues: {
|
|
7341
|
-
|
|
7298
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
7342
7299
|
},
|
|
7343
|
-
resolver: zodResolver(
|
|
7300
|
+
resolver: zodResolver(schema$2)
|
|
7344
7301
|
});
|
|
7345
|
-
const
|
|
7346
|
-
|
|
7302
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
7303
|
+
const { handleSuccess } = useRouteModal();
|
|
7304
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
7347
7305
|
await mutateAsync(
|
|
7348
7306
|
{
|
|
7349
|
-
|
|
7307
|
+
sales_channel_id: data.sales_channel_id
|
|
7350
7308
|
},
|
|
7351
7309
|
{
|
|
7352
7310
|
onSuccess: () => {
|
|
7353
|
-
toast.success("
|
|
7311
|
+
toast.success("Sales channel updated");
|
|
7354
7312
|
handleSuccess();
|
|
7355
7313
|
},
|
|
7356
7314
|
onError: (error) => {
|
|
@@ -7359,365 +7317,133 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
7359
7317
|
}
|
|
7360
7318
|
);
|
|
7361
7319
|
});
|
|
7362
|
-
const { fields, insert, remove } = useFieldArray({
|
|
7363
|
-
control: form.control,
|
|
7364
|
-
name: "metadata"
|
|
7365
|
-
});
|
|
7366
|
-
function deleteRow(index) {
|
|
7367
|
-
remove(index);
|
|
7368
|
-
if (fields.length === 1) {
|
|
7369
|
-
insert(0, {
|
|
7370
|
-
key: "",
|
|
7371
|
-
value: "",
|
|
7372
|
-
disabled: false
|
|
7373
|
-
});
|
|
7374
|
-
}
|
|
7375
|
-
}
|
|
7376
|
-
function insertRow(index, position) {
|
|
7377
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
7378
|
-
key: "",
|
|
7379
|
-
value: "",
|
|
7380
|
-
disabled: false
|
|
7381
|
-
});
|
|
7382
|
-
}
|
|
7383
7320
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
7384
7321
|
KeyboundForm,
|
|
7385
7322
|
{
|
|
7386
|
-
onSubmit: handleSubmit,
|
|
7387
7323
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
7324
|
+
onSubmit,
|
|
7388
7325
|
children: [
|
|
7389
|
-
/* @__PURE__ */
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
7393
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
7394
|
-
] }),
|
|
7395
|
-
fields.map((field, index) => {
|
|
7396
|
-
const isDisabled = field.disabled || false;
|
|
7397
|
-
let placeholder = "-";
|
|
7398
|
-
if (typeof field.value === "object") {
|
|
7399
|
-
placeholder = "{ ... }";
|
|
7400
|
-
}
|
|
7401
|
-
if (Array.isArray(field.value)) {
|
|
7402
|
-
placeholder = "[ ... ]";
|
|
7403
|
-
}
|
|
7404
|
-
return /* @__PURE__ */ jsx(
|
|
7405
|
-
ConditionalTooltip,
|
|
7406
|
-
{
|
|
7407
|
-
showTooltip: isDisabled,
|
|
7408
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
7409
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
7410
|
-
/* @__PURE__ */ jsxs(
|
|
7411
|
-
"div",
|
|
7412
|
-
{
|
|
7413
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
7414
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
7415
|
-
}),
|
|
7416
|
-
children: [
|
|
7417
|
-
/* @__PURE__ */ jsx(
|
|
7418
|
-
Form$2.Field,
|
|
7419
|
-
{
|
|
7420
|
-
control: form.control,
|
|
7421
|
-
name: `metadata.${index}.key`,
|
|
7422
|
-
render: ({ field: field2 }) => {
|
|
7423
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
7424
|
-
GridInput,
|
|
7425
|
-
{
|
|
7426
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
7427
|
-
...field2,
|
|
7428
|
-
disabled: isDisabled,
|
|
7429
|
-
placeholder: "Key"
|
|
7430
|
-
}
|
|
7431
|
-
) }) });
|
|
7432
|
-
}
|
|
7433
|
-
}
|
|
7434
|
-
),
|
|
7435
|
-
/* @__PURE__ */ jsx(
|
|
7436
|
-
Form$2.Field,
|
|
7437
|
-
{
|
|
7438
|
-
control: form.control,
|
|
7439
|
-
name: `metadata.${index}.value`,
|
|
7440
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
7441
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
7442
|
-
GridInput,
|
|
7443
|
-
{
|
|
7444
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
7445
|
-
...field2,
|
|
7446
|
-
value: isDisabled ? placeholder : value,
|
|
7447
|
-
disabled: isDisabled,
|
|
7448
|
-
placeholder: "Value"
|
|
7449
|
-
}
|
|
7450
|
-
) }) });
|
|
7451
|
-
}
|
|
7452
|
-
}
|
|
7453
|
-
)
|
|
7454
|
-
]
|
|
7455
|
-
}
|
|
7456
|
-
),
|
|
7457
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
7458
|
-
/* @__PURE__ */ jsx(
|
|
7459
|
-
DropdownMenu.Trigger,
|
|
7460
|
-
{
|
|
7461
|
-
className: clx(
|
|
7462
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
7463
|
-
{
|
|
7464
|
-
hidden: isDisabled
|
|
7465
|
-
}
|
|
7466
|
-
),
|
|
7467
|
-
disabled: isDisabled,
|
|
7468
|
-
asChild: true,
|
|
7469
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
7470
|
-
}
|
|
7471
|
-
),
|
|
7472
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
7473
|
-
/* @__PURE__ */ jsxs(
|
|
7474
|
-
DropdownMenu.Item,
|
|
7475
|
-
{
|
|
7476
|
-
className: "gap-x-2",
|
|
7477
|
-
onClick: () => insertRow(index, "above"),
|
|
7478
|
-
children: [
|
|
7479
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
7480
|
-
"Insert row above"
|
|
7481
|
-
]
|
|
7482
|
-
}
|
|
7483
|
-
),
|
|
7484
|
-
/* @__PURE__ */ jsxs(
|
|
7485
|
-
DropdownMenu.Item,
|
|
7486
|
-
{
|
|
7487
|
-
className: "gap-x-2",
|
|
7488
|
-
onClick: () => insertRow(index, "below"),
|
|
7489
|
-
children: [
|
|
7490
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
7491
|
-
"Insert row below"
|
|
7492
|
-
]
|
|
7493
|
-
}
|
|
7494
|
-
),
|
|
7495
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
7496
|
-
/* @__PURE__ */ jsxs(
|
|
7497
|
-
DropdownMenu.Item,
|
|
7498
|
-
{
|
|
7499
|
-
className: "gap-x-2",
|
|
7500
|
-
onClick: () => deleteRow(index),
|
|
7501
|
-
children: [
|
|
7502
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
7503
|
-
"Delete row"
|
|
7504
|
-
]
|
|
7505
|
-
}
|
|
7506
|
-
)
|
|
7507
|
-
] })
|
|
7508
|
-
] })
|
|
7509
|
-
] })
|
|
7510
|
-
},
|
|
7511
|
-
field.id
|
|
7512
|
-
);
|
|
7513
|
-
})
|
|
7514
|
-
] }),
|
|
7515
|
-
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
7516
|
-
] }),
|
|
7517
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7518
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
7326
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
7327
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7328
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7519
7329
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7520
7330
|
] }) })
|
|
7521
7331
|
]
|
|
7522
7332
|
}
|
|
7523
7333
|
) });
|
|
7524
7334
|
};
|
|
7525
|
-
const
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
)
|
|
7536
|
-
}
|
|
7537
|
-
|
|
7538
|
-
});
|
|
7539
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
7540
|
-
const PlaceholderInner = () => {
|
|
7541
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
7542
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
7543
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7544
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
7545
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
7546
|
-
] }) })
|
|
7547
|
-
] });
|
|
7548
|
-
};
|
|
7549
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
7550
|
-
function getDefaultValues(metadata) {
|
|
7551
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
7552
|
-
return [
|
|
7553
|
-
{
|
|
7554
|
-
key: "",
|
|
7555
|
-
value: "",
|
|
7556
|
-
disabled: false
|
|
7557
|
-
}
|
|
7558
|
-
];
|
|
7559
|
-
}
|
|
7560
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
7561
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
7562
|
-
return {
|
|
7563
|
-
key,
|
|
7564
|
-
value,
|
|
7565
|
-
disabled: true
|
|
7566
|
-
};
|
|
7567
|
-
}
|
|
7568
|
-
let stringValue = value;
|
|
7569
|
-
if (typeof value !== "string") {
|
|
7570
|
-
stringValue = JSON.stringify(value);
|
|
7571
|
-
}
|
|
7572
|
-
return {
|
|
7573
|
-
key,
|
|
7574
|
-
value: stringValue,
|
|
7575
|
-
original_key: key
|
|
7576
|
-
};
|
|
7335
|
+
const SalesChannelField = ({ control, order }) => {
|
|
7336
|
+
const salesChannels = useComboboxData({
|
|
7337
|
+
queryFn: async (params) => {
|
|
7338
|
+
return await sdk.admin.salesChannel.list(params);
|
|
7339
|
+
},
|
|
7340
|
+
queryKey: ["sales-channels"],
|
|
7341
|
+
getOptions: (data) => {
|
|
7342
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
7343
|
+
label: salesChannel.name,
|
|
7344
|
+
value: salesChannel.id
|
|
7345
|
+
}));
|
|
7346
|
+
},
|
|
7347
|
+
defaultValue: order.sales_channel_id || void 0
|
|
7577
7348
|
});
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
update[key] = true;
|
|
7601
|
-
} else if (value === "false") {
|
|
7602
|
-
update[key] = false;
|
|
7603
|
-
} else {
|
|
7604
|
-
const parsedNumber = parseFloat(value);
|
|
7605
|
-
if (!isNaN(parsedNumber)) {
|
|
7606
|
-
update[key] = parsedNumber;
|
|
7607
|
-
} else {
|
|
7608
|
-
update[key] = value;
|
|
7349
|
+
return /* @__PURE__ */ jsx(
|
|
7350
|
+
Form$2.Field,
|
|
7351
|
+
{
|
|
7352
|
+
control,
|
|
7353
|
+
name: "sales_channel_id",
|
|
7354
|
+
render: ({ field }) => {
|
|
7355
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
7356
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
7357
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
7358
|
+
Combobox,
|
|
7359
|
+
{
|
|
7360
|
+
options: salesChannels.options,
|
|
7361
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
7362
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
7363
|
+
searchValue: salesChannels.searchValue,
|
|
7364
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
7365
|
+
placeholder: "Select sales channel",
|
|
7366
|
+
...field
|
|
7367
|
+
}
|
|
7368
|
+
) }),
|
|
7369
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
7370
|
+
] });
|
|
7609
7371
|
}
|
|
7610
7372
|
}
|
|
7611
|
-
});
|
|
7612
|
-
return update;
|
|
7613
|
-
}
|
|
7614
|
-
function getHasUneditableRows(metadata) {
|
|
7615
|
-
if (!metadata) {
|
|
7616
|
-
return false;
|
|
7617
|
-
}
|
|
7618
|
-
return Object.values(metadata).some(
|
|
7619
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
7620
7373
|
);
|
|
7621
|
-
}
|
|
7622
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
7623
|
-
const promotionsQueryKeys = {
|
|
7624
|
-
list: (query2) => [
|
|
7625
|
-
PROMOTION_QUERY_KEY,
|
|
7626
|
-
query2 ? query2 : void 0
|
|
7627
|
-
],
|
|
7628
|
-
detail: (id, query2) => [
|
|
7629
|
-
PROMOTION_QUERY_KEY,
|
|
7630
|
-
id,
|
|
7631
|
-
query2 ? query2 : void 0
|
|
7632
|
-
]
|
|
7633
|
-
};
|
|
7634
|
-
const usePromotions = (query2, options) => {
|
|
7635
|
-
const { data, ...rest } = useQuery({
|
|
7636
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
7637
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
7638
|
-
...options
|
|
7639
|
-
});
|
|
7640
|
-
return { ...data, ...rest };
|
|
7641
7374
|
};
|
|
7642
|
-
const
|
|
7375
|
+
const schema$2 = z.object({
|
|
7376
|
+
sales_channel_id: z.string().min(1)
|
|
7377
|
+
});
|
|
7378
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
7379
|
+
const Shipping = () => {
|
|
7643
7380
|
const { id } = useParams();
|
|
7381
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
7382
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
7383
|
+
});
|
|
7644
7384
|
const {
|
|
7645
7385
|
order: preview,
|
|
7386
|
+
isPending: isPreviewPending,
|
|
7646
7387
|
isError: isPreviewError,
|
|
7647
7388
|
error: previewError
|
|
7648
|
-
} = useOrderPreview(id
|
|
7389
|
+
} = useOrderPreview(id);
|
|
7649
7390
|
useInitiateOrderEdit({ preview });
|
|
7650
7391
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
7392
|
+
if (isError) {
|
|
7393
|
+
throw error;
|
|
7394
|
+
}
|
|
7651
7395
|
if (isPreviewError) {
|
|
7652
7396
|
throw previewError;
|
|
7653
7397
|
}
|
|
7654
|
-
const
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7398
|
+
const orderHasItems = (order?.items?.length || 0) > 0;
|
|
7399
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
7400
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
7401
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
7402
|
+
/* @__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: [
|
|
7403
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
7404
|
+
/* @__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." }) })
|
|
7405
|
+
] }) }) }),
|
|
7406
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
7407
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
7408
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
7409
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
7410
|
+
] }) });
|
|
7659
7411
|
};
|
|
7660
|
-
const
|
|
7661
|
-
const {
|
|
7412
|
+
const ShippingForm = ({ preview, order }) => {
|
|
7413
|
+
const { setIsOpen } = useStackedModal();
|
|
7662
7414
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
7663
|
-
const [
|
|
7664
|
-
const
|
|
7665
|
-
const {
|
|
7666
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
7667
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
7415
|
+
const [data, setData] = useState(null);
|
|
7416
|
+
const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
|
|
7417
|
+
const { shipping_options } = useShippingOptions(
|
|
7668
7418
|
{
|
|
7669
|
-
id:
|
|
7419
|
+
id: appliedShippingOptionIds,
|
|
7420
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
7670
7421
|
},
|
|
7671
7422
|
{
|
|
7672
|
-
enabled:
|
|
7423
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
7673
7424
|
}
|
|
7674
7425
|
);
|
|
7675
|
-
const
|
|
7676
|
-
|
|
7677
|
-
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
return data.promotions.map((promotion) => ({
|
|
7687
|
-
label: promotion.code,
|
|
7688
|
-
value: promotion.code
|
|
7689
|
-
}));
|
|
7690
|
-
}
|
|
7691
|
-
});
|
|
7692
|
-
const add = async (value) => {
|
|
7693
|
-
if (!value) {
|
|
7694
|
-
return;
|
|
7695
|
-
}
|
|
7696
|
-
addPromotions(
|
|
7697
|
-
{
|
|
7698
|
-
promo_codes: [value]
|
|
7699
|
-
},
|
|
7700
|
-
{
|
|
7701
|
-
onError: (e) => {
|
|
7702
|
-
toast.error(e.message);
|
|
7703
|
-
comboboxData.onSearchValueChange("");
|
|
7704
|
-
setComboboxValue("");
|
|
7705
|
-
},
|
|
7706
|
-
onSuccess: () => {
|
|
7707
|
-
comboboxData.onSearchValueChange("");
|
|
7708
|
-
setComboboxValue("");
|
|
7709
|
-
}
|
|
7710
|
-
}
|
|
7711
|
-
);
|
|
7712
|
-
};
|
|
7426
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
7427
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
7428
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
7429
|
+
profiles.set(profile.id, profile);
|
|
7430
|
+
});
|
|
7431
|
+
shipping_options?.forEach((option) => {
|
|
7432
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
7433
|
+
});
|
|
7434
|
+
return Array.from(profiles.values());
|
|
7435
|
+
}, [order.items, shipping_options]);
|
|
7436
|
+
const { handleSuccess } = useRouteModal();
|
|
7713
7437
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
7714
|
-
const { mutateAsync: requestOrderEdit } =
|
|
7438
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
7439
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
7440
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
7715
7441
|
const onSubmit = async () => {
|
|
7716
7442
|
setIsSubmitting(true);
|
|
7717
7443
|
let requestSucceeded = false;
|
|
7718
7444
|
await requestOrderEdit(void 0, {
|
|
7719
7445
|
onError: (e) => {
|
|
7720
|
-
toast.error(e.message);
|
|
7446
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
7721
7447
|
},
|
|
7722
7448
|
onSuccess: () => {
|
|
7723
7449
|
requestSucceeded = true;
|
|
@@ -7729,358 +7455,7 @@ const PromotionForm = ({ preview }) => {
|
|
|
7729
7455
|
}
|
|
7730
7456
|
await confirmOrderEdit(void 0, {
|
|
7731
7457
|
onError: (e) => {
|
|
7732
|
-
toast.error(e.message);
|
|
7733
|
-
},
|
|
7734
|
-
onSuccess: () => {
|
|
7735
|
-
handleSuccess();
|
|
7736
|
-
},
|
|
7737
|
-
onSettled: () => {
|
|
7738
|
-
setIsSubmitting(false);
|
|
7739
|
-
}
|
|
7740
|
-
});
|
|
7741
|
-
};
|
|
7742
|
-
if (isError) {
|
|
7743
|
-
throw error;
|
|
7744
|
-
}
|
|
7745
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
7746
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
7747
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
7748
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
7749
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
7750
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
7751
|
-
] }),
|
|
7752
|
-
/* @__PURE__ */ jsx(
|
|
7753
|
-
Combobox,
|
|
7754
|
-
{
|
|
7755
|
-
id: "promotion-combobox",
|
|
7756
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
7757
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
7758
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
7759
|
-
options: comboboxData.options,
|
|
7760
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
7761
|
-
searchValue: comboboxData.searchValue,
|
|
7762
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
7763
|
-
onChange: add,
|
|
7764
|
-
value: comboboxValue
|
|
7765
|
-
}
|
|
7766
|
-
)
|
|
7767
|
-
] }),
|
|
7768
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
7769
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
|
|
7770
|
-
PromotionItem,
|
|
7771
|
-
{
|
|
7772
|
-
promotion,
|
|
7773
|
-
orderId: preview.id,
|
|
7774
|
-
isLoading: isPending
|
|
7775
|
-
},
|
|
7776
|
-
promotion.id
|
|
7777
|
-
)) })
|
|
7778
|
-
] }) }),
|
|
7779
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7780
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7781
|
-
/* @__PURE__ */ jsx(
|
|
7782
|
-
Button,
|
|
7783
|
-
{
|
|
7784
|
-
size: "small",
|
|
7785
|
-
type: "submit",
|
|
7786
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
7787
|
-
children: "Save"
|
|
7788
|
-
}
|
|
7789
|
-
)
|
|
7790
|
-
] }) })
|
|
7791
|
-
] });
|
|
7792
|
-
};
|
|
7793
|
-
const PromotionItem = ({
|
|
7794
|
-
promotion,
|
|
7795
|
-
orderId,
|
|
7796
|
-
isLoading
|
|
7797
|
-
}) => {
|
|
7798
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
7799
|
-
const onRemove = async () => {
|
|
7800
|
-
removePromotions(
|
|
7801
|
-
{
|
|
7802
|
-
promo_codes: [promotion.code]
|
|
7803
|
-
},
|
|
7804
|
-
{
|
|
7805
|
-
onError: (e) => {
|
|
7806
|
-
toast.error(e.message);
|
|
7807
|
-
}
|
|
7808
|
-
}
|
|
7809
|
-
);
|
|
7810
|
-
};
|
|
7811
|
-
const displayValue = getDisplayValue(promotion);
|
|
7812
|
-
return /* @__PURE__ */ jsxs(
|
|
7813
|
-
"div",
|
|
7814
|
-
{
|
|
7815
|
-
className: clx(
|
|
7816
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
7817
|
-
{
|
|
7818
|
-
"animate-pulse": isLoading
|
|
7819
|
-
}
|
|
7820
|
-
),
|
|
7821
|
-
children: [
|
|
7822
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
7823
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
7824
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
7825
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
7826
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
7827
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
7828
|
-
] }),
|
|
7829
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
7830
|
-
] })
|
|
7831
|
-
] }),
|
|
7832
|
-
/* @__PURE__ */ jsx(
|
|
7833
|
-
IconButton,
|
|
7834
|
-
{
|
|
7835
|
-
size: "small",
|
|
7836
|
-
type: "button",
|
|
7837
|
-
variant: "transparent",
|
|
7838
|
-
onClick: onRemove,
|
|
7839
|
-
isLoading: isPending || isLoading,
|
|
7840
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
7841
|
-
}
|
|
7842
|
-
)
|
|
7843
|
-
]
|
|
7844
|
-
},
|
|
7845
|
-
promotion.id
|
|
7846
|
-
);
|
|
7847
|
-
};
|
|
7848
|
-
function getDisplayValue(promotion) {
|
|
7849
|
-
const value = promotion.application_method?.value;
|
|
7850
|
-
if (!value) {
|
|
7851
|
-
return null;
|
|
7852
|
-
}
|
|
7853
|
-
if (promotion.application_method?.type === "fixed") {
|
|
7854
|
-
const currency = promotion.application_method?.currency_code;
|
|
7855
|
-
if (!currency) {
|
|
7856
|
-
return null;
|
|
7857
|
-
}
|
|
7858
|
-
return getLocaleAmount(value, currency);
|
|
7859
|
-
} else if (promotion.application_method?.type === "percentage") {
|
|
7860
|
-
return formatPercentage(value);
|
|
7861
|
-
}
|
|
7862
|
-
return null;
|
|
7863
|
-
}
|
|
7864
|
-
const formatter = new Intl.NumberFormat([], {
|
|
7865
|
-
style: "percent",
|
|
7866
|
-
minimumFractionDigits: 2
|
|
7867
|
-
});
|
|
7868
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
7869
|
-
let val = value || 0;
|
|
7870
|
-
if (!isPercentageValue) {
|
|
7871
|
-
val = val / 100;
|
|
7872
|
-
}
|
|
7873
|
-
return formatter.format(val);
|
|
7874
|
-
};
|
|
7875
|
-
function getPromotionIds(items, shippingMethods) {
|
|
7876
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
7877
|
-
for (const item of items) {
|
|
7878
|
-
if (item.adjustments) {
|
|
7879
|
-
for (const adjustment of item.adjustments) {
|
|
7880
|
-
if (adjustment.promotion_id) {
|
|
7881
|
-
promotionIds.add(adjustment.promotion_id);
|
|
7882
|
-
}
|
|
7883
|
-
}
|
|
7884
|
-
}
|
|
7885
|
-
}
|
|
7886
|
-
for (const shippingMethod of shippingMethods) {
|
|
7887
|
-
if (shippingMethod.adjustments) {
|
|
7888
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
7889
|
-
if (adjustment.promotion_id) {
|
|
7890
|
-
promotionIds.add(adjustment.promotion_id);
|
|
7891
|
-
}
|
|
7892
|
-
}
|
|
7893
|
-
}
|
|
7894
|
-
}
|
|
7895
|
-
return Array.from(promotionIds);
|
|
7896
|
-
}
|
|
7897
|
-
const SalesChannel = () => {
|
|
7898
|
-
const { id } = useParams();
|
|
7899
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
7900
|
-
id,
|
|
7901
|
-
{
|
|
7902
|
-
fields: "+sales_channel_id"
|
|
7903
|
-
},
|
|
7904
|
-
{
|
|
7905
|
-
enabled: !!id
|
|
7906
|
-
}
|
|
7907
|
-
);
|
|
7908
|
-
if (isError) {
|
|
7909
|
-
throw error;
|
|
7910
|
-
}
|
|
7911
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
7912
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
7913
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
7914
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
7915
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
7916
|
-
] }),
|
|
7917
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
7918
|
-
] });
|
|
7919
|
-
};
|
|
7920
|
-
const SalesChannelForm = ({ order }) => {
|
|
7921
|
-
const form = useForm({
|
|
7922
|
-
defaultValues: {
|
|
7923
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
7924
|
-
},
|
|
7925
|
-
resolver: zodResolver(schema$2)
|
|
7926
|
-
});
|
|
7927
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
7928
|
-
const { handleSuccess } = useRouteModal();
|
|
7929
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
7930
|
-
await mutateAsync(
|
|
7931
|
-
{
|
|
7932
|
-
sales_channel_id: data.sales_channel_id
|
|
7933
|
-
},
|
|
7934
|
-
{
|
|
7935
|
-
onSuccess: () => {
|
|
7936
|
-
toast.success("Sales channel updated");
|
|
7937
|
-
handleSuccess();
|
|
7938
|
-
},
|
|
7939
|
-
onError: (error) => {
|
|
7940
|
-
toast.error(error.message);
|
|
7941
|
-
}
|
|
7942
|
-
}
|
|
7943
|
-
);
|
|
7944
|
-
});
|
|
7945
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
7946
|
-
KeyboundForm,
|
|
7947
|
-
{
|
|
7948
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
7949
|
-
onSubmit,
|
|
7950
|
-
children: [
|
|
7951
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
7952
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7953
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7954
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7955
|
-
] }) })
|
|
7956
|
-
]
|
|
7957
|
-
}
|
|
7958
|
-
) });
|
|
7959
|
-
};
|
|
7960
|
-
const SalesChannelField = ({ control, order }) => {
|
|
7961
|
-
const salesChannels = useComboboxData({
|
|
7962
|
-
queryFn: async (params) => {
|
|
7963
|
-
return await sdk.admin.salesChannel.list(params);
|
|
7964
|
-
},
|
|
7965
|
-
queryKey: ["sales-channels"],
|
|
7966
|
-
getOptions: (data) => {
|
|
7967
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
7968
|
-
label: salesChannel.name,
|
|
7969
|
-
value: salesChannel.id
|
|
7970
|
-
}));
|
|
7971
|
-
},
|
|
7972
|
-
defaultValue: order.sales_channel_id || void 0
|
|
7973
|
-
});
|
|
7974
|
-
return /* @__PURE__ */ jsx(
|
|
7975
|
-
Form$2.Field,
|
|
7976
|
-
{
|
|
7977
|
-
control,
|
|
7978
|
-
name: "sales_channel_id",
|
|
7979
|
-
render: ({ field }) => {
|
|
7980
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
7981
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
7982
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
7983
|
-
Combobox,
|
|
7984
|
-
{
|
|
7985
|
-
options: salesChannels.options,
|
|
7986
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
7987
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
7988
|
-
searchValue: salesChannels.searchValue,
|
|
7989
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
7990
|
-
placeholder: "Select sales channel",
|
|
7991
|
-
...field
|
|
7992
|
-
}
|
|
7993
|
-
) }),
|
|
7994
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
7995
|
-
] });
|
|
7996
|
-
}
|
|
7997
|
-
}
|
|
7998
|
-
);
|
|
7999
|
-
};
|
|
8000
|
-
const schema$2 = z.object({
|
|
8001
|
-
sales_channel_id: z.string().min(1)
|
|
8002
|
-
});
|
|
8003
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
8004
|
-
const Shipping = () => {
|
|
8005
|
-
const { id } = useParams();
|
|
8006
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
8007
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
8008
|
-
});
|
|
8009
|
-
const {
|
|
8010
|
-
order: preview,
|
|
8011
|
-
isPending: isPreviewPending,
|
|
8012
|
-
isError: isPreviewError,
|
|
8013
|
-
error: previewError
|
|
8014
|
-
} = useOrderPreview(id);
|
|
8015
|
-
useInitiateOrderEdit({ preview });
|
|
8016
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
8017
|
-
if (isError) {
|
|
8018
|
-
throw error;
|
|
8019
|
-
}
|
|
8020
|
-
if (isPreviewError) {
|
|
8021
|
-
throw previewError;
|
|
8022
|
-
}
|
|
8023
|
-
const orderHasItems = (order?.items?.length || 0) > 0;
|
|
8024
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
8025
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
8026
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
8027
|
-
/* @__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: [
|
|
8028
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
8029
|
-
/* @__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." }) })
|
|
8030
|
-
] }) }) }),
|
|
8031
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
8032
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
8033
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
8034
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
8035
|
-
] }) });
|
|
8036
|
-
};
|
|
8037
|
-
const ShippingForm = ({ preview, order }) => {
|
|
8038
|
-
const { setIsOpen } = useStackedModal();
|
|
8039
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
8040
|
-
const [data, setData] = useState(null);
|
|
8041
|
-
const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
|
|
8042
|
-
const { shipping_options } = useShippingOptions(
|
|
8043
|
-
{
|
|
8044
|
-
id: appliedShippingOptionIds,
|
|
8045
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
8046
|
-
},
|
|
8047
|
-
{
|
|
8048
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
8049
|
-
}
|
|
8050
|
-
);
|
|
8051
|
-
const uniqueShippingProfiles = useMemo(() => {
|
|
8052
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
8053
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
8054
|
-
profiles.set(profile.id, profile);
|
|
8055
|
-
});
|
|
8056
|
-
shipping_options?.forEach((option) => {
|
|
8057
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
8058
|
-
});
|
|
8059
|
-
return Array.from(profiles.values());
|
|
8060
|
-
}, [order.items, shipping_options]);
|
|
8061
|
-
const { handleSuccess } = useRouteModal();
|
|
8062
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
8063
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
8064
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
8065
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
8066
|
-
const onSubmit = async () => {
|
|
8067
|
-
setIsSubmitting(true);
|
|
8068
|
-
let requestSucceeded = false;
|
|
8069
|
-
await requestOrderEdit(void 0, {
|
|
8070
|
-
onError: (e) => {
|
|
8071
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
8072
|
-
},
|
|
8073
|
-
onSuccess: () => {
|
|
8074
|
-
requestSucceeded = true;
|
|
8075
|
-
}
|
|
8076
|
-
});
|
|
8077
|
-
if (!requestSucceeded) {
|
|
8078
|
-
setIsSubmitting(false);
|
|
8079
|
-
return;
|
|
8080
|
-
}
|
|
8081
|
-
await confirmOrderEdit(void 0, {
|
|
8082
|
-
onError: (e) => {
|
|
8083
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
7458
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
8084
7459
|
},
|
|
8085
7460
|
onSuccess: () => {
|
|
8086
7461
|
handleSuccess();
|
|
@@ -9401,76 +8776,701 @@ const Illustration = () => {
|
|
|
9401
8776
|
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
9402
8777
|
"path",
|
|
9403
8778
|
{
|
|
9404
|
-
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
9405
|
-
stroke: "#A1A1AA",
|
|
9406
|
-
strokeWidth: "1.5",
|
|
9407
|
-
strokeLinecap: "round",
|
|
9408
|
-
strokeLinejoin: "round"
|
|
8779
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
8780
|
+
stroke: "#A1A1AA",
|
|
8781
|
+
strokeWidth: "1.5",
|
|
8782
|
+
strokeLinecap: "round",
|
|
8783
|
+
strokeLinejoin: "round"
|
|
8784
|
+
}
|
|
8785
|
+
) }),
|
|
8786
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
8787
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
8788
|
+
"rect",
|
|
8789
|
+
{
|
|
8790
|
+
width: "12",
|
|
8791
|
+
height: "12",
|
|
8792
|
+
fill: "white",
|
|
8793
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
8794
|
+
}
|
|
8795
|
+
) }),
|
|
8796
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
8797
|
+
"rect",
|
|
8798
|
+
{
|
|
8799
|
+
width: "12",
|
|
8800
|
+
height: "12",
|
|
8801
|
+
fill: "white",
|
|
8802
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
8803
|
+
}
|
|
8804
|
+
) }),
|
|
8805
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
8806
|
+
"rect",
|
|
8807
|
+
{
|
|
8808
|
+
width: "12",
|
|
8809
|
+
height: "12",
|
|
8810
|
+
fill: "white",
|
|
8811
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
8812
|
+
}
|
|
8813
|
+
) }),
|
|
8814
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
8815
|
+
"rect",
|
|
8816
|
+
{
|
|
8817
|
+
width: "12",
|
|
8818
|
+
height: "12",
|
|
8819
|
+
fill: "white",
|
|
8820
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
8821
|
+
}
|
|
8822
|
+
) }),
|
|
8823
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
8824
|
+
"rect",
|
|
8825
|
+
{
|
|
8826
|
+
width: "12",
|
|
8827
|
+
height: "12",
|
|
8828
|
+
fill: "white",
|
|
8829
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
8830
|
+
}
|
|
8831
|
+
) }),
|
|
8832
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
8833
|
+
"rect",
|
|
8834
|
+
{
|
|
8835
|
+
width: "12",
|
|
8836
|
+
height: "12",
|
|
8837
|
+
fill: "white",
|
|
8838
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
8839
|
+
}
|
|
8840
|
+
) })
|
|
8841
|
+
] })
|
|
8842
|
+
]
|
|
8843
|
+
}
|
|
8844
|
+
);
|
|
8845
|
+
};
|
|
8846
|
+
const schema = z.object({
|
|
8847
|
+
customer_id: z.string().min(1)
|
|
8848
|
+
});
|
|
8849
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
8850
|
+
const promotionsQueryKeys = {
|
|
8851
|
+
list: (query2) => [
|
|
8852
|
+
PROMOTION_QUERY_KEY,
|
|
8853
|
+
query2 ? query2 : void 0
|
|
8854
|
+
],
|
|
8855
|
+
detail: (id, query2) => [
|
|
8856
|
+
PROMOTION_QUERY_KEY,
|
|
8857
|
+
id,
|
|
8858
|
+
query2 ? query2 : void 0
|
|
8859
|
+
]
|
|
8860
|
+
};
|
|
8861
|
+
const usePromotions = (query2, options) => {
|
|
8862
|
+
const { data, ...rest } = useQuery({
|
|
8863
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
8864
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
8865
|
+
...options
|
|
8866
|
+
});
|
|
8867
|
+
return { ...data, ...rest };
|
|
8868
|
+
};
|
|
8869
|
+
const Promotions = () => {
|
|
8870
|
+
const { id } = useParams();
|
|
8871
|
+
const {
|
|
8872
|
+
order: preview,
|
|
8873
|
+
isError: isPreviewError,
|
|
8874
|
+
error: previewError
|
|
8875
|
+
} = useOrderPreview(id, void 0);
|
|
8876
|
+
useInitiateOrderEdit({ preview });
|
|
8877
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
8878
|
+
if (isPreviewError) {
|
|
8879
|
+
throw previewError;
|
|
8880
|
+
}
|
|
8881
|
+
const isReady = !!preview;
|
|
8882
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
8883
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
8884
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
8885
|
+
] });
|
|
8886
|
+
};
|
|
8887
|
+
const PromotionForm = ({ preview }) => {
|
|
8888
|
+
const { items, shipping_methods } = preview;
|
|
8889
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
8890
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
8891
|
+
const { handleSuccess } = useRouteModal();
|
|
8892
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
8893
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
8894
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
8895
|
+
{
|
|
8896
|
+
id: promoIds
|
|
8897
|
+
},
|
|
8898
|
+
{
|
|
8899
|
+
enabled: !!promoIds.length
|
|
8900
|
+
}
|
|
8901
|
+
);
|
|
8902
|
+
const comboboxData = useComboboxData({
|
|
8903
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
8904
|
+
queryFn: async (params) => {
|
|
8905
|
+
return await sdk.admin.promotion.list({
|
|
8906
|
+
...params,
|
|
8907
|
+
id: {
|
|
8908
|
+
$nin: promoIds
|
|
8909
|
+
}
|
|
8910
|
+
});
|
|
8911
|
+
},
|
|
8912
|
+
getOptions: (data) => {
|
|
8913
|
+
return data.promotions.map((promotion) => ({
|
|
8914
|
+
label: promotion.code,
|
|
8915
|
+
value: promotion.code
|
|
8916
|
+
}));
|
|
8917
|
+
}
|
|
8918
|
+
});
|
|
8919
|
+
const add = async (value) => {
|
|
8920
|
+
if (!value) {
|
|
8921
|
+
return;
|
|
8922
|
+
}
|
|
8923
|
+
addPromotions(
|
|
8924
|
+
{
|
|
8925
|
+
promo_codes: [value]
|
|
8926
|
+
},
|
|
8927
|
+
{
|
|
8928
|
+
onError: (e) => {
|
|
8929
|
+
toast.error(e.message);
|
|
8930
|
+
comboboxData.onSearchValueChange("");
|
|
8931
|
+
setComboboxValue("");
|
|
8932
|
+
},
|
|
8933
|
+
onSuccess: () => {
|
|
8934
|
+
comboboxData.onSearchValueChange("");
|
|
8935
|
+
setComboboxValue("");
|
|
8936
|
+
}
|
|
8937
|
+
}
|
|
8938
|
+
);
|
|
8939
|
+
};
|
|
8940
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
8941
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
8942
|
+
const onSubmit = async () => {
|
|
8943
|
+
setIsSubmitting(true);
|
|
8944
|
+
let requestSucceeded = false;
|
|
8945
|
+
await requestOrderEdit(void 0, {
|
|
8946
|
+
onError: (e) => {
|
|
8947
|
+
toast.error(e.message);
|
|
8948
|
+
},
|
|
8949
|
+
onSuccess: () => {
|
|
8950
|
+
requestSucceeded = true;
|
|
8951
|
+
}
|
|
8952
|
+
});
|
|
8953
|
+
if (!requestSucceeded) {
|
|
8954
|
+
setIsSubmitting(false);
|
|
8955
|
+
return;
|
|
8956
|
+
}
|
|
8957
|
+
await confirmOrderEdit(void 0, {
|
|
8958
|
+
onError: (e) => {
|
|
8959
|
+
toast.error(e.message);
|
|
8960
|
+
},
|
|
8961
|
+
onSuccess: () => {
|
|
8962
|
+
handleSuccess();
|
|
8963
|
+
},
|
|
8964
|
+
onSettled: () => {
|
|
8965
|
+
setIsSubmitting(false);
|
|
8966
|
+
}
|
|
8967
|
+
});
|
|
8968
|
+
};
|
|
8969
|
+
if (isError) {
|
|
8970
|
+
throw error;
|
|
8971
|
+
}
|
|
8972
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
8973
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
8974
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
8975
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
8976
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
8977
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
8978
|
+
] }),
|
|
8979
|
+
/* @__PURE__ */ jsx(
|
|
8980
|
+
Combobox,
|
|
8981
|
+
{
|
|
8982
|
+
id: "promotion-combobox",
|
|
8983
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
8984
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
8985
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
8986
|
+
options: comboboxData.options,
|
|
8987
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
8988
|
+
searchValue: comboboxData.searchValue,
|
|
8989
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
8990
|
+
onChange: add,
|
|
8991
|
+
value: comboboxValue
|
|
8992
|
+
}
|
|
8993
|
+
)
|
|
8994
|
+
] }),
|
|
8995
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
8996
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
|
|
8997
|
+
PromotionItem,
|
|
8998
|
+
{
|
|
8999
|
+
promotion,
|
|
9000
|
+
orderId: preview.id,
|
|
9001
|
+
isLoading: isPending
|
|
9002
|
+
},
|
|
9003
|
+
promotion.id
|
|
9004
|
+
)) })
|
|
9005
|
+
] }) }),
|
|
9006
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9007
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9008
|
+
/* @__PURE__ */ jsx(
|
|
9009
|
+
Button,
|
|
9010
|
+
{
|
|
9011
|
+
size: "small",
|
|
9012
|
+
type: "submit",
|
|
9013
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
9014
|
+
children: "Save"
|
|
9015
|
+
}
|
|
9016
|
+
)
|
|
9017
|
+
] }) })
|
|
9018
|
+
] });
|
|
9019
|
+
};
|
|
9020
|
+
const PromotionItem = ({
|
|
9021
|
+
promotion,
|
|
9022
|
+
orderId,
|
|
9023
|
+
isLoading
|
|
9024
|
+
}) => {
|
|
9025
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
9026
|
+
const onRemove = async () => {
|
|
9027
|
+
removePromotions(
|
|
9028
|
+
{
|
|
9029
|
+
promo_codes: [promotion.code]
|
|
9030
|
+
},
|
|
9031
|
+
{
|
|
9032
|
+
onError: (e) => {
|
|
9033
|
+
toast.error(e.message);
|
|
9034
|
+
}
|
|
9035
|
+
}
|
|
9036
|
+
);
|
|
9037
|
+
};
|
|
9038
|
+
const displayValue = getDisplayValue(promotion);
|
|
9039
|
+
return /* @__PURE__ */ jsxs(
|
|
9040
|
+
"div",
|
|
9041
|
+
{
|
|
9042
|
+
className: clx(
|
|
9043
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
9044
|
+
{
|
|
9045
|
+
"animate-pulse": isLoading
|
|
9046
|
+
}
|
|
9047
|
+
),
|
|
9048
|
+
children: [
|
|
9049
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
9050
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
9051
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
9052
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
9053
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
9054
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
9055
|
+
] }),
|
|
9056
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
9057
|
+
] })
|
|
9058
|
+
] }),
|
|
9059
|
+
/* @__PURE__ */ jsx(
|
|
9060
|
+
IconButton,
|
|
9061
|
+
{
|
|
9062
|
+
size: "small",
|
|
9063
|
+
type: "button",
|
|
9064
|
+
variant: "transparent",
|
|
9065
|
+
onClick: onRemove,
|
|
9066
|
+
isLoading: isPending || isLoading,
|
|
9067
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
9409
9068
|
}
|
|
9410
|
-
)
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9069
|
+
)
|
|
9070
|
+
]
|
|
9071
|
+
},
|
|
9072
|
+
promotion.id
|
|
9073
|
+
);
|
|
9074
|
+
};
|
|
9075
|
+
function getDisplayValue(promotion) {
|
|
9076
|
+
const value = promotion.application_method?.value;
|
|
9077
|
+
if (!value) {
|
|
9078
|
+
return null;
|
|
9079
|
+
}
|
|
9080
|
+
if (promotion.application_method?.type === "fixed") {
|
|
9081
|
+
const currency = promotion.application_method?.currency_code;
|
|
9082
|
+
if (!currency) {
|
|
9083
|
+
return null;
|
|
9084
|
+
}
|
|
9085
|
+
return getLocaleAmount(value, currency);
|
|
9086
|
+
} else if (promotion.application_method?.type === "percentage") {
|
|
9087
|
+
return formatPercentage(value);
|
|
9088
|
+
}
|
|
9089
|
+
return null;
|
|
9090
|
+
}
|
|
9091
|
+
const formatter = new Intl.NumberFormat([], {
|
|
9092
|
+
style: "percent",
|
|
9093
|
+
minimumFractionDigits: 2
|
|
9094
|
+
});
|
|
9095
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
9096
|
+
let val = value || 0;
|
|
9097
|
+
if (!isPercentageValue) {
|
|
9098
|
+
val = val / 100;
|
|
9099
|
+
}
|
|
9100
|
+
return formatter.format(val);
|
|
9101
|
+
};
|
|
9102
|
+
function getPromotionIds(items, shippingMethods) {
|
|
9103
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
9104
|
+
for (const item of items) {
|
|
9105
|
+
if (item.adjustments) {
|
|
9106
|
+
for (const adjustment of item.adjustments) {
|
|
9107
|
+
if (adjustment.promotion_id) {
|
|
9108
|
+
promotionIds.add(adjustment.promotion_id);
|
|
9109
|
+
}
|
|
9110
|
+
}
|
|
9111
|
+
}
|
|
9112
|
+
}
|
|
9113
|
+
for (const shippingMethod of shippingMethods) {
|
|
9114
|
+
if (shippingMethod.adjustments) {
|
|
9115
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
9116
|
+
if (adjustment.promotion_id) {
|
|
9117
|
+
promotionIds.add(adjustment.promotion_id);
|
|
9118
|
+
}
|
|
9119
|
+
}
|
|
9120
|
+
}
|
|
9121
|
+
}
|
|
9122
|
+
return Array.from(promotionIds);
|
|
9123
|
+
}
|
|
9124
|
+
const InlineTip = forwardRef(
|
|
9125
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9126
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9127
|
+
return /* @__PURE__ */ jsxs(
|
|
9128
|
+
"div",
|
|
9129
|
+
{
|
|
9130
|
+
ref,
|
|
9131
|
+
className: clx(
|
|
9132
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9133
|
+
className
|
|
9134
|
+
),
|
|
9135
|
+
...props,
|
|
9136
|
+
children: [
|
|
9137
|
+
/* @__PURE__ */ jsx(
|
|
9138
|
+
"div",
|
|
9459
9139
|
{
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9140
|
+
role: "presentation",
|
|
9141
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9142
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9143
|
+
})
|
|
9464
9144
|
}
|
|
9465
|
-
)
|
|
9466
|
-
|
|
9145
|
+
),
|
|
9146
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
9147
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9148
|
+
labelValue,
|
|
9149
|
+
":"
|
|
9150
|
+
] }),
|
|
9151
|
+
" ",
|
|
9152
|
+
children
|
|
9153
|
+
] })
|
|
9154
|
+
]
|
|
9155
|
+
}
|
|
9156
|
+
);
|
|
9157
|
+
}
|
|
9158
|
+
);
|
|
9159
|
+
InlineTip.displayName = "InlineTip";
|
|
9160
|
+
const MetadataFieldSchema = z.object({
|
|
9161
|
+
key: z.string(),
|
|
9162
|
+
disabled: z.boolean().optional(),
|
|
9163
|
+
value: z.any()
|
|
9164
|
+
});
|
|
9165
|
+
const MetadataSchema = z.object({
|
|
9166
|
+
metadata: z.array(MetadataFieldSchema)
|
|
9167
|
+
});
|
|
9168
|
+
const Metadata = () => {
|
|
9169
|
+
const { id } = useParams();
|
|
9170
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9171
|
+
fields: "metadata"
|
|
9172
|
+
});
|
|
9173
|
+
if (isError) {
|
|
9174
|
+
throw error;
|
|
9175
|
+
}
|
|
9176
|
+
const isReady = !isPending && !!order;
|
|
9177
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9178
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9179
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
9180
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
9181
|
+
] }),
|
|
9182
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
|
|
9183
|
+
] });
|
|
9184
|
+
};
|
|
9185
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
9186
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9187
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
9188
|
+
const { handleSuccess } = useRouteModal();
|
|
9189
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9190
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
9191
|
+
const form = useForm({
|
|
9192
|
+
defaultValues: {
|
|
9193
|
+
metadata: getDefaultValues(metadata)
|
|
9194
|
+
},
|
|
9195
|
+
resolver: zodResolver(MetadataSchema)
|
|
9196
|
+
});
|
|
9197
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
9198
|
+
const parsedData = parseValues(data);
|
|
9199
|
+
await mutateAsync(
|
|
9200
|
+
{
|
|
9201
|
+
metadata: parsedData
|
|
9202
|
+
},
|
|
9203
|
+
{
|
|
9204
|
+
onSuccess: () => {
|
|
9205
|
+
toast.success("Metadata updated");
|
|
9206
|
+
handleSuccess();
|
|
9207
|
+
},
|
|
9208
|
+
onError: (error) => {
|
|
9209
|
+
toast.error(error.message);
|
|
9210
|
+
}
|
|
9211
|
+
}
|
|
9212
|
+
);
|
|
9213
|
+
});
|
|
9214
|
+
const { fields, insert, remove } = useFieldArray({
|
|
9215
|
+
control: form.control,
|
|
9216
|
+
name: "metadata"
|
|
9217
|
+
});
|
|
9218
|
+
function deleteRow(index) {
|
|
9219
|
+
remove(index);
|
|
9220
|
+
if (fields.length === 1) {
|
|
9221
|
+
insert(0, {
|
|
9222
|
+
key: "",
|
|
9223
|
+
value: "",
|
|
9224
|
+
disabled: false
|
|
9225
|
+
});
|
|
9226
|
+
}
|
|
9227
|
+
}
|
|
9228
|
+
function insertRow(index, position) {
|
|
9229
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
9230
|
+
key: "",
|
|
9231
|
+
value: "",
|
|
9232
|
+
disabled: false
|
|
9233
|
+
});
|
|
9234
|
+
}
|
|
9235
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9236
|
+
KeyboundForm,
|
|
9237
|
+
{
|
|
9238
|
+
onSubmit: handleSubmit,
|
|
9239
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9240
|
+
children: [
|
|
9241
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
9242
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
9243
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
9244
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
9245
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
9246
|
+
] }),
|
|
9247
|
+
fields.map((field, index) => {
|
|
9248
|
+
const isDisabled = field.disabled || false;
|
|
9249
|
+
let placeholder = "-";
|
|
9250
|
+
if (typeof field.value === "object") {
|
|
9251
|
+
placeholder = "{ ... }";
|
|
9252
|
+
}
|
|
9253
|
+
if (Array.isArray(field.value)) {
|
|
9254
|
+
placeholder = "[ ... ]";
|
|
9255
|
+
}
|
|
9256
|
+
return /* @__PURE__ */ jsx(
|
|
9257
|
+
ConditionalTooltip,
|
|
9258
|
+
{
|
|
9259
|
+
showTooltip: isDisabled,
|
|
9260
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
9261
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
9262
|
+
/* @__PURE__ */ jsxs(
|
|
9263
|
+
"div",
|
|
9264
|
+
{
|
|
9265
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
9266
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9267
|
+
}),
|
|
9268
|
+
children: [
|
|
9269
|
+
/* @__PURE__ */ jsx(
|
|
9270
|
+
Form$2.Field,
|
|
9271
|
+
{
|
|
9272
|
+
control: form.control,
|
|
9273
|
+
name: `metadata.${index}.key`,
|
|
9274
|
+
render: ({ field: field2 }) => {
|
|
9275
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9276
|
+
GridInput,
|
|
9277
|
+
{
|
|
9278
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9279
|
+
...field2,
|
|
9280
|
+
disabled: isDisabled,
|
|
9281
|
+
placeholder: "Key"
|
|
9282
|
+
}
|
|
9283
|
+
) }) });
|
|
9284
|
+
}
|
|
9285
|
+
}
|
|
9286
|
+
),
|
|
9287
|
+
/* @__PURE__ */ jsx(
|
|
9288
|
+
Form$2.Field,
|
|
9289
|
+
{
|
|
9290
|
+
control: form.control,
|
|
9291
|
+
name: `metadata.${index}.value`,
|
|
9292
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
9293
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9294
|
+
GridInput,
|
|
9295
|
+
{
|
|
9296
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
9297
|
+
...field2,
|
|
9298
|
+
value: isDisabled ? placeholder : value,
|
|
9299
|
+
disabled: isDisabled,
|
|
9300
|
+
placeholder: "Value"
|
|
9301
|
+
}
|
|
9302
|
+
) }) });
|
|
9303
|
+
}
|
|
9304
|
+
}
|
|
9305
|
+
)
|
|
9306
|
+
]
|
|
9307
|
+
}
|
|
9308
|
+
),
|
|
9309
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
9310
|
+
/* @__PURE__ */ jsx(
|
|
9311
|
+
DropdownMenu.Trigger,
|
|
9312
|
+
{
|
|
9313
|
+
className: clx(
|
|
9314
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
9315
|
+
{
|
|
9316
|
+
hidden: isDisabled
|
|
9317
|
+
}
|
|
9318
|
+
),
|
|
9319
|
+
disabled: isDisabled,
|
|
9320
|
+
asChild: true,
|
|
9321
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
9322
|
+
}
|
|
9323
|
+
),
|
|
9324
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
9325
|
+
/* @__PURE__ */ jsxs(
|
|
9326
|
+
DropdownMenu.Item,
|
|
9327
|
+
{
|
|
9328
|
+
className: "gap-x-2",
|
|
9329
|
+
onClick: () => insertRow(index, "above"),
|
|
9330
|
+
children: [
|
|
9331
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
9332
|
+
"Insert row above"
|
|
9333
|
+
]
|
|
9334
|
+
}
|
|
9335
|
+
),
|
|
9336
|
+
/* @__PURE__ */ jsxs(
|
|
9337
|
+
DropdownMenu.Item,
|
|
9338
|
+
{
|
|
9339
|
+
className: "gap-x-2",
|
|
9340
|
+
onClick: () => insertRow(index, "below"),
|
|
9341
|
+
children: [
|
|
9342
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
9343
|
+
"Insert row below"
|
|
9344
|
+
]
|
|
9345
|
+
}
|
|
9346
|
+
),
|
|
9347
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
9348
|
+
/* @__PURE__ */ jsxs(
|
|
9349
|
+
DropdownMenu.Item,
|
|
9350
|
+
{
|
|
9351
|
+
className: "gap-x-2",
|
|
9352
|
+
onClick: () => deleteRow(index),
|
|
9353
|
+
children: [
|
|
9354
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
9355
|
+
"Delete row"
|
|
9356
|
+
]
|
|
9357
|
+
}
|
|
9358
|
+
)
|
|
9359
|
+
] })
|
|
9360
|
+
] })
|
|
9361
|
+
] })
|
|
9362
|
+
},
|
|
9363
|
+
field.id
|
|
9364
|
+
);
|
|
9365
|
+
})
|
|
9366
|
+
] }),
|
|
9367
|
+
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
9368
|
+
] }),
|
|
9369
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9370
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
9371
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9372
|
+
] }) })
|
|
9467
9373
|
]
|
|
9468
9374
|
}
|
|
9469
|
-
);
|
|
9375
|
+
) });
|
|
9470
9376
|
};
|
|
9471
|
-
const
|
|
9472
|
-
|
|
9377
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
9378
|
+
return /* @__PURE__ */ jsx(
|
|
9379
|
+
"input",
|
|
9380
|
+
{
|
|
9381
|
+
ref,
|
|
9382
|
+
...props,
|
|
9383
|
+
autoComplete: "off",
|
|
9384
|
+
className: clx(
|
|
9385
|
+
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
9386
|
+
className
|
|
9387
|
+
)
|
|
9388
|
+
}
|
|
9389
|
+
);
|
|
9473
9390
|
});
|
|
9391
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
9392
|
+
const PlaceholderInner = () => {
|
|
9393
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
9394
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
9395
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9396
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
9397
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
9398
|
+
] }) })
|
|
9399
|
+
] });
|
|
9400
|
+
};
|
|
9401
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
9402
|
+
function getDefaultValues(metadata) {
|
|
9403
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
9404
|
+
return [
|
|
9405
|
+
{
|
|
9406
|
+
key: "",
|
|
9407
|
+
value: "",
|
|
9408
|
+
disabled: false
|
|
9409
|
+
}
|
|
9410
|
+
];
|
|
9411
|
+
}
|
|
9412
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
9413
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
9414
|
+
return {
|
|
9415
|
+
key,
|
|
9416
|
+
value,
|
|
9417
|
+
disabled: true
|
|
9418
|
+
};
|
|
9419
|
+
}
|
|
9420
|
+
let stringValue = value;
|
|
9421
|
+
if (typeof value !== "string") {
|
|
9422
|
+
stringValue = JSON.stringify(value);
|
|
9423
|
+
}
|
|
9424
|
+
return {
|
|
9425
|
+
key,
|
|
9426
|
+
value: stringValue,
|
|
9427
|
+
original_key: key
|
|
9428
|
+
};
|
|
9429
|
+
});
|
|
9430
|
+
}
|
|
9431
|
+
function parseValues(values) {
|
|
9432
|
+
const metadata = values.metadata;
|
|
9433
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
9434
|
+
if (isEmpty) {
|
|
9435
|
+
return null;
|
|
9436
|
+
}
|
|
9437
|
+
const update = {};
|
|
9438
|
+
metadata.forEach((field) => {
|
|
9439
|
+
let key = field.key;
|
|
9440
|
+
let value = field.value;
|
|
9441
|
+
const disabled = field.disabled;
|
|
9442
|
+
if (!key || !value) {
|
|
9443
|
+
return;
|
|
9444
|
+
}
|
|
9445
|
+
if (disabled) {
|
|
9446
|
+
update[key] = value;
|
|
9447
|
+
return;
|
|
9448
|
+
}
|
|
9449
|
+
key = key.trim();
|
|
9450
|
+
value = value.trim();
|
|
9451
|
+
if (value === "true") {
|
|
9452
|
+
update[key] = true;
|
|
9453
|
+
} else if (value === "false") {
|
|
9454
|
+
update[key] = false;
|
|
9455
|
+
} else {
|
|
9456
|
+
const parsedNumber = parseFloat(value);
|
|
9457
|
+
if (!isNaN(parsedNumber)) {
|
|
9458
|
+
update[key] = parsedNumber;
|
|
9459
|
+
} else {
|
|
9460
|
+
update[key] = value;
|
|
9461
|
+
}
|
|
9462
|
+
}
|
|
9463
|
+
});
|
|
9464
|
+
return update;
|
|
9465
|
+
}
|
|
9466
|
+
function getHasUneditableRows(metadata) {
|
|
9467
|
+
if (!metadata) {
|
|
9468
|
+
return false;
|
|
9469
|
+
}
|
|
9470
|
+
return Object.values(metadata).some(
|
|
9471
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
9472
|
+
);
|
|
9473
|
+
}
|
|
9474
9474
|
const widgetModule = { widgets: [] };
|
|
9475
9475
|
const routeModule = {
|
|
9476
9476
|
routes: [
|
|
@@ -9507,14 +9507,6 @@ const routeModule = {
|
|
|
9507
9507
|
Component: Items,
|
|
9508
9508
|
path: "/draft-orders/:id/items"
|
|
9509
9509
|
},
|
|
9510
|
-
{
|
|
9511
|
-
Component: Metadata,
|
|
9512
|
-
path: "/draft-orders/:id/metadata"
|
|
9513
|
-
},
|
|
9514
|
-
{
|
|
9515
|
-
Component: Promotions,
|
|
9516
|
-
path: "/draft-orders/:id/promotions"
|
|
9517
|
-
},
|
|
9518
9510
|
{
|
|
9519
9511
|
Component: SalesChannel,
|
|
9520
9512
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -9530,6 +9522,14 @@ const routeModule = {
|
|
|
9530
9522
|
{
|
|
9531
9523
|
Component: TransferOwnership,
|
|
9532
9524
|
path: "/draft-orders/:id/transfer-ownership"
|
|
9525
|
+
},
|
|
9526
|
+
{
|
|
9527
|
+
Component: Promotions,
|
|
9528
|
+
path: "/draft-orders/:id/promotions"
|
|
9529
|
+
},
|
|
9530
|
+
{
|
|
9531
|
+
Component: Metadata,
|
|
9532
|
+
path: "/draft-orders/:id/metadata"
|
|
9533
9533
|
}
|
|
9534
9534
|
]
|
|
9535
9535
|
}
|