@medusajs/draft-order 2.10.4-preview-20250926120205 → 2.10.4-preview-20250926180153

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, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } 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, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } 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,196 +9567,6 @@ 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;
9760
9570
  const CustomItems = () => {
9761
9571
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
9572
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9765,7 +9575,7 @@ const CustomItems = () => {
9765
9575
  };
9766
9576
  const CustomItemsForm = () => {
9767
9577
  const form = useForm({
9768
- resolver: zodResolver(schema$4)
9578
+ resolver: zodResolver(schema$5)
9769
9579
  });
9770
9580
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
9581
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9775,7 +9585,7 @@ const CustomItemsForm = () => {
9775
9585
  ] }) })
9776
9586
  ] }) });
9777
9587
  };
9778
- const schema$4 = objectType({
9588
+ const schema$5 = objectType({
9779
9589
  email: stringType().email()
9780
9590
  });
9781
9591
  const Email = () => {
@@ -9800,7 +9610,7 @@ const EmailForm = ({ order }) => {
9800
9610
  defaultValues: {
9801
9611
  email: order.email ?? ""
9802
9612
  },
9803
- resolver: zodResolver(schema$3)
9613
+ resolver: zodResolver(schema$4)
9804
9614
  });
9805
9615
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
9616
  const { handleSuccess } = useRouteModal();
@@ -9843,608 +9653,258 @@ const EmailForm = ({ order }) => {
9843
9653
  }
9844
9654
  ) });
9845
9655
  };
9846
- const schema$3 = objectType({
9656
+ const schema$4 = objectType({
9847
9657
  email: stringType().email()
9848
9658
  });
9849
- const InlineTip = forwardRef(
9850
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9851
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
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
+ };
9852
9689
  return /* @__PURE__ */ jsxs(
9853
9690
  "div",
9854
9691
  {
9855
- ref,
9856
9692
  className: clx(
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",
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
+ },
9858
9699
  className
9859
9700
  ),
9860
- ...props,
9861
9701
  children: [
9862
9702
  /* @__PURE__ */ jsx(
9863
- "div",
9703
+ "input",
9864
9704
  {
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
- })
9869
- }
9870
- ),
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
- ] })
9879
- ]
9880
- }
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
+ ]
9740
+ }
9741
+ ),
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
+ )
9764
+ ]
9765
+ }
9881
9766
  );
9882
9767
  }
