@medusajs/draft-order 0.0.14 → 2.10.0-snapshot-20250826181741

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.
@@ -7869,6 +7869,13 @@ const AddressField = ({ type, control, setValue }) => {
7869
7869
  const customerId = useWatch({ control, name: "customer_id" });
7870
7870
  const addressId = useWatch({ control, name: `${type}_id` });
7871
7871
  const sameAsShipping = useWatch({ control, name: "same_as_shipping" });
7872
+ const { customer } = useCustomer(
7873
+ customerId,
7874
+ {},
7875
+ {
7876
+ enabled: !!customerId
7877
+ }
7878
+ );
7872
7879
  const addresses = useComboboxData({
7873
7880
  queryFn: async (params) => {
7874
7881
  const response = await sdk.client.fetch(
@@ -7908,7 +7915,11 @@ const AddressField = ({ type, control, setValue }) => {
7908
7915
  }
7909
7916
  );
7910
7917
  const address = response.address;
7911
- setValue(type, { ...address });
7918
+ setValue(type, {
7919
+ ...address,
7920
+ first_name: address.first_name || (customer == null ? void 0 : customer.first_name),
7921
+ last_name: address.last_name || (customer == null ? void 0 : customer.last_name)
7922
+ });
7912
7923
  };
7913
7924
  const showFields = type === "billing_address" ? !sameAsShipping : true;
7914
7925
  return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
@@ -9295,6 +9306,7 @@ const getStylizedAmount = (amount, currencyCode) => {
9295
9306
  };
9296
9307
  const SummarySection = ({ order }) => {
9297
9308
  var _a;
9309
+ const promotions = order.promotions || [];
9298
9310
  return /* @__PURE__ */ jsxs(Container, { className: "p-0 overflow-hidden", children: [
9299
9311
  /* @__PURE__ */ jsxs("div", { className: "px-6 py-4 flex items-center justify-between gap-x-4", children: [
9300
9312
  /* @__PURE__ */ jsx(Heading, { children: "Summary" }),
@@ -9342,7 +9354,7 @@ const SummarySection = ({ order }) => {
9342
9354
  total: order.total,
9343
9355
  shippingSubtotal: order.shipping_subtotal,
9344
9356
  discountTotal: order.discount_total,
9345
- promotions: order.promotions,
9357
+ promotions,
9346
9358
  taxTotal: order.tax_total,
9347
9359
  itemSubTotal: order.item_subtotal,
9348
9360
  itemCount: ((_a = order.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0
@@ -9396,7 +9408,6 @@ const Total = ({
9396
9408
  itemSubTotal,
9397
9409
  itemCount
9398
9410
  }) => {
9399
- var _a;
9400
9411
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col px-6 py-4 gap-y-2", children: [
9401
9412
  itemCount > 0 && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-3 items-center justify-between gap-x-4 text-ui-fg-subtle", children: [
9402
9413
  /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "Subtotal" }),
@@ -9418,7 +9429,7 @@ const Total = ({
9418
9429
  ),
9419
9430
  children: [
9420
9431
  /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "Discount" }),
9421
- (promotions == null ? void 0 : promotions.length) && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ jsx(Link, { to: `/promotions/${(_a = promotions == null ? void 0 : promotions[0]) == null ? void 0 : _a.id}`, children: /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: promotions.map((p) => p.code).join(", ") }) }) }),
9432
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end gap-x-2", children: promotions.map((promotion) => /* @__PURE__ */ jsx(Link, { to: `/promotions/${promotion.id}`, children: /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: promotion.code }) }, promotion.id)) }),
9422
9433
  /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: getLocaleAmount(discountTotal, currencyCode) }) })
9423
9434
  ]
9424
9435
  }
@@ -9754,6 +9765,74 @@ const CustomItemsForm = () => {
9754
9765
  const schema$4 = objectType({
9755
9766
  email: stringType().email()
9756
9767
  });
9768
+ const Email = () => {
9769
+ const { id } = useParams();
9770
+ const { order, isPending, isError, error } = useOrder(id, {
9771
+ fields: "+email"
9772
+ });
9773
+ if (isError) {
9774
+ throw error;
9775
+ }
9776
+ const isReady = !isPending && !!order;
9777
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9778
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9779
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9780
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9781
+ ] }),
9782
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9783
+ ] });
9784
+ };
9785
+ const EmailForm = ({ order }) => {
9786
+ const form = useForm({
9787
+ defaultValues: {
9788
+ email: order.email ?? ""
9789
+ },
9790
+ resolver: zodResolver(schema$3)
9791
+ });
9792
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
+ const { handleSuccess } = useRouteModal();
9794
+ const onSubmit = form.handleSubmit(async (data) => {
9795
+ await mutateAsync(
9796
+ { email: data.email },
9797
+ {
9798
+ onSuccess: () => {
9799
+ handleSuccess();
9800
+ },
9801
+ onError: (error) => {
9802
+ toast.error(error.message);
9803
+ }
9804
+ }
9805
+ );
9806
+ });
9807
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9808
+ KeyboundForm,
9809
+ {
9810
+ className: "flex flex-1 flex-col overflow-hidden",
9811
+ onSubmit,
9812
+ children: [
9813
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9814
+ Form$2.Field,
9815
+ {
9816
+ control: form.control,
9817
+ name: "email",
9818
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9819
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9820
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9821
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9822
+ ] })
9823
+ }
9824
+ ) }),
9825
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9827
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9828
+ ] }) })
9829
+ ]
9830
+ }
9831
+ ) });
9832
+ };
9833
+ const schema$3 = objectType({
9834
+ email: stringType().email()
9835
+ });
9757
9836
  const InlineTip = forwardRef(
9758
9837
  ({ variant = "tip", label, className, children, ...props }, ref) => {
9759
9838
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -10455,7 +10534,7 @@ const SalesChannelForm = ({ order }) => {
10455
10534
  defaultValues: {
10456
10535
  sales_channel_id: order.sales_channel_id || ""
10457
10536
  },
10458
- resolver: zodResolver(schema$3)
10537
+ resolver: zodResolver(schema$2)
10459
10538
  });
10460
10539
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10461
10540
  const { handleSuccess } = useRouteModal();
@@ -10530,7 +10609,7 @@ const SalesChannelField = ({ control, order }) => {
10530
10609
  }
10531
10610
  );
10532
10611
  };
10533
- const schema$3 = objectType({
10612
+ const schema$2 = objectType({
10534
10613
  sales_channel_id: stringType().min(1)
10535
10614
  });
10536
10615
  function convertNumber(value) {
@@ -11375,7 +11454,7 @@ const ShippingAddressForm = ({ order }) => {
11375
11454
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11376
11455
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11377
11456
  },
11378
- resolver: zodResolver(schema$2)
11457
+ resolver: zodResolver(schema$1)
11379
11458
  });
11380
11459
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11381
11460
  const { handleSuccess } = useRouteModal();
@@ -11545,1162 +11624,169 @@ const ShippingAddressForm = ({ order }) => {
11545
11624
  }
11546
11625
  ) });
11547
11626
  };
11548
- const schema$2 = addressSchema;
11549
- const NumberInput = forwardRef(
11550
- ({
11551
- value,
11552
- onChange,
11553
- size = "base",
11554
- min = 0,
11555
- max = 100,
11556
- step = 1,
11557
- className,
11558
- disabled,
11559
- ...props
11560
- }, ref) => {
11561
- const handleChange = (event) => {
11562
- const newValue = event.target.value === "" ? min : Number(event.target.value);
11563
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
11564
- onChange(newValue);
11565
- }
11566
- };
11567
- const handleIncrement = () => {
11568
- const newValue = value + step;
11569
- if (max === void 0 || newValue <= max) {
11570
- onChange(newValue);
11571
- }
11572
- };
11573
- const handleDecrement = () => {
11574
- const newValue = value - step;
11575
- if (min === void 0 || newValue >= min) {
11576
- onChange(newValue);
11577
- }
11578
- };
11579
- return /* @__PURE__ */ jsxs(
11580
- "div",
11581
- {
11582
- className: clx(
11583
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
11584
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
11585
- {
11586
- "h-7": size === "small",
11587
- "h-8": size === "base"
11588
- },
11589
- className
11590
- ),
11591
- children: [
11592
- /* @__PURE__ */ jsx(
11593
- "input",
11594
- {
11595
- ref,
11596
- type: "number",
11597
- value,
11598
- onChange: handleChange,
11599
- min,
11600
- max,
11601
- step,
11602
- className: clx(
11603
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
11604
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
11605
- "placeholder:text-ui-fg-muted"
11606
- ),
11607
- ...props
11608
- }
11609
- ),
11610
- /* @__PURE__ */ jsxs(
11611
- "button",
11612
- {
11613
- className: clx(
11614
- "flex items-center justify-center outline-none transition-fg",
11615
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11616
- "focus:bg-ui-bg-field-component-hover",
11617
- "hover:bg-ui-bg-field-component-hover",
11618
- {
11619
- "size-7": size === "small",
11620
- "size-8": size === "base"
11621
- }
11622
- ),
11623
- type: "button",
11624
- onClick: handleDecrement,
11625
- disabled: min !== void 0 && value <= min || disabled,
11626
- children: [
11627
- /* @__PURE__ */ jsx(Minus, {}),
11628
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
11629
- ]
11630
- }
11631
- ),
11632
- /* @__PURE__ */ jsxs(
11633
- "button",
11634
- {
11635
- className: clx(
11636
- "flex items-center justify-center outline-none transition-fg",
11637
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11638
- "focus:bg-ui-bg-field-hover",
11639
- "hover:bg-ui-bg-field-hover",
11640
- {
11641
- "size-7": size === "small",
11642
- "size-8": size === "base"
11643
- }
11644
- ),
11645
- type: "button",
11646
- onClick: handleIncrement,
11647
- disabled: max !== void 0 && value >= max || disabled,
11648
- children: [
11649
- /* @__PURE__ */ jsx(Plus, {}),
11650
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
11651
- ]
11652
- }
11653
- )
11654
- ]
11655
- }
11656
- );
11657
- }
11658
- );
11659
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
11660
- const productVariantsQueryKeys = {
11661
- list: (query2) => [
11662
- PRODUCT_VARIANTS_QUERY_KEY,
11663
- query2 ? query2 : void 0
11664
- ]
11665
- };
11666
- const useProductVariants = (query2, options) => {
11667
- const { data, ...rest } = useQuery({
11668
- queryKey: productVariantsQueryKeys.list(query2),
11669
- queryFn: async () => await sdk.admin.productVariant.list(query2),
11670
- ...options
11671
- });
11672
- return { ...data, ...rest };
11673
- };
11674
- const STACKED_MODAL_ID = "items_stacked_modal";
11675
- const Items = () => {
11627
+ const schema$1 = addressSchema;
11628
+ const TransferOwnership = () => {
11676
11629
  const { id } = useParams();
11677
- const {
11678
- order: preview,
11679
- isPending: isPreviewPending,
11680
- isError: isPreviewError,
11681
- error: previewError
11682
- } = useOrderPreview(id, void 0, {
11683
- placeholderData: keepPreviousData
11630
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11631
+ fields: "id,customer_id,customer.*"
11684
11632
  });
11685
- useInitiateOrderEdit({ preview });
11686
- const { draft_order, isPending, isError, error } = useDraftOrder(
11687
- id,
11688
- {
11689
- fields: "currency_code"
11690
- },
11691
- {
11692
- enabled: !!id
11693
- }
11694
- );
11695
- const { onCancel } = useCancelOrderEdit({ preview });
11696
11633
  if (isError) {
11697
11634
  throw error;
11698
11635
  }
11699
- if (isPreviewError) {
11700
- throw previewError;
11701
- }
11702
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
11703
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
11704
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
11705
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11706
- ] }) });
11636
+ const isReady = !isPending && !!draft_order;
11637
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11638
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11639
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11640
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11641
+ ] }),
11642
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11643
+ ] });
11707
11644
  };
