@medusajs/draft-order 2.10.2-snapshot-20250905111453 → 2.10.2-snapshot-20250905121828

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9567,6 +9567,196 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
+ const BillingAddress = () => {
9571
+ const { id } = useParams();
9572
+ const { order, isPending, isError, error } = useOrder(id, {
9573
+ fields: "+billing_address"
9574
+ });
9575
+ if (isError) {
9576
+ throw error;
9577
+ }
9578
+ const isReady = !isPending && !!order;
9579
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
+ ] }),
9584
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
+ ] });
9586
+ };
9587
+ const BillingAddressForm = ({ order }) => {
9588
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
+ const form = useForm({
9590
+ defaultValues: {
9591
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
+ },
9602
+ resolver: zodResolver(schema$5)
9603
+ });
9604
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
+ const { handleSuccess } = useRouteModal();
9606
+ const onSubmit = form.handleSubmit(async (data) => {
9607
+ await mutateAsync(
9608
+ { billing_address: data },
9609
+ {
9610
+ onSuccess: () => {
9611
+ handleSuccess();
9612
+ },
9613
+ onError: (error) => {
9614
+ toast.error(error.message);
9615
+ }
9616
+ }
9617
+ );
9618
+ });
9619
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
+ KeyboundForm,
9621
+ {
9622
+ className: "flex flex-1 flex-col overflow-hidden",
9623
+ onSubmit,
9624
+ children: [
9625
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9626
+ /* @__PURE__ */ jsx(
9627
+ Form$2.Field,
9628
+ {
9629
+ control: form.control,
9630
+ name: "country_code",
9631
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
+ ] })
9636
+ }
9637
+ ),
9638
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
+ /* @__PURE__ */ jsx(
9640
+ Form$2.Field,
9641
+ {
9642
+ control: form.control,
9643
+ name: "first_name",
9644
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
+ ] })
9649
+ }
9650
+ ),
9651
+ /* @__PURE__ */ jsx(
9652
+ Form$2.Field,
9653
+ {
9654
+ control: form.control,
9655
+ name: "last_name",
9656
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
+ ] })
9661
+ }
9662
+ )
9663
+ ] }),
9664
+ /* @__PURE__ */ jsx(
9665
+ Form$2.Field,
9666
+ {
9667
+ control: form.control,
9668
+ name: "company",
9669
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
+ ] })
9674
+ }
9675
+ ),
9676
+ /* @__PURE__ */ jsx(
9677
+ Form$2.Field,
9678
+ {
9679
+ control: form.control,
9680
+ name: "address_1",
9681
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
+ ] })
9686
+ }
9687
+ ),
9688
+ /* @__PURE__ */ jsx(
9689
+ Form$2.Field,
9690
+ {
9691
+ control: form.control,
9692
+ name: "address_2",
9693
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
+ ] })
9698
+ }
9699
+ ),
9700
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
+ /* @__PURE__ */ jsx(
9702
+ Form$2.Field,
9703
+ {
9704
+ control: form.control,
9705
+ name: "postal_code",
9706
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
+ ] })
9711
+ }
9712
+ ),
9713
+ /* @__PURE__ */ jsx(
9714
+ Form$2.Field,
9715
+ {
9716
+ control: form.control,
9717
+ name: "city",
9718
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
+ ] })
9723
+ }
9724
+ )
9725
+ ] }),
9726
+ /* @__PURE__ */ jsx(
9727
+ Form$2.Field,
9728
+ {
9729
+ control: form.control,
9730
+ name: "province",
9731
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
+ ] })
9736
+ }
9737
+ ),
9738
+ /* @__PURE__ */ jsx(
9739
+ Form$2.Field,
9740
+ {
9741
+ control: form.control,
9742
+ name: "phone",
9743
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
+ ] })
9748
+ }
9749
+ )
9750
+ ] }) }),
9751
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
+ ] }) })
9755
+ ]
9756
+ }
9757
+ ) });
9758
+ };
9759
+ const schema$5 = addressSchema;
9570
9760
  const CustomItems = () => {
9571
9761
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
9762
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9575,7 +9765,7 @@ const CustomItems = () => {
9575
9765
  };
9576
9766
  const CustomItemsForm = () => {
9577
9767
  const form = useForm({
9578
- resolver: zodResolver(schema$5)
9768
+ resolver: zodResolver(schema$4)
9579
9769
  });
9580
9770
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
9771
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9585,7 +9775,7 @@ const CustomItemsForm = () => {
9585
9775
  ] }) })
9586
9776
  ] }) });
9587
9777
  };
9588
- const schema$5 = objectType({
9778
+ const schema$4 = objectType({
9589
9779
  email: stringType().email()
9590
9780
  });
9591
9781
  const Email = () => {
@@ -9610,7 +9800,7 @@ const EmailForm = ({ order }) => {
9610
9800
  defaultValues: {
9611
9801
  email: order.email ?? ""
9612
9802
  },
9613
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9614
9804
  });
9615
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9616
9806
  const { handleSuccess } = useRouteModal();
@@ -9653,269 +9843,619 @@ const EmailForm = ({ order }) => {
9653
9843
  }
9654
9844
  ) });
9655
9845
  };
9656
- const schema$4 = objectType({
9846
+ const schema$3 = objectType({
9657
9847
  email: stringType().email()
9658
9848
  });
9659
- const NumberInput = forwardRef(
9660
- ({
9661
- value,
9662
- onChange,
9663
- size = "base",
9664
- min = 0,
9665
- max = 100,
9666
- step = 1,
9667
- className,
9668
- disabled,
9669
- ...props
9670
- }, ref) => {
9671
- const handleChange = (event) => {
9672
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9673
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9674
- onChange(newValue);
9675
- }
9676
- };
9677
- const handleIncrement = () => {
9678
- const newValue = value + step;
9679
- if (max === void 0 || newValue <= max) {
9680
- onChange(newValue);
9681
- }
9682
- };
9683
- const handleDecrement = () => {
9684
- const newValue = value - step;
9685
- if (min === void 0 || newValue >= min) {
9686
- onChange(newValue);
9687
- }
9688
- };
9849
+ const InlineTip = forwardRef(
9850
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9851
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9689
9852
  return /* @__PURE__ */ jsxs(
9690
9853
  "div",
9691
9854
  {
9855
+ ref,
9692
9856
  className: clx(
9693
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9694
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9695
- {
9696
- "h-7": size === "small",
9697
- "h-8": size === "base"
9698
- },
9857
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9699
9858
  className
9700
9859
  ),
9860
+ ...props,
9701
9861
  children: [
9702
9862
  /* @__PURE__ */ jsx(
9703
- "input",
9863
+ "div",
9704
9864
  {
9705
- ref,
9706
- type: "number",
9707
- value,
9708
- onChange: handleChange,
9709
- min,
9710
- max,
9711
- step,
9712
- className: clx(
9713
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9714
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9715
- "placeholder:text-ui-fg-muted"
9716
- ),
9717
- ...props
9718
- }
9719
- ),
9720
- /* @__PURE__ */ jsxs(
9721
- "button",
9722
- {
9723
- className: clx(
9724
- "flex items-center justify-center outline-none transition-fg",
9725
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9726
- "focus:bg-ui-bg-field-component-hover",
9727
- "hover:bg-ui-bg-field-component-hover",
9728
- {
9729
- "size-7": size === "small",
9730
- "size-8": size === "base"
9731
- }
9732
- ),
9733
- type: "button",
9734
- onClick: handleDecrement,
9735
- disabled: min !== void 0 && value <= min || disabled,
9736
- children: [
9737
- /* @__PURE__ */ jsx(Minus, {}),
9738
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9739
- ]
9865
+ role: "presentation",
9866
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9867
+ "bg-ui-tag-orange-icon": variant === "warning"
9868
+ })
9740
9869
  }
9741
9870
  ),
9742
- /* @__PURE__ */ jsxs(
9743
- "button",
9744
- {
9745
- className: clx(
9746
- "flex items-center justify-center outline-none transition-fg",
9747
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9748
- "focus:bg-ui-bg-field-hover",
9749
- "hover:bg-ui-bg-field-hover",
9750
- {
9751
- "size-7": size === "small",
9752
- "size-8": size === "base"
9753
- }
9754
- ),
9755
- type: "button",
9756
- onClick: handleIncrement,
9757
- disabled: max !== void 0 && value >= max || disabled,
9758
- children: [
9759
- /* @__PURE__ */ jsx(Plus, {}),
9760
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9761
- ]
9762
- }
9763
- )
9871
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9872
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9873
+ labelValue,
9874
+ ":"
9875
+ ] }),
9876
+ " ",
9877
+ children
9878
+ ] })
9764
9879
  ]
9765
9880
  }
9766
9881
  );
9767
9882
  }
9768
9883
  );
9769
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9770
- const productVariantsQueryKeys = {
9771
- list: (query2) => [
9772
- PRODUCT_VARIANTS_QUERY_KEY,
9773
- query2 ? query2 : void 0
9774
- ]
9775
- };
9776
- const useProductVariants = (query2, options) => {
9777
- const { data, ...rest } = useQuery({
9778
- queryKey: productVariantsQueryKeys.list(query2),
9779
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9780
- ...options
9781
- });
9782
- return { ...data, ...rest };
9783
- };
9784
- const useCancelOrderEdit = ({ preview }) => {
9785
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9786
- const onCancel = useCallback(async () => {
9787
- if (!preview) {
9788
- return true;
9789
- }
9790
- let res = false;
9791
- await cancelOrderEdit(void 0, {
9792
- onError: (e) => {
9793
- toast.error(e.message);
9794
- },
9795
- onSuccess: () => {
9796
- res = true;
9797
- }
9798
- });
9799
- return res;
9800
- }, [preview, cancelOrderEdit]);
9801
- return { onCancel };
9802
- };
9803
- let IS_REQUEST_RUNNING = false;
9804
- const useInitiateOrderEdit = ({
9805
- preview
9806
- }) => {
9807
- const navigate = useNavigate();
9808
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9809
- useEffect(() => {
9810
- async function run() {
9811
- if (IS_REQUEST_RUNNING || !preview) {
9812
- return;
9813
- }
9814
- if (preview.order_change) {
9815
- return;
9816
- }
9817
- IS_REQUEST_RUNNING = true;
9818
- await mutateAsync(void 0, {
9819
- onError: (e) => {
9820
- toast.error(e.message);
9821
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9822
- return;
9823
- }
9824
- });
9825
- IS_REQUEST_RUNNING = false;
9826
- }
9827
- run();
9828
- }, [preview, navigate, mutateAsync]);
9829
- };
9830
- function convertNumber(value) {
9831
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
9832
- }
9833
- const STACKED_MODAL_ID = "items_stacked_modal";
9834
- const Items = () => {
9884
+ InlineTip.displayName = "InlineTip";
9885
+ const MetadataFieldSchema = objectType({
9886
+ key: stringType(),
9887
+ disabled: booleanType().optional(),
9888
+ value: anyType()
9889
+ });
9890
+ const MetadataSchema = objectType({
9891
+ metadata: arrayType(MetadataFieldSchema)
9892
+ });
9893
+ const Metadata = () => {
9835
9894
  const { id } = useParams();
9836
- const {
9837
- order: preview,
9838
- isPending: isPreviewPending,
9839
- isError: isPreviewError,
9840
- error: previewError
9841
- } = useOrderPreview(id, void 0, {
9842
- placeholderData: keepPreviousData
9895
+ const { order, isPending, isError, error } = useOrder(id, {
9896
+ fields: "metadata"
9843
9897
  });
9844
- useInitiateOrderEdit({ preview });
9845
- const { draft_order, isPending, isError, error } = useDraftOrder(
9846
- id,
9847
- {
9848
- fields: "currency_code"
9849
- },
9850
- {
9851
- enabled: !!id
9852
- }
9853
- );
9854
- const { onCancel } = useCancelOrderEdit({ preview });
9855
9898
  if (isError) {
9856
9899
  throw error;
9857
9900
  }
9858
- if (isPreviewError) {
9859
- throw previewError;
9860
- }
9861
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
9862
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
9863
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
9864
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
9865
- ] }) });
9901
+ const isReady = !isPending && !!order;
9902
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9903
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9904
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9905
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9906
+ ] }),
9907
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9908
+ ] });
9866
9909
  };
