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