11708
- const ItemsForm = ({ preview, currencyCode }) => {
11709
- var _a;
11710
- const [isSubmitting, setIsSubmitting] = useState(false);
11711
- const [modalContent, setModalContent] = useState(
11712
- null
11713
- );
11714
- const { handleSuccess } = useRouteModal();
11715
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
11716
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11717
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11718
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
11719
- const matches = useMemo(() => {
11720
- return matchSorter(preview.items, query2, {
11721
- keys: ["product_title", "variant_title", "variant_sku", "title"]
11722
- });
11723
- }, [preview.items, query2]);
11724
- const onSubmit = async () => {
11725
- setIsSubmitting(true);
11726
- let requestSucceeded = false;
11727
- await requestOrderEdit(void 0, {
11728
- onError: (e) => {
11729
- toast.error(`Failed to request order edit: ${e.message}`);
11730
- },
11731
- onSuccess: () => {
11732
- requestSucceeded = true;
11733
- }
11734
- });
11735
- if (!requestSucceeded) {
11736
- setIsSubmitting(false);
11737
- return;
11738
- }
11739
- await confirmOrderEdit(void 0, {
11740
- onError: (e) => {
11741
- toast.error(`Failed to confirm order edit: ${e.message}`);
11742
- },
11743
- onSuccess: () => {
11744
- handleSuccess();
11745
- },
11746
- onSettled: () => {
11747
- setIsSubmitting(false);
11748
- }
11749
- });
11750
- };
11751
- const onKeyDown = useCallback(
11752
- (e) => {
11753
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11754
- if (modalContent || isSubmitting) {
11755
- return;
11756
- }
11757
- onSubmit();
11758
- }
11759
- },
11760
- [modalContent, isSubmitting, onSubmit]
11761
- );
11762
- useEffect(() => {
11763
- document.addEventListener("keydown", onKeyDown);
11764
- return () => {
11765
- document.removeEventListener("keydown", onKeyDown);
11766
- };
11767
- }, [onKeyDown]);
11768
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11769
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11770
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
11771
- StackedFocusModal,
11772
- {
11773
- id: STACKED_MODAL_ID,
11774
- onOpenChangeCallback: (open) => {
11775
- if (!open) {
11776
- setModalContent(null);
11777
- }
11778
- },
11779
- children: [
11780
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11781
- /* @__PURE__ */ jsxs("div", { children: [
11782
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
11783
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
11784
- ] }),
11785
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11786
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
11787
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
11788
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11789
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
11790
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
11791
- ] }),
11792
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
11793
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
11794
- Input,
11795
- {
11796
- type: "search",
11797
- placeholder: "Search items",
11798
- value: searchValue,
11799
- onChange: (e) => onSearchValueChange(e.target.value)
11800
- }
11801
- ) }),
11802
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11803
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
11804
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11805
- /* @__PURE__ */ jsx(
11806
- StackedModalTrigger,
11807
- {
11808
- type: "add-items",
11809
- setModalContent
11810
- }
11811
- ),
11812
- /* @__PURE__ */ jsx(
11813
- StackedModalTrigger,
11814
- {
11815
- type: "add-custom-item",
11816
- setModalContent
11817
- }
11818
- )
11819
- ] })
11820
- ] })
11821
- ] })
11822
- ] }),
11823
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11824
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
11825
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
11826
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
11827
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
11828
- /* @__PURE__ */ jsx("div", {})
11829
- ] }) }),
11830
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11831
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
11832
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
11833
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
11834
- Item,
11835
- {
11836
- item,
11837
- preview,
11838
- currencyCode
11839
- },
11840
- item.id
11841
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11842
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11843
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
11844
- 'No items found for "',
11845
- query2,
11846
- '".'
11847
- ] })
11848
- ] }) })
11849
- ] })
11850
- ] }),
11851
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11852
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
11853
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
11854
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
11855
- Text,
11856
- {
11857
- size: "small",
11858
- leading: "compact",
11859
- className: "text-ui-fg-subtle",
11860
- children: [
11861
- itemCount,
11862
- " ",
11863
- itemCount === 1 ? "item" : "items"
11864
- ]
11865
- }
11866
- ) }),
11867
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
11868
- ] })
11869
- ] }) }),
11870
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
11871
- CustomItemForm,
11872
- {
11873
- orderId: preview.id,
11874
- currencyCode
11875
- }
11876
- ) : null)
11877
- ]
11878
- }
11879
- ) }),
11880
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11881
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11882
- /* @__PURE__ */ jsx(
11883
- Button,
11884
- {
11885
- size: "small",
11886
- type: "button",
11887
- onClick: onSubmit,
11888
- isLoading: isSubmitting,
11889
- children: "Save"
11890
- }
11891
- )
11892
- ] }) })
11893
- ] });
11894
- };
11895
- const Item = ({ item, preview, currencyCode }) => {
11896
- if (item.variant_id) {
11897
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
11898
- }
11899
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
11900
- };
11901
- const VariantItem = ({ item, preview, currencyCode }) => {
11902
- const [editing, setEditing] = useState(false);
11645
+ const TransferOwnershipForm = ({ order }) => {
11646
+ var _a, _b;
11903
11647
  const form = useForm({
11904
11648
  defaultValues: {
11905
- quantity: item.quantity,
11906
- unit_price: item.unit_price
11649
+ customer_id: order.customer_id || ""
11907
11650
  },
11908
- resolver: zodResolver(variantItemSchema)
11651
+ resolver: zodResolver(schema)
11909
11652
  });
11910
- const actionId = useMemo(() => {
11911
- var _a, _b;
11912
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11913
- }, [item]);
11914
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11915
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11916
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11653
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11654
+ const { handleSuccess } = useRouteModal();
11655
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11656
+ const currentCustomer = order.customer ? {
11657
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11658
+ value: order.customer.id
11659
+ } : null;
11917
11660
  const onSubmit = form.handleSubmit(async (data) => {
11918
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
11919
- setEditing(false);
11920
- return;
11921
- }
11922
- if (!actionId) {
11923
- await updateOriginalItem(
11924
- {
11925
- item_id: item.id,
11926
- quantity: data.quantity,
11927
- unit_price: convertNumber(data.unit_price)
11928
- },
11929
- {
11930
- onSuccess: () => {
11931
- setEditing(false);
11932
- },
11933
- onError: (e) => {
11934
- toast.error(e.message);
11935
- }
11936
- }
11937
- );
11938
- return;
11939
- }
11940
- await updateActionItem(
11941
- {
11942
- action_id: actionId,
11943
- quantity: data.quantity,
11944
- unit_price: convertNumber(data.unit_price)
11945
- },
11661
+ await mutateAsync(
11662
+ { customer_id: data.customer_id },
11946
11663
  {
11947
11664
  onSuccess: () => {
11948
- setEditing(false);
11665
+ toast.success("Customer updated");
11666
+ handleSuccess();
11949
11667
  },
11950
- onError: (e) => {
11951
- toast.error(e.message);
11668
+ onError: (error) => {
11669
+ toast.error(error.message);
11952
11670
  }
11953
11671
  }
11954
11672
  );
11955
11673
  });
11956
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
11957
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
11958
- /* @__PURE__ */ jsx(
11959
- Thumbnail,
11960
- {
11961
- thumbnail: item.thumbnail,
11962
- alt: item.product_title ?? void 0
11963
- }
11964
- ),
11965
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11966
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11967
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11968
- /* @__PURE__ */ jsxs(
11969
- Text,
11970
- {
11971
- size: "small",
11972
- leading: "compact",
11973
- className: "text-ui-fg-subtle",
11974
- children: [
11975
- "(",
11976
- item.variant_title,
11977
- ")"
11978
- ]
11674
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11675
+ KeyboundForm,
11676
+ {
11677
+ className: "flex flex-1 flex-col overflow-hidden",
11678
+ onSubmit,
11679
+ children: [
11680
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11681
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11682
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11683
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11684
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11685
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11686
+ ] }),
11687
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11688
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11689
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11690
+ ] })
11691
+ ] }),
11692
+ /* @__PURE__ */ jsx(
11693
+ CustomerField,
11694
+ {
11695
+ control: form.control,
11696
+ currentCustomerId: order.customer_id
11979
11697
  }
11980
11698
  )
