@medusajs/draft-order 2.22.7 → 2.22.8-preview-20261117142131

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.
@@ -7409,359 +7409,6 @@ const customItemSchema = zod.z.object({
7409
7409
  const handle$6 = {
7410
7410
  permissions: EDIT_DRAFT_ORDER_PERMISSIONS
7411
7411
  };
7412
- const InlineTip = React.forwardRef(
7413
- ({ variant = "tip", label, className, children, ...props }, ref) => {
7414
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
7415
- return /* @__PURE__ */ jsxRuntime.jsxs(
7416
- "div",
7417
- {
7418
- ref,
7419
- className: ui.clx(
7420
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
7421
- className
7422
- ),
7423
- ...props,
7424
- children: [
7425
- /* @__PURE__ */ jsxRuntime.jsx(
7426
- "div",
7427
- {
7428
- role: "presentation",
7429
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
7430
- "bg-ui-tag-orange-icon": variant === "warning"
7431
- })
7432
- }
7433
- ),
7434
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
7435
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
7436
- labelValue,
7437
- ":"
7438
- ] }),
7439
- " ",
7440
- children
7441
- ] })
7442
- ]
7443
- }
7444
- );
7445
- }
7446
- );
7447
- InlineTip.displayName = "InlineTip";
7448
- const MetadataFieldSchema = zod.z.object({
7449
- key: zod.z.string(),
7450
- disabled: zod.z.boolean().optional(),
7451
- value: zod.z.any()
7452
- });
7453
- const MetadataSchema = zod.z.object({
7454
- metadata: zod.z.array(MetadataFieldSchema)
7455
- });
7456
- const Metadata = () => {
7457
- const { id } = reactRouterDom.useParams();
7458
- const { order, isPending, isError, error } = useOrder(id, {
7459
- fields: "metadata"
7460
- });
7461
- if (isError) {
7462
- throw error;
7463
- }
7464
- const isReady = !isPending && !!order;
7465
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
7466
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
7467
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
7468
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
7469
- ] }),
7470
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
7471
- ] });
7472
- };
7473
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
7474
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
7475
- const MetadataForm = ({ orderId, metadata }) => {
7476
- const { handleSuccess } = useRouteModal();
7477
- const hasUneditableRows = getHasUneditableRows(metadata);
7478
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
7479
- const form = reactHookForm.useForm({
7480
- defaultValues: {
7481
- metadata: getDefaultValues(metadata)
7482
- },
7483
- resolver: zod$1.zodResolver(MetadataSchema)
7484
- });
7485
- const handleSubmit = form.handleSubmit(async (data) => {
7486
- const parsedData = parseValues(data);
7487
- await mutateAsync(
7488
- {
7489
- metadata: parsedData
7490
- },
7491
- {
7492
- onSuccess: () => {
7493
- ui.toast.success("Metadata updated");
7494
- handleSuccess();
7495
- },
7496
- onError: (error) => {
7497
- ui.toast.error(error.message);
7498
- }
7499
- }
7500
- );
7501
- });
7502
- const { fields, insert, remove } = reactHookForm.useFieldArray({
7503
- control: form.control,
7504
- name: "metadata"
7505
- });
7506
- function deleteRow(index) {
7507
- remove(index);
7508
- if (fields.length === 1) {
7509
- insert(0, {
7510
- key: "",
7511
- value: "",
7512
- disabled: false
7513
- });
7514
- }
7515
- }
7516
- function insertRow(index, position) {
7517
- insert(index + (position === "above" ? 0 : 1), {
7518
- key: "",
7519
- value: "",
7520
- disabled: false
7521
- });
7522
- }
7523
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
7524
- KeyboundForm,
7525
- {
7526
- onSubmit: handleSubmit,
7527
- className: "flex flex-1 flex-col overflow-hidden",
7528
- children: [
7529
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
7530
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
7531
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
7532
- /* @__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" }) }),
7533
- /* @__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" }) })
7534
- ] }),
7535
- fields.map((field, index) => {
7536
- const isDisabled = field.disabled || false;
7537
- let placeholder = "-";
7538
- if (typeof field.value === "object") {
7539
- placeholder = "{ ... }";
7540
- }
7541
- if (Array.isArray(field.value)) {
7542
- placeholder = "[ ... ]";
7543
- }
7544
- return /* @__PURE__ */ jsxRuntime.jsx(
7545
- ConditionalTooltip,
7546
- {
7547
- showTooltip: isDisabled,
7548
- content: "This row is disabled because it contains non-primitive data.",
7549
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
7550
- /* @__PURE__ */ jsxRuntime.jsxs(
7551
- "div",
7552
- {
7553
- className: ui.clx("grid grid-cols-2 divide-x", {
7554
- "overflow-hidden rounded-b-lg": index === fields.length - 1
7555
- }),
7556
- children: [
7557
- /* @__PURE__ */ jsxRuntime.jsx(
7558
- Form$2.Field,
7559
- {
7560
- control: form.control,
7561
- name: `metadata.${index}.key`,
7562
- render: ({ field: field2 }) => {
7563
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7564
- GridInput,
7565
- {
7566
- "aria-labelledby": METADATA_KEY_LABEL_ID,
7567
- ...field2,
7568
- disabled: isDisabled,
7569
- placeholder: "Key"
7570
- }
7571
- ) }) });
7572
- }
7573
- }
7574
- ),
7575
- /* @__PURE__ */ jsxRuntime.jsx(
7576
- Form$2.Field,
7577
- {
7578
- control: form.control,
7579
- name: `metadata.${index}.value`,
7580
- render: ({ field: { value, ...field2 } }) => {
7581
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7582
- GridInput,
7583
- {
7584
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
7585
- ...field2,
7586
- value: isDisabled ? placeholder : value,
7587
- disabled: isDisabled,
7588
- placeholder: "Value"
7589
- }
7590
- ) }) });
7591
- }
7592
- }
7593
- )
7594
- ]
7595
- }
7596
- ),
7597
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
7598
- /* @__PURE__ */ jsxRuntime.jsx(
7599
- ui.DropdownMenu.Trigger,
7600
- {
7601
- className: ui.clx(
7602
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
7603
- {
7604
- hidden: isDisabled
7605
- }
7606
- ),
7607
- disabled: isDisabled,
7608
- asChild: true,
7609
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
7610
- }
7611
- ),
7612
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
7613
- /* @__PURE__ */ jsxRuntime.jsxs(
7614
- ui.DropdownMenu.Item,
7615
- {
7616
- className: "gap-x-2",
7617
- onClick: () => insertRow(index, "above"),
7618
- children: [
7619
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
7620
- "Insert row above"
7621
- ]
7622
- }
7623
- ),
7624
- /* @__PURE__ */ jsxRuntime.jsxs(
7625
- ui.DropdownMenu.Item,
7626
- {
7627
- className: "gap-x-2",
7628
- onClick: () => insertRow(index, "below"),
7629
- children: [
7630
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
7631
- "Insert row below"
7632
- ]
7633
- }
7634
- ),
7635
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
7636
- /* @__PURE__ */ jsxRuntime.jsxs(
7637
- ui.DropdownMenu.Item,
7638
- {
7639
- className: "gap-x-2",
7640
- onClick: () => deleteRow(index),
7641
- children: [
7642
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
7643
- "Delete row"
7644
- ]
7645
- }
7646
- )
7647
- ] })
7648
- ] })
7649
- ] })
7650
- },
7651
- field.id
7652
- );
7653
- })
7654
- ] }),
7655
- 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." })
7656
- ] }),
7657
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7658
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7659
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7660
- ] }) })
7661
- ]
7662
- }
7663
- ) });
7664
- };
7665
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
7666
- return /* @__PURE__ */ jsxRuntime.jsx(
7667
- "input",
7668
- {
7669
- ref,
7670
- ...props,
7671
- autoComplete: "off",
7672
- className: ui.clx(
7673
- "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",
7674
- className
7675
- )
7676
- }
7677
- );
7678
- });
7679
- GridInput.displayName = "MetadataForm.GridInput";
7680
- const PlaceholderInner = () => {
7681
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
7682
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
7683
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7684
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
7685
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
7686
- ] }) })
7687
- ] });
7688
- };
7689
- const EDITABLE_TYPES = ["string", "number", "boolean"];
7690
- function getDefaultValues(metadata) {
7691
- if (!metadata || !Object.keys(metadata).length) {
7692
- return [
7693
- {
7694
- key: "",
7695
- value: "",
7696
- disabled: false
7697
- }
7698
- ];
7699
- }
7700
- return Object.entries(metadata).map(([key, value]) => {
7701
- if (!EDITABLE_TYPES.includes(typeof value)) {
7702
- return {
7703
- key,
7704
- value,
7705
- disabled: true
7706
- };
7707
- }
7708
- let stringValue = value;
7709
- if (typeof value !== "string") {
7710
- stringValue = JSON.stringify(value);
7711
- }
7712
- return {
7713
- key,
7714
- value: stringValue,
7715
- original_key: key
7716
- };
7717
- });
7718
- }
7719
- function parseValues(values) {
7720
- const metadata = values.metadata;
7721
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
7722
- if (isEmpty) {
7723
- return null;
7724
- }
7725
- const update = {};
7726
- metadata.forEach((field) => {
7727
- let key = field.key;
7728
- let value = field.value;
7729
- const disabled = field.disabled;
7730
- if (!key || !value) {
7731
- return;
7732
- }
7733
- if (disabled) {
7734
- update[key] = value;
7735
- return;
7736
- }
7737
- key = key.trim();
7738
- value = value.trim();
7739
- if (value === "true") {
7740
- update[key] = true;
7741
- } else if (value === "false") {
7742
- update[key] = false;
7743
- } else {
7744
- const parsedNumber = parseFloat(value);
7745
- if (!isNaN(parsedNumber)) {
7746
- update[key] = parsedNumber;
7747
- } else {
7748
- update[key] = value;
7749
- }
7750
- }
7751
- });
7752
- return update;
7753
- }
7754
- function getHasUneditableRows(metadata) {
7755
- if (!metadata) {
7756
- return false;
7757
- }
7758
- return Object.values(metadata).some(
7759
- (value) => !EDITABLE_TYPES.includes(typeof value)
7760
- );
7761
- }
7762
- const handle$5 = {
7763
- permissions: EDIT_DRAFT_ORDER_PERMISSIONS
7764
- };
7765
7412
  const PROMOTION_QUERY_KEY = "promotions";
