@medusajs/draft-order 2.22.3 → 2.22.4-preview-20261106081111

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.
@@ -6386,584 +6386,779 @@ const schema$3 = zod.z.object({
6386
6386
  const handle$7 = {
6387
6387
  permissions: EDIT_DRAFT_ORDER_PERMISSIONS
6388
6388
  };
6389
- const NumberInput = React.forwardRef(
6390
- ({
6391
- value,
6392
- onChange,
6393
- size = "base",
6394
- min = 0,
6395
- max = 100,
6396
- step = 1,
6397
- className,
6398
- disabled,
6399
- ...props
6400
- }, ref) => {
6401
- const handleChange = (event) => {
6402
- const newValue = event.target.value === "" ? min : Number(event.target.value);
6403
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
6404
- onChange(newValue);
6405
- }
6406
- };
6407
- const handleIncrement = () => {
6408
- const newValue = value + step;
6409
- if (max === void 0 || newValue <= max) {
6410
- onChange(newValue);
6411
- }
6412
- };
6413
- const handleDecrement = () => {
6414
- const newValue = value - step;
6415
- if (min === void 0 || newValue >= min) {
6416
- onChange(newValue);
6417
- }
6418
- };
6389
+ const InlineTip = React.forwardRef(
6390
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
6391
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
6419
6392
  return /* @__PURE__ */ jsxRuntime.jsxs(
6420
6393
  "div",
6421
6394
  {
6395
+ ref,
6422
6396
  className: ui.clx(
6423
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
6424
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
6425
- {
6426
- "h-7": size === "small",
6427
- "h-8": size === "base"
6428
- },
6397
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
6429
6398
  className
6430
6399
  ),
6400
+ ...props,
6431
6401
  children: [
6432
6402
  /* @__PURE__ */ jsxRuntime.jsx(
6433
- "input",
6434
- {
6435
- ref,
6436
- type: "number",
6437
- value,
6438
- onChange: handleChange,
6439
- min,
6440
- max,
6441
- step,
6442
- className: ui.clx(
6443
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
6444
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
6445
- "placeholder:text-ui-fg-muted"
6446
- ),
6447
- ...props
6448
- }
6449
- ),
6450
- /* @__PURE__ */ jsxRuntime.jsxs(
6451
- "button",
6403
+ "div",
6452
6404
  {
6453
- className: ui.clx(
6454
- "flex items-center justify-center outline-none transition-fg",
6455
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
6456
- "focus:bg-ui-bg-field-component-hover",
6457
- "hover:bg-ui-bg-field-component-hover",
6458
- {
6459
- "size-7": size === "small",
6460
- "size-8": size === "base"
6461
- }
6462
- ),
6463
- type: "button",
6464
- onClick: handleDecrement,
6465
- disabled: min !== void 0 && value <= min || disabled,
6466
- children: [
6467
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
6468
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
6469
- ]
6405
+ role: "presentation",
6406
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
6407
+ "bg-ui-tag-orange-icon": variant === "warning"
6408
+ })
6470
6409
  }
6471
6410
  ),
6472
- /* @__PURE__ */ jsxRuntime.jsxs(
6473
- "button",
6474
- {
6475
- className: ui.clx(
6476
- "flex items-center justify-center outline-none transition-fg",
6477
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
6478
- "focus:bg-ui-bg-field-hover",
6479
- "hover:bg-ui-bg-field-hover",
6480
- {
6481
- "size-7": size === "small",
6482
- "size-8": size === "base"
6483
- }
6484
- ),
6485
- type: "button",
6486
- onClick: handleIncrement,
6487
- disabled: max !== void 0 && value >= max || disabled,
6488
- children: [
6489
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
6490
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
6491
- ]
6492
- }
6493
- )
6411
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
6412
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
6413
+ labelValue,
6414
+ ":"
6415
+ ] }),
6416
+ " ",
6417
+ children
6418
+ ] })
6494
6419
  ]
6495
6420
  }
6496
6421
  );
6497
6422
  }
6498
6423
  );
6499
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
6500
- const productVariantsQueryKeys = {
6501
- list: (query2) => [
6502
- PRODUCT_VARIANTS_QUERY_KEY,
6503
- query2 ? query2 : void 0
6504
- ]
6505
- };
6506
- const useProductVariants = (query2, options) => {
6507
- const { data, ...rest } = reactQuery.useQuery({
6508
- queryKey: productVariantsQueryKeys.list(query2),
6509
- queryFn: async () => await sdk.admin.productVariant.list(query2),
6510
- ...options
6511
- });
6512
- return { ...data, ...rest };
6513
- };
6514
- const useCancelOrderEdit = ({ preview }) => {
6515
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview?.id);
6516
- const onCancel = React.useCallback(async () => {
6517
- if (!preview) {
6518
- return true;
6519
- }
6520
- let res = false;
6521
- await cancelOrderEdit(void 0, {
6522
- onError: (e) => {
6523
- ui.toast.error(e.message);
6524
- },
6525
- onSuccess: () => {
6526
- res = true;
6527
- }
6528
- });
6529
- return res;
6530
- }, [preview, cancelOrderEdit]);
6531
- return { onCancel };
6532
- };
6533
- let IS_REQUEST_RUNNING = false;
6534
- const useInitiateOrderEdit = ({
6535
- preview
6536
- }) => {
6537
- const navigate = reactRouterDom.useNavigate();
6538
- const { mutateAsync } = useDraftOrderBeginEdit(preview?.id);
6539
- React.useEffect(() => {
6540
- async function run() {
6541
- if (IS_REQUEST_RUNNING || !preview) {
6542
- return;
6543
- }
6544
- if (preview.order_change) {
6545
- return;
6546
- }
6547
- IS_REQUEST_RUNNING = true;
6548
- await mutateAsync(void 0, {
6549
- onError: (e) => {
6550
- ui.toast.error(e.message);
6551
- navigate(`/draft-orders/${preview.id}`, { replace: true });
6552
- return;
6553
- }
6554
- });
6555
- IS_REQUEST_RUNNING = false;
6556
- }
6557
- run();
6558
- }, [preview, navigate, mutateAsync]);
6559
- };
6560
- function convertNumber(value) {
6561
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
6562
- }
6563
- const STACKED_MODAL_ID = "items_stacked_modal";
6564
- const Items = () => {
6424
+ InlineTip.displayName = "InlineTip";
6425
+ const MetadataFieldSchema = zod.z.object({
6426
+ key: zod.z.string(),
6427
+ disabled: zod.z.boolean().optional(),
6428
+ value: zod.z.any()
6429
+ });
6430
+ const MetadataSchema = zod.z.object({
6431
+ metadata: zod.z.array(MetadataFieldSchema)
6432
+ });
6433
+ const Metadata = () => {
6565
6434
  const { id } = reactRouterDom.useParams();
6566
- const {
6567
- order: preview,
6568
- isPending: isPreviewPending,
6569
- isError: isPreviewError,
6570
- error: previewError
6571
- } = useOrderPreview(id, void 0, {
6572
- placeholderData: reactQuery.keepPreviousData
6435
+ const { order, isPending, isError, error } = useOrder(id, {
6436
+ fields: "metadata"
6573
6437
  });
6574
- useInitiateOrderEdit({ preview });
6575
- const { draft_order, isPending, isError, error } = useDraftOrder(
6576
- id,
6577
- {
6578
- fields: "currency_code"
6579
- },
6580
- {
6581
- enabled: !!id
6582
- }
6583
- );
6584
- const { onCancel } = useCancelOrderEdit({ preview });
6585
6438
  if (isError) {
6586
6439
  throw error;
6587
6440
  }
6588
- if (isPreviewError) {
6589
- throw previewError;
6590
- }
6591
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
6592
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
6593
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
6594
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
6595
- ] }) });
6441
+ const isReady = !isPending && !!order;
6442
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
6443
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
6444
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
6445
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
6446
+ ] }),
6447
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
6448
+ ] });
6596
6449
  };