11981
11699
  ] }),
11982
- /* @__PURE__ */ jsx(
11983
- Text,
11984
- {
11985
- size: "small",
11986
- leading: "compact",
11987
- className: "text-ui-fg-subtle",
11988
- children: item.variant_sku
11989
- }
11990
- )
11991
- ] })
11992
- ] }),
11993
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
11994
- Form$2.Field,
11995
- {
11996
- control: form.control,
11997
- name: "quantity",
11998
- render: ({ field }) => {
11999
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12000
- }
12001
- }
12002
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
12003
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
12004
- Form$2.Field,
12005
- {
12006
- control: form.control,
12007
- name: "unit_price",
12008
- render: ({ field: { onChange, ...field } }) => {
12009
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12010
- CurrencyInput,
12011
- {
12012
- ...field,
12013
- symbol: getNativeSymbol(currencyCode),
12014
- code: currencyCode,
12015
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12016
- }
12017
- ) }) });
12018
- }
12019
- }
12020
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12021
- /* @__PURE__ */ jsx(
12022
- IconButton,
12023
- {
12024
- type: "button",
12025
- size: "small",
12026
- onClick: editing ? onSubmit : () => {
12027
- setEditing(true);
12028
- },
12029
- disabled: isPending,
12030
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12031
- }
12032
- )
12033
- ] }) }) });
11700
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11701
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11702
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11703
+ ] }) })
11704
+ ]
11705
+ }
11706
+ ) });
12034
11707
  };
12035
- const variantItemSchema = objectType({
12036
- quantity: numberType(),
12037
- unit_price: unionType([numberType(), stringType()])
12038
- });
12039
- const CustomItem = ({ item, preview, currencyCode }) => {
12040
- const [editing, setEditing] = useState(false);
12041
- const { quantity, unit_price, title } = item;
12042
- const form = useForm({
12043
- defaultValues: {
12044
- title,
12045
- quantity,
12046
- unit_price
11708
+ const CustomerField = ({ control, currentCustomerId }) => {
11709
+ const customers = useComboboxData({
11710
+ queryFn: async (params) => {
11711
+ return await sdk.admin.customer.list({
11712
+ ...params,
11713
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11714
+ });
12047
11715
  },
12048
- resolver: zodResolver(customItemSchema)
12049
- });
12050
- useEffect(() => {
12051
- form.reset({
12052
- title,
12053
- quantity,
12054
- unit_price
12055
- });
12056
- }, [form, title, quantity, unit_price]);
12057
- const actionId = useMemo(() => {
12058
- var _a, _b;
12059
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12060
- }, [item]);
12061
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12062
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12063
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12064
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12065
- const onSubmit = form.handleSubmit(async (data) => {
12066
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12067
- setEditing(false);
12068
- return;
12069
- }
12070
- if (!actionId) {
12071
- await updateOriginalItem(
12072
- {
12073
- item_id: item.id,
12074
- quantity: data.quantity,
12075
- unit_price: convertNumber(data.unit_price)
12076
- },
12077
- {
12078
- onSuccess: () => {
12079
- setEditing(false);
12080
- },
12081
- onError: (e) => {
12082
- toast.error(e.message);
12083
- }
12084
- }
12085
- );
12086
- return;
12087
- }
12088
- if (data.quantity === 0) {
12089
- await removeActionItem(actionId, {
12090
- onSuccess: () => {
12091
- setEditing(false);
12092
- },
12093
- onError: (e) => {
12094
- toast.error(e.message);
12095
- }
11716
+ queryKey: ["customers"],
11717
+ getOptions: (data) => {
11718
+ return data.customers.map((customer) => {
11719
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11720
+ return {
11721
+ label: name ? `${name} (${customer.email})` : customer.email,
11722
+ value: customer.id
11723
+ };
12096
11724
  });
12097
- return;
12098
11725
  }
12099
- await updateActionItem(
12100
- {
12101
- action_id: actionId,
12102
- quantity: data.quantity,
12103
- unit_price: convertNumber(data.unit_price)
12104
- },
12105
- {
12106
- onSuccess: () => {
12107
- setEditing(false);
12108
- },
12109
- onError: (e) => {
12110
- toast.error(e.message);
12111
- }
12112
- }
12113
- );
12114
11726
  });
12115
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12116
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12117
- /* @__PURE__ */ jsx(
12118
- Thumbnail,
12119
- {
12120
- thumbnail: item.thumbnail,
12121
- alt: item.title ?? void 0
12122
- }
12123
- ),
12124
- editing ? /* @__PURE__ */ jsx(
12125
- Form$2.Field,
12126
- {
12127
- control: form.control,
12128
- name: "title",
12129
- render: ({ field }) => {
12130
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
11727
+ return /* @__PURE__ */ jsx(
11728
+ Form$2.Field,
11729
+ {
11730
+ name: "customer_id",
11731
+ control,
11732
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11733
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11734
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11735
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11736
+ ] }),
11737
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11738
+ Combobox,
11739
+ {
11740
+ options: customers.options,
11741
+ fetchNextPage: customers.fetchNextPage,
11742
+ isFetchingNextPage: customers.isFetchingNextPage,
11743
+ searchValue: customers.searchValue,
11744
+ onSearchValueChange: customers.onSearchValueChange,
11745
+ placeholder: "Select customer",
11746
+ ...field
12131
11747
  }
12132
- }
12133
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
12134
- ] }),
12135
- editing ? /* @__PURE__ */ jsx(
12136
- Form$2.Field,
12137
- {
12138
- control: form.control,
12139
- name: "quantity",
12140
- render: ({ field }) => {
12141
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12142
- }
12143
- }
12144
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
12145
- editing ? /* @__PURE__ */ jsx(
12146
- Form$2.Field,
12147
- {
12148
- control: form.control,
12149
- name: "unit_price",
12150
- render: ({ field: { onChange, ...field } }) => {
12151
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12152
- CurrencyInput,
12153
- {
12154
- ...field,
12155
- symbol: getNativeSymbol(currencyCode),
12156
- code: currencyCode,
12157
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12158
- }
12159
- ) }) });
12160
- }
12161
- }
12162
- ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12163
- /* @__PURE__ */ jsx(
12164
- IconButton,
12165
- {
12166
- type: "button",
12167
- size: "small",
12168
- onClick: editing ? onSubmit : () => {
12169
- setEditing(true);
12170
- },
12171
- disabled: isPending,
12172
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12173
- }
12174
- )
12175
- ] }) }) });
12176
- };
12177
- const StackedModalTrigger = ({
12178
- type,
12179
- setModalContent
12180
- }) => {
12181
- const { setIsOpen } = useStackedModal();
12182
- const onClick = useCallback(() => {
12183
- setModalContent(type);
12184
- setIsOpen(STACKED_MODAL_ID, true);
12185
- }, [setModalContent, setIsOpen, type]);
12186
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12187
- };
12188
- const VARIANT_PREFIX = "items";
12189
- const LIMIT = 50;
12190
- const ExistingItemsForm = ({ orderId, items }) => {
12191
- const { setIsOpen } = useStackedModal();
12192
- const [rowSelection, setRowSelection] = useState(
12193
- items.reduce((acc, item) => {
12194
- acc[item.variant_id] = true;
12195
- return acc;
12196
- }, {})
12197
- );
12198
- useEffect(() => {
12199
- setRowSelection(
12200
- items.reduce((acc, item) => {
12201
- if (item.variant_id) {
12202
- acc[item.variant_id] = true;
12203
- }
12204
- return acc;
12205
- }, {})
12206
- );
12207
- }, [items]);
12208
- const { q, order, offset } = useQueryParams(
12209
- ["q", "order", "offset"],
12210
- VARIANT_PREFIX
12211
- );
12212
- const { variants, count, isPending, isError, error } = useProductVariants(
12213
- {
12214
- q,
12215
- order,
12216
- offset: offset ? parseInt(offset) : void 0,
12217
- limit: LIMIT
12218
- },
12219
- {
12220
- placeholderData: keepPreviousData
11748
+ ) }),
11749
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11750
+ ] })
12221
11751
  }
12222
11752
  );