9867
- const ItemsForm = ({ preview, currencyCode }) => {
9868
- var _a;
9869
- const [isSubmitting, setIsSubmitting] = useState(false);
9870
- const [modalContent, setModalContent] = useState(
9871
- null
9872
- );
9910
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9911
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9912
+ const MetadataForm = ({ orderId, metadata }) => {
9873
9913
  const { handleSuccess } = useRouteModal();
9874
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
9875
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
9876
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
9877
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
9878
- const matches = useMemo(() => {
9879
- return matchSorter(preview.items, query2, {
9880
- keys: ["product_title", "variant_title", "variant_sku", "title"]
9881
- });
9882
- }, [preview.items, query2]);
9883
- const onSubmit = async () => {
9884
- setIsSubmitting(true);
9885
- let requestSucceeded = false;
9886
- await requestOrderEdit(void 0, {
9887
- onError: (e) => {
9888
- toast.error(`Failed to request order edit: ${e.message}`);
9914
+ const hasUneditableRows = getHasUneditableRows(metadata);
9915
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9916
+ const form = useForm({
9917
+ defaultValues: {
9918
+ metadata: getDefaultValues(metadata)
9919
+ },
9920
+ resolver: zodResolver(MetadataSchema)
9921
+ });
9922
+ const handleSubmit = form.handleSubmit(async (data) => {
9923
+ const parsedData = parseValues(data);
9924
+ await mutateAsync(
9925
+ {
9926
+ metadata: parsedData
9889
9927
  },
9890
- onSuccess: () => {
9891
- requestSucceeded = true;
9928
+ {
9929
+ onSuccess: () => {
9930
+ toast.success("Metadata updated");
9931
+ handleSuccess();
9932
+ },
9933
+ onError: (error) => {
9934
+ toast.error(error.message);
9935
+ }
9892
9936
  }
9893
- });
9894
- if (!requestSucceeded) {
9895
- setIsSubmitting(false);
9896
- return;
9937
+ );
9938
+ });
9939
+ const { fields, insert, remove } = useFieldArray({
9940
+ control: form.control,
9941
+ name: "metadata"
9942
+ });
9943
+ function deleteRow(index) {
9944
+ remove(index);
9945
+ if (fields.length === 1) {
9946
+ insert(0, {
9947
+ key: "",
9948
+ value: "",
9949
+ disabled: false
9950
+ });
9897
9951
  }
9898
- await confirmOrderEdit(void 0, {
9899
- onError: (e) => {
9900
- toast.error(`Failed to confirm order edit: ${e.message}`);
9901
- },
9902
- onSuccess: () => {
9903
- handleSuccess();
9904
- },
9905
- onSettled: () => {
9906
- setIsSubmitting(false);
9907
- }
9952
+ }
9953
+ function insertRow(index, position) {
9954
+ insert(index + (position === "above" ? 0 : 1), {
9955
+ key: "",
9956
+ value: "",
9957
+ disabled: false
9908
9958
  });
9909
- };
9910
- const onKeyDown = useCallback(
9911
- (e) => {
9912
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
9913
- if (modalContent || isSubmitting) {
9914
- return;
9915
- }
9916
- onSubmit();
9917
- }
9918
- },
9959
+ }
9960
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9961
+ KeyboundForm,
9962
+ {
9963
+ onSubmit: handleSubmit,
9964
+ className: "flex flex-1 flex-col overflow-hidden",
9965
+ children: [
9966
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9967
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9968
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9969
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9970
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9971
+ ] }),
9972
+ fields.map((field, index) => {
9973
+ const isDisabled = field.disabled || false;
9974
+ let placeholder = "-";
9975
+ if (typeof field.value === "object") {
9976
+ placeholder = "{ ... }";
9977
+ }
9978
+ if (Array.isArray(field.value)) {
9979
+ placeholder = "[ ... ]";
9980
+ }
9981
+ return /* @__PURE__ */ jsx(
9982
+ ConditionalTooltip,
9983
+ {
9984
+ showTooltip: isDisabled,
9985
+ content: "This row is disabled because it contains non-primitive data.",
9986
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9987
+ /* @__PURE__ */ jsxs(
9988
+ "div",
9989
+ {
9990
+ className: clx("grid grid-cols-2 divide-x", {
9991
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9992
+ }),
9993
+ children: [
9994
+ /* @__PURE__ */ jsx(
9995
+ Form$2.Field,
9996
+ {
9997
+ control: form.control,
9998
+ name: `metadata.${index}.key`,
9999
+ render: ({ field: field2 }) => {
10000
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10001
+ GridInput,
10002
+ {
10003
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10004
+ ...field2,
10005
+ disabled: isDisabled,
10006
+ placeholder: "Key"
10007
+ }
10008
+ ) }) });
10009
+ }
10010
+ }
10011
+ ),
10012
+ /* @__PURE__ */ jsx(
10013
+ Form$2.Field,
10014
+ {
10015
+ control: form.control,
10016
+ name: `metadata.${index}.value`,
10017
+ render: ({ field: { value, ...field2 } }) => {
10018
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10019
+ GridInput,
10020
+ {
10021
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10022
+ ...field2,
10023
+ value: isDisabled ? placeholder : value,
10024
+ disabled: isDisabled,
10025
+ placeholder: "Value"
10026
+ }
10027
+ ) }) });
10028
+ }
10029
+ }
10030
+ )
10031
+ ]
10032
+ }
10033
+ ),
10034
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10035
+ /* @__PURE__ */ jsx(
10036
+ DropdownMenu.Trigger,
10037
+ {
10038
+ className: clx(
10039
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10040
+ {
10041
+ hidden: isDisabled
10042
+ }
10043
+ ),
10044
+ disabled: isDisabled,
10045
+ asChild: true,
10046
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10047
+ }
10048
+ ),
10049
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10050
+ /* @__PURE__ */ jsxs(
10051
+ DropdownMenu.Item,
10052
+ {
10053
+ className: "gap-x-2",
10054
+ onClick: () => insertRow(index, "above"),
10055
+ children: [
10056
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10057
+ "Insert row above"
10058
+ ]
10059
+ }
10060
+ ),
10061
+ /* @__PURE__ */ jsxs(
10062
+ DropdownMenu.Item,
10063
+ {
10064
+ className: "gap-x-2",
10065
+ onClick: () => insertRow(index, "below"),
10066
+ children: [
10067
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10068
+ "Insert row below"
10069
+ ]
10070
+ }
10071
+ ),
10072
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10073
+ /* @__PURE__ */ jsxs(
10074
+ DropdownMenu.Item,
10075
+ {
10076
+ className: "gap-x-2",
10077
+ onClick: () => deleteRow(index),
10078
+ children: [
10079
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10080
+ "Delete row"
10081
+ ]
10082
+ }
10083
+ )
10084
+ ] })
10085
+ ] })
10086
+ ] })
10087
+ },
10088
+ field.id
10089
+ );
10090
+ })
10091
+ ] }),
10092
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10093
+ ] }),
10094
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10095
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10096
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10097
+ ] }) })
10098
+ ]
10099
+ }
10100
+ ) });
10101
+ };
10102
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
10103
+ return /* @__PURE__ */ jsx(
10104
+ "input",
10105
+ {
10106
+ ref,
10107
+ ...props,
10108
+ autoComplete: "off",
10109
+ className: clx(
10110
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10111
+ className
10112
+ )
10113
+ }
10114
+ );
10115
+ });
10116
+ GridInput.displayName = "MetadataForm.GridInput";
10117
+ const PlaceholderInner = () => {
10118
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10119
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10120
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10121
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10122
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10123
+ ] }) })
10124
+ ] });
10125
+ };
10126
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10127
+ function getDefaultValues(metadata) {
10128
+ if (!metadata || !Object.keys(metadata).length) {
10129
+ return [
10130
+ {
10131
+ key: "",
10132
+ value: "",
10133
+ disabled: false
10134
+ }
10135
+ ];
10136
+ }
10137
+ return Object.entries(metadata).map(([key, value]) => {
10138
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10139
+ return {
10140
+ key,
10141
+ value,
10142
+ disabled: true
10143
+ };
10144
+ }
10145
+ let stringValue = value;
10146
+ if (typeof value !== "string") {
10147
+ stringValue = JSON.stringify(value);
10148
+ }
10149
+ return {
10150
+ key,
10151
+ value: stringValue,
10152
+ original_key: key
10153
+ };
10154
+ });
10155
+ }
10156
+ function parseValues(values) {
10157
+ const metadata = values.metadata;
10158
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10159
+ if (isEmpty) {
10160
+ return null;
10161
+ }
10162
+ const update = {};
10163
+ metadata.forEach((field) => {
10164
+ let key = field.key;
10165
+ let value = field.value;
10166
+ const disabled = field.disabled;
10167
+ if (!key || !value) {
10168
+ return;
10169
+ }
10170
+ if (disabled) {
10171
+ update[key] = value;
10172
+ return;
10173
+ }
10174
+ key = key.trim();
10175
+ value = value.trim();
10176
+ if (value === "true") {
10177
+ update[key] = true;
10178
+ } else if (value === "false") {
10179
+ update[key] = false;
10180
+ } else {
10181
+ const parsedNumber = parseFloat(value);
10182
+ if (!isNaN(parsedNumber)) {
10183
+ update[key] = parsedNumber;
10184
+ } else {
10185
+ update[key] = value;
10186
+ }
10187
+ }
10188
+ });
10189
+ return update;
10190
+ }
10191
+ function getHasUneditableRows(metadata) {
10192
+ if (!metadata) {
10193
+ return false;
10194
+ }
10195
+ return Object.values(metadata).some(
10196
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10197
+ );
10198
+ }
10199
+ const NumberInput = forwardRef(
10200
+ ({
10201
+ value,
10202
+ onChange,
10203
+ size = "base",
10204
+ min = 0,
10205
+ max = 100,
10206
+ step = 1,
10207
+ className,
10208
+ disabled,
10209
+ ...props
10210
+ }, ref) => {
10211
+ const handleChange = (event) => {
10212
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10213
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10214
+ onChange(newValue);
10215
+ }
10216
+ };
10217
+ const handleIncrement = () => {
10218
+ const newValue = value + step;
10219
+ if (max === void 0 || newValue <= max) {
10220
+ onChange(newValue);
10221
+ }
10222
+ };
10223
+ const handleDecrement = () => {
10224
+ const newValue = value - step;
10225
+ if (min === void 0 || newValue >= min) {
10226
+ onChange(newValue);
10227
+ }
10228
+ };
10229
+ return /* @__PURE__ */ jsxs(
10230
+ "div",
10231
+ {
10232
+ className: clx(
10233
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10234
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10235
+ {
10236
+ "h-7": size === "small",
10237
+ "h-8": size === "base"
10238
+ },
10239
+ className
10240
+ ),
10241
+ children: [
10242
+ /* @__PURE__ */ jsx(
10243
+ "input",
10244
+ {
10245
+ ref,
10246
+ type: "number",
10247
+ value,
10248
+ onChange: handleChange,
10249
+ min,
10250
+ max,
10251
+ step,
10252
+ className: clx(
10253
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10254
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10255
+ "placeholder:text-ui-fg-muted"
10256
+ ),
10257
+ ...props
10258
+ }
10259
+ ),
10260
+ /* @__PURE__ */ jsxs(
10261
+ "button",
10262
+ {
10263
+ className: clx(
10264
+ "flex items-center justify-center outline-none transition-fg",
10265
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10266
+ "focus:bg-ui-bg-field-component-hover",
10267
+ "hover:bg-ui-bg-field-component-hover",
10268
+ {
10269
+ "size-7": size === "small",
10270
+ "size-8": size === "base"
10271
+ }
10272
+ ),
10273
+ type: "button",
10274
+ onClick: handleDecrement,
10275
+ disabled: min !== void 0 && value <= min || disabled,
10276
+ children: [
10277
+ /* @__PURE__ */ jsx(Minus, {}),
10278
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10279
+ ]
10280
+ }
10281
+ ),
10282
+ /* @__PURE__ */ jsxs(
10283
+ "button",
10284
+ {
10285
+ className: clx(
10286
+ "flex items-center justify-center outline-none transition-fg",
10287
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10288
+ "focus:bg-ui-bg-field-hover",
10289
+ "hover:bg-ui-bg-field-hover",
10290
+ {
10291
+ "size-7": size === "small",
10292
+ "size-8": size === "base"
10293
+ }
10294
+ ),
10295
+ type: "button",
10296
+ onClick: handleIncrement,
10297
+ disabled: max !== void 0 && value >= max || disabled,
10298
+ children: [
10299
+ /* @__PURE__ */ jsx(Plus, {}),
10300
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10301
+ ]
10302
+ }
10303
+ )
10304
+ ]
10305
+ }
10306
+ );
10307
+ }
10308
+ );
10309
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10310
+ const productVariantsQueryKeys = {
10311
+ list: (query2) => [
10312
+ PRODUCT_VARIANTS_QUERY_KEY,
10313
+ query2 ? query2 : void 0
10314
+ ]
10315
+ };
10316
+ const useProductVariants = (query2, options) => {
10317
+ const { data, ...rest } = useQuery({
10318
+ queryKey: productVariantsQueryKeys.list(query2),
10319
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10320
+ ...options
10321
+ });
10322
+ return { ...data, ...rest };
10323
+ };
10324
+ const useCancelOrderEdit = ({ preview }) => {
10325
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10326
+ const onCancel = useCallback(async () => {
10327
+ if (!preview) {
10328
+ return true;
10329
+ }
10330
+ let res = false;
10331
+ await cancelOrderEdit(void 0, {
10332
+ onError: (e) => {
10333
+ toast.error(e.message);
10334
+ },
10335
+ onSuccess: () => {
10336
+ res = true;
10337
+ }
10338
+ });
10339
+ return res;
10340
+ }, [preview, cancelOrderEdit]);
10341
+ return { onCancel };
10342
+ };
10343
+ let IS_REQUEST_RUNNING = false;
10344
+ const useInitiateOrderEdit = ({
10345
+ preview
10346
+ }) => {
10347
+ const navigate = useNavigate();
10348
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10349
+ useEffect(() => {
10350
+ async function run() {
10351
+ if (IS_REQUEST_RUNNING || !preview) {
10352
+ return;
10353
+ }
10354
+ if (preview.order_change) {
10355
+ return;
10356
+ }
10357
+ IS_REQUEST_RUNNING = true;
10358
+ await mutateAsync(void 0, {
10359
+ onError: (e) => {
10360
+ toast.error(e.message);
10361
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10362
+ return;
10363
+ }
10364
+ });
10365
+ IS_REQUEST_RUNNING = false;
10366
+ }
10367
+ run();
10368
+ }, [preview, navigate, mutateAsync]);
10369
+ };
10370
+ function convertNumber(value) {
10371
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10372
+ }
10373
+ const STACKED_MODAL_ID = "items_stacked_modal";
10374
+ const Items = () => {
10375
+ const { id } = useParams();
10376
+ const {
10377
+ order: preview,
10378
+ isPending: isPreviewPending,
10379
+ isError: isPreviewError,
10380
+ error: previewError
10381
+ } = useOrderPreview(id, void 0, {
10382
+ placeholderData: keepPreviousData
10383
+ });
10384
+ useInitiateOrderEdit({ preview });
10385
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10386
+ id,
10387
+ {
10388
+ fields: "currency_code"
10389
+ },
10390
+ {
10391
+ enabled: !!id
10392
+ }
10393
+ );
10394
+ const { onCancel } = useCancelOrderEdit({ preview });
10395
+ if (isError) {
10396
+ throw error;
10397
+ }
10398
+ if (isPreviewError) {
10399
+ throw previewError;
10400
+ }
10401
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10402
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10403
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10404
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10405
+ ] }) });
10406
+ };
10407
+ const ItemsForm = ({ preview, currencyCode }) => {
10408
+ var _a;
10409
+ const [isSubmitting, setIsSubmitting] = useState(false);
10410
+ const [modalContent, setModalContent] = useState(
10411
+ null
10412
+ );
10413
+ const { handleSuccess } = useRouteModal();
10414
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10415
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10416
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10417
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10418
+ const matches = useMemo(() => {
10419
+ return matchSorter(preview.items, query2, {
10420
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10421
+ });
10422
+ }, [preview.items, query2]);
10423
+ const onSubmit = async () => {
10424
+ setIsSubmitting(true);
10425
+ let requestSucceeded = false;
10426
+ await requestOrderEdit(void 0, {
10427
+ onError: (e) => {
10428
+ toast.error(`Failed to request order edit: ${e.message}`);
10429
+ },
10430
+ onSuccess: () => {
10431
+ requestSucceeded = true;
10432
+ }
10433
+ });
10434
+ if (!requestSucceeded) {
10435
+ setIsSubmitting(false);
10436
+ return;
10437
+ }
10438
+ await confirmOrderEdit(void 0, {
10439
+ onError: (e) => {
10440
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10441
+ },
10442
+ onSuccess: () => {
10443
+ handleSuccess();
10444
+ },
10445
+ onSettled: () => {
10446
+ setIsSubmitting(false);
10447
+ }
10448
+ });
10449
+ };
10450
+ const onKeyDown = useCallback(
10451
+ (e) => {
10452
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10453
+ if (modalContent || isSubmitting) {
10454
+ return;
10455
+ }
10456
+ onSubmit();
10457
+ }
10458
+ },
9919
10459
  [modalContent, isSubmitting, onSubmit]
9920
10460
  );