6597
- const ItemsForm = ({ preview, currencyCode }) => {
6598
- const [isSubmitting, setIsSubmitting] = React.useState(false);
6599
- const [modalContent, setModalContent] = React.useState(
6600
- null
6601
- );
6450
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
6451
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
6452
+ const MetadataForm = ({ orderId, metadata }) => {
6602
6453
  const { handleSuccess } = useRouteModal();
6603
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
6604
- const { hasPermission } = hooks.usePermissions();
6605
- const canReadVariants = hasPermission("product_variant:read");
6606
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
6607
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
6608
- const itemCount = preview.items?.reduce((acc, item) => acc + item.quantity, 0) || 0;
6609
- const matches = React.useMemo(() => {
6610
- return matchSorter.matchSorter(preview.items, query2, {
6611
- keys: ["product_title", "variant_title", "variant_sku", "title"]
6612
- });
6613
- }, [preview.items, query2]);
6614
- const onSubmit = async () => {
6615
- setIsSubmitting(true);
6616
- let requestSucceeded = false;
6617
- await requestOrderEdit(void 0, {
6618
- onError: (e) => {
6619
- ui.toast.error(`Failed to request order edit: ${e.message}`);
6620
- },
6621
- onSuccess: () => {
6622
- requestSucceeded = true;
6623
- }
6624
- });
6625
- if (!requestSucceeded) {
6626
- setIsSubmitting(false);
6627
- return;
6628
- }
6629
- await confirmOrderEdit(void 0, {
6630
- onError: (e) => {
6631
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
6632
- },
6633
- onSuccess: () => {
6634
- handleSuccess();
6635
- },
6636
- onSettled: () => {
6637
- setIsSubmitting(false);
6638
- }
6639
- });
6640
- };
6641
- const onKeyDown = React.useCallback(
6642
- (e) => {
6643
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
6644
- if (modalContent || isSubmitting) {
6645
- return;
6646
- }
6647
- onSubmit();
6648
- }
6649
- },
6650
- [modalContent, isSubmitting, onSubmit]
6651
- );
6652
- React.useEffect(() => {
6653
- document.addEventListener("keydown", onKeyDown);
6654
- return () => {
6655
- document.removeEventListener("keydown", onKeyDown);
6656
- };
6657
- }, [onKeyDown]);
6658
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
6659
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
6660
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
6661
- StackedFocusModal,
6662
- {
6663
- id: STACKED_MODAL_ID,
6664
- onOpenChangeCallback: (open) => {
6665
- if (!open) {
6666
- setModalContent(null);
6667
- }
6668
- },
6669
- children: [
6670
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
6671
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
6672
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
6673
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
6674
- ] }),
6675
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
6676
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
6677
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
6678
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
6679
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
6680
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
6681
- ] }),
6682
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
6683
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
6684
- ui.Input,
6685
- {
6686
- type: "search",
6687
- placeholder: "Search items",
6688
- value: searchValue,
6689
- onChange: (e) => onSearchValueChange(e.target.value)
6690
- }
6691
- ) }),
6692
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
6693
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
6694
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
6695
- canReadVariants && /* @__PURE__ */ jsxRuntime.jsx(
6696
- StackedModalTrigger$1,
6697
- {
6698
- type: "add-items",
6699
- setModalContent
6700
- }
6701
- ),
6702
- /* @__PURE__ */ jsxRuntime.jsx(
6703
- StackedModalTrigger$1,
6704
- {
6705
- type: "add-custom-item",
6706
- setModalContent
6707
- }
6708
- )
6709
- ] })
6710
- ] })
6711
- ] })
6712
- ] }),
6713
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
6714
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
6715
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
6716
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
6717
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
6718
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
6719
- ] }) }),
6720
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
6721
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
6722
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
6723
- ] }) : matches.length > 0 ? matches?.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
6724
- Item,
6725
- {
6726
- item,
6727
- preview,
6728
- currencyCode
6729
- },
6730
- item.id
6731
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
6732
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
6733
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
6734
- 'No items found for "',
6735
- query2,
6736
- '".'
6737
- ] })
6738
- ] }) })
6739
- ] })
6740
- ] }),
6741
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
6742
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
6743
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
6744
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
6745
- ui.Text,
6746
- {
6747
- size: "small",
6748
- leading: "compact",
6749
- className: "text-ui-fg-subtle",
6750
- children: [
6751
- itemCount,
6752
- " ",
6753
- itemCount === 1 ? "item" : "items"
6754
- ]
6755
- }
6756
- ) }),
6757
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
6758
- ] })
6759
- ] }) }),
6760
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
6761
- CustomItemForm,
6762
- {
6763
- orderId: preview.id,
6764
- currencyCode
6765
- }
6766
- ) : null)
6767
- ]
6768
- }
6769
- ) }),
6770
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
6771
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
6772
- /* @__PURE__ */ jsxRuntime.jsx(
6773
- ui.Button,
6774
- {
6775
- size: "small",
6776
- type: "button",
6777
- onClick: onSubmit,
6778
- isLoading: isSubmitting,
6779
- children: "Save"
6780
- }
6781
- )
6782
- ] }) })
6783
- ] });
6784
- };
6785
- const Item = ({ item, preview, currencyCode }) => {
6786
- if (item.variant_id) {
6787
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
6788
- }
6789
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
6790
- };
6791
- const VariantItem = ({ item, preview, currencyCode }) => {
6792
- const [editing, setEditing] = React.useState(false);
6454
+ const hasUneditableRows = getHasUneditableRows(metadata);
6455
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
6793
6456
  const form = reactHookForm.useForm({
6794
6457
  defaultValues: {
6795
- quantity: item.quantity,
6796
- unit_price: item.unit_price
6458
+ metadata: getDefaultValues(metadata)
6797
6459
  },
6798
- resolver: zod$1.zodResolver(variantItemSchema)
6460
+ resolver: zod$1.zodResolver(MetadataSchema)
6799
6461
  });
6800
- const actionId = React.useMemo(() => {
6801
- return item.actions?.find((a) => a.action === "ITEM_ADD")?.id;
6802
- }, [item]);
6803
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
6804
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
6805
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
6806
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem || isRemovingActionItem;
6807
- const onSubmit = form.handleSubmit(async (data) => {
6808
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
6809
- setEditing(false);
6810
- return;
6811
- }
6812
- if (!actionId) {
6813
- await updateOriginalItem(
6814
- {
6815
- item_id: item.id,
6816
- quantity: data.quantity,
6817
- unit_price: convertNumber(data.unit_price)
6818
- },
6819
- {
6820
- onSuccess: () => {
6821
- setEditing(false);
6822
- },
6823
- onError: (e) => {
6824
- ui.toast.error(e.message);
6825
- }
6826
- }
6827
- );
6828
- return;
6829
- }
6830
- if (data.quantity === 0) {
6831
- await removeActionItem(actionId, {
6832
- onSuccess: () => {
6833
- setEditing(false);
6834
- },
6835
- onError: (e) => {
6836
- ui.toast.error(e.message);
6837
- }
6838
- });
6839
- return;
6840
- }
6841
- await updateActionItem(
6462
+ const handleSubmit = form.handleSubmit(async (data) => {
6463
+ const parsedData = parseValues(data);
6464
+ await mutateAsync(
6842
6465
  {
6843
- action_id: actionId,
6844
- quantity: data.quantity,
6845
- unit_price: convertNumber(data.unit_price)
6466
+ metadata: parsedData
6846
6467
  },
6847
6468
  {
6848
6469
  onSuccess: () => {
6849
- setEditing(false);
6470
+ ui.toast.success("Metadata updated");
6471
+ handleSuccess();
6850
6472
  },
6851
- onError: (e) => {
6852
- ui.toast.error(e.message);
6473
+ onError: (error) => {
6474
+ ui.toast.error(error.message);
6853
6475
  }
6854
6476
  }
6855
6477
  );
6856
6478
  });
6857
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
6858
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
6859
- /* @__PURE__ */ jsxRuntime.jsx(
6860
- Thumbnail,
6861
- {
6862
- thumbnail: item.thumbnail,
6863
- alt: item.product_title ?? void 0
6864
- }
6865
- ),
6866
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
6867
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
6868
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
6869
- /* @__PURE__ */ jsxRuntime.jsxs(
6870
- ui.Text,
6871
- {
6872
- size: "small",
6873
- leading: "compact",
6874
- className: "text-ui-fg-subtle",
6875
- children: [
6876
- "(",
6877
- item.variant_title,
6878
- ")"
6879
- ]
6880
- }
6881
- )
6882
- ] }),
6883
- /* @__PURE__ */ jsxRuntime.jsx(
6884
- ui.Text,
6885
- {
6886
- size: "small",
6887
- leading: "compact",
6888
- className: "text-ui-fg-subtle",
6889
- children: item.variant_sku
6890
- }
6891
- )
6892
- ] })
6893
- ] }),
6894
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
6895
- Form$2.Field,
6479
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
6480
+ control: form.control,
6481
+ name: "metadata"
6482
+ });
6483
+ function deleteRow(index) {
6484
+ remove(index);
6485
+ if (fields.length === 1) {
6486
+ insert(0, {
6487
+ key: "",
6488
+ value: "",
6489
+ disabled: false
6490
+ });
6491
+ }
6492
+ }
6493
+ function insertRow(index, position) {
6494
+ insert(index + (position === "above" ? 0 : 1), {
6495
+ key: "",
6496
+ value: "",
6497
+ disabled: false
6498
+ });
6499
+ }
6500
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
6501
+ KeyboundForm,
6502
+ {
6503
+ onSubmit: handleSubmit,
6504
+ className: "flex flex-1 flex-col overflow-hidden",
6505
+ children: [
6506
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
6507
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
6508
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
6509
+ /* @__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" }) }),
6510
+ /* @__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" }) })
6511
+ ] }),
6512
+ fields.map((field, index) => {
6513
+ const isDisabled = field.disabled || false;
6514
+ let placeholder = "-";
6515
+ if (typeof field.value === "object") {
6516
+ placeholder = "{ ... }";
6517
+ }
6518
+ if (Array.isArray(field.value)) {
6519
+ placeholder = "[ ... ]";
6520
+ }
6521
+ return /* @__PURE__ */ jsxRuntime.jsx(
6522
+ ConditionalTooltip,
6523
+ {
6524
+ showTooltip: isDisabled,
6525
+ content: "This row is disabled because it contains non-primitive data.",
6526
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
6527
+ /* @__PURE__ */ jsxRuntime.jsxs(
6528
+ "div",
6529
+ {
6530
+ className: ui.clx("grid grid-cols-2 divide-x", {
6531
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
6532
+ }),
6533
+ children: [
6534
+ /* @__PURE__ */ jsxRuntime.jsx(
6535
+ Form$2.Field,
6536
+ {
6537
+ control: form.control,
6538
+ name: `metadata.${index}.key`,
6539
+ render: ({ field: field2 }) => {
6540
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
6541
+ GridInput,
6542
+ {
6543
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
6544
+ ...field2,
6545
+ disabled: isDisabled,
6546
+ placeholder: "Key"
6547
+ }
6548
+ ) }) });
6549
+ }
6550
+ }
6551
+ ),
6552
+ /* @__PURE__ */ jsxRuntime.jsx(
6553
+ Form$2.Field,
6554
+ {
6555
+ control: form.control,
6556
+ name: `metadata.${index}.value`,
6557
+ render: ({ field: { value, ...field2 } }) => {
6558
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
6559
+ GridInput,
6560
+ {
6561
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
6562
+ ...field2,
6563
+ value: isDisabled ? placeholder : value,
6564
+ disabled: isDisabled,
6565
+ placeholder: "Value"
6566
+ }
6567
+ ) }) });
6568
+ }
6569
+ }
6570
+ )
6571
+ ]
6572
+ }
6573
+ ),
6574
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
6575
+ /* @__PURE__ */ jsxRuntime.jsx(
6576
+ ui.DropdownMenu.Trigger,
6577
+ {
6578
+ className: ui.clx(
6579
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
6580
+ {
6581
+ hidden: isDisabled
6582
+ }
6583
+ ),
6584
+ disabled: isDisabled,
6585
+ asChild: true,
6586
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
6587
+ }
6588
+ ),
6589
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
6590
+ /* @__PURE__ */ jsxRuntime.jsxs(
6591
+ ui.DropdownMenu.Item,
6592
+ {
6593
+ className: "gap-x-2",
6594
+ onClick: () => insertRow(index, "above"),
6595
+ children: [
6596
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
6597
+ "Insert row above"
6598
+ ]
6599
+ }
6600
+ ),
6601
+ /* @__PURE__ */ jsxRuntime.jsxs(
6602
+ ui.DropdownMenu.Item,
6603
+ {
6604
+ className: "gap-x-2",
6605
+ onClick: () => insertRow(index, "below"),
6606
+ children: [
6607
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
6608
+ "Insert row below"
6609
+ ]
6610
+ }
6611
+ ),
6612
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
6613
+ /* @__PURE__ */ jsxRuntime.jsxs(
6614
+ ui.DropdownMenu.Item,
6615
+ {
6616
+ className: "gap-x-2",
6617
+ onClick: () => deleteRow(index),
6618
+ children: [
6619
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
6620
+ "Delete row"
6621
+ ]
6622
+ }
6623
+ )
6624
+ ] })
6625
+ ] })
6626
+ ] })
6627
+ },
6628
+ field.id
6629
+ );
6630
+ })
6631
+ ] }),
6632
+ 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." })
6633
+ ] }),
6634
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
6635
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
6636
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
6637
+ ] }) })
6638
+ ]
6639
+ }
6640
+ ) });
6641
+ };
6642
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
6643
+ return /* @__PURE__ */ jsxRuntime.jsx(
6644
+ "input",
6645
+ {
6646
+ ref,
6647
+ ...props,
6648
+ autoComplete: "off",
6649
+ className: ui.clx(
6650
+ "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",
6651
+ className
6652
+ )
6653
+ }
6654
+ );
6655
+ });
6656
+ GridInput.displayName = "MetadataForm.GridInput";
6657
+ const PlaceholderInner = () => {
6658
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
6659
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
6660
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
6661
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
6662
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
6663
+ ] }) })
6664
+ ] });
6665
+ };
6666
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
6667
+ function getDefaultValues(metadata) {
6668
+ if (!metadata || !Object.keys(metadata).length) {
6669
+ return [
6896
6670
  {
6897
- control: form.control,
6898
- name: "quantity",
6899
- render: ({ field }) => {
6900
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
6671
+ key: "",
6672
+ value: "",
6673
+ disabled: false
6674
+ }
6675
+ ];
6676
+ }
6677
+ return Object.entries(metadata).map(([key, value]) => {
6678
+ if (!EDITABLE_TYPES.includes(typeof value)) {
6679
+ return {
6680
+ key,
6681
+ value,
6682
+ disabled: true
6683
+ };
6684
+ }
6685
+ let stringValue = value;
6686
+ if (typeof value !== "string") {
6687
+ stringValue = JSON.stringify(value);
6688
+ }
6689
+ return {
6690
+ key,
6691
+ value: stringValue,
6692
+ original_key: key
6693
+ };
6694
+ });
6695
+ }
6696
+ function parseValues(values) {
6697
+ const metadata = values.metadata;
6698
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
6699
+ if (isEmpty) {
6700
+ return null;
6701
+ }
6702
+ const update = {};
6703
+ metadata.forEach((field) => {
6704
+ let key = field.key;
6705
+ let value = field.value;
6706
+ const disabled = field.disabled;
6707
+ if (!key || !value) {
6708
+ return;
6709
+ }
6710
+ if (disabled) {
6711
+ update[key] = value;
6712
+ return;
6713
+ }
6714
+ key = key.trim();
6715
+ value = value.trim();
6716
+ if (value === "true") {
6717
+ update[key] = true;
6718
+ } else if (value === "false") {
6719
+ update[key] = false;
6720
+ } else {
6721
+ const parsedNumber = parseFloat(value);
6722
+ if (!isNaN(parsedNumber)) {
6723
+ update[key] = parsedNumber;
6724
+ } else {
6725
+ update[key] = value;
6726
+ }
6727
+ }
6728
+ });
6729
+ return update;
6730
+ }
6731
+ function getHasUneditableRows(metadata) {
6732
+ if (!metadata) {
6733
+ return false;
6734
+ }
6735
+ return Object.values(metadata).some(
6736
+ (value) => !EDITABLE_TYPES.includes(typeof value)
6737
+ );
6738
+ }
6739
+ const handle$6 = {
6740
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
6741
+ };
6742
+ const NumberInput = React.forwardRef(
6743
+ ({
6744
+ value,
6745
+ onChange,
6746
+ size = "base",
6747
+ min = 0,
6748
+ max = 100,
6749
+ step = 1,
6750
+ className,
6751
+ disabled,
6752
+ ...props
6753
+ }, ref) => {
6754
+ const handleChange = (event) => {
6755
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
6756
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
6757
+ onChange(newValue);
6758
+ }
6759
+ };
6760
+ const handleIncrement = () => {
6761
+ const newValue = value + step;
6762
+ if (max === void 0 || newValue <= max) {
6763
+ onChange(newValue);
6764
+ }
6765
+ };
6766
+ const handleDecrement = () => {
6767
+ const newValue = value - step;
6768
+ if (min === void 0 || newValue >= min) {
6769
+ onChange(newValue);
6770
+ }
6771
+ };
6772
+ return /* @__PURE__ */ jsxRuntime.jsxs(
6773
+ "div",
6774
+ {
6775
+ className: ui.clx(
6776
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
6777
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
6778
+ {
6779
+ "h-7": size === "small",
6780
+ "h-8": size === "base"
6781
+ },
6782
+ className
6783
+ ),
6784
+ children: [
6785
+ /* @__PURE__ */ jsxRuntime.jsx(
6786
+ "input",
6787
+ {
6788
+ ref,
6789
+ type: "number",
6790
+ value,
6791
+ onChange: handleChange,
6792
+ min,
6793
+ max,
6794
+ step,
6795
+ className: ui.clx(
6796
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
6797
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
6798
+ "placeholder:text-ui-fg-muted"
6799
+ ),
6800
+ ...props
6801
+ }
6802
+ ),
6803
+ /* @__PURE__ */ jsxRuntime.jsxs(
6804
+ "button",
6805
+ {
6806
+ className: ui.clx(
6807
+ "flex items-center justify-center outline-none transition-fg",
6808
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
6809
+ "focus:bg-ui-bg-field-component-hover",
6810
+ "hover:bg-ui-bg-field-component-hover",
6811
+ {
6812
+ "size-7": size === "small",
6813
+ "size-8": size === "base"
6814
+ }
6815
+ ),
6816
+ type: "button",
6817
+ onClick: handleDecrement,
6818
+ disabled: min !== void 0 && value <= min || disabled,
6819
+ children: [
6820
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
6821
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
6822
+ ]
6823
+ }
6824
+ ),
6825
+ /* @__PURE__ */ jsxRuntime.jsxs(
6826
+ "button",
6827
+ {
6828
+ className: ui.clx(
6829
+ "flex items-center justify-center outline-none transition-fg",
6830
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
6831
+ "focus:bg-ui-bg-field-hover",
6832
+ "hover:bg-ui-bg-field-hover",
6833
+ {
6834
+ "size-7": size === "small",
6835
+ "size-8": size === "base"
6836
+ }
6837
+ ),
6838
+ type: "button",
6839
+ onClick: handleIncrement,
6840
+ disabled: max !== void 0 && value >= max || disabled,
6841
+ children: [
6842
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
6843
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
6844
+ ]
6845
+ }
6846
+ )
6847
+ ]
6848
+ }
6849
+ );
6850
+ }
6851
+ );
6852
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
6853
+ const productVariantsQueryKeys = {
6854
+ list: (query2) => [
6855
+ PRODUCT_VARIANTS_QUERY_KEY,
6856
+ query2 ? query2 : void 0
6857
+ ]
6858
+ };
6859
+ const useProductVariants = (query2, options) => {
6860
+ const { data, ...rest } = reactQuery.useQuery({
6861
+ queryKey: productVariantsQueryKeys.list(query2),
6862
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
6863
+ ...options
6864
+ });
6865
+ return { ...data, ...rest };
6866
+ };
6867
+ const useCancelOrderEdit = ({ preview }) => {
6868
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview?.id);
6869
+ const onCancel = React.useCallback(async () => {
6870
+ if (!preview) {
6871
+ return true;
6872
+ }
6873
+ let res = false;
6874
+ await cancelOrderEdit(void 0, {
6875
+ onError: (e) => {
6876
+ ui.toast.error(e.message);
6877
+ },
6878
+ onSuccess: () => {
6879
+ res = true;
6880
+ }
6881
+ });
6882
+ return res;
6883
+ }, [preview, cancelOrderEdit]);
6884
+ return { onCancel };
6885
+ };
6886
+ let IS_REQUEST_RUNNING = false;
6887
+ const useInitiateOrderEdit = ({
6888
+ preview
6889
+ }) => {
6890
+ const navigate = reactRouterDom.useNavigate();
6891
+ const { mutateAsync } = useDraftOrderBeginEdit(preview?.id);
6892
+ React.useEffect(() => {
6893
+ async function run() {
6894
+ if (IS_REQUEST_RUNNING || !preview) {
6895
+ return;
6896
+ }
6897
+ if (preview.order_change) {
6898
+ return;
6899
+ }
6900
+ IS_REQUEST_RUNNING = true;
6901
+ await mutateAsync(void 0, {
6902
+ onError: (e) => {
6903
+ ui.toast.error(e.message);
6904
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
6905
+ return;
6901
6906
  }
6907
+ });
6908
+ IS_REQUEST_RUNNING = false;
6909
+ }
6910
+ run();
6911
+ }, [preview, navigate, mutateAsync]);
6912
+ };
6913
+ function convertNumber(value) {
6914
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
6915
+ }
6916
+ const STACKED_MODAL_ID = "items_stacked_modal";
6917
+ const Items = () => {
6918
+ const { id } = reactRouterDom.useParams();
6919
+ const {
6920
+ order: preview,
6921
+ isPending: isPreviewPending,
6922
+ isError: isPreviewError,
6923
+ error: previewError
6924
+ } = useOrderPreview(id, void 0, {
6925
+ placeholderData: reactQuery.keepPreviousData
6926
+ });
6927
+ useInitiateOrderEdit({ preview });
6928
+ const { draft_order, isPending, isError, error } = useDraftOrder(
6929
+ id,
6930
+ {
6931
+ fields: "currency_code"
6932
+ },
6933
+ {
6934
+ enabled: !!id
6935
+ }
6936
+ );
6937
+ const { onCancel } = useCancelOrderEdit({ preview });
6938
+ if (isError) {
6939
+ throw error;
6940
+ }
6941
+ if (isPreviewError) {
6942
+ throw previewError;
6943
+ }
6944
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
6945
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
6946
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
6947
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
6948
+ ] }) });
6949
+ };
6950
+ const ItemsForm = ({ preview, currencyCode }) => {
6951
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
6952
+ const [modalContent, setModalContent] = React.useState(
6953
+ null
6954
+ );
6955
+ const { handleSuccess } = useRouteModal();
6956
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
6957
+ const { hasPermission } = hooks.usePermissions();
6958
+ const canReadVariants = hasPermission("product_variant:read");
6959
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
6960
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
6961
+ const itemCount = preview.items?.reduce((acc, item) => acc + item.quantity, 0) || 0;
6962
+ const matches = React.useMemo(() => {
6963
+ return matchSorter.matchSorter(preview.items, query2, {
6964
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
6965
+ });
6966
+ }, [preview.items, query2]);
6967
+ const onSubmit = async () => {
6968
+ setIsSubmitting(true);
6969
+ let requestSucceeded = false;
6970
+ await requestOrderEdit(void 0, {
6971
+ onError: (e) => {
6972
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
6973
+ },
6974
+ onSuccess: () => {
6975
+ requestSucceeded = true;
6902
6976
  }
6903
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
6904
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
6905
- Form$2.Field,
6906
- {
6907
- control: form.control,
6908
- name: "unit_price",
6909
- render: ({ field: { onChange, ...field } }) => {
6910
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
6911
- ui.CurrencyInput,
6912
- {
6913
- ...field,
6914
- symbol: getNativeSymbol(currencyCode),
6915
- code: currencyCode,
6916
- onValueChange: (_value, _name, values) => onChange(values?.value)
6917
- }
6918
- ) }) });
6977
+ });
6978
+ if (!requestSucceeded) {
6979
+ setIsSubmitting(false);
6980
+ return;
6981
+ }
6982
+ await confirmOrderEdit(void 0, {
6983
+ onError: (e) => {
6984
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
6985
+ },
6986
+ onSuccess: () => {
6987
+ handleSuccess();
6988
+ },
6989
+ onSettled: () => {
6990
+ setIsSubmitting(false);
6991
+ }
6992
+ });
6993
+ };
6994
+ const onKeyDown = React.useCallback(
6995
+ (e) => {
6996
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
6997
+ if (modalContent || isSubmitting) {
6998
+ return;
6919
6999
  }
7000
+ onSubmit();
6920
7001
  }
6921
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
6922
- /* @__PURE__ */ jsxRuntime.jsx(
6923
- ui.IconButton,
7002
+ },
7003
+ [modalContent, isSubmitting, onSubmit]
7004
+ );
7005
+ React.useEffect(() => {
7006
+ document.addEventListener("keydown", onKeyDown);
7007
+ return () => {
7008
+ document.removeEventListener("keydown", onKeyDown);
7009
+ };
7010
+ }, [onKeyDown]);
7011
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
7012
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
7013
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
7014
+ StackedFocusModal,
6924
7015
  {
6925
- type: "button",
6926
- size: "small",
6927
- onClick: editing ? onSubmit : () => {
6928
- setEditing(true);
7016
+ id: STACKED_MODAL_ID,
7017
+ onOpenChangeCallback: (open) => {
7018
+ if (!open) {
7019
+ setModalContent(null);
7020
+ }
6929
7021
  },
6930
- disabled: isPending,
6931
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
7022
+ children: [
7023
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
7024
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7025
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
7026
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
7027
+ ] }),
7028
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7029
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
7030
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
7031
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
7032
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
7033
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
7034
+ ] }),
7035
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
7036
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
7037
+ ui.Input,
7038
+ {
7039
+ type: "search",
7040
+ placeholder: "Search items",
7041
+ value: searchValue,
7042
+ onChange: (e) => onSearchValueChange(e.target.value)
7043
+ }
7044
+ ) }),
7045
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
7046
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
7047
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
7048
+ canReadVariants && /* @__PURE__ */ jsxRuntime.jsx(
7049
+ StackedModalTrigger$1,
7050
+ {
7051
+ type: "add-items",
7052
+ setModalContent
7053
+ }
7054
+ ),
7055
+ /* @__PURE__ */ jsxRuntime.jsx(
7056
+ StackedModalTrigger$1,
7057
+ {
7058
+ type: "add-custom-item",
7059
+ setModalContent
7060
+ }
7061
+ )
7062
+ ] })
7063
+ ] })
7064
+ ] })
7065
+ ] }),
7066
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
7067
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
7068
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
7069
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
7070
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
7071
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
7072
+ ] }) }),
7073
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
7074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
7075
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
7076
+ ] }) : matches.length > 0 ? matches?.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
7077
+ Item,
7078
+ {
7079
+ item,
7080
+ preview,
7081
+ currencyCode
7082
+ },
7083
+ item.id
7084
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
7085
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
7086
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
7087
+ 'No items found for "',
7088
+ query2,
7089
+ '".'
7090
+ ] })
7091
+ ] }) })
7092
+ ] })
7093
+ ] }),
7094
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7095
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
7096
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
7097
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
7098
+ ui.Text,
7099
+ {
7100
+ size: "small",
7101
+ leading: "compact",
7102
+ className: "text-ui-fg-subtle",
7103
+ children: [
7104
+ itemCount,
7105
+ " ",
7106
+ itemCount === 1 ? "item" : "items"
7107
+ ]
7108
+ }
7109
+ ) }),
7110
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
7111
+ ] })
7112
+ ] }) }),
7113
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
7114
+ CustomItemForm,
7115
+ {
7116
+ orderId: preview.id,
7117
+ currencyCode
7118
+ }
7119
+ ) : null)
7120
+ ]
6932
7121
  }