12223
- const columns = useColumns();
12224
- const { mutateAsync } = useDraftOrderAddItems(orderId);
12225
- const onSubmit = async () => {
12226
- const ids = Object.keys(rowSelection).filter(
12227
- (id) => !items.find((i) => i.variant_id === id)
12228
- );
12229
- await mutateAsync(
12230
- {
12231
- items: ids.map((id) => ({
12232
- variant_id: id,
12233
- quantity: 1
12234
- }))
12235
- },
12236
- {
12237
- onSuccess: () => {
12238
- setRowSelection({});
12239
- setIsOpen(STACKED_MODAL_ID, false);
12240
- },
12241
- onError: (e) => {
12242
- toast.error(e.message);
12243
- }
12244
- }
12245
- );
12246
- };
12247
- if (isError) {
12248
- throw error;
12249
- }
11753
+ };
11754
+ const Illustration = () => {
12250
11755
  return /* @__PURE__ */ jsxs(
12251
- StackedFocusModal.Content,
11756
+ "svg",
12252
11757
  {
12253
- onOpenAutoFocus: (e) => {
12254
- e.preventDefault();
12255
- const searchInput = document.querySelector(
12256
- "[data-modal-id='modal-search-input']"
12257
- );
12258
- if (searchInput) {
12259
- searchInput.focus();
12260
- }
12261
- },
11758
+ width: "280",
11759
+ height: "180",
11760
+ viewBox: "0 0 280 180",
11761
+ fill: "none",
11762
+ xmlns: "http://www.w3.org/2000/svg",
12262
11763
  children: [
12263
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
12264
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12265
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12266
- ] }),
12267
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
12268
- DataTable,
11764
+ /* @__PURE__ */ jsx(
11765
+ "rect",
12269
11766
  {
12270
- data: variants,
12271
- columns,
12272
- isLoading: isPending,
12273
- getRowId: (row) => row.id,
12274
- rowCount: count,
12275
- prefix: VARIANT_PREFIX,
12276
- layout: "fill",
12277
- rowSelection: {
12278
- state: rowSelection,
12279
- onRowSelectionChange: setRowSelection,
12280
- enableRowSelection: (row) => {
12281
- return !items.find((i) => i.variant_id === row.original.id);
12282
- }
12283
- },
12284
- autoFocusSearch: true
11767
+ x: "0.00428286",
11768
+ y: "-0.742904",
11769
+ width: "33.5",
11770
+ height: "65.5",
11771
+ rx: "6.75",
11772
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11773
+ fill: "#D4D4D8",
11774
+ stroke: "#52525B",
11775
+ strokeWidth: "1.5"
12285
11776
  }
12286
- ) }),
12287
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12288
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12289
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12290
- ] }) })
12291
- ]
12292
- }
12293
- );
12294
- };
12295
- const columnHelper = createDataTableColumnHelper();
12296
- const useColumns = () => {
12297
- return useMemo(() => {
12298
- return [
12299
- columnHelper.select(),
12300
- columnHelper.accessor("product.title", {
12301
- header: "Product",
12302
- cell: ({ row }) => {
12303
- var _a, _b, _c;
12304
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
12305
- /* @__PURE__ */ jsx(
12306
- Thumbnail,
12307
- {
12308
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12309
- alt: (_b = row.original.product) == null ? void 0 : _b.title
12310
- }
12311
- ),
12312
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12313
- ] });
12314
- },
12315
- enableSorting: true
12316
- }),
12317
- columnHelper.accessor("title", {
12318
- header: "Variant",
12319
- enableSorting: true
12320
- }),
12321
- columnHelper.accessor("sku", {
12322
- header: "SKU",
12323
- cell: ({ getValue }) => {
12324
- return getValue() ?? "-";
12325
- },
12326
- enableSorting: true
12327
- }),
12328
- columnHelper.accessor("updated_at", {
12329
- header: "Updated",
12330
- cell: ({ getValue }) => {
12331
- return /* @__PURE__ */ jsx(
12332
- Tooltip,
12333
- {
12334
- content: getFullDate({ date: getValue(), includeTime: true }),
12335
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
12336
- }
12337
- );
12338
- },
12339
- enableSorting: true,
12340
- sortAscLabel: "Oldest first",
12341
- sortDescLabel: "Newest first"
12342
- }),
12343
- columnHelper.accessor("created_at", {
12344
- header: "Created",
12345
- cell: ({ getValue }) => {
12346
- return /* @__PURE__ */ jsx(
12347
- Tooltip,
12348
- {
12349
- content: getFullDate({ date: getValue(), includeTime: true }),
12350
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
12351
- }
12352
- );
12353
- },
12354
- enableSorting: true,
12355
- sortAscLabel: "Oldest first",
12356
- sortDescLabel: "Newest first"
12357
- })
12358
- ];
12359
- }, []);
12360
- };
12361
- const CustomItemForm = ({ orderId, currencyCode }) => {
12362
- const { setIsOpen } = useStackedModal();
12363
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12364
- const form = useForm({
12365
- defaultValues: {
12366
- title: "",
12367
- quantity: 1,
12368
- unit_price: ""
12369
- },
12370
- resolver: zodResolver(customItemSchema)
12371
- });
12372
- const onSubmit = form.handleSubmit(async (data) => {
12373
- await addItems(
12374
- {
12375
- items: [
11777
+ ),
11778
+ /* @__PURE__ */ jsx(
11779
+ "rect",
12376
11780
  {
12377
- title: data.title,
12378
- quantity: data.quantity,
12379
- unit_price: convertNumber(data.unit_price)
12380
- }
12381
- ]
12382
- },
12383
- {
12384
- onSuccess: () => {
12385
- setIsOpen(STACKED_MODAL_ID, false);
12386
- },
12387
- onError: (e) => {
12388
- toast.error(e.message);
12389
- }
12390
- }
12391
- );
12392
- });
12393
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
12394
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12395
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12396
- /* @__PURE__ */ jsxs("div", { children: [
12397
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
12398
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(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." }) })
12399
- ] }),
12400
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12401
- /* @__PURE__ */ jsx(
12402
- Form$2.Field,
12403
- {
12404
- control: form.control,
12405
- name: "title",
12406
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12407
- /* @__PURE__ */ jsxs("div", { children: [
12408
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
12409
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
12410
- ] }),
12411
- /* @__PURE__ */ jsxs("div", { children: [
12412
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12413
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12414
- ] })
12415
- ] }) })
12416
- }
12417
- ),
12418
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12419
- /* @__PURE__ */ jsx(
12420
- Form$2.Field,
12421
- {
12422
- control: form.control,
12423
- name: "unit_price",
12424
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12425
- /* @__PURE__ */ jsxs("div", { children: [
12426
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
12427
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12428
- ] }),
12429
- /* @__PURE__ */ jsxs("div", { children: [
12430
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12431
- CurrencyInput,
12432
- {
12433
- symbol: getNativeSymbol(currencyCode),
12434
- code: currencyCode,
12435
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12436
- ...field
12437
- }
12438
- ) }),
12439
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12440
- ] })
12441
- ] }) })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12445
- /* @__PURE__ */ jsx(
12446
- Form$2.Field,
12447
- {
12448
- control: form.control,
12449
- name: "quantity",
12450
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12451
- /* @__PURE__ */ jsxs("div", { children: [
12452
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
12453
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
12454
- ] }),
12455
- /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
12456
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
12457
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12458
- ] })
12459
- ] }) })
12460
- }
12461
- )
12462
- ] }) }) }),
12463
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12464
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12465
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
12466
- ] }) })
12467
- ] }) }) });
12468
- };
12469
- const customItemSchema = objectType({
12470
- title: stringType().min(1),
12471
- quantity: numberType(),
12472
- unit_price: unionType([numberType(), stringType()])
12473
- });
12474
- const Email = () => {
12475
- const { id } = useParams();
12476
- const { order, isPending, isError, error } = useOrder(id, {
12477
- fields: "+email"
12478
- });
12479
- if (isError) {
12480
- throw error;
12481
- }
12482
- const isReady = !isPending && !!order;
12483
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12484
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12485
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12486
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12487
- ] }),
12488
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12489
- ] });
12490
- };
12491
- const EmailForm = ({ order }) => {
12492
- const form = useForm({
12493
- defaultValues: {
12494
- email: order.email ?? ""
12495
- },
12496
- resolver: zodResolver(schema$1)
12497
- });
12498
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12499
- const { handleSuccess } = useRouteModal();
12500
- const onSubmit = form.handleSubmit(async (data) => {
12501
- await mutateAsync(
12502
- { email: data.email },
12503
- {
12504
- onSuccess: () => {
12505
- handleSuccess();
12506
- },
12507
- onError: (error) => {
12508
- toast.error(error.message);
12509
- }
12510
- }
12511
- );
12512
- });
12513
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12514
- KeyboundForm,
12515
- {
12516
- className: "flex flex-1 flex-col overflow-hidden",
12517
- onSubmit,
12518
- children: [
12519
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
12520
- Form$2.Field,
12521
- {
12522
- control: form.control,
12523
- name: "email",
12524
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
12526
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
- ] })
12529
- }
12530
- ) }),
12531
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12532
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12533
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12534
- ] }) })
12535
- ]
12536
- }
12537
- ) });
12538
- };
12539
- const schema$1 = objectType({
12540
- email: stringType().email()
12541
- });
12542
- const TransferOwnership = () => {
12543
- const { id } = useParams();
12544
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12545
- fields: "id,customer_id,customer.*"
12546
- });
12547
- if (isError) {
12548
- throw error;
12549
- }
12550
- const isReady = !isPending && !!draft_order;
12551
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12552
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12553
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12554
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12555
- ] }),
12556
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12557
- ] });
12558
- };
12559
- const TransferOwnershipForm = ({ order }) => {
12560
- var _a, _b;
12561
- const form = useForm({
12562
- defaultValues: {
12563
- customer_id: order.customer_id || ""
12564
- },
12565
- resolver: zodResolver(schema)
12566
- });
12567
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12568
- const { handleSuccess } = useRouteModal();
12569
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12570
- const currentCustomer = order.customer ? {
12571
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12572
- value: order.customer.id
12573
- } : null;
12574
- const onSubmit = form.handleSubmit(async (data) => {
12575
- await mutateAsync(
12576
- { customer_id: data.customer_id },
12577
- {
12578
- onSuccess: () => {
12579
- toast.success("Customer updated");
12580
- handleSuccess();
12581
- },
12582
- onError: (error) => {
12583
- toast.error(error.message);
12584
- }
12585
- }
12586
- );
12587
- });
12588
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12589
- KeyboundForm,
12590
- {
12591
- className: "flex flex-1 flex-col overflow-hidden",
12592
- onSubmit,
12593
- children: [
12594
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12595
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12596
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12597
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12598
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12599
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12600
- ] }),
12601
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12602
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12603
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12604
- ] })
12605
- ] }),
12606
- /* @__PURE__ */ jsx(
12607
- CustomerField,
12608
- {
12609
- control: form.control,
12610
- currentCustomerId: order.customer_id
12611
- }
12612
- )
12613
- ] }),
12614
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12615
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12616
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12617
- ] }) })
12618
- ]
12619
- }
12620
- ) });
12621
- };
12622
- const CustomerField = ({ control, currentCustomerId }) => {
12623
- const customers = useComboboxData({
12624
- queryFn: async (params) => {
12625
- return await sdk.admin.customer.list({
12626
- ...params,
12627
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12628
- });
12629
- },
12630
- queryKey: ["customers"],
12631
- getOptions: (data) => {
12632
- return data.customers.map((customer) => {
12633
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12634
- return {
12635
- label: name ? `${name} (${customer.email})` : customer.email,
12636
- value: customer.id
12637
- };
12638
- });
12639
- }
12640
- });
12641
- return /* @__PURE__ */ jsx(
12642
- Form$2.Field,
12643
- {
12644
- name: "customer_id",
12645
- control,
12646
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12647
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12648
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12649
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12650
- ] }),
12651
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12652
- Combobox,
12653
- {
12654
- options: customers.options,
12655
- fetchNextPage: customers.fetchNextPage,
12656
- isFetchingNextPage: customers.isFetchingNextPage,
12657
- searchValue: customers.searchValue,
12658
- onSearchValueChange: customers.onSearchValueChange,
12659
- placeholder: "Select customer",
12660
- ...field
12661
- }
12662
- ) }),
12663
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12664
- ] })
12665
- }
12666
- );
12667
- };
12668
- const Illustration = () => {
12669
- return /* @__PURE__ */ jsxs(
12670
- "svg",
12671
- {
12672
- width: "280",
12673
- height: "180",
12674
- viewBox: "0 0 280 180",
12675
- fill: "none",
12676
- xmlns: "http://www.w3.org/2000/svg",
12677
- children: [
12678
- /* @__PURE__ */ jsx(
12679
- "rect",
12680
- {
12681
- x: "0.00428286",
12682
- y: "-0.742904",
12683
- width: "33.5",
12684
- height: "65.5",
12685
- rx: "6.75",
12686
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12687
- fill: "#D4D4D8",
12688
- stroke: "#52525B",
12689
- strokeWidth: "1.5"
12690
- }
12691
- ),
12692
- /* @__PURE__ */ jsx(
12693
- "rect",
12694
- {
12695
- x: "0.00428286",
12696
- y: "-0.742904",
12697
- width: "33.5",
12698
- height: "65.5",
12699
- rx: "6.75",
12700
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12701
- fill: "white",
12702
- stroke: "#52525B",
12703
- strokeWidth: "1.5"
11781
+ x: "0.00428286",
11782
+ y: "-0.742904",
11783
+ width: "33.5",
11784
+ height: "65.5",
11785
+ rx: "6.75",
11786
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11787
+ fill: "white",
11788
+ stroke: "#52525B",
11789
+ strokeWidth: "1.5"
12704
11790
  }
12705
11791
  ),
12706
11792
  /* @__PURE__ */ jsx(
@@ -12861,159 +11947,1084 @@ const Illustration = () => {
12861
11947
  /* @__PURE__ */ jsx(
12862
11948
  "path",
12863
11949
  {
12864
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12865
- fill: "#A1A1AA"
12866
- }
11950
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11951
+ fill: "#A1A1AA"
11952
+ }
11953
+ ),
11954
+ /* @__PURE__ */ jsx(
11955
+ "rect",
11956
+ {
11957
+ width: "17",
11958
+ height: "3",
11959
+ rx: "1.5",
11960
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11961
+ fill: "#A1A1AA"
11962
+ }
11963
+ ),
11964
+ /* @__PURE__ */ jsx(
11965
+ "rect",
11966
+ {
11967
+ width: "12",
11968
+ height: "3",
11969
+ rx: "1.5",
11970
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11971
+ fill: "#A1A1AA"
11972
+ }
11973
+ ),
11974
+ /* @__PURE__ */ jsx(
11975
+ "path",
11976
+ {
11977
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11978
+ fill: "#52525B"
11979
+ }
11980
+ ),
11981
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11982
+ "path",
11983
+ {
11984
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11985
+ stroke: "#A1A1AA",
11986
+ strokeWidth: "1.5",
11987
+ strokeLinecap: "round",
11988
+ strokeLinejoin: "round"
11989
+ }
11990
+ ) }),
11991
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11992
+ "path",
11993
+ {
11994
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11995
+ stroke: "#A1A1AA",
11996
+ strokeWidth: "1.5",
11997
+ strokeLinecap: "round",
11998
+ strokeLinejoin: "round"
11999
+ }
12000
+ ) }),
12001
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12002
+ "path",
12003
+ {
12004
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12005
+ stroke: "#A1A1AA",
12006
+ strokeWidth: "1.5",
12007
+ strokeLinecap: "round",
12008
+ strokeLinejoin: "round"
12009
+ }
12010
+ ) }),
12011
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12012
+ "path",
12013
+ {
12014
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12015
+ stroke: "#A1A1AA",
12016
+ strokeWidth: "1.5",
12017
+ strokeLinecap: "round",
12018
+ strokeLinejoin: "round"
12019
+ }
12020
+ ) }),
12021
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12022
+ "path",
12023
+ {
12024
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12025
+ stroke: "#A1A1AA",
12026
+ strokeWidth: "1.5",
12027
+ strokeLinecap: "round",
12028
+ strokeLinejoin: "round"
12029
+ }
12030
+ ) }),
12031
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12032
+ "path",
12033
+ {
12034
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12035
+ stroke: "#A1A1AA",
12036
+ strokeWidth: "1.5",
12037
+ strokeLinecap: "round",
12038
+ strokeLinejoin: "round"
12039
+ }
12040
+ ) }),
12041
+ /* @__PURE__ */ jsxs("defs", { children: [
12042
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12043
+ "rect",
12044
+ {
12045
+ width: "12",
12046
+ height: "12",
12047
+ fill: "white",
12048
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12049
+ }
12050
+ ) }),
12051
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12052
+ "rect",
12053
+ {
12054
+ width: "12",
12055
+ height: "12",
12056
+ fill: "white",
12057
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12058
+ }
12059
+ ) }),
12060
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12061
+ "rect",
12062
+ {
12063
+ width: "12",
12064
+ height: "12",
12065
+ fill: "white",
12066
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12067
+ }
12068
+ ) }),
12069
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12070
+ "rect",
12071
+ {
12072
+ width: "12",
12073
+ height: "12",
12074
+ fill: "white",
12075
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12076
+ }
12077
+ ) }),
12078
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12079
+ "rect",
12080
+ {
12081
+ width: "12",
12082
+ height: "12",
12083
+ fill: "white",
12084
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12085
+ }
12086
+ ) }),
12087
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12088
+ "rect",
12089
+ {
12090
+ width: "12",
12091
+ height: "12",
12092
+ fill: "white",
12093
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12094
+ }
12095
+ ) })
12096
+ ] })
12097
+ ]
12098
+ }
12099
+ );
12100
+ };
12101
+ const schema = objectType({
12102
+ customer_id: stringType().min(1)
12103
+ });
12104
+ const NumberInput = forwardRef(
12105
+ ({
12106
+ value,
12107
+ onChange,
12108
+ size = "base",
12109
+ min = 0,
12110
+ max = 100,
12111
+ step = 1,
12112
+ className,
12113
+ disabled,
12114
+ ...props
12115
+ }, ref) => {
12116
+ const handleChange = (event) => {
12117
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
12118
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12119
+ onChange(newValue);
12120
+ }
12121
+ };
12122
+ const handleIncrement = () => {
12123
+ const newValue = value + step;
12124
+ if (max === void 0 || newValue <= max) {
12125
+ onChange(newValue);
12126
+ }
12127
+ };
12128
+ const handleDecrement = () => {
12129
+ const newValue = value - step;
12130
+ if (min === void 0 || newValue >= min) {
12131
+ onChange(newValue);
12132
+ }
12133
+ };
12134
+ return /* @__PURE__ */ jsxs(
12135
+ "div",
12136
+ {
12137
+ className: clx(
12138
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12139
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12140
+ {
12141
+ "h-7": size === "small",
12142
+ "h-8": size === "base"
12143
+ },
12144
+ className
12867
12145
  ),
12868
- /* @__PURE__ */ jsx(
12869
- "rect",
12870
- {
12871
- width: "17",
12872
- height: "3",
12873
- rx: "1.5",
12874
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12875
- fill: "#A1A1AA"
12146
+ children: [
12147
+ /* @__PURE__ */ jsx(
12148
+ "input",
12149
+ {
12150
+ ref,
12151
+ type: "number",
12152
+ value,
12153
+ onChange: handleChange,
12154
+ min,
12155
+ max,
12156
+ step,
12157
+ className: clx(
12158
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12159
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12160
+ "placeholder:text-ui-fg-muted"
12161
+ ),
12162
+ ...props
12163
+ }
12164
+ ),
12165
+ /* @__PURE__ */ jsxs(
12166
+ "button",
12167
+ {
12168
+ className: clx(
12169
+ "flex items-center justify-center outline-none transition-fg",
12170
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12171
+ "focus:bg-ui-bg-field-component-hover",
12172
+ "hover:bg-ui-bg-field-component-hover",
12173
+ {
12174
+ "size-7": size === "small",
12175
+ "size-8": size === "base"
12176
+ }
12177
+ ),
12178
+ type: "button",
12179
+ onClick: handleDecrement,
12180
+ disabled: min !== void 0 && value <= min || disabled,
12181
+ children: [
12182
+ /* @__PURE__ */ jsx(Minus, {}),
12183
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12184
+ ]
12185
+ }
12186
+ ),
12187
+ /* @__PURE__ */ jsxs(
12188
+ "button",
12189
+ {
12190
+ className: clx(
12191
+ "flex items-center justify-center outline-none transition-fg",
12192
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12193
+ "focus:bg-ui-bg-field-hover",
12194
+ "hover:bg-ui-bg-field-hover",
12195
+ {
12196
+ "size-7": size === "small",
12197
+ "size-8": size === "base"
12198
+ }
12199
+ ),
12200
+ type: "button",
12201
+ onClick: handleIncrement,
12202
+ disabled: max !== void 0 && value >= max || disabled,
12203
+ children: [
12204
+ /* @__PURE__ */ jsx(Plus, {}),
12205
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12206
+ ]
12207
+ }
12208
+ )
12209
+ ]
12210
+ }
12211
+ );
12212
+ }
12213
+ );
12214
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12215
+ const productVariantsQueryKeys = {
12216
+ list: (query2) => [
12217
+ PRODUCT_VARIANTS_QUERY_KEY,
12218
+ query2 ? query2 : void 0
12219
+ ]
12220
+ };
12221
+ const useProductVariants = (query2, options) => {
12222
+ const { data, ...rest } = useQuery({
12223
+ queryKey: productVariantsQueryKeys.list(query2),
12224
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
12225
+ ...options
12226
+ });
12227
+ return { ...data, ...rest };
12228
+ };
12229
+ const STACKED_MODAL_ID = "items_stacked_modal";
12230
+ const Items = () => {
12231
+ const { id } = useParams();
12232
+ const {
12233
+ order: preview,
12234
+ isPending: isPreviewPending,
12235
+ isError: isPreviewError,
12236
+ error: previewError
12237
+ } = useOrderPreview(id, void 0, {
12238
+ placeholderData: keepPreviousData
12239
+ });
12240
+ useInitiateOrderEdit({ preview });
12241
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12242
+ id,
12243
+ {
12244
+ fields: "currency_code"
12245
+ },
12246
+ {
12247
+ enabled: !!id
12248
+ }
12249
+ );
12250
+ const { onCancel } = useCancelOrderEdit({ preview });
12251
+ if (isError) {
12252
+ throw error;
12253
+ }
12254
+ if (isPreviewError) {
12255
+ throw previewError;
12256
+ }
12257
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12258
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
12259
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12260
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12261
+ ] }) });
12262
+ };
12263
+ const ItemsForm = ({ preview, currencyCode }) => {
12264
+ var _a;
12265
+ const [isSubmitting, setIsSubmitting] = useState(false);
12266
+ const [modalContent, setModalContent] = useState(
12267
+ null
12268
+ );
12269
+ const { handleSuccess } = useRouteModal();
12270
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12271
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12272
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12273
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12274
+ const matches = useMemo(() => {
12275
+ return matchSorter(preview.items, query2, {
12276
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
12277
+ });
12278
+ }, [preview.items, query2]);
12279
+ const onSubmit = async () => {
12280
+ setIsSubmitting(true);
12281
+ let requestSucceeded = false;
12282
+ await requestOrderEdit(void 0, {
12283
+ onError: (e) => {
12284
+ toast.error(`Failed to request order edit: ${e.message}`);
12285
+ },
12286
+ onSuccess: () => {
12287
+ requestSucceeded = true;
12288
+ }
12289
+ });
12290
+ if (!requestSucceeded) {
12291
+ setIsSubmitting(false);
12292
+ return;
12293
+ }
12294
+ await confirmOrderEdit(void 0, {
12295
+ onError: (e) => {
12296
+ toast.error(`Failed to confirm order edit: ${e.message}`);
12297
+ },
12298
+ onSuccess: () => {
12299
+ handleSuccess();
12300
+ },
12301
+ onSettled: () => {
12302
+ setIsSubmitting(false);
12303
+ }
12304
+ });
12305
+ };
12306
+ const onKeyDown = useCallback(
12307
+ (e) => {
12308
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12309
+ if (modalContent || isSubmitting) {
12310
+ return;
12311
+ }
12312
+ onSubmit();
12313
+ }
12314
+ },
12315
+ [modalContent, isSubmitting, onSubmit]
12316
+ );
12317
+ useEffect(() => {
12318
+ document.addEventListener("keydown", onKeyDown);
12319
+ return () => {
12320
+ document.removeEventListener("keydown", onKeyDown);
12321
+ };
12322
+ }, [onKeyDown]);
12323
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12324
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12325
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
12326
+ StackedFocusModal,
12327
+ {
12328
+ id: STACKED_MODAL_ID,
12329
+ onOpenChangeCallback: (open) => {
12330
+ if (!open) {
12331
+ setModalContent(null);
12876
12332
  }
12877
- ),
12878
- /* @__PURE__ */ jsx(
12879
- "rect",
12880
- {
12881
- width: "12",
12882
- height: "3",
12883
- rx: "1.5",
12884
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12885
- fill: "#A1A1AA"
12333
+ },
12334
+ children: [
12335
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12336
+ /* @__PURE__ */ jsxs("div", { children: [
12337
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
12338
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
12339
+ ] }),
12340
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12341
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12342
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12343
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12345
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12346
+ ] }),
12347
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
12348
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
12349
+ Input,
12350
+ {
12351
+ type: "search",
12352
+ placeholder: "Search items",
12353
+ value: searchValue,
12354
+ onChange: (e) => onSearchValueChange(e.target.value)
12355
+ }
12356
+ ) }),
12357
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
12358
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
12359
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
12360
+ /* @__PURE__ */ jsx(
12361
+ StackedModalTrigger,
12362
+ {
12363
+ type: "add-items",
12364
+ setModalContent
12365
+ }
12366
+ ),
12367
+ /* @__PURE__ */ jsx(
12368
+ StackedModalTrigger,
12369
+ {
12370
+ type: "add-custom-item",
12371
+ setModalContent
12372
+ }
12373
+ )
12374
+ ] })
12375
+ ] })
12376
+ ] })
12377
+ ] }),
12378
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12379
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
12380
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12381
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12382
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
12383
+ /* @__PURE__ */ jsx("div", {})
12384
+ ] }) }),
12385
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12386
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12387
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12388
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
12389
+ Item,
12390
+ {
12391
+ item,
12392
+ preview,
12393
+ currencyCode
12394
+ },
12395
+ item.id
12396
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12397
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12398
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12399
+ 'No items found for "',
12400
+ query2,
12401
+ '".'
12402
+ ] })
12403
+ ] }) })
12404
+ ] })
12405
+ ] }),
12406
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12407
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12408
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12409
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
12410
+ Text,
12411
+ {
12412
+ size: "small",
12413
+ leading: "compact",
12414
+ className: "text-ui-fg-subtle",
12415
+ children: [
12416
+ itemCount,
12417
+ " ",
12418
+ itemCount === 1 ? "item" : "items"
12419
+ ]
12420
+ }
12421
+ ) }),
12422
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12423
+ ] })
12424
+ ] }) }),
12425
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
12426
+ CustomItemForm,
12427
+ {
12428
+ orderId: preview.id,
12429
+ currencyCode
12430
+ }
12431
+ ) : null)
12432
+ ]
12433
+ }
12434
+ ) }),
12435
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12436
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12437
+ /* @__PURE__ */ jsx(
12438
+ Button,
12439
+ {
12440
+ size: "small",
12441
+ type: "button",
12442
+ onClick: onSubmit,
12443
+ isLoading: isSubmitting,
12444
+ children: "Save"
12445
+ }
12446
+ )
12447
+ ] }) })
12448
+ ] });
12449
+ };
12450
+ const Item = ({ item, preview, currencyCode }) => {
12451
+ if (item.variant_id) {
12452
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
12453
+ }
12454
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
12455
+ };
12456
+ const VariantItem = ({ item, preview, currencyCode }) => {
12457
+ const [editing, setEditing] = useState(false);
12458
+ const form = useForm({
12459
+ defaultValues: {
12460
+ quantity: item.quantity,
12461
+ unit_price: item.unit_price
12462
+ },
12463
+ resolver: zodResolver(variantItemSchema)
12464
+ });
12465
+ const actionId = useMemo(() => {
12466
+ var _a, _b;
12467
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12468
+ }, [item]);
12469
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12470
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12471
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12472
+ const onSubmit = form.handleSubmit(async (data) => {
12473
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12474
+ setEditing(false);
12475
+ return;
12476
+ }
12477
+ if (!actionId) {
12478
+ await updateOriginalItem(
12479
+ {
12480
+ item_id: item.id,
12481
+ quantity: data.quantity,
12482
+ unit_price: convertNumber(data.unit_price)
12483
+ },
12484
+ {
12485
+ onSuccess: () => {
12486
+ setEditing(false);
12487
+ },
12488
+ onError: (e) => {
12489
+ toast.error(e.message);
12886
12490
  }
12887
- ),
12491
+ }
12492
+ );
12493
+ return;
12494
+ }
12495
+ await updateActionItem(
12496
+ {
12497
+ action_id: actionId,
12498
+ quantity: data.quantity,
12499
+ unit_price: convertNumber(data.unit_price)
12500
+ },
12501
+ {
12502
+ onSuccess: () => {
12503
+ setEditing(false);
12504
+ },
12505
+ onError: (e) => {
12506
+ toast.error(e.message);
12507
+ }
12508
+ }
12509
+ );
12510
+ });
12511
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12512
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
12513
+ /* @__PURE__ */ jsx(
12514
+ Thumbnail,
12515
+ {
12516
+ thumbnail: item.thumbnail,
12517
+ alt: item.product_title ?? void 0
12518
+ }
12519
+ ),
12520
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12521
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12522
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12523
+ /* @__PURE__ */ jsxs(
12524
+ Text,
12525
+ {
12526
+ size: "small",
12527
+ leading: "compact",
12528
+ className: "text-ui-fg-subtle",
12529
+ children: [
12530
+ "(",
12531
+ item.variant_title,
12532
+ ")"
12533
+ ]
12534
+ }
12535
+ )
12536
+ ] }),
12888
12537
  /* @__PURE__ */ jsx(
12889
- "path",
12890
- {
12891
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12892
- fill: "#52525B"
12893
- }
12894
- ),
12895
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12896
- "path",
12897
- {
12898
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12899
- stroke: "#A1A1AA",
12900
- strokeWidth: "1.5",
12901
- strokeLinecap: "round",
12902
- strokeLinejoin: "round"
12903
- }
12904
- ) }),
12905
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12906
- "path",
12907
- {
12908
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12909
- stroke: "#A1A1AA",
12910
- strokeWidth: "1.5",
12911
- strokeLinecap: "round",
12912
- strokeLinejoin: "round"
12913
- }
12914
- ) }),
12915
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12916
- "path",
12538
+ Text,
12917
12539
  {
12918
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12919
- stroke: "#A1A1AA",
12920
- strokeWidth: "1.5",
12921
- strokeLinecap: "round",
12922
- strokeLinejoin: "round"
12540
+ size: "small",
12541
+ leading: "compact",
12542
+ className: "text-ui-fg-subtle",
12543
+ children: item.variant_sku
12923
12544
  }