7766
7413
  const promotionsQueryKeys = {
7767
7414
  list: (query2) => [
@@ -8037,7 +7684,7 @@ function getPromotionIds(items, shippingMethods) {
8037
7684
  }
8038
7685
  return Array.from(promotionIds);
8039
7686
  }
8040
- const handle$4 = {
7687
+ const handle$5 = {
8041
7688
  permissions: EDIT_DRAFT_ORDER_PROMOTIONS_PERMISSIONS
8042
7689
  };
8043
7690
  const SalesChannel = () => {
@@ -8146,7 +7793,7 @@ const SalesChannelField = ({ control, order }) => {
8146
7793
  const schema$2 = zod.z.object({
8147
7794
  sales_channel_id: zod.z.string().min(1)
8148
7795
  });
8149
- const handle$3 = {
7796
+ const handle$4 = {
8150
7797
  permissions: EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
8151
7798
  };
8152
7799
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -8943,7 +8590,7 @@ const CustomAmountField = ({
8943
8590
  }
8944
8591
  );
8945
8592
  };
8946
- const handle$2 = {
8593
+ const handle$3 = {
8947
8594
  permissions: EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS
8948
8595
  };
8949
8596
  const ShippingAddress = () => {
@@ -9148,7 +8795,7 @@ const ShippingAddressForm = ({ order }) => {
9148
8795
  ) });
9149
8796
  };
9150
8797
  const schema$1 = addressSchema;
9151
- const handle$1 = {
8798
+ const handle$2 = {
9152
8799
  permissions: EDIT_DRAFT_ORDER_PERMISSIONS
9153
8800
  };
9154
8801
  const TransferOwnership = () => {
@@ -9623,13 +9270,366 @@ const Illustration = () => {
9623
9270
  ] })
9624
9271
  ]
9625
9272
  }
9626
- );
9273
+ );
9274
+ };
9275
+ const schema = zod.z.object({
9276
+ customer_id: zod.z.string().min(1)
9277
+ });
9278
+ const handle$1 = {
9279
+ permissions: TRANSFER_DRAFT_ORDER_PERMISSIONS
9280
+ };
9281
+ const InlineTip = React.forwardRef(
9282
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9283
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9284
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9285
+ "div",
9286
+ {
9287
+ ref,
9288
+ className: ui.clx(
9289
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9290
+ className
9291
+ ),
9292
+ ...props,
9293
+ children: [
9294
+ /* @__PURE__ */ jsxRuntime.jsx(
9295
+ "div",
9296
+ {
9297
+ role: "presentation",
9298
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9299
+ "bg-ui-tag-orange-icon": variant === "warning"
9300
+ })
9301
+ }
9302
+ ),
9303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9304
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9305
+ labelValue,
9306
+ ":"
9307
+ ] }),
9308
+ " ",
9309
+ children
9310
+ ] })
9311
+ ]
9312
+ }
9313
+ );
9314
+ }
9315
+ );
9316
+ InlineTip.displayName = "InlineTip";
9317
+ const MetadataFieldSchema = zod.z.object({
9318
+ key: zod.z.string(),
9319
+ disabled: zod.z.boolean().optional(),
9320
+ value: zod.z.any()
9321
+ });
9322
+ const MetadataSchema = zod.z.object({
9323
+ metadata: zod.z.array(MetadataFieldSchema)
9324
+ });
9325
+ const Metadata = () => {
9326
+ const { id } = reactRouterDom.useParams();
9327
+ const { order, isPending, isError, error } = useOrder(id, {
9328
+ fields: "metadata"
9329
+ });
9330
+ if (isError) {
9331
+ throw error;
9332
+ }
9333
+ const isReady = !isPending && !!order;
9334
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9335
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9336
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9337
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9338
+ ] }),
9339
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
9340
+ ] });
9341
+ };
9342
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9343
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9344
+ const MetadataForm = ({ orderId, metadata }) => {
9345
+ const { handleSuccess } = useRouteModal();
9346
+ const hasUneditableRows = getHasUneditableRows(metadata);
9347
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9348
+ const form = reactHookForm.useForm({
9349
+ defaultValues: {
9350
+ metadata: getDefaultValues(metadata)
9351
+ },
9352
+ resolver: zod$1.zodResolver(MetadataSchema)
9353
+ });
9354
+ const handleSubmit = form.handleSubmit(async (data) => {
9355
+ const parsedData = parseValues(data);
9356
+ await mutateAsync(
9357
+ {
9358
+ metadata: parsedData
9359
+ },
9360
+ {
9361
+ onSuccess: () => {
9362
+ ui.toast.success("Metadata updated");
9363
+ handleSuccess();
9364
+ },
9365
+ onError: (error) => {
9366
+ ui.toast.error(error.message);
9367
+ }
9368
+ }
9369
+ );
9370
+ });
9371
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9372
+ control: form.control,
9373
+ name: "metadata"
9374
+ });
9375
+ function deleteRow(index) {
9376
+ remove(index);
9377
+ if (fields.length === 1) {
9378
+ insert(0, {
9379
+ key: "",
9380
+ value: "",
9381
+ disabled: false
9382
+ });
9383
+ }
9384
+ }
9385
+ function insertRow(index, position) {
9386
+ insert(index + (position === "above" ? 0 : 1), {
9387
+ key: "",
9388
+ value: "",
9389
+ disabled: false
9390
+ });
9391
+ }
9392
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9393
+ KeyboundForm,
9394
+ {
9395
+ onSubmit: handleSubmit,
9396
+ className: "flex flex-1 flex-col overflow-hidden",
9397
+ children: [
9398
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9399
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9400
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9401
+ /* @__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" }) }),
9402
+ /* @__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" }) })
9403
+ ] }),
9404
+ fields.map((field, index) => {
9405
+ const isDisabled = field.disabled || false;
9406
+ let placeholder = "-";
9407
+ if (typeof field.value === "object") {
9408
+ placeholder = "{ ... }";
9409
+ }
9410
+ if (Array.isArray(field.value)) {
9411
+ placeholder = "[ ... ]";
9412
+ }
9413
+ return /* @__PURE__ */ jsxRuntime.jsx(
9414
+ ConditionalTooltip,
9415
+ {
9416
+ showTooltip: isDisabled,
9417
+ content: "This row is disabled because it contains non-primitive data.",
9418
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9419
+ /* @__PURE__ */ jsxRuntime.jsxs(
9420
+ "div",
9421
+ {
9422
+ className: ui.clx("grid grid-cols-2 divide-x", {
9423
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9424
+ }),
9425
+ children: [
9426
+ /* @__PURE__ */ jsxRuntime.jsx(
9427
+ Form$2.Field,
9428
+ {
9429
+ control: form.control,
9430
+ name: `metadata.${index}.key`,
9431
+ render: ({ field: field2 }) => {
9432
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9433
+ GridInput,
9434
+ {
9435
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9436
+ ...field2,
9437
+ disabled: isDisabled,
9438
+ placeholder: "Key"
9439
+ }
9440
+ ) }) });
9441
+ }
9442
+ }
9443
+ ),
9444
+ /* @__PURE__ */ jsxRuntime.jsx(
9445
+ Form$2.Field,
9446
+ {
9447
+ control: form.control,
9448
+ name: `metadata.${index}.value`,
9449
+ render: ({ field: { value, ...field2 } }) => {
9450
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9451
+ GridInput,
9452
+ {
9453
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9454
+ ...field2,
9455
+ value: isDisabled ? placeholder : value,
9456
+ disabled: isDisabled,
9457
+ placeholder: "Value"
9458
+ }
9459
+ ) }) });
9460
+ }
9461
+ }
9462
+ )
9463
+ ]
9464
+ }
9465
+ ),
9466
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9467
+ /* @__PURE__ */ jsxRuntime.jsx(
9468
+ ui.DropdownMenu.Trigger,
9469
+ {
9470
+ className: ui.clx(
9471
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9472
+ {
9473
+ hidden: isDisabled
9474
+ }
9475
+ ),
9476
+ disabled: isDisabled,
9477
+ asChild: true,
9478
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9479
+ }
9480
+ ),
9481
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9482
+ /* @__PURE__ */ jsxRuntime.jsxs(
9483
+ ui.DropdownMenu.Item,
9484
+ {
9485
+ className: "gap-x-2",
9486
+ onClick: () => insertRow(index, "above"),
9487
+ children: [
9488
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9489
+ "Insert row above"
9490
+ ]
9491
+ }
9492
+ ),
9493
+ /* @__PURE__ */ jsxRuntime.jsxs(
9494
+ ui.DropdownMenu.Item,
9495
+ {
9496
+ className: "gap-x-2",
9497
+ onClick: () => insertRow(index, "below"),
9498
+ children: [
9499
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9500
+ "Insert row below"
9501
+ ]
9502
+ }
9503
+ ),
9504
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9505
+ /* @__PURE__ */ jsxRuntime.jsxs(
9506
+ ui.DropdownMenu.Item,
9507
+ {
9508
+ className: "gap-x-2",
9509
+ onClick: () => deleteRow(index),
9510
+ children: [
9511
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
9512
+ "Delete row"
9513
+ ]
9514
+ }
9515
+ )
9516
+ ] })
9517
+ ] })
9518
+ ] })
9519
+ },
9520
+ field.id
9521
+ );
9522
+ })
9523
+ ] }),
9524
+ 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." })
9525
+ ] }),
9526
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9527
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9528
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9529
+ ] }) })
9530
+ ]
9531
+ }
9532
+ ) });
9627
9533
  };