6933
- )
6934
- ] }) }) });
7122
+ ) }),
7123
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7124
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7125
+ /* @__PURE__ */ jsxRuntime.jsx(
7126
+ ui.Button,
7127
+ {
7128
+ size: "small",
7129
+ type: "button",
7130
+ onClick: onSubmit,
7131
+ isLoading: isSubmitting,
7132
+ children: "Save"
7133
+ }
7134
+ )
7135
+ ] }) })
7136
+ ] });
6935
7137
  };
6936
- const variantItemSchema = zod.z.object({
6937
- quantity: zod.z.number(),
6938
- unit_price: zod.z.union([zod.z.number(), zod.z.string()])
6939
- });
6940
- const CustomItem = ({ item, preview, currencyCode }) => {
7138
+ const Item = ({ item, preview, currencyCode }) => {
7139
+ if (item.variant_id) {
7140
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
7141
+ }
7142
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
7143
+ };
7144
+ const VariantItem = ({ item, preview, currencyCode }) => {
6941
7145
  const [editing, setEditing] = React.useState(false);
6942
- const { quantity, unit_price, title } = item;
6943
7146
  const form = reactHookForm.useForm({
6944
7147
  defaultValues: {
6945
- title,
6946
- quantity,
6947
- unit_price
7148
+ quantity: item.quantity,
7149
+ unit_price: item.unit_price
6948
7150
  },
6949
- resolver: zod$1.zodResolver(customItemSchema)
7151
+ resolver: zod$1.zodResolver(variantItemSchema)
6950
7152
  });
6951
- React.useEffect(() => {
6952
- form.reset({
6953
- title,
6954
- quantity,
6955
- unit_price
6956
- });
6957
- }, [form, title, quantity, unit_price]);
6958
7153
  const actionId = React.useMemo(() => {
6959
7154
  return item.actions?.find((a) => a.action === "ITEM_ADD")?.id;
6960
7155
  }, [item]);
6961
7156
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
6962
7157
  const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
6963
7158
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
6964
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
7159
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem || isRemovingActionItem;
6965
7160
  const onSubmit = form.handleSubmit(async (data) => {
6966
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
7161
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
6967
7162
  setEditing(false);
6968
7163
  return;
6969
7164
  }
@@ -6981,344 +7176,188 @@ const CustomItem = ({ item, preview, currencyCode }) => {
6981
7176
  onError: (e) => {
6982
7177
  ui.toast.error(e.message);
6983
7178
  }
6984
- }
6985
- );
6986
- return;
6987
- }
6988
- if (data.quantity === 0) {
6989
- await removeActionItem(actionId, {
6990
- onSuccess: () => {
6991
- setEditing(false);
6992
- },
6993
- onError: (e) => {
6994
- ui.toast.error(e.message);
6995
- }
6996
- });
6997
- return;
6998
- }
6999
- await updateActionItem(
7000
- {
7001
- action_id: actionId,
7002
- quantity: data.quantity,
7003
- unit_price: convertNumber(data.unit_price)
7004
- },
7005
- {
7006
- onSuccess: () => {
7007
- setEditing(false);
7008
- },
7009
- onError: (e) => {
7010
- ui.toast.error(e.message);
7011
- }
7012
- }
7013
- );
7014
- });
7015
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
7016
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
7017
- /* @__PURE__ */ jsxRuntime.jsx(
7018
- Thumbnail,
7019
- {
7020
- thumbnail: item.thumbnail,
7021
- alt: item.title ?? void 0
7022
- }
7023
- ),
7024
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
7025
- Form$2.Field,
7026
- {
7027
- control: form.control,
7028
- name: "title",
7029
- render: ({ field }) => {
7030
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
7031
- }
7032
- }
7033
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
7034
- ] }),
7035
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
7036
- Form$2.Field,
7037
- {
7038
- control: form.control,
7039
- name: "quantity",
7040
- render: ({ field }) => {
7041
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
7042
- }
7043
- }
7044
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
7045
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
7046
- Form$2.Field,
7047
- {
7048
- control: form.control,
7049
- name: "unit_price",
7050
- render: ({ field: { onChange, ...field } }) => {
7051
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7052
- ui.CurrencyInput,
7053
- {
7054
- ...field,
7055
- symbol: getNativeSymbol(currencyCode),
7056
- code: currencyCode,
7057
- onValueChange: (_value, _name, values) => onChange(values?.value)
7058
- }
7059
- ) }) });
7060
- }
7061
- }
7062
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
7063
- /* @__PURE__ */ jsxRuntime.jsx(
7064
- ui.IconButton,
7065
- {
7066
- type: "button",
7067
- size: "small",
7068
- onClick: editing ? onSubmit : () => {
7069
- setEditing(true);
7070
- },
7071
- disabled: isPending,
7072
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
7073
- }
7074
- )
7075
- ] }) }) });
7076
- };
7077
- const StackedModalTrigger$1 = ({
7078
- type,
7079
- setModalContent
7080
- }) => {
7081
- const { setIsOpen } = useStackedModal();
7082
- const onClick = React.useCallback(() => {
7083
- setModalContent(type);
7084
- setIsOpen(STACKED_MODAL_ID, true);
7085
- }, [setModalContent, setIsOpen, type]);
7086
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
7087
- };
7088
- const VARIANT_PREFIX = "items";
7089
- const LIMIT = 50;
7090
- const ExistingItemsForm = ({ orderId, items }) => {
7091
- const { setIsOpen } = useStackedModal();
7092
- const [rowSelection, setRowSelection] = React.useState(
7093
- items.reduce((acc, item) => {
7094
- acc[item.variant_id] = true;
7095
- return acc;
7096
- }, {})
7097
- );
7098
- React.useEffect(() => {
7099
- setRowSelection(
7100
- items.reduce((acc, item) => {
7101
- if (item.variant_id) {
7102
- acc[item.variant_id] = true;
7103
- }
7104
- return acc;
7105
- }, {})
7106
- );
7107
- }, [items]);
7108
- const { q, order, offset } = useQueryParams(
7109
- ["q", "order", "offset"],
7110
- VARIANT_PREFIX
7111
- );
7112
- const { variants, count, isPending, isError, error } = useProductVariants(
7113
- {
7114
- q,
7115
- order,
7116
- offset: offset ? parseInt(offset) : void 0,
7117
- limit: LIMIT,
7118
- fields: "*inventory_items.inventory.location_levels,+inventory_quantity,+manage_inventory"
7119
- },
7120
- {
7121
- placeholderData: reactQuery.keepPreviousData
7122
- }
7123
- );
7124
- const columns = useColumns();
7125
- const { mutateAsync } = useDraftOrderAddItems(orderId);
7126
- const onSubmit = async () => {
7127
- const ids = Object.keys(rowSelection).filter(
7128
- (id) => !items.find((i) => i.variant_id === id)
7129
- );
7130
- await mutateAsync(
7131
- {
7132
- items: ids.map((id) => ({
7133
- variant_id: id,
7134
- quantity: 1
7135
- }))
7136
- },
7137
- {
7138
- onSuccess: () => {
7139
- setRowSelection({});
7140
- setIsOpen(STACKED_MODAL_ID, false);
7141
- },
7142
- onError: (e) => {
7143
- ui.toast.error(e.message);
7144
- }
7145
- }
7146
- );
7147
- };
7148
- if (isError) {
7149
- throw error;
7150
- }
7151
- return /* @__PURE__ */ jsxRuntime.jsxs(
7152
- StackedFocusModal.Content,
7153
- {
7154
- onOpenAutoFocus: (e) => {
7155
- e.preventDefault();
7156
- const searchInput = document.querySelector(
7157
- "[data-modal-id='modal-search-input']"
7158
- );
7159
- if (searchInput) {
7160
- searchInput.focus();
7161
- }
7162
- },
7163
- children: [
7164
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
7165
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
7166
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
7167
- ] }),
7168
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
7169
- DataTable,
7170
- {
7171
- data: variants,
7172
- columns,
7173
- isLoading: isPending,
7174
- getRowId: (row) => row.id,
7175
- rowCount: count,
7176
- prefix: VARIANT_PREFIX,
7177
- layout: "fill",
7178
- rowSelection: {
7179
- state: rowSelection,
7180
- onRowSelectionChange: setRowSelection,
7181
- enableRowSelection: (row) => {
7182
- return !items.find((i) => i.variant_id === row.original.id);
7183
- }
7184
- },
7185
- autoFocusSearch: true
7186
- }
7187
- ) }),
7188
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7189
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7190
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
7191
- ] }) })
7192
- ]
7179
+ }
7180
+ );
7181
+ return;
7193
7182
  }