12924
- ) }),
12925
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12926
- "path",
12927
- {
12928
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12929
- stroke: "#A1A1AA",
12930
- strokeWidth: "1.5",
12931
- strokeLinecap: "round",
12932
- strokeLinejoin: "round"
12545
+ )
12546
+ ] })
12547
+ ] }),
12548
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
12549
+ Form$2.Field,
12550
+ {
12551
+ control: form.control,
12552
+ name: "quantity",
12553
+ render: ({ field }) => {
12554
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12555
+ }
12556
+ }
12557
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
12558
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
12559
+ Form$2.Field,
12560
+ {
12561
+ control: form.control,
12562
+ name: "unit_price",
12563
+ render: ({ field: { onChange, ...field } }) => {
12564
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12565
+ CurrencyInput,
12566
+ {
12567
+ ...field,
12568
+ symbol: getNativeSymbol(currencyCode),
12569
+ code: currencyCode,
12570
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12571
+ }
12572
+ ) }) });
12573
+ }
12574
+ }
12575
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12576
+ /* @__PURE__ */ jsx(
12577
+ IconButton,
12578
+ {
12579
+ type: "button",
12580
+ size: "small",
12581
+ onClick: editing ? onSubmit : () => {
12582
+ setEditing(true);
12583
+ },
12584
+ disabled: isPending,
12585
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12586
+ }
12587
+ )
12588
+ ] }) }) });
12589
+ };
12590
+ const variantItemSchema = objectType({
12591
+ quantity: numberType(),
12592
+ unit_price: unionType([numberType(), stringType()])
12593
+ });
12594
+ const CustomItem = ({ item, preview, currencyCode }) => {
12595
+ const [editing, setEditing] = useState(false);
12596
+ const { quantity, unit_price, title } = item;
12597
+ const form = useForm({
12598
+ defaultValues: {
12599
+ title,
12600
+ quantity,
12601
+ unit_price
12602
+ },
12603
+ resolver: zodResolver(customItemSchema)
12604
+ });
12605
+ useEffect(() => {
12606
+ form.reset({
12607
+ title,
12608
+ quantity,
12609
+ unit_price
12610
+ });
12611
+ }, [form, title, quantity, unit_price]);
12612
+ const actionId = useMemo(() => {
12613
+ var _a, _b;
12614
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12615
+ }, [item]);
12616
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12617
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12618
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12619
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12620
+ const onSubmit = form.handleSubmit(async (data) => {
12621
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12622
+ setEditing(false);
12623
+ return;
12624
+ }
12625
+ if (!actionId) {
12626
+ await updateOriginalItem(
12627
+ {
12628
+ item_id: item.id,
12629
+ quantity: data.quantity,
12630
+ unit_price: convertNumber(data.unit_price)
12631
+ },
12632
+ {
12633
+ onSuccess: () => {
12634
+ setEditing(false);
12635
+ },
12636
+ onError: (e) => {
12637
+ toast.error(e.message);
12933
12638
  }
12934
- ) }),
12935
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12936
- "path",
12937
- {
12938
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12939
- stroke: "#A1A1AA",
12940
- strokeWidth: "1.5",
12941
- strokeLinecap: "round",
12942
- strokeLinejoin: "round"
12639
+ }
12640
+ );
12641
+ return;
12642
+ }
12643
+ if (data.quantity === 0) {
12644
+ await removeActionItem(actionId, {
12645
+ onSuccess: () => {
12646
+ setEditing(false);
12647
+ },
12648
+ onError: (e) => {
12649
+ toast.error(e.message);
12650
+ }
12651
+ });
12652
+ return;
12653
+ }
12654
+ await updateActionItem(
12655
+ {
12656
+ action_id: actionId,
12657
+ quantity: data.quantity,
12658
+ unit_price: convertNumber(data.unit_price)
12659
+ },
12660
+ {
12661
+ onSuccess: () => {
12662
+ setEditing(false);
12663
+ },
12664
+ onError: (e) => {
12665
+ toast.error(e.message);
12666
+ }
12667
+ }
12668
+ );
12669
+ });
12670
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12671
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12672
+ /* @__PURE__ */ jsx(
12673
+ Thumbnail,
12674
+ {
12675
+ thumbnail: item.thumbnail,
12676
+ alt: item.title ?? void 0
12677
+ }
12678
+ ),
12679
+ editing ? /* @__PURE__ */ jsx(
12680
+ Form$2.Field,
12681
+ {
12682
+ control: form.control,
12683
+ name: "title",
12684
+ render: ({ field }) => {
12685
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
12943
12686
  }
12944
- ) }),
12945
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12946
- "path",
12687
+ }
12688
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
12689
+ ] }),
12690
+ editing ? /* @__PURE__ */ jsx(
12691
+ Form$2.Field,
12692
+ {
12693
+ control: form.control,
12694
+ name: "quantity",
12695
+ render: ({ field }) => {
12696
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12697
+ }
12698
+ }
12699
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
12700
+ editing ? /* @__PURE__ */ jsx(
12701
+ Form$2.Field,
12702
+ {
12703
+ control: form.control,
12704
+ name: "unit_price",
12705
+ render: ({ field: { onChange, ...field } }) => {
12706
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12707
+ CurrencyInput,
12708
+ {
12709
+ ...field,
12710
+ symbol: getNativeSymbol(currencyCode),
12711
+ code: currencyCode,
12712
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12713
+ }
12714
+ ) }) });
12715
+ }
12716
+ }
12717
+ ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12718
+ /* @__PURE__ */ jsx(
12719
+ IconButton,
12720
+ {
12721
+ type: "button",
12722
+ size: "small",
12723
+ onClick: editing ? onSubmit : () => {
12724
+ setEditing(true);
12725
+ },
12726
+ disabled: isPending,
12727
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12728
+ }
12729
+ )
12730
+ ] }) }) });
12731
+ };
12732
+ const StackedModalTrigger = ({
12733
+ type,
12734
+ setModalContent
12735
+ }) => {
12736
+ const { setIsOpen } = useStackedModal();
12737
+ const onClick = useCallback(() => {
12738
+ setModalContent(type);
12739
+ setIsOpen(STACKED_MODAL_ID, true);
12740
+ }, [setModalContent, setIsOpen, type]);
12741
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12742
+ };
12743
+ const VARIANT_PREFIX = "items";
12744
+ const LIMIT = 50;
12745
+ const ExistingItemsForm = ({ orderId, items }) => {
12746
+ const { setIsOpen } = useStackedModal();
12747
+ const [rowSelection, setRowSelection] = useState(
12748
+ items.reduce((acc, item) => {
12749
+ acc[item.variant_id] = true;
12750
+ return acc;
12751
+ }, {})
12752
+ );
12753
+ useEffect(() => {
12754
+ setRowSelection(
12755
+ items.reduce((acc, item) => {
12756
+ if (item.variant_id) {
12757
+ acc[item.variant_id] = true;
12758
+ }
12759
+ return acc;
12760
+ }, {})
12761
+ );
12762
+ }, [items]);
12763
+ const { q, order, offset } = useQueryParams(
12764
+ ["q", "order", "offset"],
12765
+ VARIANT_PREFIX
12766
+ );
12767
+ const { variants, count, isPending, isError, error } = useProductVariants(
12768
+ {
12769
+ q,
12770
+ order,
12771
+ offset: offset ? parseInt(offset) : void 0,
12772
+ limit: LIMIT
12773
+ },
12774
+ {
12775
+ placeholderData: keepPreviousData
12776
+ }
12777
+ );
12778
+ const columns = useColumns();
12779
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
12780
+ const onSubmit = async () => {
12781
+ const ids = Object.keys(rowSelection).filter(
12782
+ (id) => !items.find((i) => i.variant_id === id)
12783
+ );
12784
+ await mutateAsync(
12785
+ {
12786
+ items: ids.map((id) => ({
12787
+ variant_id: id,
12788
+ quantity: 1
12789
+ }))
12790
+ },
12791
+ {
12792
+ onSuccess: () => {
12793
+ setRowSelection({});
12794
+ setIsOpen(STACKED_MODAL_ID, false);
12795
+ },
12796
+ onError: (e) => {
12797
+ toast.error(e.message);
12798
+ }
12799
+ }
12800
+ );
12801
+ };
12802
+ if (isError) {
12803
+ throw error;
12804
+ }
12805
+ return /* @__PURE__ */ jsxs(
12806
+ StackedFocusModal.Content,
12807
+ {
12808
+ onOpenAutoFocus: (e) => {
12809
+ e.preventDefault();
12810
+ const searchInput = document.querySelector(
12811
+ "[data-modal-id='modal-search-input']"
12812
+ );
12813
+ if (searchInput) {
12814
+ searchInput.focus();
12815
+ }
12816
+ },
12817
+ children: [
12818
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
12819
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12820
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12821
+ ] }),
12822
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
12823
+ DataTable,
12947
12824
  {
12948
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12949
- stroke: "#A1A1AA",
12950
- strokeWidth: "1.5",
12951
- strokeLinecap: "round",
12952
- strokeLinejoin: "round"
12825
+ data: variants,
12826
+ columns,
12827
+ isLoading: isPending,
12828
+ getRowId: (row) => row.id,
12829
+ rowCount: count,
12830
+ prefix: VARIANT_PREFIX,
12831
+ layout: "fill",
12832
+ rowSelection: {
12833
+ state: rowSelection,
12834
+ onRowSelectionChange: setRowSelection,
12835
+ enableRowSelection: (row) => {
12836
+ return !items.find((i) => i.variant_id === row.original.id);
12837
+ }
12838
+ },
12839
+ autoFocusSearch: true
12953
12840
  }
12954
12841
  ) }),