9921
10461
  useEffect(() => {
@@ -10064,165 +10604,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10064
10604
  quantity: item.quantity,
10065
10605
  unit_price: item.unit_price
10066
10606
  },
10067
- resolver: zodResolver(variantItemSchema)
10068
- });
10069
- const actionId = useMemo(() => {
10070
- var _a, _b;
10071
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10072
- }, [item]);
10073
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10074
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10075
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10076
- const onSubmit = form.handleSubmit(async (data) => {
10077
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10078
- setEditing(false);
10079
- return;
10080
- }
10081
- if (!actionId) {
10082
- await updateOriginalItem(
10083
- {
10084
- item_id: item.id,
10085
- quantity: data.quantity,
10086
- unit_price: convertNumber(data.unit_price)
10087
- },
10088
- {
10089
- onSuccess: () => {
10090
- setEditing(false);
10091
- },
10092
- onError: (e) => {
10093
- toast.error(e.message);
10094
- }
10095
- }
10096
- );
10097
- return;
10098
- }
10099
- await updateActionItem(
10100
- {
10101
- action_id: actionId,
10102
- quantity: data.quantity,
10103
- unit_price: convertNumber(data.unit_price)
10104
- },
10105
- {
10106
- onSuccess: () => {
10107
- setEditing(false);
10108
- },
10109
- onError: (e) => {
10110
- toast.error(e.message);
10111
- }
10112
- }
10113
- );
10114
- });
10115
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10116
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10117
- /* @__PURE__ */ jsx(
10118
- Thumbnail,
10119
- {
10120
- thumbnail: item.thumbnail,
10121
- alt: item.product_title ?? void 0
10122
- }
10123
- ),
10124
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10125
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10126
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10127
- /* @__PURE__ */ jsxs(
10128
- Text,
10129
- {
10130
- size: "small",
10131
- leading: "compact",
10132
- className: "text-ui-fg-subtle",
10133
- children: [
10134
- "(",
10135
- item.variant_title,
10136
- ")"
10137
- ]
10138
- }
10139
- )
10140
- ] }),
10141
- /* @__PURE__ */ jsx(
10142
- Text,
10143
- {
10144
- size: "small",
10145
- leading: "compact",
10146
- className: "text-ui-fg-subtle",
10147
- children: item.variant_sku
10148
- }
10149
- )
10150
- ] })
10151
- ] }),
10152
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10153
- Form$2.Field,
10154
- {
10155
- control: form.control,
10156
- name: "quantity",
10157
- render: ({ field }) => {
10158
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10159
- }
10160
- }
10161
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10162
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10163
- Form$2.Field,
10164
- {
10165
- control: form.control,
10166
- name: "unit_price",
10167
- render: ({ field: { onChange, ...field } }) => {
10168
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10169
- CurrencyInput,
10170
- {
10171
- ...field,
10172
- symbol: getNativeSymbol(currencyCode),
10173
- code: currencyCode,
10174
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10175
- }
10176
- ) }) });
10177
- }
10178
- }
10179
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10180
- /* @__PURE__ */ jsx(
10181
- IconButton,
10182
- {
10183
- type: "button",
10184
- size: "small",
10185
- onClick: editing ? onSubmit : () => {
10186
- setEditing(true);
10187
- },
10188
- disabled: isPending,
10189
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10190
- }
10191
- )
10192
- ] }) }) });
10193
- };
10194
- const variantItemSchema = objectType({
10195
- quantity: numberType(),
10196
- unit_price: unionType([numberType(), stringType()])
10197
- });
10198
- const CustomItem = ({ item, preview, currencyCode }) => {
10199
- const [editing, setEditing] = useState(false);
10200
- const { quantity, unit_price, title } = item;
10201
- const form = useForm({
10202
- defaultValues: {
10203
- title,
10204
- quantity,
10205
- unit_price
10206
- },
10207
- resolver: zodResolver(customItemSchema)
10607
+ resolver: zodResolver(variantItemSchema)
10208
10608
  });
10209
- useEffect(() => {
10210
- form.reset({
10211
- title,
10212
- quantity,
10213
- unit_price
10214
- });
10215
- }, [form, title, quantity, unit_price]);
10216
10609
  const actionId = useMemo(() => {
10217
10610
  var _a, _b;
10218
10611
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10219
10612
  }, [item]);
10220
10613
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10221
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10222
10614
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10223
10615
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10224
10616
  const onSubmit = form.handleSubmit(async (data) => {
10225
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10617
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10226
10618
  setEditing(false);
10227
10619
  return;
10228
10620
  }
@@ -10244,17 +10636,6 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10244
10636
  );
10245
10637
  return;
10246
10638
  }