7194
- );
7195
- };
7196
- const columnHelper = ui.createDataTableColumnHelper();
7197
- const getVariantInventory = (variant) => {
7198
- if (!variant.manage_inventory) {
7199
- return { text: "Not managed", hasInventoryKit: false, notManaged: true };
7200
- }
7201
- const quantity = variant.inventory_quantity;
7202
- const inventoryItems = variant.inventory_items?.map((i) => i.inventory).filter(Boolean) ?? [];
7203
- const hasInventoryKit = inventoryItems.length > 1;
7204
- const locations = {};
7205
- inventoryItems.forEach((i) => {
7206
- i.location_levels?.forEach((l) => {
7207
- locations[l.id] = true;
7208
- });
7209
- });
7210
- const locationCount = Object.keys(locations).length;
7211
- const text = hasInventoryKit ? `${quantity} available` : `${quantity} available at ${locationCount} location${locationCount === 1 ? "" : "s"}`;
7212
- return { text, hasInventoryKit, quantity, notManaged: false };
7213
- };
7214
- const useColumns = () => {
7215
- return React.useMemo(() => {
7216
- return [
7217
- columnHelper.select(),
7218
- columnHelper.accessor("product.title", {
7219
- header: "Product",
7220
- cell: ({ row }) => {
7221
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
7222
- /* @__PURE__ */ jsxRuntime.jsx(
7223
- Thumbnail,
7224
- {
7225
- thumbnail: row.original.product?.thumbnail,
7226
- alt: row.original.product?.title
7227
- }
7228
- ),
7229
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: row.original.product?.title })
7230
- ] });
7183
+ if (data.quantity === 0) {
7184
+ await removeActionItem(actionId, {
7185
+ onSuccess: () => {
7186
+ setEditing(false);
7231
7187
  },
7232
- enableSorting: true
7233
- }),
7234
- columnHelper.accessor("title", {
7235
- header: "Variant",
7236
- enableSorting: true
7237
- }),
7238
- columnHelper.accessor("sku", {
7239
- header: "SKU",
7240
- cell: ({ getValue }) => {
7241
- return getValue() ?? "-";
7188
+ onError: (e) => {
7189
+ ui.toast.error(e.message);
7190
+ }
7191
+ });
7192
+ return;
7193
+ }
7194
+ await updateActionItem(
7195
+ {
7196
+ action_id: actionId,
7197
+ quantity: data.quantity,
7198
+ unit_price: convertNumber(data.unit_price)
7199
+ },
7200
+ {
7201
+ onSuccess: () => {
7202
+ setEditing(false);
7242
7203
  },
7243
- enableSorting: true
7244
- }),
7245
- columnHelper.accessor("updated_at", {
7246
- header: "Updated",
7247
- cell: ({ getValue }) => {
7248
- return /* @__PURE__ */ jsxRuntime.jsx(
7249
- ui.Tooltip,
7204
+ onError: (e) => {
7205
+ ui.toast.error(e.message);
7206
+ }
7207
+ }
7208
+ );
7209
+ });
7210
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
7211
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
7212
+ /* @__PURE__ */ jsxRuntime.jsx(
7213
+ Thumbnail,
7214
+ {
7215
+ thumbnail: item.thumbnail,
7216
+ alt: item.product_title ?? void 0
7217
+ }
7218
+ ),
7219
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
7220
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
7221
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
7222
+ /* @__PURE__ */ jsxRuntime.jsxs(
7223
+ ui.Text,
7250
7224
  {
7251
- content: getFullDate({ date: getValue(), includeTime: true }),
7252
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
7225
+ size: "small",
7226
+ leading: "compact",
7227
+ className: "text-ui-fg-subtle",
7228
+ children: [
7229
+ "(",
7230
+ item.variant_title,
7231
+ ")"
7232
+ ]
7253
7233
  }
7254
- );
7255
- },
7256
- enableSorting: true,
7257
- sortAscLabel: "Oldest first",
7258
- sortDescLabel: "Newest first"
7259
- }),
7260
- columnHelper.accessor("created_at", {
7261
- header: "Created",
7262
- cell: ({ getValue }) => {
7263
- return /* @__PURE__ */ jsxRuntime.jsx(
7264
- ui.Tooltip,
7234
+ )
7235
+ ] }),
7236
+ /* @__PURE__ */ jsxRuntime.jsx(
7237
+ ui.Text,
7238
+ {
7239
+ size: "small",
7240
+ leading: "compact",
7241
+ className: "text-ui-fg-subtle",
7242
+ children: item.variant_sku
7243
+ }
7244
+ )
7245
+ ] })
7246
+ ] }),
7247
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
7248
+ Form$2.Field,
7249
+ {
7250
+ control: form.control,
7251
+ name: "quantity",
7252
+ render: ({ field }) => {
7253
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
7254
+ }
7255
+ }
7256
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
7257
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
7258
+ Form$2.Field,
7259
+ {
7260
+ control: form.control,
7261
+ name: "unit_price",
7262
+ render: ({ field: { onChange, ...field } }) => {
7263
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7264
+ ui.CurrencyInput,
7265
7265
  {
7266
- content: getFullDate({ date: getValue(), includeTime: true }),
7267
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
7266
+ ...field,
7267
+ symbol: getNativeSymbol(currencyCode),
7268
+ code: currencyCode,
7269
+ onValueChange: (_value, _name, values) => onChange(values?.value)
7268
7270
  }
7269
- );
7271
+ ) }) });
7272
+ }
7273
+ }
7274
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
7275
+ /* @__PURE__ */ jsxRuntime.jsx(
7276
+ ui.IconButton,
7277
+ {
7278
+ type: "button",
7279
+ size: "small",
7280
+ onClick: editing ? onSubmit : () => {
7281
+ setEditing(true);
7270
7282
  },
7271
- enableSorting: true,
7272
- sortAscLabel: "Oldest first",
7273
- sortDescLabel: "Newest first"
7274
- }),
7275
- columnHelper.display({
7276
- id: "inventory",
7277
- header: "Stock",
7278
- cell: ({ row }) => {
7279
- const { text, hasInventoryKit, quantity, notManaged } = getVariantInventory(row.original);
7280
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: text, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full w-full items-center gap-2 overflow-hidden", children: [
7281
- hasInventoryKit && /* @__PURE__ */ jsxRuntime.jsx(icons.Component, {}),
7282
- /* @__PURE__ */ jsxRuntime.jsx(
7283
- "span",
7284
- {
7285
- className: ui.clx("truncate", {
7286
- "text-ui-fg-error": !quantity && !notManaged
7287
- }),
7288
- children: text
7289
- }
7290
- )
7291
- ] }) });
7283
+ disabled: isPending,
7284
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
7285
+ }
7286
+ )
7287
+ ] }) }) });
7288
+ };
7289
+ const variantItemSchema = zod.z.object({
7290
+ quantity: zod.z.number(),
7291
+ unit_price: zod.z.union([zod.z.number(), zod.z.string()])
7292
+ });
7293
+ const CustomItem = ({ item, preview, currencyCode }) => {
7294
+ const [editing, setEditing] = React.useState(false);
7295
+ const { quantity, unit_price, title } = item;
7296
+ const form = reactHookForm.useForm({
7297
+ defaultValues: {
7298
+ title,
7299
+ quantity,
7300
+ unit_price
7301
+ },
7302
+ resolver: zod$1.zodResolver(customItemSchema)
7303
+ });
7304
+ React.useEffect(() => {
7305
+ form.reset({
7306
+ title,
7307
+ quantity,
7308
+ unit_price
7309
+ });
7310
+ }, [form, title, quantity, unit_price]);
7311
+ const actionId = React.useMemo(() => {
7312
+ return item.actions?.find((a) => a.action === "ITEM_ADD")?.id;
7313
+ }, [item]);
7314
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
7315
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
7316
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
7317
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
7318
+ const onSubmit = form.handleSubmit(async (data) => {
7319
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
7320
+ setEditing(false);
7321
+ return;
7322
+ }
7323
+ if (!actionId) {
7324
+ await updateOriginalItem(
7325
+ {
7326
+ item_id: item.id,
7327
+ quantity: data.quantity,
7328
+ unit_price: convertNumber(data.unit_price)
7329
+ },
7330
+ {
7331
+ onSuccess: () => {
7332
+ setEditing(false);
7333
+ },
7334
+ onError: (e) => {
7335
+ ui.toast.error(e.message);
7336
+ }
7337
+ }
7338
+ );
7339
+ return;
7340
+ }
7341
+ if (data.quantity === 0) {
7342
+ await removeActionItem(actionId, {
7343
+ onSuccess: () => {
7344
+ setEditing(false);
7345
+ },
7346
+ onError: (e) => {
7347
+ ui.toast.error(e.message);
7292
7348
  }
7293
- })
7294
- ];
7295
- }, []);
7296
- };
7297
- const CustomItemForm = ({ orderId, currencyCode }) => {
7298
- const { setIsOpen } = useStackedModal();
7299
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
7300
- const form = reactHookForm.useForm({
7301
- defaultValues: {
7302
- title: "",
7303
- quantity: 1,
7304
- unit_price: ""
7305
- },
7306
- resolver: zod$1.zodResolver(customItemSchema)
7307
- });
7308
- const onSubmit = form.handleSubmit(async (data) => {
7309
- await addItems(
7349
+ });
7350
+ return;
7351
+ }
7352
+ await updateActionItem(
7310
7353
  {
7311
- items: [
7312
- {
7313
- title: data.title,
7314
- quantity: data.quantity,
7315
- unit_price: convertNumber(data.unit_price)
7316
- }
7317
- ]
7354
+ action_id: actionId,
7355
+ quantity: data.quantity,
7356
+ unit_price: convertNumber(data.unit_price)
7318
7357
  },
7319
7358
  {
7320
7359
  onSuccess: () => {
7321
- setIsOpen(STACKED_MODAL_ID, false);
7360
+ setEditing(false);
7322
7361
  },
7323
7362
  onError: (e) => {
7324
7363
  ui.toast.error(e.message);
@@ -7326,440 +7365,401 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
7326
7365
  }
7327
7366
  );
7328
7367
  });