12955
- /* @__PURE__ */ jsxs("defs", { children: [
12956
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12957
- "rect",
12958
- {
12959
- width: "12",
12960
- height: "12",
12961
- fill: "white",
12962
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12963
- }
12964
- ) }),
12965
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12966
- "rect",
12967
- {
12968
- width: "12",
12969
- height: "12",
12970
- fill: "white",
12971
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12972
- }
12973
- ) }),
12974
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12975
- "rect",
12976
- {
12977
- width: "12",
12978
- height: "12",
12979
- fill: "white",
12980
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12981
- }
12982
- ) }),
12983
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12984
- "rect",
12985
- {
12986
- width: "12",
12987
- height: "12",
12988
- fill: "white",
12989
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12990
- }
12991
- ) }),
12992
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12993
- "rect",
12842
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12843
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12844
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12845
+ ] }) })
12846
+ ]
12847
+ }
12848
+ );
12849
+ };
12850
+ const columnHelper = createDataTableColumnHelper();
12851
+ const useColumns = () => {
12852
+ return useMemo(() => {
12853
+ return [
12854
+ columnHelper.select(),
12855
+ columnHelper.accessor("product.title", {
12856
+ header: "Product",
12857
+ cell: ({ row }) => {
12858
+ var _a, _b, _c;
12859
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
12860
+ /* @__PURE__ */ jsx(
12861
+ Thumbnail,
12862
+ {
12863
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12864
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
12865
+ }
12866
+ ),
12867
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12868
+ ] });
12869
+ },
12870
+ enableSorting: true
12871
+ }),
12872
+ columnHelper.accessor("title", {
12873
+ header: "Variant",
12874
+ enableSorting: true
12875
+ }),
12876
+ columnHelper.accessor("sku", {
12877
+ header: "SKU",
12878
+ cell: ({ getValue }) => {
12879
+ return getValue() ?? "-";
12880
+ },
12881
+ enableSorting: true
12882
+ }),
12883
+ columnHelper.accessor("updated_at", {
12884
+ header: "Updated",
12885
+ cell: ({ getValue }) => {
12886
+ return /* @__PURE__ */ jsx(
12887
+ Tooltip,
12994
12888
  {
12995
- width: "12",
12996
- height: "12",
12997
- fill: "white",
12998
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12889
+ content: getFullDate({ date: getValue(), includeTime: true }),
12890
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
12999
12891
  }
13000
- ) }),
13001
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13002
- "rect",
12892
+ );
12893
+ },
12894
+ enableSorting: true,
12895
+ sortAscLabel: "Oldest first",
12896
+ sortDescLabel: "Newest first"
12897
+ }),
12898
+ columnHelper.accessor("created_at", {
12899
+ header: "Created",
12900
+ cell: ({ getValue }) => {
12901
+ return /* @__PURE__ */ jsx(
12902
+ Tooltip,
13003
12903
  {
13004
- width: "12",
13005
- height: "12",
13006
- fill: "white",
13007
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12904
+ content: getFullDate({ date: getValue(), includeTime: true }),
12905
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
13008
12906
  }
13009
- ) })
13010
- ] })
13011
- ]
13012
- }
13013
- );
12907
+ );
12908
+ },
12909
+ enableSorting: true,
12910
+ sortAscLabel: "Oldest first",
12911
+ sortDescLabel: "Newest first"
12912
+ })
12913
+ ];
12914
+ }, []);
13014
12915
  };