10247
- if (data.quantity === 0) {
10248
- await removeActionItem(actionId, {
10249
- onSuccess: () => {
10250
- setEditing(false);
10251
- },
10252
- onError: (e) => {
10253
- toast.error(e.message);
10254
- }
10255
- });
10256
- return;
10257
- }
10258
10639
  await updateActionItem(
10259
10640
  {
10260
10641
  action_id: actionId,
@@ -10272,26 +10653,43 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10272
10653
  );
10273
10654
  });
10274
10655
  return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10275
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10656
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10276
10657
  /* @__PURE__ */ jsx(
10277
10658
  Thumbnail,
10278
10659
  {
10279
10660
  thumbnail: item.thumbnail,
10280
- alt: item.title ?? void 0
10661
+ alt: item.product_title ?? void 0
10281
10662
  }
10282
10663
  ),
10283
- editing ? /* @__PURE__ */ jsx(
10284
- Form$2.Field,
10285
- {
10286
- control: form.control,
10287
- name: "title",
10288
- render: ({ field }) => {
10289
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10664
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10665
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10666
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10667
+ /* @__PURE__ */ jsxs(
10668
+ Text,
10669
+ {
10670
+ size: "small",
10671
+ leading: "compact",
10672
+ className: "text-ui-fg-subtle",
10673
+ children: [
10674
+ "(",
10675
+ item.variant_title,
10676
+ ")"
10677
+ ]
10678
+ }
10679
+ )
10680
+ ] }),
10681
+ /* @__PURE__ */ jsx(
10682
+ Text,
10683
+ {
10684
+ size: "small",
10685
+ leading: "compact",
10686
+ className: "text-ui-fg-subtle",
10687
+ children: item.variant_sku
10290
10688
  }
10291
- }
10292
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10689
+ )
10690
+ ] })
10293
10691
  ] }),
10294
- editing ? /* @__PURE__ */ jsx(
10692
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10295
10693
  Form$2.Field,
10296
10694
  {
10297
10695
  control: form.control,
@@ -10300,8 +10698,8 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10300
10698
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10301
10699
  }
10302
10700
  }
10303
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10304
- editing ? /* @__PURE__ */ jsx(
10701
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10702
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10305
10703
  Form$2.Field,
10306
10704
  {
10307
10705
  control: form.control,
@@ -10318,230 +10716,94 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10318
10716
  ) }) });
10319
10717
  }
10320
10718
  }
10321
- ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10719
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10322
10720
  /* @__PURE__ */ jsx(
10323
10721
  IconButton,
10324
10722
  {
10325
10723
  type: "button",
10326
- size: "small",
10327
- onClick: editing ? onSubmit : () => {
10328
- setEditing(true);
10329
- },
10330
- disabled: isPending,
10331
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10332
- }
10333
- )
10334
- ] }) }) });
10335
- };
10336
- const StackedModalTrigger$1 = ({
10337
- type,
10338
- setModalContent
10339
- }) => {
10340
- const { setIsOpen } = useStackedModal();
10341
- const onClick = useCallback(() => {
10342
- setModalContent(type);
10343
- setIsOpen(STACKED_MODAL_ID, true);
10344
- }, [setModalContent, setIsOpen, type]);
10345
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10346
- };
10347
- const VARIANT_PREFIX = "items";
10348
- const LIMIT = 50;
10349
- const ExistingItemsForm = ({ orderId, items }) => {
10350
- const { setIsOpen } = useStackedModal();
10351
- const [rowSelection, setRowSelection] = useState(
10352
- items.reduce((acc, item) => {
10353
- acc[item.variant_id] = true;
10354
- return acc;
10355
- }, {})
10356
- );
10357
- useEffect(() => {
10358
- setRowSelection(
10359
- items.reduce((acc, item) => {
10360
- if (item.variant_id) {
10361
- acc[item.variant_id] = true;
10362
- }
10363
- return acc;
10364
- }, {})
10365
- );
10366
- }, [items]);
10367
- const { q, order, offset } = useQueryParams(
10368
- ["q", "order", "offset"],
10369
- VARIANT_PREFIX
10370
- );
10371
- const { variants, count, isPending, isError, error } = useProductVariants(
10372
- {
10373
- q,
10374
- order,
10375
- offset: offset ? parseInt(offset) : void 0,
10376
- limit: LIMIT
10377
- },
10378
- {
10379
- placeholderData: keepPreviousData
10380
- }
10381
- );
10382
- const columns = useColumns();
10383
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10384
- const onSubmit = async () => {
10385
- const ids = Object.keys(rowSelection).filter(
10386
- (id) => !items.find((i) => i.variant_id === id)
10387
- );
10388
- await mutateAsync(
10389
- {
10390
- items: ids.map((id) => ({
10391
- variant_id: id,
10392
- quantity: 1
10393
- }))
10394
- },
10395
- {
10396
- onSuccess: () => {
10397
- setRowSelection({});
10398
- setIsOpen(STACKED_MODAL_ID, false);
10399
- },
10400
- onError: (e) => {
10401
- toast.error(e.message);
10402
- }
10403
- }
10404
- );
10405
- };
10406
- if (isError) {
10407
- throw error;
10408
- }
10409
- return /* @__PURE__ */ jsxs(
10410
- StackedFocusModal.Content,
10411
- {
10412
- onOpenAutoFocus: (e) => {
10413
- e.preventDefault();
10414
- const searchInput = document.querySelector(
10415
- "[data-modal-id='modal-search-input']"
10416
- );
10417
- if (searchInput) {
10418
- searchInput.focus();
10419
- }
10420
- },
10421
- children: [
10422
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10423
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10424
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10425
- ] }),
10426
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10427
- DataTable,
10428
- {
10429
- data: variants,
10430
- columns,
10431
- isLoading: isPending,
10432
- getRowId: (row) => row.id,
10433
- rowCount: count,
10434
- prefix: VARIANT_PREFIX,
10435
- layout: "fill",
10436
- rowSelection: {
10437
- state: rowSelection,
10438
- onRowSelectionChange: setRowSelection,
10439
- enableRowSelection: (row) => {
10440
- return !items.find((i) => i.variant_id === row.original.id);
10441
- }
10442
- },
10443
- autoFocusSearch: true
10444
- }
10445
- ) }),
10446
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10447
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10448
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10449
- ] }) })
10450
- ]
10451
- }
10452
- );
10453
- };
10454
- const columnHelper = createDataTableColumnHelper();
10455
- const useColumns = () => {
10456
- return useMemo(() => {
10457
- return [
10458
- columnHelper.select(),
10459
- columnHelper.accessor("product.title", {
10460
- header: "Product",
10461
- cell: ({ row }) => {
10462
- var _a, _b, _c;
10463
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10464
- /* @__PURE__ */ jsx(
10465
- Thumbnail,
10466
- {
10467
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10468
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10469
- }
10470
- ),
10471
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10472
- ] });
10473
- },
10474
- enableSorting: true
10475
- }),
10476
- columnHelper.accessor("title", {
10477
- header: "Variant",
10478
- enableSorting: true
10479
- }),
10480
- columnHelper.accessor("sku", {
10481
- header: "SKU",
10482
- cell: ({ getValue }) => {
10483
- return getValue() ?? "-";
10484
- },
10485
- enableSorting: true
10486
- }),
10487
- columnHelper.accessor("updated_at", {
10488
- header: "Updated",
10489
- cell: ({ getValue }) => {
10490
- return /* @__PURE__ */ jsx(
10491
- Tooltip,
10492
- {
10493
- content: getFullDate({ date: getValue(), includeTime: true }),
10494
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10495
- }
10496
- );
10497
- },
10498
- enableSorting: true,
10499
- sortAscLabel: "Oldest first",
10500
- sortDescLabel: "Newest first"
10501
- }),
10502
- columnHelper.accessor("created_at", {
10503
- header: "Created",
10504
- cell: ({ getValue }) => {
10505
- return /* @__PURE__ */ jsx(
10506
- Tooltip,
10507
- {
10508
- content: getFullDate({ date: getValue(), includeTime: true }),
10509
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10510
- }
10511
- );
10724
+ size: "small",
10725
+ onClick: editing ? onSubmit : () => {
10726
+ setEditing(true);
10512
10727
  },
10513
- enableSorting: true,
10514
- sortAscLabel: "Oldest first",
10515
- sortDescLabel: "Newest first"
10516
- })
10517
- ];
10518
- }, []);
10728
+ disabled: isPending,
10729
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10730
+ }
10731
+ )
10732
+ ] }) }) });
10519
10733
  };