7329
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
7330
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
7331
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
7332
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7333
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
7334
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
7335
- ] }),
7336
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7368
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
7369
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
7337
7370
  /* @__PURE__ */ jsxRuntime.jsx(
7338
- Form$2.Field,
7371
+ Thumbnail,
7339
7372
  {
7340
- control: form.control,
7341
- name: "title",
7342
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
7343
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7344
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
7345
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
7346
- ] }),
7347
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7348
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7349
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7350
- ] })
7351
- ] }) })
7373
+ thumbnail: item.thumbnail,
7374
+ alt: item.title ?? void 0
7352
7375
  }
7353
7376
  ),
7354
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7355
- /* @__PURE__ */ jsxRuntime.jsx(
7377
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
7356
7378
  Form$2.Field,
7357
7379
  {
7358
7380
  control: form.control,
7359
- name: "unit_price",
7360
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
7361
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7362
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
7363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
7364
- ] }),
7365
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7367
- ui.CurrencyInput,
7368
- {
7369
- symbol: getNativeSymbol(currencyCode),
7370
- code: currencyCode,
7371
- onValueChange: (_value, _name, values) => onChange(values?.value),
7372
- ...field
7373
- }
7374
- ) }),
7375
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7376
- ] })
7377
- ] }) })
7381
+ name: "title",
7382
+ render: ({ field }) => {
7383
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
7384
+ }
7378
7385
  }