9883
9768
  );
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 = () => {
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 = () => {
9894
9835
  const { id } = useParams();
9895
- const { order, isPending, isError, error } = useOrder(id, {
9896
- fields: "metadata"
9836
+ const {
9837
+ order: preview,
9838
+ isPending: isPreviewPending,
9839
+ isError: isPreviewError,
9840
+ error: previewError
9841
+ } = useOrderPreview(id, void 0, {
9842
+ placeholderData: keepPreviousData
9897
9843
  });
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 });
9898
9855
  if (isError) {
9899
9856
  throw error;
9900
9857
  }
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
- ] });
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
+ ] }) });
9909
9866
  };
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 }) => {
9867
+ const ItemsForm = ({ preview, currencyCode }) => {
9868
+ var _a;
9869
+ const [isSubmitting, setIsSubmitting] = useState(false);
9870
+ const [modalContent, setModalContent] = useState(
9871
+ null
9872
+ );
9913
9873
  const { handleSuccess } = useRouteModal();
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
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}`);
9927
9889
  },
9928
- {
9929
- onSuccess: () => {
9930
- toast.success("Metadata updated");
9931
- handleSuccess();
9932
- },
9933
- onError: (error) => {
9934
- toast.error(error.message);
9935
- }
9890
+ onSuccess: () => {
9891
+ requestSucceeded = true;
9936
9892
  }
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
- });
9893
+ });
9894
+ if (!requestSucceeded) {
9895
+ setIsSubmitting(false);
9896
+ return;
9951
9897
  }
9952
- }
9953
- function insertRow(index, position) {
9954
- insert(index + (position === "above" ? 0 : 1), {
9955
- key: "",
9956
- value: "",
9957
- disabled: false
9958
- });
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
- }
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
+ }
10448
9908
  });
10449
9909
  };
10450
9910
  const onKeyDown = useCallback(
@@ -10601,20 +10061,168 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10601
10061
  const [editing, setEditing] = useState(false);
10602
10062
  const form = useForm({
10603
10063
  defaultValues: {
10604
- quantity: item.quantity,
10605
- unit_price: item.unit_price
10064
+ quantity: item.quantity,
10065
+ unit_price: item.unit_price
10066
+ },
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
10606
10206
  },
10607
- resolver: zodResolver(variantItemSchema)
10207
+ resolver: zodResolver(customItemSchema)
10608
10208
  });
10209
+ useEffect(() => {
10210
+ form.reset({
10211
+ title,
10212
+ quantity,
10213
+ unit_price
10214
+ });
10215
+ }, [form, title, quantity, unit_price]);
10609
10216
  const actionId = useMemo(() => {
10610
10217
  var _a, _b;
10611
10218
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10612
10219
  }, [item]);
10613
10220
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10221
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10614
10222
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10615
10223
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10616
10224
  const onSubmit = form.handleSubmit(async (data) => {
10617
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10225
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10618
10226
  setEditing(false);
10619
10227
  return;
10620
10228
  }
@@ -10636,6 +10244,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10636
10244
  );
10637
10245
  return;
10638
10246
  }
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
+ }
10639
10258
  await updateActionItem(
10640
10259
  {
10641
10260
  action_id: actionId,
@@ -10653,43 +10272,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10653
10272
  );
10654
10273
  });
10655
10274
  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: [
10656
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10275
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10657
10276
  /* @__PURE__ */ jsx(
10658
10277
  Thumbnail,
10659
10278
  {
10660
10279
  thumbnail: item.thumbnail,
10661
- alt: item.product_title ?? void 0
10280
+ alt: item.title ?? void 0
10662
10281
  }
10663
10282
  ),
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
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 }) }) });
10688
10290
  }
10689
- )
10690
- ] })
10291
+ }
10292
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10691
10293
  ] }),
10692
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10294
+ editing ? /* @__PURE__ */ jsx(
10693
10295
  Form$2.Field,
10694
10296
  {
10695
10297
  control: form.control,
@@ -10698,8 +10300,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10698
10300
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10699
10301
  }
10700
10302
  }
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(
10303
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10304
+ editing ? /* @__PURE__ */ jsx(
10703
10305
  Form$2.Field,
10704
10306
  {
10705
10307
  control: form.control,
@@ -10716,7 +10318,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10716
10318
  ) }) });
10717
10319
  }
10718
10320
  }
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) }) }),
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) }) }),
10720
10322
  /* @__PURE__ */ jsx(
10721
10323
  IconButton,
10722
10324
  {
@@ -10725,85 +10327,221 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10725
10327
  onClick: editing ? onSubmit : () => {
10726
10328
  setEditing(true);
10727
10329
  },
10728
- disabled: isPending,
10729
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10730
- }
10731
- )
10732
- ] }) }) });
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
+ );
10512
+ },
10513
+ enableSorting: true,
10514
+ sortAscLabel: "Oldest first",
10515
+ sortDescLabel: "Newest first"
10516
+ })
10517
+ ];
10518
+ }, []);
10733
10519
  };
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;
10520
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10521
+ const { setIsOpen } = useStackedModal();
10522
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10741
10523
  const form = useForm({
10742
10524
  defaultValues: {
10743
- title,
10744
- quantity,
10745
- unit_price
10525
+ title: "",
10526
+ quantity: 1,
10527
+ unit_price: ""
10746
10528
  },
10747
10529
  resolver: zodResolver(customItemSchema)
10748
10530
  });
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;
10764
10531
  const onSubmit = form.handleSubmit(async (data) => {
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);
10782
- }
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(
10532
+ await addItems(
10799
10533
  {
10800
- action_id: actionId,
10801
- quantity: data.quantity,
10802
- unit_price: convertNumber(data.unit_price)
10534
+ items: [
10535
+ {
10536
+ title: data.title,
10537
+ quantity: data.quantity,
10538
+ unit_price: convertNumber(data.unit_price)
10539
+ }
10540
+ ]
10803
10541
  },
10804
10542
  {
10805
10543
  onSuccess: () => {
10806
- setEditing(false);
10544
+ setIsOpen(STACKED_MODAL_ID, false);
10807
10545
  },
10808
10546
  onError: (e) => {
10809
10547
  toast.error(e.message);
@@ -10811,365 +10549,437 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10811
10549
  }
10812
10550
  );
10813
10551
  });
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: [
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" }),
10816
10560
  /* @__PURE__ */ jsx(
10817
- Thumbnail,
10561
+ Form$2.Field,
10818
10562
  {
10819
- thumbnail: item.thumbnail,
10820
- alt: item.title ?? void 0
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
+ ] }) })
10821
10575
  }
10822
10576
  ),
10823
- editing ? /* @__PURE__ */ jsx(
10577
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10578
+ /* @__PURE__ */ jsx(
10824
10579
  Form$2.Field,
10825
10580
  {
10826
10581
  control: form.control,
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
- }
10831
- }
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 }) }) });
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
+ ] }) })
10841
10601
  }
10842
- }
10843
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10844
- editing ? /* @__PURE__ */ jsx(
10845
- Form$2.Field,
10846
- {
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,
10852
- {
10853
- ...field,
10854
- symbol: getNativeSymbol(currencyCode),
10855
- code: currencyCode,
10856
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10857
- }
10858
- ) }) });
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
+ ] }) })
10859
10619
  }
10860
- }
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
- )
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
+ ] }) })
10874
10626
  ] }) }) });
10875
10627
  };
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
- }, {})
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",
10638
+ {
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",
10648
+ {
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
+ })
10653
+ }
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
+ ]
10664
+ }
10905
10665
  );
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
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
+ ] });
10693
+ };
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)
10917
10703
  },
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
- );
10704
+ resolver: zodResolver(MetadataSchema)
10705
+ });
10706
+ const handleSubmit = form.handleSubmit(async (data) => {
10707
+ const parsedData = parseValues(data);
10928
10708
  await mutateAsync(
10929
10709
  {
10930
- items: ids.map((id) => ({
10931
- variant_id: id,
10932
- quantity: 1
10933
- }))
10710
+ metadata: parsedData
10934
10711
  },
10935
10712
  {
10936
10713
  onSuccess: () => {
10937
- setRowSelection({});
10938
- setIsOpen(STACKED_MODAL_ID, false);
10714
+ toast.success("Metadata updated");
10715
+ handleSuccess();
10939
10716
  },
10940
- onError: (e) => {
10941
- toast.error(e.message);
10717
+ onError: (error) => {
10718
+ toast.error(error.message);
10942
10719
  }
10943
10720
  }
10944
10721
  );
10945
- };
10946
- if (isError) {
10947
- throw error;
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
+ }
10948
10736
  }
10949
- return /* @__PURE__ */ jsxs(
10950
- StackedFocusModal.Content,
10737
+ function insertRow(index, position) {
10738
+ insert(index + (position === "above" ? 0 : 1), {
10739
+ key: "",
10740
+ value: "",
10741
+ disabled: false
10742
+ });
10743
+ }
10744
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10745
+ KeyboundForm,
10951
10746
  {
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
- },
10747
+ onSubmit: handleSubmit,
10748
+ className: "flex flex-1 flex-col overflow-hidden",
10961
10749
  children: [
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." }) })
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." })
10965
10877
  ] }),
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" })
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" })
10989
10881
  ] }) })
10990
10882
  ]
10991
10883
  }
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
+ }
10992
10898
  );
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
+ ] });
10993
10909
  };
10994
- const columnHelper = createDataTableColumnHelper();
10995
- const useColumns = () => {
10996
- return useMemo(() => {
10910
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10911
+ function getDefaultValues(metadata) {
10912
+ if (!metadata || !Object.keys(metadata).length) {
10997
10913
  return [
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
- })
11057
- ];
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)
11070
- });
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
10914
  {
11083
- onSuccess: () => {
11084
- setIsOpen(STACKED_MODAL_ID, false);
11085
- },
11086
- onError: (e) => {
11087
- toast.error(e.message);
11088
- }
10915
+ key: "",
10916
+ value: "",
10917
+ disabled: false
11089
10918
  }
11090
- );
10919
+ ];
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
+ };
11091
10938
  });
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
- });
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;
10970
+ }
10971
+ }
10972
+ });
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
+ }
11173
10983
  const PROMOTION_QUERY_KEY = "promotions";
11174
10984
  const promotionsQueryKeys = {
11175
10985
  list: (query2) => [
@@ -11475,7 +11285,7 @@ const SalesChannelForm = ({ order }) => {
11475
11285
  defaultValues: {
11476
11286
  sales_channel_id: order.sales_channel_id || ""
11477
11287
  },
11478
- resolver: zodResolver(schema$2)
11288
+ resolver: zodResolver(schema$3)
11479
11289
  });
11480
11290
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
11291
  const { handleSuccess } = useRouteModal();
@@ -11550,7 +11360,7 @@ const SalesChannelField = ({ control, order }) => {
11550
11360
  }
11551
11361
  );
11552
11362
  };
11553
- const schema$2 = objectType({
11363
+ const schema$3 = objectType({
11554
11364
  sales_channel_id: stringType().min(1)
11555
11365
  });
11556
11366
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12392,7 +12202,7 @@ const ShippingAddressForm = ({ order }) => {
12392
12202
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
12203
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
12204
  },
12395
- resolver: zodResolver(schema$1)
12205
+ resolver: zodResolver(schema$2)
12396
12206
  });
12397
12207
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
12208
  const { handleSuccess } = useRouteModal();
@@ -12562,7 +12372,7 @@ const ShippingAddressForm = ({ order }) => {
12562
12372
  }
12563
12373
  ) });
12564
12374
  };
12565
- const schema$1 = addressSchema;
12375
+ const schema$2 = addressSchema;
12566
12376
  const TransferOwnership = () => {
12567
12377
  const { id } = useParams();
12568
12378
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12586,7 +12396,7 @@ const TransferOwnershipForm = ({ order }) => {
12586
12396
  defaultValues: {
12587
12397
  customer_id: order.customer_id || ""
12588
12398
  },
12589
- resolver: zodResolver(schema)
12399
+ resolver: zodResolver(schema$1)
12590
12400
  });
12591
12401
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
12402
  const { handleSuccess } = useRouteModal();
@@ -13036,9 +12846,199 @@ const Illustration = () => {
13036
12846
  }
13037
12847
  );
13038
12848
  };
13039
- const schema = objectType({
12849
+ const schema$1 = objectType({
13040
12850
  customer_id: stringType().min(1)
13041
12851
  });
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,10 +13059,6 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
- {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13065
- },
13066
13062
  {
13067
13063
  Component: CustomItems,
13068
13064
  path: "/draft-orders/:id/custom-items"
@@ -13071,14 +13067,14 @@ const routeModule = {
13071
13067
  Component: Email,
13072
13068
  path: "/draft-orders/:id/email"
13073
13069
  },
13074
- {
13075
- Component: Metadata,
13076
- path: "/draft-orders/:id/metadata"
13077
- },
13078
13070
  {
13079
13071
  Component: Items,
13080
13072
  path: "/draft-orders/:id/items"
13081
13073
  },
13074
+ {
13075
+ Component: Metadata,
13076
+ path: "/draft-orders/:id/metadata"
13077
+ },
13082
13078
  {
13083
13079
  Component: Promotions,
13084
13080
  path: "/draft-orders/:id/promotions"
@@ -13098,6 +13094,10 @@ const routeModule = {
13098
13094
  {
13099
13095
  Component: TransferOwnership,
13100
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
+ },
13098
+ {
13099
+ Component: BillingAddress,
13100
+ path: "/draft-orders/:id/billing-address"
13101
13101
  }
13102
13102
  ]
13103
13103
  }