10520
- const CustomItemForm = ({ orderId, currencyCode }) => {
10521
- const { setIsOpen } = useStackedModal();
10522
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10734
+ const variantItemSchema = objectType({
10735
+ quantity: numberType(),
10736
+ unit_price: unionType([numberType(), stringType()])
10737
+ });
10738
+ const CustomItem = ({ item, preview, currencyCode }) => {
10739
+ const [editing, setEditing] = useState(false);
10740
+ const { quantity, unit_price, title } = item;
10523
10741
  const form = useForm({
10524
10742
  defaultValues: {
10525
- title: "",
10526
- quantity: 1,
10527
- unit_price: ""
10743
+ title,
10744
+ quantity,
10745
+ unit_price
10528
10746
  },
10529
10747
  resolver: zodResolver(customItemSchema)
10530
10748
  });
10749
+ useEffect(() => {
10750
+ form.reset({
10751
+ title,
10752
+ quantity,
10753
+ unit_price
10754
+ });
10755
+ }, [form, title, quantity, unit_price]);
10756
+ const actionId = useMemo(() => {
10757
+ var _a, _b;
10758
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10759
+ }, [item]);
10760
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10761
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10762
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10763
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10531
10764
  const onSubmit = form.handleSubmit(async (data) => {
10532
- await addItems(
10533
- {
10534
- items: [
10535
- {
10536
- title: data.title,
10537
- quantity: data.quantity,
10538
- unit_price: convertNumber(data.unit_price)
10765
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10766
+ setEditing(false);
10767
+ return;
10768
+ }
10769
+ if (!actionId) {
10770
+ await updateOriginalItem(
10771
+ {
10772
+ item_id: item.id,
10773
+ quantity: data.quantity,
10774
+ unit_price: convertNumber(data.unit_price)
10775
+ },
10776
+ {
10777
+ onSuccess: () => {
10778
+ setEditing(false);
10779
+ },
10780
+ onError: (e) => {
10781
+ toast.error(e.message);
10539
10782
  }
10540
- ]
10783
+ }
10784
+ );
10785
+ return;
10786
+ }
10787
+ if (data.quantity === 0) {
10788
+ await removeActionItem(actionId, {
10789
+ onSuccess: () => {
10790
+ setEditing(false);
10791
+ },
10792
+ onError: (e) => {
10793
+ toast.error(e.message);
10794
+ }
10795
+ });
10796
+ return;
10797
+ }
10798
+ await updateActionItem(
10799
+ {
10800
+ action_id: actionId,
10801
+ quantity: data.quantity,
10802
+ unit_price: convertNumber(data.unit_price)
10541
10803
  },
10542
10804
  {
10543
10805
  onSuccess: () => {
10544
- setIsOpen(STACKED_MODAL_ID, false);
10806
+ setEditing(false);
10545
10807
  },
10546
10808
  onError: (e) => {
10547
10809
  toast.error(e.message);
@@ -10549,437 +10811,365 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10549
10811
  }
10550
10812
  );
10551
10813
  });
10552
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10553
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10554
- /* @__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: [
10555
- /* @__PURE__ */ jsxs("div", { children: [
10556
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10557
- /* @__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." }) })
10558
- ] }),
10559
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10814
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10815
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10560
10816
  /* @__PURE__ */ jsx(
10561
- Form$2.Field,
10817
+ Thumbnail,
10562
10818
  {
10563
- control: form.control,
10564
- name: "title",
10565
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10566
- /* @__PURE__ */ jsxs("div", { children: [
10567
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10568
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10569
- ] }),
10570
- /* @__PURE__ */ jsxs("div", { children: [
10571
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10572
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10573
- ] })
10574
- ] }) })
10819
+ thumbnail: item.thumbnail,
10820
+ alt: item.title ?? void 0
10575
10821
  }
10576
10822
  ),
10577
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10578
- /* @__PURE__ */ jsx(
10823
+ editing ? /* @__PURE__ */ jsx(
10579
10824
  Form$2.Field,
10580
10825
  {
10581
10826
  control: form.control,
10582
- name: "unit_price",
10583
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10584
- /* @__PURE__ */ jsxs("div", { children: [
10585
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10586
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10587
- ] }),
10588
- /* @__PURE__ */ jsxs("div", { children: [
10589
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10590
- CurrencyInput,
10591
- {
10592
- symbol: getNativeSymbol(currencyCode),
10593
- code: currencyCode,
10594
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10595
- ...field
10596
- }
10597
- ) }),
10598
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10599
- ] })
10600
- ] }) })
10827
+ name: "title",
10828
+ render: ({ field }) => {
10829
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10830
+ }
10601
10831
  }
10602
- ),
10603
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10604
- /* @__PURE__ */ jsx(
10605
- Form$2.Field,
10606
- {
10607
- control: form.control,
10608
- name: "quantity",
10609
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10610
- /* @__PURE__ */ jsxs("div", { children: [
10611
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10612
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10613
- ] }),
10614
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10615
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10616
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10617
- ] })
10618
- ] }) })
10832
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10833
+ ] }),
10834
+ editing ? /* @__PURE__ */ jsx(
10835
+ Form$2.Field,
10836
+ {
10837
+ control: form.control,
10838
+ name: "quantity",
10839
+ render: ({ field }) => {
10840
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10619
10841
  }
10620
- )
10621
- ] }) }) }),
10622
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10623
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10624
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10625
- ] }) })
10626
- ] }) }) });
10627
- };
10628
- const customItemSchema = objectType({
10629
- title: stringType().min(1),
10630
- quantity: numberType(),
10631
- unit_price: unionType([numberType(), stringType()])
10632
- });
10633
- const InlineTip = forwardRef(
10634
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10635
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10636
- return /* @__PURE__ */ jsxs(
10637
- "div",
10842
+ }
10843
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10844
+ editing ? /* @__PURE__ */ jsx(
10845
+ Form$2.Field,
10638
10846
  {
10639
- ref,
10640
- className: clx(
10641
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10642
- className
10643
- ),
10644
- ...props,
10645
- children: [
10646
- /* @__PURE__ */ jsx(
10647
- "div",
10847
+ control: form.control,
10848
+ name: "unit_price",
10849
+ render: ({ field: { onChange, ...field } }) => {
10850
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10851
+ CurrencyInput,
10648
10852
  {
10649
- role: "presentation",
10650
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10651
- "bg-ui-tag-orange-icon": variant === "warning"
10652
- })
10853
+ ...field,
10854
+ symbol: getNativeSymbol(currencyCode),
10855
+ code: currencyCode,
10856
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10653
10857
  }
10654
- ),
10655
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10656
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10657
- labelValue,
10658
- ":"
10659
- ] }),
10660
- " ",
10661
- children
10662
- ] })
10663
- ]
10858
+ ) }) });
10859
+ }
10664
10860
  }
10665
- );
10666
- }
10667
- );
10668
- InlineTip.displayName = "InlineTip";
10669
- const MetadataFieldSchema = objectType({
10670
- key: stringType(),
10671
- disabled: booleanType().optional(),
10672
- value: anyType()
10673
- });
10674
- const MetadataSchema = objectType({
10675
- metadata: arrayType(MetadataFieldSchema)
10676
- });
10677
- const Metadata = () => {
10678
- const { id } = useParams();
10679
- const { order, isPending, isError, error } = useOrder(id, {
10680
- fields: "metadata"
10681
- });
10682
- if (isError) {
10683
- throw error;
10684
- }
10685
- const isReady = !isPending && !!order;
10686
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10687
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10688
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10689
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10690
- ] }),
10691
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10692
- ] });
10861
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10862
+ /* @__PURE__ */ jsx(
10863
+ IconButton,
10864
+ {
10865
+ type: "button",
10866
+ size: "small",
10867
+ onClick: editing ? onSubmit : () => {
10868
+ setEditing(true);
10869
+ },
10870
+ disabled: isPending,
10871
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10872
+ }
10873
+ )
10874
+ ] }) }) });
10693
10875
  };