7379
- ),
7380
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7381
- /* @__PURE__ */ jsxRuntime.jsx(
7382
- Form$2.Field,
7383
- {
7384
- control: form.control,
7385
- name: "quantity",
7386
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
7387
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7388
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
7389
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
7390
- ] }),
7391
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
7392
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
7393
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7394
- ] })
7395
- ] }) })
7386
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
7387
+ ] }),
7388
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
7389
+ Form$2.Field,
7390
+ {
7391
+ control: form.control,
7392
+ name: "quantity",
7393
+ render: ({ field }) => {
7394
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
7396
7395
  }
7397
- )
7398
- ] }) }) }),
7399
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7400
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7401
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
7402
- ] }) })
7403
- ] }) }) });
7404
- };
7405
- const customItemSchema = zod.z.object({
7406
- title: zod.z.string().min(1),
7407
- quantity: zod.z.number(),
7408
- unit_price: zod.z.union([zod.z.number(), zod.z.string()])
7409
- });
7410
- const handle$6 = {
7411
- permissions: EDIT_DRAFT_ORDER_PERMISSIONS
7412
- };
7413
- const InlineTip = React.forwardRef(
7414
- ({ variant = "tip", label, className, children, ...props }, ref) => {
7415
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
7416
- return /* @__PURE__ */ jsxRuntime.jsxs(
7417
- "div",
7396
+ }
7397
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
7398
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
7399
+ Form$2.Field,
7418
7400
  {
7419
- ref,
7420
- className: ui.clx(
7421
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
7422
- className
7423
- ),
7424
- ...props,
7425
- children: [
7426
- /* @__PURE__ */ jsxRuntime.jsx(
7427
- "div",
7401
+ control: form.control,
7402
+ name: "unit_price",
7403
+ render: ({ field: { onChange, ...field } }) => {
7404
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7405
+ ui.CurrencyInput,
7428
7406
  {
7429
- role: "presentation",
7430
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
7431
- "bg-ui-tag-orange-icon": variant === "warning"
7432
- })
7407
+ ...field,
7408
+ symbol: getNativeSymbol(currencyCode),
7409
+ code: currencyCode,
7410
+ onValueChange: (_value, _name, values) => onChange(values?.value)
7433
7411
  }
7434
- ),
7435
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
7436
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
7437
- labelValue,
7438
- ":"
7439
- ] }),
7440
- " ",
7441
- children
7442
- ] })
7443
- ]
7412
+ ) }) });
7413
+ }
7444
7414
  }
7445
- );
7446
- }
7447
- );
7448
- InlineTip.displayName = "InlineTip";
7449
- const MetadataFieldSchema = zod.z.object({
7450
- key: zod.z.string(),
7451
- disabled: zod.z.boolean().optional(),
7452
- value: zod.z.any()
7453
- });
7454
- const MetadataSchema = zod.z.object({
7455
- metadata: zod.z.array(MetadataFieldSchema)
7456
- });
7457
- const Metadata = () => {
7458
- const { id } = reactRouterDom.useParams();
7459
- const { order, isPending, isError, error } = useOrder(id, {
7460
- fields: "metadata"
7461
- });
7462
- if (isError) {
7463
- throw error;
7464
- }
7465
- const isReady = !isPending && !!order;
7466
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
7467
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
7468
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
7469
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
7470
- ] }),
7471
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
7472
- ] });
7415
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
7416
+ /* @__PURE__ */ jsxRuntime.jsx(
7417
+ ui.IconButton,
7418
+ {
7419
+ type: "button",
7420
+ size: "small",
7421
+ onClick: editing ? onSubmit : () => {
7422
+ setEditing(true);
7423
+ },
7424
+ disabled: isPending,
7425
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
7426
+ }
7427
+ )
7428
+ ] }) }) });
7473
7429
  };
7474
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
7475
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
7476
- const MetadataForm = ({ orderId, metadata }) => {
7477
- const { handleSuccess } = useRouteModal();
7478
- const hasUneditableRows = getHasUneditableRows(metadata);
7479
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
7480
- const form = reactHookForm.useForm({
7481
- defaultValues: {
7482
- metadata: getDefaultValues(metadata)
7430
+ const StackedModalTrigger$1 = ({
7431
+ type,
7432
+ setModalContent
7433
+ }) => {
7434
+ const { setIsOpen } = useStackedModal();
7435
+ const onClick = React.useCallback(() => {
7436
+ setModalContent(type);
7437
+ setIsOpen(STACKED_MODAL_ID, true);
7438
+ }, [setModalContent, setIsOpen, type]);
7439
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
7440
+ };
7441
+ const VARIANT_PREFIX = "items";
7442
+ const LIMIT = 50;
7443
+ const ExistingItemsForm = ({ orderId, items }) => {
7444
+ const { setIsOpen } = useStackedModal();
7445
+ const [rowSelection, setRowSelection] = React.useState(
7446
+ items.reduce((acc, item) => {
7447
+ acc[item.variant_id] = true;
7448
+ return acc;
7449
+ }, {})
7450
+ );
7451
+ React.useEffect(() => {
7452
+ setRowSelection(
7453
+ items.reduce((acc, item) => {
7454
+ if (item.variant_id) {
7455
+ acc[item.variant_id] = true;
7456
+ }
7457
+ return acc;
7458
+ }, {})
7459
+ );
7460
+ }, [items]);
7461
+ const { q, order, offset } = useQueryParams(
7462
+ ["q", "order", "offset"],
7463
+ VARIANT_PREFIX
7464
+ );
7465
+ const { variants, count, isPending, isError, error } = useProductVariants(
7466
+ {
7467
+ q,
7468
+ order,
7469
+ offset: offset ? parseInt(offset) : void 0,
7470
+ limit: LIMIT,
7471
+ fields: "*inventory_items.inventory.location_levels,+inventory_quantity,+manage_inventory"
7483
7472
  },
7484
- resolver: zod$1.zodResolver(MetadataSchema)
7485
- });
7486
- const handleSubmit = form.handleSubmit(async (data) => {
7487
- const parsedData = parseValues(data);
7473
+ {
7474
+ placeholderData: reactQuery.keepPreviousData
7475
+ }
7476
+ );
7477
+ const columns = useColumns();
7478
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
7479
+ const onSubmit = async () => {
7480
+ const ids = Object.keys(rowSelection).filter(
7481
+ (id) => !items.find((i) => i.variant_id === id)
7482
+ );
7488
7483
  await mutateAsync(
7489
7484
  {
7490
- metadata: parsedData
7485
+ items: ids.map((id) => ({
7486
+ variant_id: id,
7487
+ quantity: 1
7488
+ }))
7491
7489
  },
7492
7490
  {
7493
7491
  onSuccess: () => {
7494
- ui.toast.success("Metadata updated");
7495
- handleSuccess();
7492
+ setRowSelection({});
7493
+ setIsOpen(STACKED_MODAL_ID, false);
7496
7494
  },
7497
- onError: (error) => {
7498
- ui.toast.error(error.message);
7495
+ onError: (e) => {
7496
+ ui.toast.error(e.message);
7499
7497
  }
7500
7498
  }
7501
7499
  );
7502
- });
7503
- const { fields, insert, remove } = reactHookForm.useFieldArray({
7504
- control: form.control,
7505
- name: "metadata"
7506
- });
7507
- function deleteRow(index) {
7508
- remove(index);
7509
- if (fields.length === 1) {
7510
- insert(0, {
7511
- key: "",
7512
- value: "",
7513
- disabled: false
7514
- });
7515
- }
7516
- }
7517
- function insertRow(index, position) {
7518
- insert(index + (position === "above" ? 0 : 1), {
7519
- key: "",
7520
- value: "",
7521
- disabled: false
7522
- });
7500
+ };
7501
+ if (isError) {
7502
+ throw error;
7523
7503
  }
7524
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
7525
- KeyboundForm,
7504
+ return /* @__PURE__ */ jsxRuntime.jsxs(
7505
+ StackedFocusModal.Content,
7526
7506
  {
7527
- onSubmit: handleSubmit,
7528
- className: "flex flex-1 flex-col overflow-hidden",
7507
+ onOpenAutoFocus: (e) => {
7508
+ e.preventDefault();
7509
+ const searchInput = document.querySelector(
7510
+ "[data-modal-id='modal-search-input']"
7511
+ );
7512
+ if (searchInput) {
7513
+ searchInput.focus();
7514
+ }
7515
+ },
7529
7516
  children: [
7530
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
7531
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
7532
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
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_KEY_LABEL_ID, children: "Key" }) }),
7534
- /* @__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" }) })
7535
- ] }),
7536
- fields.map((field, index) => {
7537
- const isDisabled = field.disabled || false;
7538
- let placeholder = "-";
7539
- if (typeof field.value === "object") {
7540
- placeholder = "{ ... }";
7541
- }
7542
- if (Array.isArray(field.value)) {
7543
- placeholder = "[ ... ]";
7544
- }
7545
- return /* @__PURE__ */ jsxRuntime.jsx(
7546
- ConditionalTooltip,
7547
- {
7548
- showTooltip: isDisabled,
7549
- content: "This row is disabled because it contains non-primitive data.",
7550
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
7551
- /* @__PURE__ */ jsxRuntime.jsxs(
7552
- "div",
7553
- {
7554
- className: ui.clx("grid grid-cols-2 divide-x", {
7555
- "overflow-hidden rounded-b-lg": index === fields.length - 1
7556
- }),
7557
- children: [
7558
- /* @__PURE__ */ jsxRuntime.jsx(
7559
- Form$2.Field,
7560
- {
7561
- control: form.control,
7562
- name: `metadata.${index}.key`,
7563
- render: ({ field: field2 }) => {
7564
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7565
- GridInput,
7566
- {
7567
- "aria-labelledby": METADATA_KEY_LABEL_ID,
7568
- ...field2,
7569
- disabled: isDisabled,
7570
- placeholder: "Key"
7571
- }
7572
- ) }) });
7573
- }
7574
- }
7575
- ),
7576
- /* @__PURE__ */ jsxRuntime.jsx(
7577
- Form$2.Field,
7578
- {
7579
- control: form.control,
7580
- name: `metadata.${index}.value`,
7581
- render: ({ field: { value, ...field2 } }) => {
7582
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7583
- GridInput,
7584
- {
7585
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
7586
- ...field2,
7587
- value: isDisabled ? placeholder : value,
7588
- disabled: isDisabled,
7589
- placeholder: "Value"
7590
- }
7591
- ) }) });
7592
- }
7593
- }
7594
- )
7595
- ]
7596
- }
7597
- ),
7598
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
7599
- /* @__PURE__ */ jsxRuntime.jsx(
7600
- ui.DropdownMenu.Trigger,
7601
- {
7602
- className: ui.clx(
7603
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
7604
- {
7605
- hidden: isDisabled
7606
- }
7607
- ),
7608
- disabled: isDisabled,
7609
- asChild: true,
7610
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
7611
- }
7612
- ),
7613
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
7614
- /* @__PURE__ */ jsxRuntime.jsxs(
7615
- ui.DropdownMenu.Item,
7616
- {
7617
- className: "gap-x-2",
7618
- onClick: () => insertRow(index, "above"),
7619
- children: [
7620
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
7621
- "Insert row above"
7622
- ]
7623
- }
7624
- ),
7625
- /* @__PURE__ */ jsxRuntime.jsxs(
7626
- ui.DropdownMenu.Item,
7627
- {
7628
- className: "gap-x-2",
7629
- onClick: () => insertRow(index, "below"),
7630
- children: [
7631
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
7632
- "Insert row below"
7633
- ]
7634
- }
7635
- ),
7636
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
7637
- /* @__PURE__ */ jsxRuntime.jsxs(
7638
- ui.DropdownMenu.Item,
7639
- {
7640
- className: "gap-x-2",
7641
- onClick: () => deleteRow(index),
7642
- children: [
7643
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
7644
- "Delete row"
7645
- ]
7646
- }
7647
- )
7648
- ] })
7649
- ] })
7650
- ] })
7651
- },
7652
- field.id
7653
- );
7654
- })
7655
- ] }),
7656
- 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." })
7517
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
7518
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
7519
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
7657
7520
  ] }),
