@medusajs/draft-order 2.21.2 → 2.22.0-preview-20261002101246
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 +472 -472
- package/.medusa/server/src/admin/index.mjs +472 -472
- package/package.json +19 -19
|
@@ -7276,356 +7276,6 @@ const customItemSchema = zod.z.object({
|
|
|
7276
7276
|
quantity: zod.z.number(),
|
|
7277
7277
|
unit_price: zod.z.union([zod.z.number(), zod.z.string()])
|
|
7278
7278
|
});
|
|
7279
|
-
const InlineTip = React.forwardRef(
|
|
7280
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
7281
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
7282
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7283
|
-
"div",
|
|
7284
|
-
{
|
|
7285
|
-
ref,
|
|
7286
|
-
className: ui.clx(
|
|
7287
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
7288
|
-
className
|
|
7289
|
-
),
|
|
7290
|
-
...props,
|
|
7291
|
-
children: [
|
|
7292
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7293
|
-
"div",
|
|
7294
|
-
{
|
|
7295
|
-
role: "presentation",
|
|
7296
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
7297
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
7298
|
-
})
|
|
7299
|
-
}
|
|
7300
|
-
),
|
|
7301
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
7302
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
7303
|
-
labelValue,
|
|
7304
|
-
":"
|
|
7305
|
-
] }),
|
|
7306
|
-
" ",
|
|
7307
|
-
children
|
|
7308
|
-
] })
|
|
7309
|
-
]
|
|
7310
|
-
}
|
|
7311
|
-
);
|
|
7312
|
-
}
|
|
7313
|
-
);
|
|
7314
|
-
InlineTip.displayName = "InlineTip";
|
|
7315
|
-
const MetadataFieldSchema = zod.z.object({
|
|
7316
|
-
key: zod.z.string(),
|
|
7317
|
-
disabled: zod.z.boolean().optional(),
|
|
7318
|
-
value: zod.z.any()
|
|
7319
|
-
});
|
|
7320
|
-
const MetadataSchema = zod.z.object({
|
|
7321
|
-
metadata: zod.z.array(MetadataFieldSchema)
|
|
7322
|
-
});
|
|
7323
|
-
const Metadata = () => {
|
|
7324
|
-
const { id } = reactRouterDom.useParams();
|
|
7325
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
7326
|
-
fields: "metadata"
|
|
7327
|
-
});
|
|
7328
|
-
if (isError) {
|
|
7329
|
-
throw error;
|
|
7330
|
-
}
|
|
7331
|
-
const isReady = !isPending && !!order;
|
|
7332
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7333
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
7334
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
7335
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
7336
|
-
] }),
|
|
7337
|
-
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
|
|
7338
|
-
] });
|
|
7339
|
-
};
|
|
7340
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
7341
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
7342
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
7343
|
-
const { handleSuccess } = useRouteModal();
|
|
7344
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
7345
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
7346
|
-
const form = reactHookForm.useForm({
|
|
7347
|
-
defaultValues: {
|
|
7348
|
-
metadata: getDefaultValues(metadata)
|
|
7349
|
-
},
|
|
7350
|
-
resolver: zod$1.zodResolver(MetadataSchema)
|
|
7351
|
-
});
|
|
7352
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
7353
|
-
const parsedData = parseValues(data);
|
|
7354
|
-
await mutateAsync(
|
|
7355
|
-
{
|
|
7356
|
-
metadata: parsedData
|
|
7357
|
-
},
|
|
7358
|
-
{
|
|
7359
|
-
onSuccess: () => {
|
|
7360
|
-
ui.toast.success("Metadata updated");
|
|
7361
|
-
handleSuccess();
|
|
7362
|
-
},
|
|
7363
|
-
onError: (error) => {
|
|
7364
|
-
ui.toast.error(error.message);
|
|
7365
|
-
}
|
|
7366
|
-
}
|
|
7367
|
-
);
|
|
7368
|
-
});
|
|
7369
|
-
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
7370
|
-
control: form.control,
|
|
7371
|
-
name: "metadata"
|
|
7372
|
-
});
|
|
7373
|
-
function deleteRow(index) {
|
|
7374
|
-
remove(index);
|
|
7375
|
-
if (fields.length === 1) {
|
|
7376
|
-
insert(0, {
|
|
7377
|
-
key: "",
|
|
7378
|
-
value: "",
|
|
7379
|
-
disabled: false
|
|
7380
|
-
});
|
|
7381
|
-
}
|
|
7382
|
-
}
|
|
7383
|
-
function insertRow(index, position) {
|
|
7384
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
7385
|
-
key: "",
|
|
7386
|
-
value: "",
|
|
7387
|
-
disabled: false
|
|
7388
|
-
});
|
|
7389
|
-
}
|
|
7390
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7391
|
-
KeyboundForm,
|
|
7392
|
-
{
|
|
7393
|
-
onSubmit: handleSubmit,
|
|
7394
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
7395
|
-
children: [
|
|
7396
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
7397
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
7398
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
7399
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
7400
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
7401
|
-
] }),
|
|
7402
|
-
fields.map((field, index) => {
|
|
7403
|
-
const isDisabled = field.disabled || false;
|
|
7404
|
-
let placeholder = "-";
|
|
7405
|
-
if (typeof field.value === "object") {
|
|
7406
|
-
placeholder = "{ ... }";
|
|
7407
|
-
}
|
|
7408
|
-
if (Array.isArray(field.value)) {
|
|
7409
|
-
placeholder = "[ ... ]";
|
|
7410
|
-
}
|
|
7411
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7412
|
-
ConditionalTooltip,
|
|
7413
|
-
{
|
|
7414
|
-
showTooltip: isDisabled,
|
|
7415
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
7416
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
7417
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7418
|
-
"div",
|
|
7419
|
-
{
|
|
7420
|
-
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
7421
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
7422
|
-
}),
|
|
7423
|
-
children: [
|
|
7424
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7425
|
-
Form$2.Field,
|
|
7426
|
-
{
|
|
7427
|
-
control: form.control,
|
|
7428
|
-
name: `metadata.${index}.key`,
|
|
7429
|
-
render: ({ field: field2 }) => {
|
|
7430
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7431
|
-
GridInput,
|
|
7432
|
-
{
|
|
7433
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
7434
|
-
...field2,
|
|
7435
|
-
disabled: isDisabled,
|
|
7436
|
-
placeholder: "Key"
|
|
7437
|
-
}
|
|
7438
|
-
) }) });
|
|
7439
|
-
}
|
|
7440
|
-
}
|
|
7441
|
-
),
|
|
7442
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7443
|
-
Form$2.Field,
|
|
7444
|
-
{
|
|
7445
|
-
control: form.control,
|
|
7446
|
-
name: `metadata.${index}.value`,
|
|
7447
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
7448
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7449
|
-
GridInput,
|
|
7450
|
-
{
|
|
7451
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
7452
|
-
...field2,
|
|
7453
|
-
value: isDisabled ? placeholder : value,
|
|
7454
|
-
disabled: isDisabled,
|
|
7455
|
-
placeholder: "Value"
|
|
7456
|
-
}
|
|
7457
|
-
) }) });
|
|
7458
|
-
}
|
|
7459
|
-
}
|
|
7460
|
-
)
|
|
7461
|
-
]
|
|
7462
|
-
}
|
|
7463
|
-
),
|
|
7464
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
7465
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7466
|
-
ui.DropdownMenu.Trigger,
|
|
7467
|
-
{
|
|
7468
|
-
className: ui.clx(
|
|
7469
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
7470
|
-
{
|
|
7471
|
-
hidden: isDisabled
|
|
7472
|
-
}
|
|
7473
|
-
),
|
|
7474
|
-
disabled: isDisabled,
|
|
7475
|
-
asChild: true,
|
|
7476
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
7477
|
-
}
|
|
7478
|
-
),
|
|
7479
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
7480
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7481
|
-
ui.DropdownMenu.Item,
|
|
7482
|
-
{
|
|
7483
|
-
className: "gap-x-2",
|
|
7484
|
-
onClick: () => insertRow(index, "above"),
|
|
7485
|
-
children: [
|
|
7486
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
7487
|
-
"Insert row above"
|
|
7488
|
-
]
|
|
7489
|
-
}
|
|
7490
|
-
),
|
|
7491
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7492
|
-
ui.DropdownMenu.Item,
|
|
7493
|
-
{
|
|
7494
|
-
className: "gap-x-2",
|
|
7495
|
-
onClick: () => insertRow(index, "below"),
|
|
7496
|
-
children: [
|
|
7497
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
7498
|
-
"Insert row below"
|
|
7499
|
-
]
|
|
7500
|
-
}
|
|
7501
|
-
),
|
|
7502
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
7503
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7504
|
-
ui.DropdownMenu.Item,
|
|
7505
|
-
{
|
|
7506
|
-
className: "gap-x-2",
|
|
7507
|
-
onClick: () => deleteRow(index),
|
|
7508
|
-
children: [
|
|
7509
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
7510
|
-
"Delete row"
|
|
7511
|
-
]
|
|
7512
|
-
}
|
|
7513
|
-
)
|
|
7514
|
-
] })
|
|
7515
|
-
] })
|
|
7516
|
-
] })
|
|
7517
|
-
},
|
|
7518
|
-
field.id
|
|
7519
|
-
);
|
|
7520
|
-
})
|
|
7521
|
-
] }),
|
|
7522
|
-
hasUneditableRows && /* @__PURE__ */ jsxRuntime.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." })
|
|
7523
|
-
] }),
|
|
7524
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7525
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
7526
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7527
|
-
] }) })
|
|
7528
|
-
]
|
|
7529
|
-
}
|
|
7530
|
-
) });
|
|
7531
|
-
};
|
|
7532
|
-
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
7533
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7534
|
-
"input",
|
|
7535
|
-
{
|
|
7536
|
-
ref,
|
|
7537
|
-
...props,
|
|
7538
|
-
autoComplete: "off",
|
|
7539
|
-
className: ui.clx(
|
|
7540
|
-
"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",
|
|
7541
|
-
className
|
|
7542
|
-
)
|
|
7543
|
-
}
|
|
7544
|
-
);
|
|
7545
|
-
});
|
|
7546
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
7547
|
-
const PlaceholderInner = () => {
|
|
7548
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
7549
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
7550
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7551
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
7552
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
7553
|
-
] }) })
|
|
7554
|
-
] });
|
|
7555
|
-
};
|
|
7556
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
7557
|
-
function getDefaultValues(metadata) {
|
|
7558
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
7559
|
-
return [
|
|
7560
|
-
{
|
|
7561
|
-
key: "",
|
|
7562
|
-
value: "",
|
|
7563
|
-
disabled: false
|
|
7564
|
-
}
|
|
7565
|
-
];
|
|
7566
|
-
}
|
|
7567
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
7568
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
7569
|
-
return {
|
|
7570
|
-
key,
|
|
7571
|
-
value,
|
|
7572
|
-
disabled: true
|
|
7573
|
-
};
|
|
7574
|
-
}
|
|
7575
|
-
let stringValue = value;
|
|
7576
|
-
if (typeof value !== "string") {
|
|
7577
|
-
stringValue = JSON.stringify(value);
|
|
7578
|
-
}
|
|
7579
|
-
return {
|
|
7580
|
-
key,
|
|
7581
|
-
value: stringValue,
|
|
7582
|
-
original_key: key
|
|
7583
|
-
};
|
|
7584
|
-
});
|
|
7585
|
-
}
|
|
7586
|
-
function parseValues(values) {
|
|
7587
|
-
const metadata = values.metadata;
|
|
7588
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
7589
|
-
if (isEmpty) {
|
|
7590
|
-
return null;
|
|
7591
|
-
}
|
|
7592
|
-
const update = {};
|
|
7593
|
-
metadata.forEach((field) => {
|
|
7594
|
-
let key = field.key;
|
|
7595
|
-
let value = field.value;
|
|
7596
|
-
const disabled = field.disabled;
|
|
7597
|
-
if (!key || !value) {
|
|
7598
|
-
return;
|
|
7599
|
-
}
|
|
7600
|
-
if (disabled) {
|
|
7601
|
-
update[key] = value;
|
|
7602
|
-
return;
|
|
7603
|
-
}
|
|
7604
|
-
key = key.trim();
|
|
7605
|
-
value = value.trim();
|
|
7606
|
-
if (value === "true") {
|
|
7607
|
-
update[key] = true;
|
|
7608
|
-
} else if (value === "false") {
|
|
7609
|
-
update[key] = false;
|
|
7610
|
-
} else {
|
|
7611
|
-
const parsedNumber = parseFloat(value);
|
|
7612
|
-
if (!isNaN(parsedNumber)) {
|
|
7613
|
-
update[key] = parsedNumber;
|
|
7614
|
-
} else {
|
|
7615
|
-
update[key] = value;
|
|
7616
|
-
}
|
|
7617
|
-
}
|
|
7618
|
-
});
|
|
7619
|
-
return update;
|
|
7620
|
-
}
|
|
7621
|
-
function getHasUneditableRows(metadata) {
|
|
7622
|
-
if (!metadata) {
|
|
7623
|
-
return false;
|
|
7624
|
-
}
|
|
7625
|
-
return Object.values(metadata).some(
|
|
7626
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
7627
|
-
);
|
|
7628
|
-
}
|
|
7629
7279
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
7630
7280
|
const promotionsQueryKeys = {
|
|
7631
7281
|
list: (query2) => [
|
|
@@ -7898,9 +7548,115 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
7898
7548
|
}
|
|
7899
7549
|
}
|
|
7900
7550
|
}
|
|
7901
|
-
}
|
|
7902
|
-
return Array.from(promotionIds);
|
|
7903
|
-
}
|
|
7551
|
+
}
|
|
7552
|
+
return Array.from(promotionIds);
|
|
7553
|
+
}
|
|
7554
|
+
const SalesChannel = () => {
|
|
7555
|
+
const { id } = reactRouterDom.useParams();
|
|
7556
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
7557
|
+
id,
|
|
7558
|
+
{
|
|
7559
|
+
fields: "+sales_channel_id"
|
|
7560
|
+
},
|
|
7561
|
+
{
|
|
7562
|
+
enabled: !!id
|
|
7563
|
+
}
|
|
7564
|
+
);
|
|
7565
|
+
if (isError) {
|
|
7566
|
+
throw error;
|
|
7567
|
+
}
|
|
7568
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
7569
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7570
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
7571
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
7572
|
+
/* @__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" }) })
|
|
7573
|
+
] }),
|
|
7574
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
7575
|
+
] });
|
|
7576
|
+
};
|
|
7577
|
+
const SalesChannelForm = ({ order }) => {
|
|
7578
|
+
const form = reactHookForm.useForm({
|
|
7579
|
+
defaultValues: {
|
|
7580
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
7581
|
+
},
|
|
7582
|
+
resolver: zod$1.zodResolver(schema$2)
|
|
7583
|
+
});
|
|
7584
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
7585
|
+
const { handleSuccess } = useRouteModal();
|
|
7586
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
7587
|
+
await mutateAsync(
|
|
7588
|
+
{
|
|
7589
|
+
sales_channel_id: data.sales_channel_id
|
|
7590
|
+
},
|
|
7591
|
+
{
|
|
7592
|
+
onSuccess: () => {
|
|
7593
|
+
ui.toast.success("Sales channel updated");
|
|
7594
|
+
handleSuccess();
|
|
7595
|
+
},
|
|
7596
|
+
onError: (error) => {
|
|
7597
|
+
ui.toast.error(error.message);
|
|
7598
|
+
}
|
|
7599
|
+
}
|
|
7600
|
+
);
|
|
7601
|
+
});
|
|
7602
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7603
|
+
KeyboundForm,
|
|
7604
|
+
{
|
|
7605
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
7606
|
+
onSubmit,
|
|
7607
|
+
children: [
|
|
7608
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
7609
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7610
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7611
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7612
|
+
] }) })
|
|
7613
|
+
]
|
|
7614
|
+
}
|
|
7615
|
+
) });
|
|
7616
|
+
};
|
|
7617
|
+
const SalesChannelField = ({ control, order }) => {
|
|
7618
|
+
const salesChannels = useComboboxData({
|
|
7619
|
+
queryFn: async (params) => {
|
|
7620
|
+
return await sdk.admin.salesChannel.list(params);
|
|
7621
|
+
},
|
|
7622
|
+
queryKey: ["sales-channels"],
|
|
7623
|
+
getOptions: (data) => {
|
|
7624
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
7625
|
+
label: salesChannel.name,
|
|
7626
|
+
value: salesChannel.id
|
|
7627
|
+
}));
|
|
7628
|
+
},
|
|
7629
|
+
defaultValue: order.sales_channel_id || void 0
|
|
7630
|
+
});
|
|
7631
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7632
|
+
Form$2.Field,
|
|
7633
|
+
{
|
|
7634
|
+
control,
|
|
7635
|
+
name: "sales_channel_id",
|
|
7636
|
+
render: ({ field }) => {
|
|
7637
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
7638
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
7639
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7640
|
+
Combobox,
|
|
7641
|
+
{
|
|
7642
|
+
options: salesChannels.options,
|
|
7643
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
7644
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
7645
|
+
searchValue: salesChannels.searchValue,
|
|
7646
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
7647
|
+
placeholder: "Select sales channel",
|
|
7648
|
+
...field
|
|
7649
|
+
}
|
|
7650
|
+
) }),
|
|
7651
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
7652
|
+
] });
|
|
7653
|
+
}
|
|
7654
|
+
}
|
|
7655
|
+
);
|
|
7656
|
+
};
|
|
7657
|
+
const schema$2 = zod.z.object({
|
|
7658
|
+
sales_channel_id: zod.z.string().min(1)
|
|
7659
|
+
});
|
|
7904
7660
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
7905
7661
|
const Shipping = () => {
|
|
7906
7662
|
const { id } = reactRouterDom.useParams();
|
|
@@ -8726,7 +8482,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
8726
8482
|
postal_code: order.shipping_address?.postal_code ?? "",
|
|
8727
8483
|
phone: order.shipping_address?.phone ?? ""
|
|
8728
8484
|
},
|
|
8729
|
-
resolver: zod$1.zodResolver(schema$
|
|
8485
|
+
resolver: zod$1.zodResolver(schema$1)
|
|
8730
8486
|
});
|
|
8731
8487
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
8732
8488
|
const { handleSuccess } = useRouteModal();
|
|
@@ -8896,113 +8652,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
8896
8652
|
}
|
|
8897
8653
|
) });
|
|
8898
8654
|
};
|
|
8899
|
-
const schema$
|
|
8900
|
-
const SalesChannel = () => {
|
|
8901
|
-
const { id } = reactRouterDom.useParams();
|
|
8902
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
8903
|
-
id,
|
|
8904
|
-
{
|
|
8905
|
-
fields: "+sales_channel_id"
|
|
8906
|
-
},
|
|
8907
|
-
{
|
|
8908
|
-
enabled: !!id
|
|
8909
|
-
}
|
|
8910
|
-
);
|
|
8911
|
-
if (isError) {
|
|
8912
|
-
throw error;
|
|
8913
|
-
}
|
|
8914
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
8915
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
8916
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
8917
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
8918
|
-
/* @__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" }) })
|
|
8919
|
-
] }),
|
|
8920
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
8921
|
-
] });
|
|
8922
|
-
};
|
|
8923
|
-
const SalesChannelForm = ({ order }) => {
|
|
8924
|
-
const form = reactHookForm.useForm({
|
|
8925
|
-
defaultValues: {
|
|
8926
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
8927
|
-
},
|
|
8928
|
-
resolver: zod$1.zodResolver(schema$1)
|
|
8929
|
-
});
|
|
8930
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
8931
|
-
const { handleSuccess } = useRouteModal();
|
|
8932
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
8933
|
-
await mutateAsync(
|
|
8934
|
-
{
|
|
8935
|
-
sales_channel_id: data.sales_channel_id
|
|
8936
|
-
},
|
|
8937
|
-
{
|
|
8938
|
-
onSuccess: () => {
|
|
8939
|
-
ui.toast.success("Sales channel updated");
|
|
8940
|
-
handleSuccess();
|
|
8941
|
-
},
|
|
8942
|
-
onError: (error) => {
|
|
8943
|
-
ui.toast.error(error.message);
|
|
8944
|
-
}
|
|
8945
|
-
}
|
|
8946
|
-
);
|
|
8947
|
-
});
|
|
8948
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8949
|
-
KeyboundForm,
|
|
8950
|
-
{
|
|
8951
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
8952
|
-
onSubmit,
|
|
8953
|
-
children: [
|
|
8954
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
8955
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
8956
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
8957
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
8958
|
-
] }) })
|
|
8959
|
-
]
|
|
8960
|
-
}
|
|
8961
|
-
) });
|
|
8962
|
-
};
|
|
8963
|
-
const SalesChannelField = ({ control, order }) => {
|
|
8964
|
-
const salesChannels = useComboboxData({
|
|
8965
|
-
queryFn: async (params) => {
|
|
8966
|
-
return await sdk.admin.salesChannel.list(params);
|
|
8967
|
-
},
|
|
8968
|
-
queryKey: ["sales-channels"],
|
|
8969
|
-
getOptions: (data) => {
|
|
8970
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
8971
|
-
label: salesChannel.name,
|
|
8972
|
-
value: salesChannel.id
|
|
8973
|
-
}));
|
|
8974
|
-
},
|
|
8975
|
-
defaultValue: order.sales_channel_id || void 0
|
|
8976
|
-
});
|
|
8977
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8978
|
-
Form$2.Field,
|
|
8979
|
-
{
|
|
8980
|
-
control,
|
|
8981
|
-
name: "sales_channel_id",
|
|
8982
|
-
render: ({ field }) => {
|
|
8983
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
8984
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
8985
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8986
|
-
Combobox,
|
|
8987
|
-
{
|
|
8988
|
-
options: salesChannels.options,
|
|
8989
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
8990
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
8991
|
-
searchValue: salesChannels.searchValue,
|
|
8992
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
8993
|
-
placeholder: "Select sales channel",
|
|
8994
|
-
...field
|
|
8995
|
-
}
|
|
8996
|
-
) }),
|
|
8997
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
8998
|
-
] });
|
|
8999
|
-
}
|
|
9000
|
-
}
|
|
9001
|
-
);
|
|
9002
|
-
};
|
|
9003
|
-
const schema$1 = zod.z.object({
|
|
9004
|
-
sales_channel_id: zod.z.string().min(1)
|
|
9005
|
-
});
|
|
8655
|
+
const schema$1 = addressSchema;
|
|
9006
8656
|
const TransferOwnership = () => {
|
|
9007
8657
|
const { id } = reactRouterDom.useParams();
|
|
9008
8658
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -9473,11 +9123,361 @@ const Illustration = () => {
|
|
|
9473
9123
|
] })
|
|
9474
9124
|
]
|
|
9475
9125
|
}
|
|
9476
|
-
);
|
|
9126
|
+
);
|
|
9127
|
+
};
|
|
9128
|
+
const schema = zod.z.object({
|
|
9129
|
+
customer_id: zod.z.string().min(1)
|
|
9130
|
+
});
|
|
9131
|
+
const InlineTip = React.forwardRef(
|
|
9132
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9133
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9134
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9135
|
+
"div",
|
|
9136
|
+
{
|
|
9137
|
+
ref,
|
|
9138
|
+
className: ui.clx(
|
|
9139
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9140
|
+
className
|
|
9141
|
+
),
|
|
9142
|
+
...props,
|
|
9143
|
+
children: [
|
|
9144
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9145
|
+
"div",
|
|
9146
|
+
{
|
|
9147
|
+
role: "presentation",
|
|
9148
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9149
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9150
|
+
})
|
|
9151
|
+
}
|
|
9152
|
+
),
|
|
9153
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
9154
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9155
|
+
labelValue,
|
|
9156
|
+
":"
|
|
9157
|
+
] }),
|
|
9158
|
+
" ",
|
|
9159
|
+
children
|
|
9160
|
+
] })
|
|
9161
|
+
]
|
|
9162
|
+
}
|
|
9163
|
+
);
|
|
9164
|
+
}
|
|
9165
|
+
);
|
|
9166
|
+
InlineTip.displayName = "InlineTip";
|
|
9167
|
+
const MetadataFieldSchema = zod.z.object({
|
|
9168
|
+
key: zod.z.string(),
|
|
9169
|
+
disabled: zod.z.boolean().optional(),
|
|
9170
|
+
value: zod.z.any()
|
|
9171
|
+
});
|
|
9172
|
+
const MetadataSchema = zod.z.object({
|
|
9173
|
+
metadata: zod.z.array(MetadataFieldSchema)
|
|
9174
|
+
});
|
|
9175
|
+
const Metadata = () => {
|
|
9176
|
+
const { id } = reactRouterDom.useParams();
|
|
9177
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9178
|
+
fields: "metadata"
|
|
9179
|
+
});
|
|
9180
|
+
if (isError) {
|
|
9181
|
+
throw error;
|
|
9182
|
+
}
|
|
9183
|
+
const isReady = !isPending && !!order;
|
|
9184
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9185
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9186
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
9187
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
9188
|
+
] }),
|
|
9189
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
|
|
9190
|
+
] });
|
|
9191
|
+
};
|
|
9192
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
9193
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9194
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
9195
|
+
const { handleSuccess } = useRouteModal();
|
|
9196
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9197
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
9198
|
+
const form = reactHookForm.useForm({
|
|
9199
|
+
defaultValues: {
|
|
9200
|
+
metadata: getDefaultValues(metadata)
|
|
9201
|
+
},
|
|
9202
|
+
resolver: zod$1.zodResolver(MetadataSchema)
|
|
9203
|
+
});
|
|
9204
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
9205
|
+
const parsedData = parseValues(data);
|
|
9206
|
+
await mutateAsync(
|
|
9207
|
+
{
|
|
9208
|
+
metadata: parsedData
|
|
9209
|
+
},
|
|
9210
|
+
{
|
|
9211
|
+
onSuccess: () => {
|
|
9212
|
+
ui.toast.success("Metadata updated");
|
|
9213
|
+
handleSuccess();
|
|
9214
|
+
},
|
|
9215
|
+
onError: (error) => {
|
|
9216
|
+
ui.toast.error(error.message);
|
|
9217
|
+
}
|
|
9218
|
+
}
|
|
9219
|
+
);
|
|
9220
|
+
});
|
|
9221
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
9222
|
+
control: form.control,
|
|
9223
|
+
name: "metadata"
|
|
9224
|
+
});
|
|
9225
|
+
function deleteRow(index) {
|
|
9226
|
+
remove(index);
|
|
9227
|
+
if (fields.length === 1) {
|
|
9228
|
+
insert(0, {
|
|
9229
|
+
key: "",
|
|
9230
|
+
value: "",
|
|
9231
|
+
disabled: false
|
|
9232
|
+
});
|
|
9233
|
+
}
|
|
9234
|
+
}
|
|
9235
|
+
function insertRow(index, position) {
|
|
9236
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
9237
|
+
key: "",
|
|
9238
|
+
value: "",
|
|
9239
|
+
disabled: false
|
|
9240
|
+
});
|
|
9241
|
+
}
|
|
9242
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9243
|
+
KeyboundForm,
|
|
9244
|
+
{
|
|
9245
|
+
onSubmit: handleSubmit,
|
|
9246
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9247
|
+
children: [
|
|
9248
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
9249
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
9250
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
9251
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
9252
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
9253
|
+
] }),
|
|
9254
|
+
fields.map((field, index) => {
|
|
9255
|
+
const isDisabled = field.disabled || false;
|
|
9256
|
+
let placeholder = "-";
|
|
9257
|
+
if (typeof field.value === "object") {
|
|
9258
|
+
placeholder = "{ ... }";
|
|
9259
|
+
}
|
|
9260
|
+
if (Array.isArray(field.value)) {
|
|
9261
|
+
placeholder = "[ ... ]";
|
|
9262
|
+
}
|
|
9263
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9264
|
+
ConditionalTooltip,
|
|
9265
|
+
{
|
|
9266
|
+
showTooltip: isDisabled,
|
|
9267
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
9268
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
9269
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9270
|
+
"div",
|
|
9271
|
+
{
|
|
9272
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
9273
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9274
|
+
}),
|
|
9275
|
+
children: [
|
|
9276
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9277
|
+
Form$2.Field,
|
|
9278
|
+
{
|
|
9279
|
+
control: form.control,
|
|
9280
|
+
name: `metadata.${index}.key`,
|
|
9281
|
+
render: ({ field: field2 }) => {
|
|
9282
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9283
|
+
GridInput,
|
|
9284
|
+
{
|
|
9285
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9286
|
+
...field2,
|
|
9287
|
+
disabled: isDisabled,
|
|
9288
|
+
placeholder: "Key"
|
|
9289
|
+
}
|
|
9290
|
+
) }) });
|
|
9291
|
+
}
|
|
9292
|
+
}
|
|
9293
|
+
),
|
|
9294
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9295
|
+
Form$2.Field,
|
|
9296
|
+
{
|
|
9297
|
+
control: form.control,
|
|
9298
|
+
name: `metadata.${index}.value`,
|
|
9299
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
9300
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9301
|
+
GridInput,
|
|
9302
|
+
{
|
|
9303
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
9304
|
+
...field2,
|
|
9305
|
+
value: isDisabled ? placeholder : value,
|
|
9306
|
+
disabled: isDisabled,
|
|
9307
|
+
placeholder: "Value"
|
|
9308
|
+
}
|
|
9309
|
+
) }) });
|
|
9310
|
+
}
|
|
9311
|
+
}
|
|
9312
|
+
)
|
|
9313
|
+
]
|
|
9314
|
+
}
|
|
9315
|
+
),
|
|
9316
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
9317
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9318
|
+
ui.DropdownMenu.Trigger,
|
|
9319
|
+
{
|
|
9320
|
+
className: ui.clx(
|
|
9321
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
9322
|
+
{
|
|
9323
|
+
hidden: isDisabled
|
|
9324
|
+
}
|
|
9325
|
+
),
|
|
9326
|
+
disabled: isDisabled,
|
|
9327
|
+
asChild: true,
|
|
9328
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
9329
|
+
}
|
|
9330
|
+
),
|
|
9331
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
9332
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9333
|
+
ui.DropdownMenu.Item,
|
|
9334
|
+
{
|
|
9335
|
+
className: "gap-x-2",
|
|
9336
|
+
onClick: () => insertRow(index, "above"),
|
|
9337
|
+
children: [
|
|
9338
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
9339
|
+
"Insert row above"
|
|
9340
|
+
]
|
|
9341
|
+
}
|
|
9342
|
+
),
|
|
9343
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9344
|
+
ui.DropdownMenu.Item,
|
|
9345
|
+
{
|
|
9346
|
+
className: "gap-x-2",
|
|
9347
|
+
onClick: () => insertRow(index, "below"),
|
|
9348
|
+
children: [
|
|
9349
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
9350
|
+
"Insert row below"
|
|
9351
|
+
]
|
|
9352
|
+
}
|
|
9353
|
+
),
|
|
9354
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
9355
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9356
|
+
ui.DropdownMenu.Item,
|
|
9357
|
+
{
|
|
9358
|
+
className: "gap-x-2",
|
|
9359
|
+
onClick: () => deleteRow(index),
|
|
9360
|
+
children: [
|
|
9361
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
9362
|
+
"Delete row"
|
|
9363
|
+
]
|
|
9364
|
+
}
|
|
9365
|
+
)
|
|
9366
|
+
] })
|
|
9367
|
+
] })
|
|
9368
|
+
] })
|
|
9369
|
+
},
|
|
9370
|
+
field.id
|
|
9371
|
+
);
|
|
9372
|
+
})
|
|
9373
|
+
] }),
|
|
9374
|
+
hasUneditableRows && /* @__PURE__ */ jsxRuntime.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." })
|
|
9375
|
+
] }),
|
|
9376
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9377
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
9378
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9379
|
+
] }) })
|
|
9380
|
+
]
|
|
9381
|
+
}
|
|
9382
|
+
) });
|
|
9477
9383
|
};
|
|
9478
|
-
const
|
|
9479
|
-
|
|
9384
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
9385
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9386
|
+
"input",
|
|
9387
|
+
{
|
|
9388
|
+
ref,
|
|
9389
|
+
...props,
|
|
9390
|
+
autoComplete: "off",
|
|
9391
|
+
className: ui.clx(
|
|
9392
|
+
"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",
|
|
9393
|
+
className
|
|
9394
|
+
)
|
|
9395
|
+
}
|
|
9396
|
+
);
|
|
9480
9397
|
});
|
|
9398
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
9399
|
+
const PlaceholderInner = () => {
|
|
9400
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
9401
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
9402
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9403
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
9404
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
9405
|
+
] }) })
|
|
9406
|
+
] });
|
|
9407
|
+
};
|
|
9408
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
9409
|
+
function getDefaultValues(metadata) {
|
|
9410
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
9411
|
+
return [
|
|
9412
|
+
{
|
|
9413
|
+
key: "",
|
|
9414
|
+
value: "",
|
|
9415
|
+
disabled: false
|
|
9416
|
+
}
|
|
9417
|
+
];
|
|
9418
|
+
}
|
|
9419
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
9420
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
9421
|
+
return {
|
|
9422
|
+
key,
|
|
9423
|
+
value,
|
|
9424
|
+
disabled: true
|
|
9425
|
+
};
|
|
9426
|
+
}
|
|
9427
|
+
let stringValue = value;
|
|
9428
|
+
if (typeof value !== "string") {
|
|
9429
|
+
stringValue = JSON.stringify(value);
|
|
9430
|
+
}
|
|
9431
|
+
return {
|
|
9432
|
+
key,
|
|
9433
|
+
value: stringValue,
|
|
9434
|
+
original_key: key
|
|
9435
|
+
};
|
|
9436
|
+
});
|
|
9437
|
+
}
|
|
9438
|
+
function parseValues(values) {
|
|
9439
|
+
const metadata = values.metadata;
|
|
9440
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
9441
|
+
if (isEmpty) {
|
|
9442
|
+
return null;
|
|
9443
|
+
}
|
|
9444
|
+
const update = {};
|
|
9445
|
+
metadata.forEach((field) => {
|
|
9446
|
+
let key = field.key;
|
|
9447
|
+
let value = field.value;
|
|
9448
|
+
const disabled = field.disabled;
|
|
9449
|
+
if (!key || !value) {
|
|
9450
|
+
return;
|
|
9451
|
+
}
|
|
9452
|
+
if (disabled) {
|
|
9453
|
+
update[key] = value;
|
|
9454
|
+
return;
|
|
9455
|
+
}
|
|
9456
|
+
key = key.trim();
|
|
9457
|
+
value = value.trim();
|
|
9458
|
+
if (value === "true") {
|
|
9459
|
+
update[key] = true;
|
|
9460
|
+
} else if (value === "false") {
|
|
9461
|
+
update[key] = false;
|
|
9462
|
+
} else {
|
|
9463
|
+
const parsedNumber = parseFloat(value);
|
|
9464
|
+
if (!isNaN(parsedNumber)) {
|
|
9465
|
+
update[key] = parsedNumber;
|
|
9466
|
+
} else {
|
|
9467
|
+
update[key] = value;
|
|
9468
|
+
}
|
|
9469
|
+
}
|
|
9470
|
+
});
|
|
9471
|
+
return update;
|
|
9472
|
+
}
|
|
9473
|
+
function getHasUneditableRows(metadata) {
|
|
9474
|
+
if (!metadata) {
|
|
9475
|
+
return false;
|
|
9476
|
+
}
|
|
9477
|
+
return Object.values(metadata).some(
|
|
9478
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
9479
|
+
);
|
|
9480
|
+
}
|
|
9481
9481
|
const widgetModule = { widgets: [] };
|
|
9482
9482
|
const routeModule = {
|
|
9483
9483
|
routes: [
|
|
@@ -9514,14 +9514,14 @@ const routeModule = {
|
|
|
9514
9514
|
Component: Items,
|
|
9515
9515
|
path: "/draft-orders/:id/items"
|
|
9516
9516
|
},
|
|
9517
|
-
{
|
|
9518
|
-
Component: Metadata,
|
|
9519
|
-
path: "/draft-orders/:id/metadata"
|
|
9520
|
-
},
|
|
9521
9517
|
{
|
|
9522
9518
|
Component: Promotions,
|
|
9523
9519
|
path: "/draft-orders/:id/promotions"
|
|
9524
9520
|
},
|
|
9521
|
+
{
|
|
9522
|
+
Component: SalesChannel,
|
|
9523
|
+
path: "/draft-orders/:id/sales-channel"
|
|
9524
|
+
},
|
|
9525
9525
|
{
|
|
9526
9526
|
Component: Shipping,
|
|
9527
9527
|
path: "/draft-orders/:id/shipping"
|
|
@@ -9530,13 +9530,13 @@ const routeModule = {
|
|
|
9530
9530
|
Component: ShippingAddress,
|
|
9531
9531
|
path: "/draft-orders/:id/shipping-address"
|
|
9532
9532
|
},
|
|
9533
|
-
{
|
|
9534
|
-
Component: SalesChannel,
|
|
9535
|
-
path: "/draft-orders/:id/sales-channel"
|
|
9536
|
-
},
|
|
9537
9533
|
{
|
|
9538
9534
|
Component: TransferOwnership,
|
|
9539
9535
|
path: "/draft-orders/:id/transfer-ownership"
|
|
9536
|
+
},
|
|
9537
|
+
{
|
|
9538
|
+
Component: Metadata,
|
|
9539
|
+
path: "/draft-orders/:id/metadata"
|
|
9540
9540
|
}
|
|
9541
9541
|
]
|
|
9542
9542
|
}
|