@medusajs/draft-order 0.0.13 → 2.10.0-snapshot-20250825072447

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