7658
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7659
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7660
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7521
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
7522
+ DataTable,
7523
+ {
7524
+ data: variants,
7525
+ columns,
7526
+ isLoading: isPending,
7527
+ getRowId: (row) => row.id,
7528
+ rowCount: count,
7529
+ prefix: VARIANT_PREFIX,
7530
+ layout: "fill",
7531
+ rowSelection: {
7532
+ state: rowSelection,
7533
+ onRowSelectionChange: setRowSelection,
7534
+ enableRowSelection: (row) => {
7535
+ return !items.find((i) => i.variant_id === row.original.id);
7536
+ }
7537
+ },
7538
+ autoFocusSearch: true
7539
+ }
7540
+ ) }),
7541
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7542
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7543
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
7661
7544
  ] }) })
7662
7545
  ]
7663
7546
  }
7664
- ) });
7665
- };
7666
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
7667
- return /* @__PURE__ */ jsxRuntime.jsx(
7668
- "input",
7669
- {
7670
- ref,
7671
- ...props,
7672
- autoComplete: "off",
7673
- className: ui.clx(
7674
- "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",
7675
- className
7676
- )
7677
- }
7678
7547
  );
7679
- });
7680
- GridInput.displayName = "MetadataForm.GridInput";
7681
- const PlaceholderInner = () => {
7682
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
7683
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
7684
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7685
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
7686
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
7687
- ] }) })
7688
- ] });
7689
7548
  };
7690
- const EDITABLE_TYPES = ["string", "number", "boolean"];
7691
- function getDefaultValues(metadata) {
7692
- if (!metadata || !Object.keys(metadata).length) {
7549
+ const columnHelper = ui.createDataTableColumnHelper();
7550
+ const getVariantInventory = (variant) => {
7551
+ if (!variant.manage_inventory) {
7552
+ return { text: "Not managed", hasInventoryKit: false, notManaged: true };
7553
+ }
7554
+ const quantity = variant.inventory_quantity;
7555
+ const inventoryItems = variant.inventory_items?.map((i) => i.inventory).filter(Boolean) ?? [];
7556
+ const hasInventoryKit = inventoryItems.length > 1;
7557
+ const locations = {};
7558
+ inventoryItems.forEach((i) => {
7559
+ i.location_levels?.forEach((l) => {
7560
+ locations[l.id] = true;
7561
+ });
7562
+ });
7563
+ const locationCount = Object.keys(locations).length;
7564
+ const text = hasInventoryKit ? `${quantity} available` : `${quantity} available at ${locationCount} location${locationCount === 1 ? "" : "s"}`;
7565
+ return { text, hasInventoryKit, quantity, notManaged: false };
7566
+ };
7567
+ const useColumns = () => {
7568
+ return React.useMemo(() => {
7693
7569
  return [
7694
- {
7695
- key: "",
7696
- value: "",
7697
- disabled: false
7698
- }
7570
+ columnHelper.select(),
7571
+ columnHelper.accessor("product.title", {
7572
+ header: "Product",
7573
+ cell: ({ row }) => {
7574
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
7575
+ /* @__PURE__ */ jsxRuntime.jsx(
7576
+ Thumbnail,
7577
+ {
7578
+ thumbnail: row.original.product?.thumbnail,
7579
+ alt: row.original.product?.title
7580
+ }
7581
+ ),
7582
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: row.original.product?.title })
7583
+ ] });
7584
+ },
7585
+ enableSorting: true
7586
+ }),
7587
+ columnHelper.accessor("title", {
7588
+ header: "Variant",
7589
+ enableSorting: true
7590
+ }),
7591
+ columnHelper.accessor("sku", {
7592
+ header: "SKU",
7593
+ cell: ({ getValue }) => {
7594
+ return getValue() ?? "-";
7595
+ },
7596
+ enableSorting: true
7597
+ }),
7598
+ columnHelper.accessor("updated_at", {
7599
+ header: "Updated",
7600
+ cell: ({ getValue }) => {
7601
+ return /* @__PURE__ */ jsxRuntime.jsx(
7602
+ ui.Tooltip,
7603
+ {
7604
+ content: getFullDate({ date: getValue(), includeTime: true }),
7605
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
7606
+ }
7607
+ );
7608
+ },
7609
+ enableSorting: true,
7610
+ sortAscLabel: "Oldest first",
7611
+ sortDescLabel: "Newest first"
7612
+ }),
7613
+ columnHelper.accessor("created_at", {
7614
+ header: "Created",
7615
+ cell: ({ getValue }) => {
7616
+ return /* @__PURE__ */ jsxRuntime.jsx(
7617
+ ui.Tooltip,
7618
+ {
7619
+ content: getFullDate({ date: getValue(), includeTime: true }),
7620
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
7621
+ }
7622
+ );
7623
+ },
7624
+ enableSorting: true,
7625
+ sortAscLabel: "Oldest first",
7626
+ sortDescLabel: "Newest first"
7627
+ }),
7628
+ columnHelper.display({
7629
+ id: "inventory",
7630
+ header: "Stock",
7631
+ cell: ({ row }) => {
7632
+ const { text, hasInventoryKit, quantity, notManaged } = getVariantInventory(row.original);
7633
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: text, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full w-full items-center gap-2 overflow-hidden", children: [
7634
+ hasInventoryKit && /* @__PURE__ */ jsxRuntime.jsx(icons.Component, {}),
7635
+ /* @__PURE__ */ jsxRuntime.jsx(
7636
+ "span",
7637
+ {
7638
+ className: ui.clx("truncate", {
7639
+ "text-ui-fg-error": !quantity && !notManaged
7640
+ }),
7641
+ children: text
7642
+ }
7643
+ )
7644
+ ] }) });
7645
+ }
7646
+ })
7699
7647
  ];
7700
- }
7701
- return Object.entries(metadata).map(([key, value]) => {
7702
- if (!EDITABLE_TYPES.includes(typeof value)) {
7703
- return {
7704
- key,
7705
- value,
7706
- disabled: true
7707
- };
7708
- }
7709
- let stringValue = value;
7710
- if (typeof value !== "string") {
7711
- stringValue = JSON.stringify(value);
7712
- }
7713
- return {
7714
- key,
7715
- value: stringValue,
7716
- original_key: key
7717
- };
7648
+ }, []);
7649
+ };
7650
+ const CustomItemForm = ({ orderId, currencyCode }) => {
7651
+ const { setIsOpen } = useStackedModal();
7652
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
7653
+ const form = reactHookForm.useForm({
7654
+ defaultValues: {
7655
+ title: "",
7656
+ quantity: 1,
7657
+ unit_price: ""
7658
+ },
7659
+ resolver: zod$1.zodResolver(customItemSchema)
7718
7660
  });
7719
- }
7720
- function parseValues(values) {
7721
- const metadata = values.metadata;
7722
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
7723
- if (isEmpty) {
7724
- return null;
7725
- }
7726
- const update = {};
7727
- metadata.forEach((field) => {
7728
- let key = field.key;
7729
- let value = field.value;
7730
- const disabled = field.disabled;
7731
- if (!key || !value) {
7732
- return;
7733
- }
7734
- if (disabled) {
7735
- update[key] = value;
7736
- return;
7737
- }
7738
- key = key.trim();
7739
- value = value.trim();
7740
- if (value === "true") {
7741
- update[key] = true;
7742
- } else if (value === "false") {
7743
- update[key] = false;
7744
- } else {
7745
- const parsedNumber = parseFloat(value);
7746
- if (!isNaN(parsedNumber)) {
7747
- update[key] = parsedNumber;
7748
- } else {
7749
- update[key] = value;
7661
+ const onSubmit = form.handleSubmit(async (data) => {
7662
+ await addItems(
7663
+ {
7664
+ items: [
7665
+ {
7666
+ title: data.title,
7667
+ quantity: data.quantity,
7668
+ unit_price: convertNumber(data.unit_price)
7669
+ }
7670
+ ]
7671
+ },
7672
+ {
7673
+ onSuccess: () => {
7674
+ setIsOpen(STACKED_MODAL_ID, false);
7675
+ },
7676
+ onError: (e) => {
7677
+ ui.toast.error(e.message);
7678
+ }
7750
7679
  }
7751
- }
7680
+ );
7752
7681
  });
7753
- return update;
7754
- }
7755
- function getHasUneditableRows(metadata) {
7756
- if (!metadata) {
7757
- return false;
7758
- }
7759
- return Object.values(metadata).some(
7760
- (value) => !EDITABLE_TYPES.includes(typeof value)
7761
- );
7762
- }
7682
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
7683
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
7684
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
7685
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7686
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
7687
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
7688
+ ] }),
7689
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7690
+ /* @__PURE__ */ jsxRuntime.jsx(
7691
+ Form$2.Field,
7692
+ {
7693
+ control: form.control,
7694
+ name: "title",
7695
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
7696
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7697
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
7698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
7699
+ ] }),
7700
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7702
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7703
+ ] })
7704
+ ] }) })
7705
+ }
7706
+ ),
7707
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7708
+ /* @__PURE__ */ jsxRuntime.jsx(
7709
+ Form$2.Field,
7710
+ {
7711
+ control: form.control,
7712
+ name: "unit_price",
7713
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
7714
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7715
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
7716
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
7717
+ ] }),
7718
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7719
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7720
+ ui.CurrencyInput,
7721
+ {
7722
+ symbol: getNativeSymbol(currencyCode),
7723
+ code: currencyCode,
7724
+ onValueChange: (_value, _name, values) => onChange(values?.value),
7725
+ ...field
7726
+ }
7727
+ ) }),
7728
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7729
+ ] })
7730
+ ] }) })
7731
+ }
7732
+ ),
7733
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7734
+ /* @__PURE__ */ jsxRuntime.jsx(
7735
+ Form$2.Field,
7736
+ {
7737
+ control: form.control,
7738
+ name: "quantity",
7739
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
7740
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7741
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
7742
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
7743
+ ] }),
7744
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
7745
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
7746
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7747
+ ] })
7748
+ ] }) })
7749
+ }
7750
+ )
7751
+ ] }) }) }),
7752
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7753
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7754
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
7755
+ ] }) })
7756
+ ] }) }) });
7757
+ };
7758
+ const customItemSchema = zod.z.object({
7759
+ title: zod.z.string().min(1),
7760
+ quantity: zod.z.number(),
7761
+ unit_price: zod.z.union([zod.z.number(), zod.z.string()])
7762
+ });
7763
7763
  const handle$5 = {
7764
7764
  permissions: EDIT_DRAFT_ORDER_PERMISSIONS
7765
7765
  };