9628
- const schema = zod.z.object({
9629
- customer_id: zod.z.string().min(1)
9534
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
9535
+ return /* @__PURE__ */ jsxRuntime.jsx(
9536
+ "input",
9537
+ {
9538
+ ref,
9539
+ ...props,
9540
+ autoComplete: "off",
9541
+ className: ui.clx(
9542
+ "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",
9543
+ className
9544
+ )
9545
+ }
9546
+ );
9630
9547
  });
9548
+ GridInput.displayName = "MetadataForm.GridInput";
9549
+ const PlaceholderInner = () => {
9550
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9551
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9552
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9553
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
9554
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
9555
+ ] }) })
9556
+ ] });
9557
+ };
9558
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
9559
+ function getDefaultValues(metadata) {
9560
+ if (!metadata || !Object.keys(metadata).length) {
9561
+ return [
9562
+ {
9563
+ key: "",
9564
+ value: "",
9565
+ disabled: false
9566
+ }
9567
+ ];
9568
+ }
9569
+ return Object.entries(metadata).map(([key, value]) => {
9570
+ if (!EDITABLE_TYPES.includes(typeof value)) {
9571
+ return {
9572
+ key,
9573
+ value,
9574
+ disabled: true
9575
+ };
9576
+ }
9577
+ let stringValue = value;
9578
+ if (typeof value !== "string") {
9579
+ stringValue = JSON.stringify(value);
9580
+ }
9581
+ return {
9582
+ key,
9583
+ value: stringValue,
9584
+ original_key: key
9585
+ };
9586
+ });
9587
+ }
9588
+ function parseValues(values) {
9589
+ const metadata = values.metadata;
9590
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9591
+ if (isEmpty) {
9592
+ return null;
9593
+ }
9594
+ const update = {};
9595
+ metadata.forEach((field) => {
9596
+ let key = field.key;
9597
+ let value = field.value;
9598
+ const disabled = field.disabled;
9599
+ if (!key || !value) {
9600
+ return;
9601
+ }
9602
+ if (disabled) {
9603
+ update[key] = value;
9604
+ return;
9605
+ }
9606
+ key = key.trim();
9607
+ value = value.trim();
9608
+ if (value === "true") {
9609
+ update[key] = true;
9610
+ } else if (value === "false") {
9611
+ update[key] = false;
9612
+ } else {
9613
+ const parsedNumber = parseFloat(value);
9614
+ if (!isNaN(parsedNumber)) {
9615
+ update[key] = parsedNumber;
9616
+ } else {
9617
+ update[key] = value;
9618
+ }
9619
+ }
9620
+ });
9621
+ return update;
9622
+ }
9623
+ function getHasUneditableRows(metadata) {
9624
+ if (!metadata) {
9625
+ return false;
9626
+ }
9627
+ return Object.values(metadata).some(
9628
+ (value) => !EDITABLE_TYPES.includes(typeof value)
9629
+ );
9630
+ }
9631
9631
  const handle = {
9632
- permissions: TRANSFER_DRAFT_ORDER_PERMISSIONS
9632
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
9633
9633
  };