13015
- const schema = objectType({
13016
- customer_id: stringType().min(1)
12916
+ const CustomItemForm = ({ orderId, currencyCode }) => {
12917
+ const { setIsOpen } = useStackedModal();
12918
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12919
+ const form = useForm({
12920
+ defaultValues: {
12921
+ title: "",
12922
+ quantity: 1,
12923
+ unit_price: ""
12924
+ },
12925
+ resolver: zodResolver(customItemSchema)
12926
+ });
12927
+ const onSubmit = form.handleSubmit(async (data) => {
12928
+ await addItems(
12929
+ {
12930
+ items: [
12931
+ {
12932
+ title: data.title,
12933
+ quantity: data.quantity,
12934
+ unit_price: convertNumber(data.unit_price)
12935
+ }
12936
+ ]
12937
+ },
12938
+ {
12939
+ onSuccess: () => {
12940
+ setIsOpen(STACKED_MODAL_ID, false);
12941
+ },
12942
+ onError: (e) => {
12943
+ toast.error(e.message);
12944
+ }
12945
+ }
12946
+ );
12947
+ });
12948
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
12949
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12950
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12951
+ /* @__PURE__ */ jsxs("div", { children: [
12952
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
12953
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(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." }) })
12954
+ ] }),
12955
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12956
+ /* @__PURE__ */ jsx(
12957
+ Form$2.Field,
12958
+ {
12959
+ control: form.control,
12960
+ name: "title",
12961
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12962
+ /* @__PURE__ */ jsxs("div", { children: [
12963
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
12964
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
12965
+ ] }),
12966
+ /* @__PURE__ */ jsxs("div", { children: [
12967
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12968
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12969
+ ] })
12970
+ ] }) })
12971
+ }
12972
+ ),
12973
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12974
+ /* @__PURE__ */ jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "unit_price",
12979
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12980
+ /* @__PURE__ */ jsxs("div", { children: [
12981
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
12982
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12983
+ ] }),
12984
+ /* @__PURE__ */ jsxs("div", { children: [
12985
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12986
+ CurrencyInput,
12987
+ {
12988
+ symbol: getNativeSymbol(currencyCode),
12989
+ code: currencyCode,
12990
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12991
+ ...field
12992
+ }
12993
+ ) }),
12994
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12995
+ ] })
12996
+ ] }) })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
13000
+ /* @__PURE__ */ jsx(
13001
+ Form$2.Field,
13002
+ {
13003
+ control: form.control,
13004
+ name: "quantity",
13005
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13006
+ /* @__PURE__ */ jsxs("div", { children: [
13007
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
13008
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
13009
+ ] }),
13010
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
13011
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
13012
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13013
+ ] })
13014
+ ] }) })
13015
+ }
13016
+ )
13017
+ ] }) }) }),
13018
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
13019
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13020
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
13021
+ ] }) })
13022
+ ] }) }) });
13023
+ };
13024
+ const customItemSchema = objectType({
13025
+ title: stringType().min(1),
13026
+ quantity: numberType(),
13027
+ unit_price: unionType([numberType(), stringType()])
13017
13028
  });
13018
13029
  const widgetModule = { widgets: [] };
13019
13030
  const routeModule = {
@@ -13043,6 +13054,10 @@ const routeModule = {
13043
13054
  Component: CustomItems,
13044
13055
  path: "/draft-orders/:id/custom-items"
13045
13056
  },
13057
+ {
13058
+ Component: Email,
13059
+ path: "/draft-orders/:id/email"
13060
+ },
13046
13061
  {
13047
13062
  Component: Metadata,
13048
13063
  path: "/draft-orders/:id/metadata"
@@ -13063,17 +13078,13 @@ const routeModule = {
13063
13078
  Component: ShippingAddress,
13064
13079
  path: "/draft-orders/:id/shipping-address"
13065
13080
  },
13066
- {
13067
- Component: Items,
13068
- path: "/draft-orders/:id/items"
13069
- },
13070
- {
13071
- Component: Email,
13072
- path: "/draft-orders/:id/email"
13073
- },
13074
13081
  {
13075
13082
  Component: TransferOwnership,
13076
13083
  path: "/draft-orders/:id/transfer-ownership"
13084
+ },
13085
+ {
13086
+ Component: Items,
13087
+ path: "/draft-orders/:id/items"
13077
13088
  }
13078
13089
  ]
13079
13090
  }