@@ -8041,115 +8041,6 @@ function getPromotionIds(items, shippingMethods) {
8041
8041
  const handle$4 = {
8042
8042
  permissions: EDIT_DRAFT_ORDER_PROMOTIONS_PERMISSIONS
8043
8043
  };
8044
- const SalesChannel = () => {
8045
- const { id } = reactRouterDom.useParams();
8046
- const { draft_order, isPending, isError, error } = useDraftOrder(
8047
- id,
8048
- {
8049
- fields: "+sales_channel_id"
8050
- },
8051
- {
8052
- enabled: !!id
8053
- }
8054
- );
8055
- if (isError) {
8056
- throw error;
8057
- }
8058
- const ISrEADY = !!draft_order && !isPending;
8059
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
8060
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
8061
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
8062
- /* @__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" }) })
8063
- ] }),
8064
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
8065
- ] });
8066
- };
8067
- const SalesChannelForm = ({ order }) => {
8068
- const form = reactHookForm.useForm({
8069
- defaultValues: {
8070
- sales_channel_id: order.sales_channel_id || ""
8071
- },
8072
- resolver: zod$1.zodResolver(schema$2)
8073
- });
8074
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8075
- const { handleSuccess } = useRouteModal();
8076
- const onSubmit = form.handleSubmit(async (data) => {
8077
- await mutateAsync(
8078
- {
8079
- sales_channel_id: data.sales_channel_id
8080
- },
8081
- {
8082
- onSuccess: () => {
8083
- ui.toast.success("Sales channel updated");
8084
- handleSuccess();
8085
- },
8086
- onError: (error) => {
8087
- ui.toast.error(error.message);
8088
- }
8089
- }
8090
- );
8091
- });
8092
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
8093
- KeyboundForm,
8094
- {
8095
- className: "flex flex-1 flex-col overflow-hidden",
8096
- onSubmit,
8097
- children: [
8098
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
8099
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
8100
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8102
- ] }) })
8103
- ]
8104
- }
8105
- ) });
8106
- };
8107
- const SalesChannelField = ({ control, order }) => {
8108
- const salesChannels = useComboboxData({
8109
- queryFn: async (params) => {
8110
- return await sdk.admin.salesChannel.list(params);
8111
- },
8112
- queryKey: ["sales-channels"],
8113
- getOptions: (data) => {
8114
- return data.sales_channels.map((salesChannel) => ({
8115
- label: salesChannel.name,
8116
- value: salesChannel.id
8117
- }));
8118
- },
8119
- defaultValue: order.sales_channel_id || void 0
8120
- });
8121
- return /* @__PURE__ */ jsxRuntime.jsx(
8122
- Form$2.Field,
8123
- {
8124
- control,
8125
- name: "sales_channel_id",
8126
- render: ({ field }) => {
8127
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8128
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
8129
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8130
- Combobox,
8131
- {
8132
- options: salesChannels.options,
8133
- fetchNextPage: salesChannels.fetchNextPage,
8134
- isFetchingNextPage: salesChannels.isFetchingNextPage,
8135
- searchValue: salesChannels.searchValue,
8136
- onSearchValueChange: salesChannels.onSearchValueChange,
8137
- placeholder: "Select sales channel",
8138
- ...field
8139
- }
8140
- ) }),
8141
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8142
- ] });
8143
- }
8144
- }
8145
- );
8146
- };
8147
- const schema$2 = zod.z.object({
8148
- sales_channel_id: zod.z.string().min(1)
8149
- });
8150
- const handle$3 = {
8151
- permissions: EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
8152
- };
8153
8044
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
8154
8045
  const Shipping = () => {
8155
8046
  const { id } = reactRouterDom.useParams();
@@ -8944,9 +8835,118 @@ const CustomAmountField = ({
8944
8835
  }
8945
8836
  );
8946
8837
  };
8947
- const handle$2 = {
8838
+ const handle$3 = {
8948
8839
  permissions: EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS
8949
8840
  };
8841
+ const SalesChannel = () => {
8842
+ const { id } = reactRouterDom.useParams();
8843
+ const { draft_order, isPending, isError, error } = useDraftOrder(
8844
+ id,
8845
+ {
8846
+ fields: "+sales_channel_id"
8847
+ },
8848
+ {
8849
+ enabled: !!id
8850
+ }
8851
+ );
8852
+ if (isError) {
8853
+ throw error;
8854
+ }
8855
+ const ISrEADY = !!draft_order && !isPending;
8856
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
8857
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
8858
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
8859
+ /* @__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" }) })
8860
+ ] }),
8861
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
8862
+ ] });
8863
+ };
8864
+ const SalesChannelForm = ({ order }) => {
8865
+ const form = reactHookForm.useForm({
8866
+ defaultValues: {
8867
+ sales_channel_id: order.sales_channel_id || ""
8868
+ },
8869
+ resolver: zod$1.zodResolver(schema$2)
8870
+ });
8871
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8872
+ const { handleSuccess } = useRouteModal();
8873
+ const onSubmit = form.handleSubmit(async (data) => {
8874
+ await mutateAsync(
8875
+ {
8876
+ sales_channel_id: data.sales_channel_id
8877
+ },
8878
+ {
8879
+ onSuccess: () => {
8880
+ ui.toast.success("Sales channel updated");
8881
+ handleSuccess();
8882
+ },
8883
+ onError: (error) => {
8884
+ ui.toast.error(error.message);
8885
+ }
8886
+ }
8887
+ );
8888
+ });
8889
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
8890
+ KeyboundForm,
8891
+ {
8892
+ className: "flex flex-1 flex-col overflow-hidden",
8893
+ onSubmit,
8894
+ children: [
8895
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
8896
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
8897
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8898
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8899
+ ] }) })
8900
+ ]
8901
+ }
8902
+ ) });
8903
+ };
8904
+ const SalesChannelField = ({ control, order }) => {
8905
+ const salesChannels = useComboboxData({
8906
+ queryFn: async (params) => {
8907
+ return await sdk.admin.salesChannel.list(params);
8908
+ },
8909
+ queryKey: ["sales-channels"],
8910
+ getOptions: (data) => {
8911
+ return data.sales_channels.map((salesChannel) => ({
8912
+ label: salesChannel.name,
8913
+ value: salesChannel.id
8914
+ }));
8915
+ },
8916
+ defaultValue: order.sales_channel_id || void 0
8917
+ });
8918
+ return /* @__PURE__ */ jsxRuntime.jsx(
8919
+ Form$2.Field,
8920
+ {
8921
+ control,
8922
+ name: "sales_channel_id",
8923
+ render: ({ field }) => {
8924
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8925
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
8926
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8927
+ Combobox,
8928
+ {
8929
+ options: salesChannels.options,
8930
+ fetchNextPage: salesChannels.fetchNextPage,
8931
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
8932
+ searchValue: salesChannels.searchValue,
8933
+ onSearchValueChange: salesChannels.onSearchValueChange,
8934
+ placeholder: "Select sales channel",
8935
+ ...field
8936
+ }
8937
+ ) }),
8938
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8939
+ ] });
8940
+ }
8941
+ }
8942
+ );
8943
+ };
8944
+ const schema$2 = zod.z.object({
8945
+ sales_channel_id: zod.z.string().min(1)
8946
+ });
8947
+ const handle$2 = {
8948
+ permissions: EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
8949
+ };
8950
8950
  const ShippingAddress = () => {
8951
8951
  const { id } = reactRouterDom.useParams();
8952
8952
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9669,13 +9669,13 @@ const routeModule = {
9669
9669
  handle: handle$7
9670
9670
  },
9671
9671
  {
9672
- Component: Items,
9673
- path: "/draft-orders/:id/items",
9672
+ Component: Metadata,
9673
+ path: "/draft-orders/:id/metadata",
9674
9674
  handle: handle$6
9675
9675
  },
9676
9676
  {
9677
- Component: Metadata,
9678
- path: "/draft-orders/:id/metadata",
9677
+ Component: Items,
9678
+ path: "/draft-orders/:id/items",
9679
9679
  handle: handle$5
9680
9680
  },
9681
9681
  {
@@ -9684,13 +9684,13 @@ const routeModule = {
9684
9684
  handle: handle$4
9685
9685
  },
9686
9686
  {
9687
- Component: SalesChannel,
9688
- path: "/draft-orders/:id/sales-channel",
9687
+ Component: Shipping,
9688
+ path: "/draft-orders/:id/shipping",
9689
9689
  handle: handle$3
9690
9690
  },
9691
9691
  {
9692
- Component: Shipping,
9693
- path: "/draft-orders/:id/shipping",
9692
+ Component: SalesChannel,
9693
+ path: "/draft-orders/:id/sales-channel",
9694
9694
  handle: handle$2
9695
9695
  },
9696
9696
  {