9634
9634
  const widgetModule = { widgets: [] };
9635
9635
  const routeModule = {
@@ -9672,34 +9672,34 @@ const routeModule = {
9672
9672
  path: "/draft-orders/:id/items",
9673
9673
  handle: handle$6
9674
9674
  },
9675
- {
9676
- Component: Metadata,
9677
- path: "/draft-orders/:id/metadata",
9678
- handle: handle$5
9679
- },
9680
9675
  {
9681
9676
  Component: Promotions,
9682
9677
  path: "/draft-orders/:id/promotions",
9683
- handle: handle$4
9678
+ handle: handle$5
9684
9679
  },
9685
9680
  {
9686
9681
  Component: SalesChannel,
9687
9682
  path: "/draft-orders/:id/sales-channel",
9688
- handle: handle$3
9683
+ handle: handle$4
9689
9684
  },
9690
9685
  {
9691
9686
  Component: Shipping,
9692
9687
  path: "/draft-orders/:id/shipping",
9693
- handle: handle$2
9688
+ handle: handle$3
9694
9689
  },
9695
9690
  {
9696
9691
  Component: ShippingAddress,
9697
9692
  path: "/draft-orders/:id/shipping-address",
9698
- handle: handle$1
9693
+ handle: handle$2
9699
9694
  },
9700
9695
  {
9701
9696
  Component: TransferOwnership,
9702
9697
  path: "/draft-orders/:id/transfer-ownership",
9698
+ handle: handle$1
9699
+ },
9700
+ {
9701
+ Component: Metadata,
9702
+ path: "/draft-orders/:id/metadata",
9703
9703
  handle
9704
9704
  }
9705
9705
  ]