10694
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10695
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10696
- const MetadataForm = ({ orderId, metadata }) => {
10697
- const { handleSuccess } = useRouteModal();
10698
- const hasUneditableRows = getHasUneditableRows(metadata);
10699
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10700
- const form = useForm({
10701
- defaultValues: {
10702
- metadata: getDefaultValues(metadata)
10876
+ const StackedModalTrigger$1 = ({
10877
+ type,
10878
+ setModalContent
10879
+ }) => {
10880
+ const { setIsOpen } = useStackedModal();
10881
+ const onClick = useCallback(() => {
10882
+ setModalContent(type);
10883
+ setIsOpen(STACKED_MODAL_ID, true);
10884
+ }, [setModalContent, setIsOpen, type]);
10885
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10886
+ };
10887
+ const VARIANT_PREFIX = "items";
10888
+ const LIMIT = 50;
10889
+ const ExistingItemsForm = ({ orderId, items }) => {
10890
+ const { setIsOpen } = useStackedModal();
10891
+ const [rowSelection, setRowSelection] = useState(
10892
+ items.reduce((acc, item) => {
10893
+ acc[item.variant_id] = true;
10894
+ return acc;
10895
+ }, {})
10896
+ );
10897
+ useEffect(() => {
10898
+ setRowSelection(
10899
+ items.reduce((acc, item) => {
10900
+ if (item.variant_id) {
10901
+ acc[item.variant_id] = true;
10902
+ }
10903
+ return acc;
10904
+ }, {})
10905
+ );
10906
+ }, [items]);
10907
+ const { q, order, offset } = useQueryParams(
10908
+ ["q", "order", "offset"],
10909
+ VARIANT_PREFIX
10910
+ );
10911
+ const { variants, count, isPending, isError, error } = useProductVariants(
10912
+ {
10913
+ q,
10914
+ order,
10915
+ offset: offset ? parseInt(offset) : void 0,
10916
+ limit: LIMIT
10703
10917
  },
10704
- resolver: zodResolver(MetadataSchema)
10705
- });
10706
- const handleSubmit = form.handleSubmit(async (data) => {
10707
- const parsedData = parseValues(data);
10918
+ {
10919
+ placeholderData: keepPreviousData
10920
+ }
10921
+ );
10922
+ const columns = useColumns();
10923
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10924
+ const onSubmit = async () => {
10925
+ const ids = Object.keys(rowSelection).filter(
10926
+ (id) => !items.find((i) => i.variant_id === id)
10927
+ );
10708
10928
  await mutateAsync(
10709
10929
  {
10710
- metadata: parsedData
10930
+ items: ids.map((id) => ({
10931
+ variant_id: id,
10932
+ quantity: 1
10933
+ }))
10711
10934
  },
10712
10935
  {
10713
10936
  onSuccess: () => {
10714
- toast.success("Metadata updated");
10715
- handleSuccess();
10937
+ setRowSelection({});
10938
+ setIsOpen(STACKED_MODAL_ID, false);
10716
10939
  },
10717
- onError: (error) => {
10718
- toast.error(error.message);
10940
+ onError: (e) => {
10941
+ toast.error(e.message);
10719
10942
  }
10720
10943
  }
10721
10944
  );
10722
- });
10723
- const { fields, insert, remove } = useFieldArray({
10724
- control: form.control,
10725
- name: "metadata"
10726
- });
10727
- function deleteRow(index) {
10728
- remove(index);
10729
- if (fields.length === 1) {
10730
- insert(0, {
10731
- key: "",
10732
- value: "",
10733
- disabled: false
10734
- });
10735
- }
10736
- }
10737
- function insertRow(index, position) {
10738
- insert(index + (position === "above" ? 0 : 1), {
10739
- key: "",
10740
- value: "",
10741
- disabled: false
10742
- });
10945
+ };
10946
+ if (isError) {
10947
+ throw error;
10743
10948
  }
10744
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10745
- KeyboundForm,
10949
+ return /* @__PURE__ */ jsxs(
10950
+ StackedFocusModal.Content,
10746
10951
  {
10747
- onSubmit: handleSubmit,
10748
- className: "flex flex-1 flex-col overflow-hidden",
10952
+ onOpenAutoFocus: (e) => {
10953
+ e.preventDefault();
10954
+ const searchInput = document.querySelector(
10955
+ "[data-modal-id='modal-search-input']"
10956
+ );
10957
+ if (searchInput) {
10958
+ searchInput.focus();
10959
+ }
10960
+ },
10749
10961
  children: [
10750
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10751
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10752
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10753
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10754
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10755
- ] }),
10756
- fields.map((field, index) => {
10757
- const isDisabled = field.disabled || false;
10758
- let placeholder = "-";
10759
- if (typeof field.value === "object") {
10760
- placeholder = "{ ... }";
10761
- }
10762
- if (Array.isArray(field.value)) {
10763
- placeholder = "[ ... ]";
10764
- }
10765
- return /* @__PURE__ */ jsx(
10766
- ConditionalTooltip,
10767
- {
10768
- showTooltip: isDisabled,
10769
- content: "This row is disabled because it contains non-primitive data.",
10770
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10771
- /* @__PURE__ */ jsxs(
10772
- "div",
10773
- {
10774
- className: clx("grid grid-cols-2 divide-x", {
10775
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10776
- }),
10777
- children: [
10778
- /* @__PURE__ */ jsx(
10779
- Form$2.Field,
10780
- {
10781
- control: form.control,
10782
- name: `metadata.${index}.key`,
10783
- render: ({ field: field2 }) => {
10784
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10785
- GridInput,
10786
- {
10787
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10788
- ...field2,
10789
- disabled: isDisabled,
10790
- placeholder: "Key"
10791
- }
10792
- ) }) });
10793
- }
10794
- }
10795
- ),
10796
- /* @__PURE__ */ jsx(
10797
- Form$2.Field,
10798
- {
10799
- control: form.control,
10800
- name: `metadata.${index}.value`,
10801
- render: ({ field: { value, ...field2 } }) => {
10802
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10803
- GridInput,
10804
- {
10805
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10806
- ...field2,
10807
- value: isDisabled ? placeholder : value,
10808
- disabled: isDisabled,
10809
- placeholder: "Value"
10810
- }
10811
- ) }) });
10812
- }
10813
- }
10814
- )
10815
- ]
10816
- }
10817
- ),
10818
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10819
- /* @__PURE__ */ jsx(
10820
- DropdownMenu.Trigger,
10821
- {
10822
- className: clx(
10823
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10824
- {
10825
- hidden: isDisabled
10826
- }
10827
- ),
10828
- disabled: isDisabled,
10829
- asChild: true,
10830
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10831
- }
10832
- ),
10833
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10834
- /* @__PURE__ */ jsxs(
10835
- DropdownMenu.Item,
10836
- {
10837
- className: "gap-x-2",
10838
- onClick: () => insertRow(index, "above"),
10839
- children: [
10840
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10841
- "Insert row above"
10842
- ]
10843
- }
10844
- ),
10845
- /* @__PURE__ */ jsxs(
10846
- DropdownMenu.Item,
10847
- {
10848
- className: "gap-x-2",
10849
- onClick: () => insertRow(index, "below"),
10850
- children: [
10851
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10852
- "Insert row below"
10853
- ]
10854
- }
10855
- ),
10856
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10857
- /* @__PURE__ */ jsxs(
10858
- DropdownMenu.Item,
10859
- {
10860
- className: "gap-x-2",
10861
- onClick: () => deleteRow(index),
10862
- children: [
10863
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10864
- "Delete row"
10865
- ]
10866
- }
10867
- )
10868
- ] })
10869
- ] })
10870
- ] })
10871
- },
10872
- field.id
10873
- );
10874
- })
10875
- ] }),
10876
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10962
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10963
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10964
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10877
10965
  ] }),
10878
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10879
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10880
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10966
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10967
+ DataTable,
10968
+ {
10969
+ data: variants,
10970
+ columns,
10971
+ isLoading: isPending,
10972
+ getRowId: (row) => row.id,
10973
+ rowCount: count,
10974
+ prefix: VARIANT_PREFIX,
10975
+ layout: "fill",
10976
+ rowSelection: {
10977
+ state: rowSelection,
10978
+ onRowSelectionChange: setRowSelection,
10979
+ enableRowSelection: (row) => {
10980
+ return !items.find((i) => i.variant_id === row.original.id);
10981
+ }
10982
+ },
10983
+ autoFocusSearch: true
10984
+ }
10985
+ ) }),
10986
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10987
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10988
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10881
10989
  ] }) })
10882
10990
  ]
10883
10991
  }
10884
- ) });
10885
- };
10886
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10887
- return /* @__PURE__ */ jsx(
10888
- "input",
10889
- {
10890
- ref,
10891
- ...props,
10892
- autoComplete: "off",
10893
- className: clx(
10894
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10895
- className
10896
- )
10897
- }
10898
10992
  );
10899
- });
10900
- GridInput.displayName = "MetadataForm.GridInput";
10901
- const PlaceholderInner = () => {
10902
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10903
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10904
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10905
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10906
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10907
- ] }) })
10908
- ] });
10909
10993
  };
10910
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10911
- function getDefaultValues(metadata) {
10912
- if (!metadata || !Object.keys(metadata).length) {
10994
+ const columnHelper = createDataTableColumnHelper();
10995
+ const useColumns = () => {
10996
+ return useMemo(() => {
10913
10997
  return [
10914
- {
10915
- key: "",
10916
- value: "",
10917
- disabled: false
10918
- }
10998
+ columnHelper.select(),
10999
+ columnHelper.accessor("product.title", {
11000
+ header: "Product",
11001
+ cell: ({ row }) => {
11002
+ var _a, _b, _c;
11003
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
11004
+ /* @__PURE__ */ jsx(
11005
+ Thumbnail,
11006
+ {
11007
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11008
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
11009
+ }
11010
+ ),
11011
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11012
+ ] });
11013
+ },
11014
+ enableSorting: true
11015
+ }),
11016
+ columnHelper.accessor("title", {
11017
+ header: "Variant",
11018
+ enableSorting: true
11019
+ }),
11020
+ columnHelper.accessor("sku", {
11021
+ header: "SKU",
11022
+ cell: ({ getValue }) => {
11023
+ return getValue() ?? "-";
11024
+ },
11025
+ enableSorting: true
11026
+ }),
11027
+ columnHelper.accessor("updated_at", {
11028
+ header: "Updated",
11029
+ cell: ({ getValue }) => {
11030
+ return /* @__PURE__ */ jsx(
11031
+ Tooltip,
11032
+ {
11033
+ content: getFullDate({ date: getValue(), includeTime: true }),
11034
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11035
+ }
11036
+ );
11037
+ },
11038
+ enableSorting: true,
11039
+ sortAscLabel: "Oldest first",
11040
+ sortDescLabel: "Newest first"
11041
+ }),
11042
+ columnHelper.accessor("created_at", {
11043
+ header: "Created",
11044
+ cell: ({ getValue }) => {
11045
+ return /* @__PURE__ */ jsx(
11046
+ Tooltip,
11047
+ {
11048
+ content: getFullDate({ date: getValue(), includeTime: true }),
11049
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11050
+ }
11051
+ );
11052
+ },
11053
+ enableSorting: true,
11054
+ sortAscLabel: "Oldest first",
11055
+ sortDescLabel: "Newest first"
11056
+ })
10919
11057
  ];
10920
- }
10921
- return Object.entries(metadata).map(([key, value]) => {
10922
- if (!EDITABLE_TYPES.includes(typeof value)) {
10923
- return {
10924
- key,
10925
- value,
10926
- disabled: true
10927
- };
10928
- }
10929
- let stringValue = value;
10930
- if (typeof value !== "string") {
10931
- stringValue = JSON.stringify(value);
10932
- }
10933
- return {
10934
- key,
10935
- value: stringValue,
10936
- original_key: key
10937
- };
11058
+ }, []);
11059
+ };
11060
+ const CustomItemForm = ({ orderId, currencyCode }) => {
11061
+ const { setIsOpen } = useStackedModal();
11062
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11063
+ const form = useForm({
11064
+ defaultValues: {
11065
+ title: "",
11066
+ quantity: 1,
11067
+ unit_price: ""
11068
+ },
11069
+ resolver: zodResolver(customItemSchema)
10938
11070
  });
10939
- }
10940
- function parseValues(values) {
10941
- const metadata = values.metadata;
10942
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10943
- if (isEmpty) {
10944
- return null;
10945
- }
10946
- const update = {};
10947
- metadata.forEach((field) => {
10948
- let key = field.key;
10949
- let value = field.value;
10950
- const disabled = field.disabled;
10951
- if (!key || !value) {
10952
- return;
10953
- }
10954
- if (disabled) {
10955
- update[key] = value;
10956
- return;
10957
- }
10958
- key = key.trim();
10959
- value = value.trim();
10960
- if (value === "true") {
10961
- update[key] = true;
10962
- } else if (value === "false") {
10963
- update[key] = false;
10964
- } else {
10965
- const parsedNumber = parseFloat(value);
10966
- if (!isNaN(parsedNumber)) {
10967
- update[key] = parsedNumber;
10968
- } else {
10969
- update[key] = value;
11071
+ const onSubmit = form.handleSubmit(async (data) => {
11072
+ await addItems(
11073
+ {
11074
+ items: [
11075
+ {
11076
+ title: data.title,
11077
+ quantity: data.quantity,
11078
+ unit_price: convertNumber(data.unit_price)
11079
+ }
11080
+ ]
11081
+ },
11082
+ {
11083
+ onSuccess: () => {
11084
+ setIsOpen(STACKED_MODAL_ID, false);
11085
+ },
11086
+ onError: (e) => {
11087
+ toast.error(e.message);
11088
+ }
10970
11089
  }
10971
- }
11090
+ );
10972
11091
  });
10973
- return update;
10974
- }
10975
- function getHasUneditableRows(metadata) {
10976
- if (!metadata) {
10977
- return false;
10978
- }
10979
- return Object.values(metadata).some(
10980
- (value) => !EDITABLE_TYPES.includes(typeof value)
10981
- );
10982
- }
11092
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
11093
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11094
+ /* @__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: [
11095
+ /* @__PURE__ */ jsxs("div", { children: [
11096
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
11097
+ /* @__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." }) })
11098
+ ] }),
11099
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11100
+ /* @__PURE__ */ jsx(
11101
+ Form$2.Field,
11102
+ {
11103
+ control: form.control,
11104
+ name: "title",
11105
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11106
+ /* @__PURE__ */ jsxs("div", { children: [
11107
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
11108
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
11109
+ ] }),
11110
+ /* @__PURE__ */ jsxs("div", { children: [
11111
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11112
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11113
+ ] })
11114
+ ] }) })
11115
+ }
11116
+ ),
11117
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11118
+ /* @__PURE__ */ jsx(
11119
+ Form$2.Field,
11120
+ {
11121
+ control: form.control,
11122
+ name: "unit_price",
11123
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11124
+ /* @__PURE__ */ jsxs("div", { children: [
11125
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
11126
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11127
+ ] }),
11128
+ /* @__PURE__ */ jsxs("div", { children: [
11129
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11130
+ CurrencyInput,
11131
+ {
11132
+ symbol: getNativeSymbol(currencyCode),
11133
+ code: currencyCode,
11134
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11135
+ ...field
11136
+ }
11137
+ ) }),
11138
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11139
+ ] })
11140
+ ] }) })
11141
+ }
11142
+ ),
11143
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11144
+ /* @__PURE__ */ jsx(
11145
+ Form$2.Field,
11146
+ {
11147
+ control: form.control,
11148
+ name: "quantity",
11149
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11150
+ /* @__PURE__ */ jsxs("div", { children: [
11151
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
11152
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11153
+ ] }),
11154
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
11155
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11156
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11157
+ ] })
11158
+ ] }) })
11159
+ }
11160
+ )
11161
+ ] }) }) }),
11162
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11163
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11164
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11165
+ ] }) })
11166
+ ] }) }) });
11167
+ };
11168
+ const customItemSchema = objectType({
11169
+ title: stringType().min(1),
11170
+ quantity: numberType(),
11171
+ unit_price: unionType([numberType(), stringType()])
11172
+ });
10983
11173
  const PROMOTION_QUERY_KEY = "promotions";
