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