10984
11174
  const promotionsQueryKeys = {
10985
11175
  list: (query2) => [
@@ -11285,7 +11475,7 @@ const SalesChannelForm = ({ order }) => {
11285
11475
  defaultValues: {
11286
11476
  sales_channel_id: order.sales_channel_id || ""
11287
11477
  },
11288
- resolver: zodResolver(schema$3)
11478
+ resolver: zodResolver(schema$2)
11289
11479
  });
11290
11480
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11291
11481
  const { handleSuccess } = useRouteModal();
@@ -11320,49 +11510,252 @@ const SalesChannelForm = ({ order }) => {
11320
11510
  }
11321
11511
  ) });
11322
11512
  };
11323
- const SalesChannelField = ({ control, order }) => {
11324
- const salesChannels = useComboboxData({
11325
- queryFn: async (params) => {
11326
- return await sdk.admin.salesChannel.list(params);
11327
- },
11328
- queryKey: ["sales-channels"],
11329
- getOptions: (data) => {
11330
- return data.sales_channels.map((salesChannel) => ({
11331
- label: salesChannel.name,
11332
- value: salesChannel.id
11333
- }));
11334
- },
11335
- defaultValue: order.sales_channel_id || void 0
11336
- });
11337
- return /* @__PURE__ */ jsx(
11338
- Form$2.Field,
11339
- {
11340
- control,
11341
- name: "sales_channel_id",
11342
- render: ({ field }) => {
11343
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11344
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11345
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11346
- Combobox,
11347
- {
11348
- options: salesChannels.options,
11349
- fetchNextPage: salesChannels.fetchNextPage,
11350
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11351
- searchValue: salesChannels.searchValue,
11352
- onSearchValueChange: salesChannels.onSearchValueChange,
11353
- placeholder: "Select sales channel",
11354
- ...field
11355
- }
11356
- ) }),
11357
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11358
- ] });
11359
- }
11360
- }
11361
- );
11362
- };
11363
- const schema$3 = objectType({
11364
- sales_channel_id: stringType().min(1)
11365
- });
11513
+ const SalesChannelField = ({ control, order }) => {
11514
+ const salesChannels = useComboboxData({
11515
+ queryFn: async (params) => {
11516
+ return await sdk.admin.salesChannel.list(params);
11517
+ },
11518
+ queryKey: ["sales-channels"],
11519
+ getOptions: (data) => {
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11523
+ }));
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11526
+ });
11527
+ return /* @__PURE__ */ jsx(
11528
+ Form$2.Field,
11529
+ {
11530
+ control,
11531
+ name: "sales_channel_id",
11532
+ render: ({ field }) => {
11533
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
+ Combobox,
11537
+ {
11538
+ options: salesChannels.options,
11539
+ fetchNextPage: salesChannels.fetchNextPage,
11540
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
+ searchValue: salesChannels.searchValue,
11542
+ onSearchValueChange: salesChannels.onSearchValueChange,
11543
+ placeholder: "Select sales channel",
11544
+ ...field
11545
+ }
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11549
+ }
11550
+ }
11551
+ );
11552
+ };
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
11555
+ });
11556
+ const ShippingAddress = () => {
11557
+ const { id } = useParams();
11558
+ const { order, isPending, isError, error } = useOrder(id, {
11559
+ fields: "+shipping_address"
11560
+ });
11561
+ if (isError) {
11562
+ throw error;
11563
+ }
11564
+ const isReady = !isPending && !!order;
11565
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11566
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11567
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11568
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11569
+ ] }),
11570
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11571
+ ] });
11572
+ };
11573
+ const ShippingAddressForm = ({ order }) => {
11574
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11575
+ const form = useForm({
11576
+ defaultValues: {
11577
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11578
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11579
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11580
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11581
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11582
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11583
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11584
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11585
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11586
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11587
+ },
11588
+ resolver: zodResolver(schema$1)
11589
+ });
11590
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11591
+ const { handleSuccess } = useRouteModal();
11592
+ const onSubmit = form.handleSubmit(async (data) => {
11593
+ await mutateAsync(
11594
+ {
11595
+ shipping_address: {
11596
+ first_name: data.first_name,
11597
+ last_name: data.last_name,
11598
+ company: data.company,
11599
+ address_1: data.address_1,
11600
+ address_2: data.address_2,
11601
+ city: data.city,
11602
+ province: data.province,
11603
+ country_code: data.country_code,
11604
+ postal_code: data.postal_code,
11605
+ phone: data.phone
11606
+ }
11607
+ },
11608
+ {
11609
+ onSuccess: () => {
11610
+ handleSuccess();
11611
+ },
11612
+ onError: (error) => {
11613
+ toast.error(error.message);
11614
+ }
11615
+ }
11616
+ );
11617
+ });
11618
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11619
+ KeyboundForm,
11620
+ {
11621
+ className: "flex flex-1 flex-col overflow-hidden",
11622
+ onSubmit,
11623
+ children: [
11624
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11625
+ /* @__PURE__ */ jsx(
11626
+ Form$2.Field,
11627
+ {
11628
+ control: form.control,
11629
+ name: "country_code",
11630
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11631
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11632
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11633
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11634
+ ] })
11635
+ }
11636
+ ),
11637
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11638
+ /* @__PURE__ */ jsx(
11639
+ Form$2.Field,
11640
+ {
11641
+ control: form.control,
11642
+ name: "first_name",
11643
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11644
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11645
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11646
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11647
+ ] })
11648
+ }
11649
+ ),
11650
+ /* @__PURE__ */ jsx(
11651
+ Form$2.Field,
11652
+ {
11653
+ control: form.control,
11654
+ name: "last_name",
11655
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11656
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11657
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11658
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11659
+ ] })
11660
+ }
11661
+ )
11662
+ ] }),
11663
+ /* @__PURE__ */ jsx(
11664
+ Form$2.Field,
11665
+ {
11666
+ control: form.control,
11667
+ name: "company",
11668
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11669
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11670
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11671
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11672
+ ] })
11673
+ }
11674
+ ),
11675
+ /* @__PURE__ */ jsx(
11676
+ Form$2.Field,
11677
+ {
11678
+ control: form.control,
11679
+ name: "address_1",
11680
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11681
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11682
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11683
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11684
+ ] })
11685
+ }
11686
+ ),
11687
+ /* @__PURE__ */ jsx(
11688
+ Form$2.Field,
11689
+ {
11690
+ control: form.control,
11691
+ name: "address_2",
11692
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11693
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11694
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11695
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11696
+ ] })
11697
+ }
11698
+ ),
11699
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11700
+ /* @__PURE__ */ jsx(
11701
+ Form$2.Field,
11702
+ {
11703
+ control: form.control,
11704
+ name: "postal_code",
11705
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11706
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11707
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11708
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11709
+ ] })
11710
+ }
11711
+ ),
11712
+ /* @__PURE__ */ jsx(
11713
+ Form$2.Field,
11714
+ {
11715
+ control: form.control,
11716
+ name: "city",
11717
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11718
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11719
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11720
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11721
+ ] })
11722
+ }
11723
+ )
11724
+ ] }),
11725
+ /* @__PURE__ */ jsx(
11726
+ Form$2.Field,
11727
+ {
11728
+ control: form.control,
11729
+ name: "province",
11730
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11731
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11732
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11733
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11734
+ ] })
11735
+ }
11736
+ ),
11737
+ /* @__PURE__ */ jsx(
11738
+ Form$2.Field,
11739
+ {
11740
+ control: form.control,
11741
+ name: "phone",
11742
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11743
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11744
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11745
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11746
+ ] })
11747
+ }
11748
+ )
11749
+ ] }) }),
11750
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11751
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11752
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11753
+ ] }) })
11754
+ ]
11755
+ }
11756
+ ) });
11757
+ };
11758
+ const schema$1 = addressSchema;
11366
11759
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11367
11760
  const Shipping = () => {
11368
11761
  var _a;
@@ -12153,226 +12546,23 @@ const CustomAmountField = ({
12153
12546
  render: ({ field: { onChange, ...field } }) => {
12154
12547
  return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12155
12548
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12156
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12157
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12158
- ] }),
12159
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12160
- CurrencyInput,
12161
- {
12162
- ...field,
12163
- onValueChange: (value) => onChange(value),
12164
- symbol: getNativeSymbol(currencyCode),
12165
- code: currencyCode
12166
- }
12167
- ) })
12168
- ] });
12169
- }
12170
- }
12171
- );
12172
- };
12173
- const ShippingAddress = () => {
12174
- const { id } = useParams();
12175
- const { order, isPending, isError, error } = useOrder(id, {
12176
- fields: "+shipping_address"
12177
- });
12178
- if (isError) {
12179
- throw error;
12180
- }
12181
- const isReady = !isPending && !!order;
12182
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12183
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12184
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12185
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12186
- ] }),
12187
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12188
- ] });
12189
- };
12190
- const ShippingAddressForm = ({ order }) => {
12191
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12192
- const form = useForm({
12193
- defaultValues: {
12194
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12195
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12196
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12197
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12198
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12199
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12200
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12201
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12202
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12203
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12204
- },
12205
- resolver: zodResolver(schema$2)
12206
- });
12207
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12208
- const { handleSuccess } = useRouteModal();
12209
- const onSubmit = form.handleSubmit(async (data) => {
12210
- await mutateAsync(
12211
- {
12212
- shipping_address: {
12213
- first_name: data.first_name,
12214
- last_name: data.last_name,
12215
- company: data.company,
12216
- address_1: data.address_1,
12217
- address_2: data.address_2,
12218
- city: data.city,
12219
- province: data.province,
12220
- country_code: data.country_code,
12221
- postal_code: data.postal_code,
12222
- phone: data.phone
12223
- }
12224
- },
12225
- {
12226
- onSuccess: () => {
12227
- handleSuccess();
12228
- },
12229
- onError: (error) => {
12230
- toast.error(error.message);
12231
- }
12232
- }
12233
- );
12234
- });
12235
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12236
- KeyboundForm,
12237
- {
12238
- className: "flex flex-1 flex-col overflow-hidden",
12239
- onSubmit,
12240
- children: [
12241
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12242
- /* @__PURE__ */ jsx(
12243
- Form$2.Field,
12244
- {
12245
- control: form.control,
12246
- name: "country_code",
12247
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12248
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12249
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12250
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12251
- ] })
12252
- }
12253
- ),
12254
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12255
- /* @__PURE__ */ jsx(
12256
- Form$2.Field,
12257
- {
12258
- control: form.control,
12259
- name: "first_name",
12260
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12261
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12262
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12263
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12264
- ] })
12265
- }
12266
- ),
12267
- /* @__PURE__ */ jsx(
12268
- Form$2.Field,
12269
- {
12270
- control: form.control,
12271
- name: "last_name",
12272
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12273
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12274
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12275
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12276
- ] })
12277
- }
12278
- )
12279
- ] }),
12280
- /* @__PURE__ */ jsx(
12281
- Form$2.Field,
12282
- {
12283
- control: form.control,
12284
- name: "company",
12285
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12286
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12287
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12288
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12289
- ] })
12290
- }
12291
- ),
12292
- /* @__PURE__ */ jsx(
12293
- Form$2.Field,
12294
- {
12295
- control: form.control,
12296
- name: "address_1",
12297
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12298
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12299
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12300
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12301
- ] })
12302
- }
12303
- ),
12304
- /* @__PURE__ */ jsx(
12305
- Form$2.Field,
12306
- {
12307
- control: form.control,
12308
- name: "address_2",
12309
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12310
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12311
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12312
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12313
- ] })
12314
- }
12315
- ),
12316
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12317
- /* @__PURE__ */ jsx(
12318
- Form$2.Field,
12319
- {
12320
- control: form.control,
12321
- name: "postal_code",
12322
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12323
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12324
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12325
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12326
- ] })
12327
- }
12328
- ),
12329
- /* @__PURE__ */ jsx(
12330
- Form$2.Field,
12331
- {
12332
- control: form.control,
12333
- name: "city",
12334
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12335
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12336
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12337
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12338
- ] })
12339
- }
12340
- )
12549
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12550
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12341
12551
  ] }),
12342
- /* @__PURE__ */ jsx(
12343
- Form$2.Field,
12344
- {
12345
- control: form.control,
12346
- name: "province",
12347
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12348
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12349
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12350
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12351
- ] })
12352
- }
12353
- ),
12354
- /* @__PURE__ */ jsx(
12355
- Form$2.Field,
12552
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12553
+ CurrencyInput,
12356
12554
  {
12357
- control: form.control,
12358
- name: "phone",
12359
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12360
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12361
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12362
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12363
- ] })
12555
+ ...field,
12556
+ onValueChange: (value) => onChange(value),
12557
+ symbol: getNativeSymbol(currencyCode),
12558
+ code: currencyCode
12364
12559
  }
12365
- )
12366
- ] }) }),
12367
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12368
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12369
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12370
- ] }) })
12371
- ]
12560
+ ) })
12561
+ ] });
12562
+ }
12372
12563
  }
12373
- ) });
12564
+ );
12374
12565
  };
12375
- const schema$2 = addressSchema;
12376
12566
  const TransferOwnership = () => {
12377
12567
  const { id } = useParams();
12378
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12396,7 +12586,7 @@ const TransferOwnershipForm = ({ order }) => {
12396
12586
  defaultValues: {
12397
12587
  customer_id: order.customer_id || ""
12398
12588
  },
12399
- resolver: zodResolver(schema$1)
12589
+ resolver: zodResolver(schema)
12400
12590
  });
12401
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
12592
  const { handleSuccess } = useRouteModal();
@@ -12846,199 +13036,9 @@ const Illustration = () => {
12846
13036
  }
12847
13037
  );
12848
13038
  };
12849
- const schema$1 = objectType({
13039
+ const schema = objectType({
12850
13040
  customer_id: stringType().min(1)
12851
13041
  });
12852
- const BillingAddress = () => {
12853
- const { id } = useParams();
12854
- const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12856
- });
12857
- if (isError) {
12858
- throw error;
12859
- }
12860
- const isReady = !isPending && !!order;
12861
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12865
- ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12867
- ] });
12868
- };
12869
- const BillingAddressForm = ({ order }) => {
12870
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
- const form = useForm({
12872
- defaultValues: {
12873
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12883
- },
12884
- resolver: zodResolver(schema)
12885
- });
12886
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
- const { handleSuccess } = useRouteModal();
12888
- const onSubmit = form.handleSubmit(async (data) => {
12889
- await mutateAsync(
12890
- { billing_address: data },
12891
- {
12892
- onSuccess: () => {
12893
- handleSuccess();
12894
- },
12895
- onError: (error) => {
12896
- toast.error(error.message);
12897
- }
12898
- }
12899
- );
12900
- });
12901
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
- KeyboundForm,
12903
- {
12904
- className: "flex flex-1 flex-col overflow-hidden",
12905
- onSubmit,
12906
- children: [
12907
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- control: form.control,
12912
- name: "country_code",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
- /* @__PURE__ */ jsx(
12922
- Form$2.Field,
12923
- {
12924
- control: form.control,
12925
- name: "first_name",
12926
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
- ] })
12931
- }
12932
- ),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "last_name",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- )
12945
- ] }),
12946
- /* @__PURE__ */ jsx(
12947
- Form$2.Field,
12948
- {
12949
- control: form.control,
12950
- name: "company",
12951
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
- ] })
12956
- }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12960
- {
12961
- control: form.control,
12962
- name: "address_1",
12963
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
- ] })
12968
- }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
12972
- {
12973
- control: form.control,
12974
- name: "address_2",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
12980
- }
12981
- ),
12982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
- /* @__PURE__ */ jsx(
12984
- Form$2.Field,
12985
- {
12986
- control: form.control,
12987
- name: "postal_code",
12988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
- ] })
12993
- }
12994
- ),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "city",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- )
13007
- ] }),
13008
- /* @__PURE__ */ jsx(
13009
- Form$2.Field,
13010
- {
13011
- control: form.control,
13012
- name: "province",
13013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
- ] })
13018
- }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13022
- {
13023
- control: form.control,
13024
- name: "phone",
13025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
- ] })
13030
- }
13031
- )
13032
- ] }) }),
13033
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
- ] }) })
13037
- ]
13038
- }
13039
- ) });
13040
- };
13041
- const schema = addressSchema;
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,6 +13059,10 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
+ {
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
+ },
13062
13066
  {
13063
13067
  Component: CustomItems,
13064
13068
  path: "/draft-orders/:id/custom-items"
@@ -13067,14 +13071,14 @@ const routeModule = {
13067
13071
  Component: Email,
13068
13072
  path: "/draft-orders/:id/email"
13069
13073
  },
13070
- {
13071
- Component: Items,
13072
- path: "/draft-orders/:id/items"
13073
- },
13074
13074
  {
13075
13075
  Component: Metadata,
13076
13076
  path: "/draft-orders/:id/metadata"
13077
13077
  },
13078
+ {
13079
+ Component: Items,
13080
+ path: "/draft-orders/:id/items"
13081
+ },
13078
13082
  {
13079
13083
  Component: Promotions,
13080
13084
  path: "/draft-orders/:id/promotions"
@@ -13083,21 +13087,17 @@ const routeModule = {
13083
13087
  Component: SalesChannel,
13084
13088
  path: "/draft-orders/:id/sales-channel"
13085
13089
  },
13086
- {
13087
- Component: Shipping,
13088
- path: "/draft-orders/:id/shipping"
13089
- },
13090
13090
  {
13091
13091
  Component: ShippingAddress,
13092
13092
  path: "/draft-orders/:id/shipping-address"
13093
13093
  },
13094
13094
  {
13095
- Component: TransferOwnership,
13096
- path: "/draft-orders/:id/transfer-ownership"
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
13097
  },
13098
13098
  {
13099
- Component: BillingAddress,
13100
- path: "/draft-orders/:id/billing-address"
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  }
13102
13102
  ]
13103
13103
  }