@medusajs/draft-order 2.10.4-snapshot-20251003132946 → 2.10.4-snapshot-20251003141424

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9567,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,269 +9653,619 @@ 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 NumberInput = forwardRef(
9850
- ({
9851
- value,
9852
- onChange,
9853
- size = "base",
9854
- min = 0,
9855
- max = 100,
9856
- step = 1,
9857
- className,
9858
- disabled,
9859
- ...props
9860
- }, ref) => {
9861
- const handleChange = (event) => {
9862
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9863
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9864
- onChange(newValue);
9865
- }
9866
- };
9867
- const handleIncrement = () => {
9868
- const newValue = value + step;
9869
- if (max === void 0 || newValue <= max) {
9870
- onChange(newValue);
9871
- }
9872
- };
9873
- const handleDecrement = () => {
9874
- const newValue = value - step;
9875
- if (min === void 0 || newValue >= min) {
9876
- onChange(newValue);
9877
- }
9878
- };
9659
+ const InlineTip = forwardRef(
9660
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9661
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9879
9662
  return /* @__PURE__ */ jsxs(
9880
9663
  "div",
9881
9664
  {
9665
+ ref,
9882
9666
  className: clx(
9883
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9884
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9885
- {
9886
- "h-7": size === "small",
9887
- "h-8": size === "base"
9888
- },
9667
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9889
9668
  className
9890
9669
  ),
9670
+ ...props,
9891
9671
  children: [
9892
9672
  /* @__PURE__ */ jsx(
9893
- "input",
9673
+ "div",
9894
9674
  {
9895
- ref,
9896
- type: "number",
9897
- value,
9898
- onChange: handleChange,
9899
- min,
9900
- max,
9901
- step,
9902
- className: clx(
9903
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9904
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9905
- "placeholder:text-ui-fg-muted"
9906
- ),
9907
- ...props
9908
- }
9909
- ),
9910
- /* @__PURE__ */ jsxs(
9911
- "button",
9912
- {
9913
- className: clx(
9914
- "flex items-center justify-center outline-none transition-fg",
9915
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9916
- "focus:bg-ui-bg-field-component-hover",
9917
- "hover:bg-ui-bg-field-component-hover",
9918
- {
9919
- "size-7": size === "small",
9920
- "size-8": size === "base"
9921
- }
9922
- ),
9923
- type: "button",
9924
- onClick: handleDecrement,
9925
- disabled: min !== void 0 && value <= min || disabled,
9926
- children: [
9927
- /* @__PURE__ */ jsx(Minus, {}),
9928
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9929
- ]
9675
+ role: "presentation",
9676
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9677
+ "bg-ui-tag-orange-icon": variant === "warning"
9678
+ })
9930
9679
  }
9931
9680
  ),
9932
- /* @__PURE__ */ jsxs(
9933
- "button",
9934
- {
9935
- className: clx(
9936
- "flex items-center justify-center outline-none transition-fg",
9937
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9938
- "focus:bg-ui-bg-field-hover",
9939
- "hover:bg-ui-bg-field-hover",
9940
- {
9941
- "size-7": size === "small",
9942
- "size-8": size === "base"
9943
- }
9944
- ),
9945
- type: "button",
9946
- onClick: handleIncrement,
9947
- disabled: max !== void 0 && value >= max || disabled,
9948
- children: [
9949
- /* @__PURE__ */ jsx(Plus, {}),
9950
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9951
- ]
9952
- }
9953
- )
9681
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9682
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9683
+ labelValue,
9684
+ ":"
9685
+ ] }),
9686
+ " ",
9687
+ children
9688
+ ] })
9954
9689
  ]
9955
9690
  }
9956
9691
  );
9957
9692
  }
9958
9693
  );
9959
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9960
- const productVariantsQueryKeys = {
9961
- list: (query2) => [
9962
- PRODUCT_VARIANTS_QUERY_KEY,
9963
- query2 ? query2 : void 0
9964
- ]
9965
- };
9966
- const useProductVariants = (query2, options) => {
9967
- const { data, ...rest } = useQuery({
9968
- queryKey: productVariantsQueryKeys.list(query2),
9969
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9970
- ...options
9971
- });
9972
- return { ...data, ...rest };
9973
- };
9974
- const useCancelOrderEdit = ({ preview }) => {
9975
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9976
- const onCancel = useCallback(async () => {
9977
- if (!preview) {
9978
- return true;
9979
- }
9980
- let res = false;
9981
- await cancelOrderEdit(void 0, {
9982
- onError: (e) => {
9983
- toast.error(e.message);
9984
- },
9985
- onSuccess: () => {
9986
- res = true;
9987
- }
9988
- });
9989
- return res;
9990
- }, [preview, cancelOrderEdit]);
9991
- return { onCancel };
9992
- };
9993
- let IS_REQUEST_RUNNING = false;
9994
- const useInitiateOrderEdit = ({
9995
- preview
9996
- }) => {
9997
- const navigate = useNavigate();
9998
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9999
- useEffect(() => {
10000
- async function run() {
10001
- if (IS_REQUEST_RUNNING || !preview) {
10002
- return;
10003
- }
10004
- if (preview.order_change) {
10005
- return;
10006
- }
10007
- IS_REQUEST_RUNNING = true;
10008
- await mutateAsync(void 0, {
10009
- onError: (e) => {
10010
- toast.error(e.message);
10011
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10012
- return;
10013
- }
10014
- });
10015
- IS_REQUEST_RUNNING = false;
10016
- }
10017
- run();
10018
- }, [preview, navigate, mutateAsync]);
10019
- };
10020
- function convertNumber(value) {
10021
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10022
- }
10023
- const STACKED_MODAL_ID = "items_stacked_modal";
10024
- const Items = () => {
9694
+ InlineTip.displayName = "InlineTip";
9695
+ const MetadataFieldSchema = objectType({
9696
+ key: stringType(),
9697
+ disabled: booleanType().optional(),
9698
+ value: anyType()
9699
+ });
9700
+ const MetadataSchema = objectType({
9701
+ metadata: arrayType(MetadataFieldSchema)
9702
+ });
9703
+ const Metadata = () => {
10025
9704
  const { id } = useParams();
10026
- const {
10027
- order: preview,
10028
- isPending: isPreviewPending,
10029
- isError: isPreviewError,
10030
- error: previewError
10031
- } = useOrderPreview(id, void 0, {
10032
- placeholderData: keepPreviousData
9705
+ const { order, isPending, isError, error } = useOrder(id, {
9706
+ fields: "metadata"
10033
9707
  });
10034
- useInitiateOrderEdit({ preview });
10035
- const { draft_order, isPending, isError, error } = useDraftOrder(
10036
- id,
10037
- {
10038
- fields: "currency_code"
10039
- },
10040
- {
10041
- enabled: !!id
10042
- }
10043
- );
10044
- const { onCancel } = useCancelOrderEdit({ preview });
10045
9708
  if (isError) {
10046
9709
  throw error;
10047
9710
  }
10048
- if (isPreviewError) {
10049
- throw previewError;
10050
- }
10051
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10052
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10053
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10054
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10055
- ] }) });
9711
+ const isReady = !isPending && !!order;
9712
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9713
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9714
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9715
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9716
+ ] }),
9717
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9718
+ ] });
10056
9719
  };
10057
- const ItemsForm = ({ preview, currencyCode }) => {
10058
- var _a;
10059
- const [isSubmitting, setIsSubmitting] = useState(false);
10060
- const [modalContent, setModalContent] = useState(
10061
- null
10062
- );
9720
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9721
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9722
+ const MetadataForm = ({ orderId, metadata }) => {
10063
9723
  const { handleSuccess } = useRouteModal();
10064
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10065
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10066
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10067
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10068
- const matches = useMemo(() => {
10069
- return matchSorter(preview.items, query2, {
10070
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10071
- });
10072
- }, [preview.items, query2]);
10073
- const onSubmit = async () => {
10074
- setIsSubmitting(true);
10075
- let requestSucceeded = false;
10076
- await requestOrderEdit(void 0, {
10077
- onError: (e) => {
10078
- toast.error(`Failed to request order edit: ${e.message}`);
9724
+ const hasUneditableRows = getHasUneditableRows(metadata);
9725
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9726
+ const form = useForm({
9727
+ defaultValues: {
9728
+ metadata: getDefaultValues(metadata)
9729
+ },
9730
+ resolver: zodResolver(MetadataSchema)
9731
+ });
9732
+ const handleSubmit = form.handleSubmit(async (data) => {
9733
+ const parsedData = parseValues(data);
9734
+ await mutateAsync(
9735
+ {
9736
+ metadata: parsedData
10079
9737
  },
10080
- onSuccess: () => {
10081
- requestSucceeded = true;
9738
+ {
9739
+ onSuccess: () => {
9740
+ toast.success("Metadata updated");
9741
+ handleSuccess();
9742
+ },
9743
+ onError: (error) => {
9744
+ toast.error(error.message);
9745
+ }
10082
9746
  }
10083
- });
10084
- if (!requestSucceeded) {
10085
- setIsSubmitting(false);
10086
- return;
9747
+ );
9748
+ });
9749
+ const { fields, insert, remove } = useFieldArray({
9750
+ control: form.control,
9751
+ name: "metadata"
9752
+ });
9753
+ function deleteRow(index) {
9754
+ remove(index);
9755
+ if (fields.length === 1) {
9756
+ insert(0, {
9757
+ key: "",
9758
+ value: "",
9759
+ disabled: false
9760
+ });
10087
9761
  }
10088
- await confirmOrderEdit(void 0, {
10089
- onError: (e) => {
10090
- toast.error(`Failed to confirm order edit: ${e.message}`);
10091
- },
10092
- onSuccess: () => {
10093
- handleSuccess();
10094
- },
10095
- onSettled: () => {
10096
- setIsSubmitting(false);
10097
- }
9762
+ }
9763
+ function insertRow(index, position) {
9764
+ insert(index + (position === "above" ? 0 : 1), {
9765
+ key: "",
9766
+ value: "",
9767
+ disabled: false
10098
9768
  });
10099
- };
10100
- const onKeyDown = useCallback(
10101
- (e) => {
10102
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10103
- if (modalContent || isSubmitting) {
10104
- return;
10105
- }
10106
- onSubmit();
10107
- }
10108
- },
9769
+ }
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9771
+ KeyboundForm,
9772
+ {
9773
+ onSubmit: handleSubmit,
9774
+ className: "flex flex-1 flex-col overflow-hidden",
9775
+ children: [
9776
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9777
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9778
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9779
+ /* @__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" }) }),
9780
+ /* @__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" }) })
9781
+ ] }),
9782
+ fields.map((field, index) => {
9783
+ const isDisabled = field.disabled || false;
9784
+ let placeholder = "-";
9785
+ if (typeof field.value === "object") {
9786
+ placeholder = "{ ... }";
9787
+ }
9788
+ if (Array.isArray(field.value)) {
9789
+ placeholder = "[ ... ]";
9790
+ }
9791
+ return /* @__PURE__ */ jsx(
9792
+ ConditionalTooltip,
9793
+ {
9794
+ showTooltip: isDisabled,
9795
+ content: "This row is disabled because it contains non-primitive data.",
9796
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9797
+ /* @__PURE__ */ jsxs(
9798
+ "div",
9799
+ {
9800
+ className: clx("grid grid-cols-2 divide-x", {
9801
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9802
+ }),
9803
+ children: [
9804
+ /* @__PURE__ */ jsx(
9805
+ Form$2.Field,
9806
+ {
9807
+ control: form.control,
9808
+ name: `metadata.${index}.key`,
9809
+ render: ({ field: field2 }) => {
9810
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9811
+ GridInput,
9812
+ {
9813
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9814
+ ...field2,
9815
+ disabled: isDisabled,
9816
+ placeholder: "Key"
9817
+ }
9818
+ ) }) });
9819
+ }
9820
+ }
9821
+ ),
9822
+ /* @__PURE__ */ jsx(
9823
+ Form$2.Field,
9824
+ {
9825
+ control: form.control,
9826
+ name: `metadata.${index}.value`,
9827
+ render: ({ field: { value, ...field2 } }) => {
9828
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9829
+ GridInput,
9830
+ {
9831
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9832
+ ...field2,
9833
+ value: isDisabled ? placeholder : value,
9834
+ disabled: isDisabled,
9835
+ placeholder: "Value"
9836
+ }
9837
+ ) }) });
9838
+ }
9839
+ }
9840
+ )
9841
+ ]
9842
+ }
9843
+ ),
9844
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
9845
+ /* @__PURE__ */ jsx(
9846
+ DropdownMenu.Trigger,
9847
+ {
9848
+ className: clx(
9849
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9850
+ {
9851
+ hidden: isDisabled
9852
+ }
9853
+ ),
9854
+ disabled: isDisabled,
9855
+ asChild: true,
9856
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
9857
+ }
9858
+ ),
9859
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9860
+ /* @__PURE__ */ jsxs(
9861
+ DropdownMenu.Item,
9862
+ {
9863
+ className: "gap-x-2",
9864
+ onClick: () => insertRow(index, "above"),
9865
+ children: [
9866
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
9867
+ "Insert row above"
9868
+ ]
9869
+ }
9870
+ ),
9871
+ /* @__PURE__ */ jsxs(
9872
+ DropdownMenu.Item,
9873
+ {
9874
+ className: "gap-x-2",
9875
+ onClick: () => insertRow(index, "below"),
9876
+ children: [
9877
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
9878
+ "Insert row below"
9879
+ ]
9880
+ }
9881
+ ),
9882
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
9883
+ /* @__PURE__ */ jsxs(
9884
+ DropdownMenu.Item,
9885
+ {
9886
+ className: "gap-x-2",
9887
+ onClick: () => deleteRow(index),
9888
+ children: [
9889
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
9890
+ "Delete row"
9891
+ ]
9892
+ }
9893
+ )
9894
+ ] })
9895
+ ] })
9896
+ ] })
9897
+ },
9898
+ field.id
9899
+ );
9900
+ })
9901
+ ] }),
9902
+ 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." })
9903
+ ] }),
9904
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9905
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9906
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9907
+ ] }) })
9908
+ ]
9909
+ }
9910
+ ) });
9911
+ };
9912
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
9913
+ return /* @__PURE__ */ jsx(
9914
+ "input",
9915
+ {
9916
+ ref,
9917
+ ...props,
9918
+ autoComplete: "off",
9919
+ className: clx(
9920
+ "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",
9921
+ className
9922
+ )
9923
+ }
9924
+ );
9925
+ });
9926
+ GridInput.displayName = "MetadataForm.GridInput";
9927
+ const PlaceholderInner = () => {
9928
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9929
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9930
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9931
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
9932
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
9933
+ ] }) })
9934
+ ] });
9935
+ };
9936
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
9937
+ function getDefaultValues(metadata) {
9938
+ if (!metadata || !Object.keys(metadata).length) {
9939
+ return [
9940
+ {
9941
+ key: "",
9942
+ value: "",
9943
+ disabled: false
9944
+ }
9945
+ ];
9946
+ }
9947
+ return Object.entries(metadata).map(([key, value]) => {
9948
+ if (!EDITABLE_TYPES.includes(typeof value)) {
9949
+ return {
9950
+ key,
9951
+ value,
9952
+ disabled: true
9953
+ };
9954
+ }
9955
+ let stringValue = value;
9956
+ if (typeof value !== "string") {
9957
+ stringValue = JSON.stringify(value);
9958
+ }
9959
+ return {
9960
+ key,
9961
+ value: stringValue,
9962
+ original_key: key
9963
+ };
9964
+ });
9965
+ }
9966
+ function parseValues(values) {
9967
+ const metadata = values.metadata;
9968
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9969
+ if (isEmpty) {
9970
+ return null;
9971
+ }
9972
+ const update = {};
9973
+ metadata.forEach((field) => {
9974
+ let key = field.key;
9975
+ let value = field.value;
9976
+ const disabled = field.disabled;
9977
+ if (!key || !value) {
9978
+ return;
9979
+ }
9980
+ if (disabled) {
9981
+ update[key] = value;
9982
+ return;
9983
+ }
9984
+ key = key.trim();
9985
+ value = value.trim();
9986
+ if (value === "true") {
9987
+ update[key] = true;
9988
+ } else if (value === "false") {
9989
+ update[key] = false;
9990
+ } else {
9991
+ const parsedNumber = parseFloat(value);
9992
+ if (!isNaN(parsedNumber)) {
9993
+ update[key] = parsedNumber;
9994
+ } else {
9995
+ update[key] = value;
9996
+ }
9997
+ }
9998
+ });
9999
+ return update;
10000
+ }
10001
+ function getHasUneditableRows(metadata) {
10002
+ if (!metadata) {
10003
+ return false;
10004
+ }
10005
+ return Object.values(metadata).some(
10006
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10007
+ );
10008
+ }
10009
+ const NumberInput = forwardRef(
10010
+ ({
10011
+ value,
10012
+ onChange,
10013
+ size = "base",
10014
+ min = 0,
10015
+ max = 100,
10016
+ step = 1,
10017
+ className,
10018
+ disabled,
10019
+ ...props
10020
+ }, ref) => {
10021
+ const handleChange = (event) => {
10022
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10023
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10024
+ onChange(newValue);
10025
+ }
10026
+ };
10027
+ const handleIncrement = () => {
10028
+ const newValue = value + step;
10029
+ if (max === void 0 || newValue <= max) {
10030
+ onChange(newValue);
10031
+ }
10032
+ };
10033
+ const handleDecrement = () => {
10034
+ const newValue = value - step;
10035
+ if (min === void 0 || newValue >= min) {
10036
+ onChange(newValue);
10037
+ }
10038
+ };
10039
+ return /* @__PURE__ */ jsxs(
10040
+ "div",
10041
+ {
10042
+ className: clx(
10043
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10044
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10045
+ {
10046
+ "h-7": size === "small",
10047
+ "h-8": size === "base"
10048
+ },
10049
+ className
10050
+ ),
10051
+ children: [
10052
+ /* @__PURE__ */ jsx(
10053
+ "input",
10054
+ {
10055
+ ref,
10056
+ type: "number",
10057
+ value,
10058
+ onChange: handleChange,
10059
+ min,
10060
+ max,
10061
+ step,
10062
+ className: clx(
10063
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10064
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10065
+ "placeholder:text-ui-fg-muted"
10066
+ ),
10067
+ ...props
10068
+ }
10069
+ ),
10070
+ /* @__PURE__ */ jsxs(
10071
+ "button",
10072
+ {
10073
+ className: clx(
10074
+ "flex items-center justify-center outline-none transition-fg",
10075
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10076
+ "focus:bg-ui-bg-field-component-hover",
10077
+ "hover:bg-ui-bg-field-component-hover",
10078
+ {
10079
+ "size-7": size === "small",
10080
+ "size-8": size === "base"
10081
+ }
10082
+ ),
10083
+ type: "button",
10084
+ onClick: handleDecrement,
10085
+ disabled: min !== void 0 && value <= min || disabled,
10086
+ children: [
10087
+ /* @__PURE__ */ jsx(Minus, {}),
10088
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10089
+ ]
10090
+ }
10091
+ ),
10092
+ /* @__PURE__ */ jsxs(
10093
+ "button",
10094
+ {
10095
+ className: clx(
10096
+ "flex items-center justify-center outline-none transition-fg",
10097
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10098
+ "focus:bg-ui-bg-field-hover",
10099
+ "hover:bg-ui-bg-field-hover",
10100
+ {
10101
+ "size-7": size === "small",
10102
+ "size-8": size === "base"
10103
+ }
10104
+ ),
10105
+ type: "button",
10106
+ onClick: handleIncrement,
10107
+ disabled: max !== void 0 && value >= max || disabled,
10108
+ children: [
10109
+ /* @__PURE__ */ jsx(Plus, {}),
10110
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10111
+ ]
10112
+ }
10113
+ )
10114
+ ]
10115
+ }
10116
+ );
10117
+ }
10118
+ );
10119
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10120
+ const productVariantsQueryKeys = {
10121
+ list: (query2) => [
10122
+ PRODUCT_VARIANTS_QUERY_KEY,
10123
+ query2 ? query2 : void 0
10124
+ ]
10125
+ };
10126
+ const useProductVariants = (query2, options) => {
10127
+ const { data, ...rest } = useQuery({
10128
+ queryKey: productVariantsQueryKeys.list(query2),
10129
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10130
+ ...options
10131
+ });
10132
+ return { ...data, ...rest };
10133
+ };
10134
+ const useCancelOrderEdit = ({ preview }) => {
10135
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10136
+ const onCancel = useCallback(async () => {
10137
+ if (!preview) {
10138
+ return true;
10139
+ }
10140
+ let res = false;
10141
+ await cancelOrderEdit(void 0, {
10142
+ onError: (e) => {
10143
+ toast.error(e.message);
10144
+ },
10145
+ onSuccess: () => {
10146
+ res = true;
10147
+ }
10148
+ });
10149
+ return res;
10150
+ }, [preview, cancelOrderEdit]);
10151
+ return { onCancel };
10152
+ };
10153
+ let IS_REQUEST_RUNNING = false;
10154
+ const useInitiateOrderEdit = ({
10155
+ preview
10156
+ }) => {
10157
+ const navigate = useNavigate();
10158
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10159
+ useEffect(() => {
10160
+ async function run() {
10161
+ if (IS_REQUEST_RUNNING || !preview) {
10162
+ return;
10163
+ }
10164
+ if (preview.order_change) {
10165
+ return;
10166
+ }
10167
+ IS_REQUEST_RUNNING = true;
10168
+ await mutateAsync(void 0, {
10169
+ onError: (e) => {
10170
+ toast.error(e.message);
10171
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10172
+ return;
10173
+ }
10174
+ });
10175
+ IS_REQUEST_RUNNING = false;
10176
+ }
10177
+ run();
10178
+ }, [preview, navigate, mutateAsync]);
10179
+ };
10180
+ function convertNumber(value) {
10181
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10182
+ }
10183
+ const STACKED_MODAL_ID = "items_stacked_modal";
10184
+ const Items = () => {
10185
+ const { id } = useParams();
10186
+ const {
10187
+ order: preview,
10188
+ isPending: isPreviewPending,
10189
+ isError: isPreviewError,
10190
+ error: previewError
10191
+ } = useOrderPreview(id, void 0, {
10192
+ placeholderData: keepPreviousData
10193
+ });
10194
+ useInitiateOrderEdit({ preview });
10195
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10196
+ id,
10197
+ {
10198
+ fields: "currency_code"
10199
+ },
10200
+ {
10201
+ enabled: !!id
10202
+ }
10203
+ );
10204
+ const { onCancel } = useCancelOrderEdit({ preview });
10205
+ if (isError) {
10206
+ throw error;
10207
+ }
10208
+ if (isPreviewError) {
10209
+ throw previewError;
10210
+ }
10211
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10212
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10213
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10214
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10215
+ ] }) });
10216
+ };
10217
+ const ItemsForm = ({ preview, currencyCode }) => {
10218
+ var _a;
10219
+ const [isSubmitting, setIsSubmitting] = useState(false);
10220
+ const [modalContent, setModalContent] = useState(
10221
+ null
10222
+ );
10223
+ const { handleSuccess } = useRouteModal();
10224
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10225
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10226
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10227
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10228
+ const matches = useMemo(() => {
10229
+ return matchSorter(preview.items, query2, {
10230
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10231
+ });
10232
+ }, [preview.items, query2]);
10233
+ const onSubmit = async () => {
10234
+ setIsSubmitting(true);
10235
+ let requestSucceeded = false;
10236
+ await requestOrderEdit(void 0, {
10237
+ onError: (e) => {
10238
+ toast.error(`Failed to request order edit: ${e.message}`);
10239
+ },
10240
+ onSuccess: () => {
10241
+ requestSucceeded = true;
10242
+ }
10243
+ });
10244
+ if (!requestSucceeded) {
10245
+ setIsSubmitting(false);
10246
+ return;
10247
+ }
10248
+ await confirmOrderEdit(void 0, {
10249
+ onError: (e) => {
10250
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10251
+ },
10252
+ onSuccess: () => {
10253
+ handleSuccess();
10254
+ },
10255
+ onSettled: () => {
10256
+ setIsSubmitting(false);
10257
+ }
10258
+ });
10259
+ };
10260
+ const onKeyDown = useCallback(
10261
+ (e) => {
10262
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10263
+ if (modalContent || isSubmitting) {
10264
+ return;
10265
+ }
10266
+ onSubmit();
10267
+ }
10268
+ },
10109
10269
  [modalContent, isSubmitting, onSubmit]
10110
10270
  );
10111
10271
  useEffect(() => {
@@ -10254,165 +10414,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10254
10414
  quantity: item.quantity,
10255
10415
  unit_price: item.unit_price
10256
10416
  },
10257
- resolver: zodResolver(variantItemSchema)
10258
- });
10259
- const actionId = useMemo(() => {
10260
- var _a, _b;
10261
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10262
- }, [item]);
10263
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10264
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10265
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10266
- const onSubmit = form.handleSubmit(async (data) => {
10267
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10268
- setEditing(false);
10269
- return;
10270
- }
10271
- if (!actionId) {
10272
- await updateOriginalItem(
10273
- {
10274
- item_id: item.id,
10275
- quantity: data.quantity,
10276
- unit_price: convertNumber(data.unit_price)
10277
- },
10278
- {
10279
- onSuccess: () => {
10280
- setEditing(false);
10281
- },
10282
- onError: (e) => {
10283
- toast.error(e.message);
10284
- }
10285
- }
10286
- );
10287
- return;
10288
- }
10289
- await updateActionItem(
10290
- {
10291
- action_id: actionId,
10292
- quantity: data.quantity,
10293
- unit_price: convertNumber(data.unit_price)
10294
- },
10295
- {
10296
- onSuccess: () => {
10297
- setEditing(false);
10298
- },
10299
- onError: (e) => {
10300
- toast.error(e.message);
10301
- }
10302
- }
10303
- );
10304
- });
10305
- 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: [
10306
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10307
- /* @__PURE__ */ jsx(
10308
- Thumbnail,
10309
- {
10310
- thumbnail: item.thumbnail,
10311
- alt: item.product_title ?? void 0
10312
- }
10313
- ),
10314
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10315
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10316
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10317
- /* @__PURE__ */ jsxs(
10318
- Text,
10319
- {
10320
- size: "small",
10321
- leading: "compact",
10322
- className: "text-ui-fg-subtle",
10323
- children: [
10324
- "(",
10325
- item.variant_title,
10326
- ")"
10327
- ]
10328
- }
10329
- )
10330
- ] }),
10331
- /* @__PURE__ */ jsx(
10332
- Text,
10333
- {
10334
- size: "small",
10335
- leading: "compact",
10336
- className: "text-ui-fg-subtle",
10337
- children: item.variant_sku
10338
- }
10339
- )
10340
- ] })
10341
- ] }),
10342
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10343
- Form$2.Field,
10344
- {
10345
- control: form.control,
10346
- name: "quantity",
10347
- render: ({ field }) => {
10348
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10349
- }
10350
- }
10351
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10352
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10353
- Form$2.Field,
10354
- {
10355
- control: form.control,
10356
- name: "unit_price",
10357
- render: ({ field: { onChange, ...field } }) => {
10358
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10359
- CurrencyInput,
10360
- {
10361
- ...field,
10362
- symbol: getNativeSymbol(currencyCode),
10363
- code: currencyCode,
10364
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10365
- }
10366
- ) }) });
10367
- }
10368
- }
10369
- ) }) : /* @__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) }) }),
10370
- /* @__PURE__ */ jsx(
10371
- IconButton,
10372
- {
10373
- type: "button",
10374
- size: "small",
10375
- onClick: editing ? onSubmit : () => {
10376
- setEditing(true);
10377
- },
10378
- disabled: isPending,
10379
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10380
- }
10381
- )
10382
- ] }) }) });
10383
- };
10384
- const variantItemSchema = objectType({
10385
- quantity: numberType(),
10386
- unit_price: unionType([numberType(), stringType()])
10387
- });
10388
- const CustomItem = ({ item, preview, currencyCode }) => {
10389
- const [editing, setEditing] = useState(false);
10390
- const { quantity, unit_price, title } = item;
10391
- const form = useForm({
10392
- defaultValues: {
10393
- title,
10394
- quantity,
10395
- unit_price
10396
- },
10397
- resolver: zodResolver(customItemSchema)
10417
+ resolver: zodResolver(variantItemSchema)
10398
10418
  });
10399
- useEffect(() => {
10400
- form.reset({
10401
- title,
10402
- quantity,
10403
- unit_price
10404
- });
10405
- }, [form, title, quantity, unit_price]);
10406
10419
  const actionId = useMemo(() => {
10407
10420
  var _a, _b;
10408
10421
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10409
10422
  }, [item]);
10410
10423
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10411
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10412
10424
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10413
10425
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10414
10426
  const onSubmit = form.handleSubmit(async (data) => {
10415
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10427
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10416
10428
  setEditing(false);
10417
10429
  return;
10418
10430
  }
@@ -10434,17 +10446,6 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10434
10446
  );
10435
10447
  return;
10436
10448
  }
10437
- if (data.quantity === 0) {
10438
- await removeActionItem(actionId, {
10439
- onSuccess: () => {
10440
- setEditing(false);
10441
- },
10442
- onError: (e) => {
10443
- toast.error(e.message);
10444
- }
10445
- });
10446
- return;
10447
- }
10448
10449
  await updateActionItem(
10449
10450
  {
10450
10451
  action_id: actionId,
@@ -10462,26 +10463,43 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10462
10463
  );
10463
10464
  });
10464
10465
  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: [
10465
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10466
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10466
10467
  /* @__PURE__ */ jsx(
10467
10468
  Thumbnail,
10468
10469
  {
10469
10470
  thumbnail: item.thumbnail,
10470
- alt: item.title ?? void 0
10471
+ alt: item.product_title ?? void 0
10471
10472
  }
10472
10473
  ),
10473
- editing ? /* @__PURE__ */ jsx(
10474
- Form$2.Field,
10475
- {
10476
- control: form.control,
10477
- name: "title",
10478
- render: ({ field }) => {
10479
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10474
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10475
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10476
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10477
+ /* @__PURE__ */ jsxs(
10478
+ Text,
10479
+ {
10480
+ size: "small",
10481
+ leading: "compact",
10482
+ className: "text-ui-fg-subtle",
10483
+ children: [
10484
+ "(",
10485
+ item.variant_title,
10486
+ ")"
10487
+ ]
10488
+ }
10489
+ )
10490
+ ] }),
10491
+ /* @__PURE__ */ jsx(
10492
+ Text,
10493
+ {
10494
+ size: "small",
10495
+ leading: "compact",
10496
+ className: "text-ui-fg-subtle",
10497
+ children: item.variant_sku
10480
10498
  }
10481
- }
10482
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10499
+ )
10500
+ ] })
10483
10501
  ] }),
10484
- editing ? /* @__PURE__ */ jsx(
10502
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10485
10503
  Form$2.Field,
10486
10504
  {
10487
10505
  control: form.control,
@@ -10490,8 +10508,8 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10490
10508
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10491
10509
  }
10492
10510
  }
10493
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10494
- editing ? /* @__PURE__ */ jsx(
10511
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10512
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10495
10513
  Form$2.Field,
10496
10514
  {
10497
10515
  control: form.control,
@@ -10508,230 +10526,94 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10508
10526
  ) }) });
10509
10527
  }
10510
10528
  }
10511
- ) : /* @__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) }) }),
10529
+ ) }) : /* @__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) }) }),
10512
10530
  /* @__PURE__ */ jsx(
10513
10531
  IconButton,
10514
10532
  {
10515
10533
  type: "button",
10516
- size: "small",
10517
- onClick: editing ? onSubmit : () => {
10518
- setEditing(true);
10519
- },
10520
- disabled: isPending,
10521
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10522
- }
10523
- )
10524
- ] }) }) });
10525
- };
10526
- const StackedModalTrigger$1 = ({
10527
- type,
10528
- setModalContent
10529
- }) => {
10530
- const { setIsOpen } = useStackedModal();
10531
- const onClick = useCallback(() => {
10532
- setModalContent(type);
10533
- setIsOpen(STACKED_MODAL_ID, true);
10534
- }, [setModalContent, setIsOpen, type]);
10535
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10536
- };
10537
- const VARIANT_PREFIX = "items";
10538
- const LIMIT = 50;
10539
- const ExistingItemsForm = ({ orderId, items }) => {
10540
- const { setIsOpen } = useStackedModal();
10541
- const [rowSelection, setRowSelection] = useState(
10542
- items.reduce((acc, item) => {
10543
- acc[item.variant_id] = true;
10544
- return acc;
10545
- }, {})
10546
- );
10547
- useEffect(() => {
10548
- setRowSelection(
10549
- items.reduce((acc, item) => {
10550
- if (item.variant_id) {
10551
- acc[item.variant_id] = true;
10552
- }
10553
- return acc;
10554
- }, {})
10555
- );
10556
- }, [items]);
10557
- const { q, order, offset } = useQueryParams(
10558
- ["q", "order", "offset"],
10559
- VARIANT_PREFIX
10560
- );
10561
- const { variants, count, isPending, isError, error } = useProductVariants(
10562
- {
10563
- q,
10564
- order,
10565
- offset: offset ? parseInt(offset) : void 0,
10566
- limit: LIMIT
10567
- },
10568
- {
10569
- placeholderData: keepPreviousData
10570
- }
10571
- );
10572
- const columns = useColumns();
10573
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10574
- const onSubmit = async () => {
10575
- const ids = Object.keys(rowSelection).filter(
10576
- (id) => !items.find((i) => i.variant_id === id)
10577
- );
10578
- await mutateAsync(
10579
- {
10580
- items: ids.map((id) => ({
10581
- variant_id: id,
10582
- quantity: 1
10583
- }))
10584
- },
10585
- {
10586
- onSuccess: () => {
10587
- setRowSelection({});
10588
- setIsOpen(STACKED_MODAL_ID, false);
10589
- },
10590
- onError: (e) => {
10591
- toast.error(e.message);
10592
- }
10593
- }
10594
- );
10595
- };
10596
- if (isError) {
10597
- throw error;
10598
- }
10599
- return /* @__PURE__ */ jsxs(
10600
- StackedFocusModal.Content,
10601
- {
10602
- onOpenAutoFocus: (e) => {
10603
- e.preventDefault();
10604
- const searchInput = document.querySelector(
10605
- "[data-modal-id='modal-search-input']"
10606
- );
10607
- if (searchInput) {
10608
- searchInput.focus();
10609
- }
10610
- },
10611
- children: [
10612
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10613
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10614
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10615
- ] }),
10616
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10617
- DataTable,
10618
- {
10619
- data: variants,
10620
- columns,
10621
- isLoading: isPending,
10622
- getRowId: (row) => row.id,
10623
- rowCount: count,
10624
- prefix: VARIANT_PREFIX,
10625
- layout: "fill",
10626
- rowSelection: {
10627
- state: rowSelection,
10628
- onRowSelectionChange: setRowSelection,
10629
- enableRowSelection: (row) => {
10630
- return !items.find((i) => i.variant_id === row.original.id);
10631
- }
10632
- },
10633
- autoFocusSearch: true
10634
- }
10635
- ) }),
10636
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10637
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10638
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10639
- ] }) })
10640
- ]
10641
- }
10642
- );
10643
- };
10644
- const columnHelper = createDataTableColumnHelper();
10645
- const useColumns = () => {
10646
- return useMemo(() => {
10647
- return [
10648
- columnHelper.select(),
10649
- columnHelper.accessor("product.title", {
10650
- header: "Product",
10651
- cell: ({ row }) => {
10652
- var _a, _b, _c;
10653
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10654
- /* @__PURE__ */ jsx(
10655
- Thumbnail,
10656
- {
10657
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10658
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10659
- }
10660
- ),
10661
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10662
- ] });
10663
- },
10664
- enableSorting: true
10665
- }),
10666
- columnHelper.accessor("title", {
10667
- header: "Variant",
10668
- enableSorting: true
10669
- }),
10670
- columnHelper.accessor("sku", {
10671
- header: "SKU",
10672
- cell: ({ getValue }) => {
10673
- return getValue() ?? "-";
10674
- },
10675
- enableSorting: true
10676
- }),
10677
- columnHelper.accessor("updated_at", {
10678
- header: "Updated",
10679
- cell: ({ getValue }) => {
10680
- return /* @__PURE__ */ jsx(
10681
- Tooltip,
10682
- {
10683
- content: getFullDate({ date: getValue(), includeTime: true }),
10684
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10685
- }
10686
- );
10687
- },
10688
- enableSorting: true,
10689
- sortAscLabel: "Oldest first",
10690
- sortDescLabel: "Newest first"
10691
- }),
10692
- columnHelper.accessor("created_at", {
10693
- header: "Created",
10694
- cell: ({ getValue }) => {
10695
- return /* @__PURE__ */ jsx(
10696
- Tooltip,
10697
- {
10698
- content: getFullDate({ date: getValue(), includeTime: true }),
10699
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10700
- }
10701
- );
10534
+ size: "small",
10535
+ onClick: editing ? onSubmit : () => {
10536
+ setEditing(true);
10702
10537
  },
10703
- enableSorting: true,
10704
- sortAscLabel: "Oldest first",
10705
- sortDescLabel: "Newest first"
10706
- })
10707
- ];
10708
- }, []);
10538
+ disabled: isPending,
10539
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10540
+ }
10541
+ )
10542
+ ] }) }) });
10709
10543
  };
10710
- const CustomItemForm = ({ orderId, currencyCode }) => {
10711
- const { setIsOpen } = useStackedModal();
10712
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10544
+ const variantItemSchema = objectType({
10545
+ quantity: numberType(),
10546
+ unit_price: unionType([numberType(), stringType()])
10547
+ });
10548
+ const CustomItem = ({ item, preview, currencyCode }) => {
10549
+ const [editing, setEditing] = useState(false);
10550
+ const { quantity, unit_price, title } = item;
10713
10551
  const form = useForm({
10714
10552
  defaultValues: {
10715
- title: "",
10716
- quantity: 1,
10717
- unit_price: ""
10553
+ title,
10554
+ quantity,
10555
+ unit_price
10718
10556
  },
10719
10557
  resolver: zodResolver(customItemSchema)
10720
10558
  });
10559
+ useEffect(() => {
10560
+ form.reset({
10561
+ title,
10562
+ quantity,
10563
+ unit_price
10564
+ });
10565
+ }, [form, title, quantity, unit_price]);
10566
+ const actionId = useMemo(() => {
10567
+ var _a, _b;
10568
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10569
+ }, [item]);
10570
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10571
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10572
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10573
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10721
10574
  const onSubmit = form.handleSubmit(async (data) => {
10722
- await addItems(
10723
- {
10724
- items: [
10725
- {
10726
- title: data.title,
10727
- quantity: data.quantity,
10728
- unit_price: convertNumber(data.unit_price)
10575
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10576
+ setEditing(false);
10577
+ return;
10578
+ }
10579
+ if (!actionId) {
10580
+ await updateOriginalItem(
10581
+ {
10582
+ item_id: item.id,
10583
+ quantity: data.quantity,
10584
+ unit_price: convertNumber(data.unit_price)
10585
+ },
10586
+ {
10587
+ onSuccess: () => {
10588
+ setEditing(false);
10589
+ },
10590
+ onError: (e) => {
10591
+ toast.error(e.message);
10729
10592
  }
10730
- ]
10593
+ }
10594
+ );
10595
+ return;
10596
+ }
10597
+ if (data.quantity === 0) {
10598
+ await removeActionItem(actionId, {
10599
+ onSuccess: () => {
10600
+ setEditing(false);
10601
+ },
10602
+ onError: (e) => {
10603
+ toast.error(e.message);
10604
+ }
10605
+ });
10606
+ return;
10607
+ }
10608
+ await updateActionItem(
10609
+ {
10610
+ action_id: actionId,
10611
+ quantity: data.quantity,
10612
+ unit_price: convertNumber(data.unit_price)
10731
10613
  },
10732
10614
  {
10733
10615
  onSuccess: () => {
10734
- setIsOpen(STACKED_MODAL_ID, false);
10616
+ setEditing(false);
10735
10617
  },
10736
10618
  onError: (e) => {
10737
10619
  toast.error(e.message);
@@ -10739,437 +10621,365 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10739
10621
  }
10740
10622
  );
10741
10623
  });
10742
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10743
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10744
- /* @__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: [
10745
- /* @__PURE__ */ jsxs("div", { children: [
10746
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10747
- /* @__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." }) })
10748
- ] }),
10749
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10624
+ 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: [
10625
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10750
10626
  /* @__PURE__ */ jsx(
10751
- Form$2.Field,
10627
+ Thumbnail,
10752
10628
  {
10753
- control: form.control,
10754
- name: "title",
10755
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10756
- /* @__PURE__ */ jsxs("div", { children: [
10757
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10758
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10759
- ] }),
10760
- /* @__PURE__ */ jsxs("div", { children: [
10761
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10762
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10763
- ] })
10764
- ] }) })
10629
+ thumbnail: item.thumbnail,
10630
+ alt: item.title ?? void 0
10765
10631
  }
10766
10632
  ),
10767
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10768
- /* @__PURE__ */ jsx(
10633
+ editing ? /* @__PURE__ */ jsx(
10769
10634
  Form$2.Field,
10770
10635
  {
10771
10636
  control: form.control,
10772
- name: "unit_price",
10773
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10774
- /* @__PURE__ */ jsxs("div", { children: [
10775
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10776
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10777
- ] }),
10778
- /* @__PURE__ */ jsxs("div", { children: [
10779
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10780
- CurrencyInput,
10781
- {
10782
- symbol: getNativeSymbol(currencyCode),
10783
- code: currencyCode,
10784
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10785
- ...field
10786
- }
10787
- ) }),
10788
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10789
- ] })
10790
- ] }) })
10637
+ name: "title",
10638
+ render: ({ field }) => {
10639
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10640
+ }
10791
10641
  }
10792
- ),
10793
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10794
- /* @__PURE__ */ jsx(
10795
- Form$2.Field,
10796
- {
10797
- control: form.control,
10798
- name: "quantity",
10799
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10800
- /* @__PURE__ */ jsxs("div", { children: [
10801
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10802
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10803
- ] }),
10804
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10805
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10806
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10807
- ] })
10808
- ] }) })
10642
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10643
+ ] }),
10644
+ editing ? /* @__PURE__ */ jsx(
10645
+ Form$2.Field,
10646
+ {
10647
+ control: form.control,
10648
+ name: "quantity",
10649
+ render: ({ field }) => {
10650
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10809
10651
  }
10810
- )
10811
- ] }) }) }),
10812
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10813
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10814
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10815
- ] }) })
10816
- ] }) }) });
10817
- };
10818
- const customItemSchema = objectType({
10819
- title: stringType().min(1),
10820
- quantity: numberType(),
10821
- unit_price: unionType([numberType(), stringType()])
10822
- });
10823
- const InlineTip = forwardRef(
10824
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10825
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10826
- return /* @__PURE__ */ jsxs(
10827
- "div",
10652
+ }
10653
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10654
+ editing ? /* @__PURE__ */ jsx(
10655
+ Form$2.Field,
10828
10656
  {
10829
- ref,
10830
- className: clx(
10831
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10832
- className
10833
- ),
10834
- ...props,
10835
- children: [
10836
- /* @__PURE__ */ jsx(
10837
- "div",
10657
+ control: form.control,
10658
+ name: "unit_price",
10659
+ render: ({ field: { onChange, ...field } }) => {
10660
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10661
+ CurrencyInput,
10838
10662
  {
10839
- role: "presentation",
10840
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10841
- "bg-ui-tag-orange-icon": variant === "warning"
10842
- })
10663
+ ...field,
10664
+ symbol: getNativeSymbol(currencyCode),
10665
+ code: currencyCode,
10666
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10843
10667
  }
10844
- ),
10845
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10846
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10847
- labelValue,
10848
- ":"
10849
- ] }),
10850
- " ",
10851
- children
10852
- ] })
10853
- ]
10668
+ ) }) });
10669
+ }
10854
10670
  }
10855
- );
10856
- }
10857
- );
10858
- InlineTip.displayName = "InlineTip";
10859
- const MetadataFieldSchema = objectType({
10860
- key: stringType(),
10861
- disabled: booleanType().optional(),
10862
- value: anyType()
10863
- });
10864
- const MetadataSchema = objectType({
10865
- metadata: arrayType(MetadataFieldSchema)
10866
- });
10867
- const Metadata = () => {
10868
- const { id } = useParams();
10869
- const { order, isPending, isError, error } = useOrder(id, {
10870
- fields: "metadata"
10871
- });
10872
- if (isError) {
10873
- throw error;
10874
- }
10875
- const isReady = !isPending && !!order;
10876
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10877
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10878
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10879
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10880
- ] }),
10881
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10882
- ] });
10671
+ ) : /* @__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) }) }),
10672
+ /* @__PURE__ */ jsx(
10673
+ IconButton,
10674
+ {
10675
+ type: "button",
10676
+ size: "small",
10677
+ onClick: editing ? onSubmit : () => {
10678
+ setEditing(true);
10679
+ },
10680
+ disabled: isPending,
10681
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10682
+ }
10683
+ )
10684
+ ] }) }) });
10883
10685
  };
10884
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10885
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10886
- const MetadataForm = ({ orderId, metadata }) => {
10887
- const { handleSuccess } = useRouteModal();
10888
- const hasUneditableRows = getHasUneditableRows(metadata);
10889
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10890
- const form = useForm({
10891
- defaultValues: {
10892
- metadata: getDefaultValues(metadata)
10686
+ const StackedModalTrigger$1 = ({
10687
+ type,
10688
+ setModalContent
10689
+ }) => {
10690
+ const { setIsOpen } = useStackedModal();
10691
+ const onClick = useCallback(() => {
10692
+ setModalContent(type);
10693
+ setIsOpen(STACKED_MODAL_ID, true);
10694
+ }, [setModalContent, setIsOpen, type]);
10695
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10696
+ };
10697
+ const VARIANT_PREFIX = "items";
10698
+ const LIMIT = 50;
10699
+ const ExistingItemsForm = ({ orderId, items }) => {
10700
+ const { setIsOpen } = useStackedModal();
10701
+ const [rowSelection, setRowSelection] = useState(
10702
+ items.reduce((acc, item) => {
10703
+ acc[item.variant_id] = true;
10704
+ return acc;
10705
+ }, {})
10706
+ );
10707
+ useEffect(() => {
10708
+ setRowSelection(
10709
+ items.reduce((acc, item) => {
10710
+ if (item.variant_id) {
10711
+ acc[item.variant_id] = true;
10712
+ }
10713
+ return acc;
10714
+ }, {})
10715
+ );
10716
+ }, [items]);
10717
+ const { q, order, offset } = useQueryParams(
10718
+ ["q", "order", "offset"],
10719
+ VARIANT_PREFIX
10720
+ );
10721
+ const { variants, count, isPending, isError, error } = useProductVariants(
10722
+ {
10723
+ q,
10724
+ order,
10725
+ offset: offset ? parseInt(offset) : void 0,
10726
+ limit: LIMIT
10893
10727
  },
10894
- resolver: zodResolver(MetadataSchema)
10895
- });
10896
- const handleSubmit = form.handleSubmit(async (data) => {
10897
- const parsedData = parseValues(data);
10728
+ {
10729
+ placeholderData: keepPreviousData
10730
+ }
10731
+ );
10732
+ const columns = useColumns();
10733
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10734
+ const onSubmit = async () => {
10735
+ const ids = Object.keys(rowSelection).filter(
10736
+ (id) => !items.find((i) => i.variant_id === id)
10737
+ );
10898
10738
  await mutateAsync(
10899
10739
  {
10900
- metadata: parsedData
10740
+ items: ids.map((id) => ({
10741
+ variant_id: id,
10742
+ quantity: 1
10743
+ }))
10901
10744
  },
10902
10745
  {
10903
10746
  onSuccess: () => {
10904
- toast.success("Metadata updated");
10905
- handleSuccess();
10747
+ setRowSelection({});
10748
+ setIsOpen(STACKED_MODAL_ID, false);
10906
10749
  },
10907
- onError: (error) => {
10908
- toast.error(error.message);
10750
+ onError: (e) => {
10751
+ toast.error(e.message);
10909
10752
  }
10910
10753
  }
10911
10754
  );
10912
- });
10913
- const { fields, insert, remove } = useFieldArray({
10914
- control: form.control,
10915
- name: "metadata"
10916
- });
10917
- function deleteRow(index) {
10918
- remove(index);
10919
- if (fields.length === 1) {
10920
- insert(0, {
10921
- key: "",
10922
- value: "",
10923
- disabled: false
10924
- });
10925
- }
10926
- }
10927
- function insertRow(index, position) {
10928
- insert(index + (position === "above" ? 0 : 1), {
10929
- key: "",
10930
- value: "",
10931
- disabled: false
10932
- });
10755
+ };
10756
+ if (isError) {
10757
+ throw error;
10933
10758
  }
10934
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10935
- KeyboundForm,
10759
+ return /* @__PURE__ */ jsxs(
10760
+ StackedFocusModal.Content,
10936
10761
  {
10937
- onSubmit: handleSubmit,
10938
- className: "flex flex-1 flex-col overflow-hidden",
10762
+ onOpenAutoFocus: (e) => {
10763
+ e.preventDefault();
10764
+ const searchInput = document.querySelector(
10765
+ "[data-modal-id='modal-search-input']"
10766
+ );
10767
+ if (searchInput) {
10768
+ searchInput.focus();
10769
+ }
10770
+ },
10939
10771
  children: [
10940
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10941
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10942
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10943
- /* @__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" }) }),
10944
- /* @__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" }) })
10945
- ] }),
10946
- fields.map((field, index) => {
10947
- const isDisabled = field.disabled || false;
10948
- let placeholder = "-";
10949
- if (typeof field.value === "object") {
10950
- placeholder = "{ ... }";
10951
- }
10952
- if (Array.isArray(field.value)) {
10953
- placeholder = "[ ... ]";
10954
- }
10955
- return /* @__PURE__ */ jsx(
10956
- ConditionalTooltip,
10957
- {
10958
- showTooltip: isDisabled,
10959
- content: "This row is disabled because it contains non-primitive data.",
10960
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10961
- /* @__PURE__ */ jsxs(
10962
- "div",
10963
- {
10964
- className: clx("grid grid-cols-2 divide-x", {
10965
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10966
- }),
10967
- children: [
10968
- /* @__PURE__ */ jsx(
10969
- Form$2.Field,
10970
- {
10971
- control: form.control,
10972
- name: `metadata.${index}.key`,
10973
- render: ({ field: field2 }) => {
10974
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10975
- GridInput,
10976
- {
10977
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10978
- ...field2,
10979
- disabled: isDisabled,
10980
- placeholder: "Key"
10981
- }
10982
- ) }) });
10983
- }
10984
- }
10985
- ),
10986
- /* @__PURE__ */ jsx(
10987
- Form$2.Field,
10988
- {
10989
- control: form.control,
10990
- name: `metadata.${index}.value`,
10991
- render: ({ field: { value, ...field2 } }) => {
10992
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10993
- GridInput,
10994
- {
10995
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10996
- ...field2,
10997
- value: isDisabled ? placeholder : value,
10998
- disabled: isDisabled,
10999
- placeholder: "Value"
11000
- }
11001
- ) }) });
11002
- }
11003
- }
11004
- )
11005
- ]
11006
- }
11007
- ),
11008
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11009
- /* @__PURE__ */ jsx(
11010
- DropdownMenu.Trigger,
11011
- {
11012
- className: clx(
11013
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11014
- {
11015
- hidden: isDisabled
11016
- }
11017
- ),
11018
- disabled: isDisabled,
11019
- asChild: true,
11020
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11021
- }
11022
- ),
11023
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11024
- /* @__PURE__ */ jsxs(
11025
- DropdownMenu.Item,
11026
- {
11027
- className: "gap-x-2",
11028
- onClick: () => insertRow(index, "above"),
11029
- children: [
11030
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11031
- "Insert row above"
11032
- ]
11033
- }
11034
- ),
11035
- /* @__PURE__ */ jsxs(
11036
- DropdownMenu.Item,
11037
- {
11038
- className: "gap-x-2",
11039
- onClick: () => insertRow(index, "below"),
11040
- children: [
11041
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11042
- "Insert row below"
11043
- ]
11044
- }
11045
- ),
11046
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11047
- /* @__PURE__ */ jsxs(
11048
- DropdownMenu.Item,
11049
- {
11050
- className: "gap-x-2",
11051
- onClick: () => deleteRow(index),
11052
- children: [
11053
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11054
- "Delete row"
11055
- ]
11056
- }
11057
- )
11058
- ] })
11059
- ] })
11060
- ] })
11061
- },
11062
- field.id
11063
- );
11064
- })
11065
- ] }),
11066
- 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." })
10772
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10773
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10774
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11067
10775
  ] }),
11068
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11069
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11070
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10776
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10777
+ DataTable,
10778
+ {
10779
+ data: variants,
10780
+ columns,
10781
+ isLoading: isPending,
10782
+ getRowId: (row) => row.id,
10783
+ rowCount: count,
10784
+ prefix: VARIANT_PREFIX,
10785
+ layout: "fill",
10786
+ rowSelection: {
10787
+ state: rowSelection,
10788
+ onRowSelectionChange: setRowSelection,
10789
+ enableRowSelection: (row) => {
10790
+ return !items.find((i) => i.variant_id === row.original.id);
10791
+ }
10792
+ },
10793
+ autoFocusSearch: true
10794
+ }
10795
+ ) }),
10796
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10797
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10798
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11071
10799
  ] }) })
11072
10800
  ]
11073
10801
  }
11074
- ) });
11075
- };
11076
- const GridInput = forwardRef(({ className, ...props }, ref) => {
11077
- return /* @__PURE__ */ jsx(
11078
- "input",
11079
- {
11080
- ref,
11081
- ...props,
11082
- autoComplete: "off",
11083
- className: clx(
11084
- "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",
11085
- className
11086
- )
11087
- }
11088
10802
  );
11089
- });
11090
- GridInput.displayName = "MetadataForm.GridInput";
11091
- const PlaceholderInner = () => {
11092
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11093
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11094
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11095
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11096
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11097
- ] }) })
11098
- ] });
11099
10803
  };
11100
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11101
- function getDefaultValues(metadata) {
11102
- if (!metadata || !Object.keys(metadata).length) {
10804
+ const columnHelper = createDataTableColumnHelper();
10805
+ const useColumns = () => {
10806
+ return useMemo(() => {
11103
10807
  return [
11104
- {
11105
- key: "",
11106
- value: "",
11107
- disabled: false
11108
- }
10808
+ columnHelper.select(),
10809
+ columnHelper.accessor("product.title", {
10810
+ header: "Product",
10811
+ cell: ({ row }) => {
10812
+ var _a, _b, _c;
10813
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10814
+ /* @__PURE__ */ jsx(
10815
+ Thumbnail,
10816
+ {
10817
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10818
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10819
+ }
10820
+ ),
10821
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10822
+ ] });
10823
+ },
10824
+ enableSorting: true
10825
+ }),
10826
+ columnHelper.accessor("title", {
10827
+ header: "Variant",
10828
+ enableSorting: true
10829
+ }),
10830
+ columnHelper.accessor("sku", {
10831
+ header: "SKU",
10832
+ cell: ({ getValue }) => {
10833
+ return getValue() ?? "-";
10834
+ },
10835
+ enableSorting: true
10836
+ }),
10837
+ columnHelper.accessor("updated_at", {
10838
+ header: "Updated",
10839
+ cell: ({ getValue }) => {
10840
+ return /* @__PURE__ */ jsx(
10841
+ Tooltip,
10842
+ {
10843
+ content: getFullDate({ date: getValue(), includeTime: true }),
10844
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10845
+ }
10846
+ );
10847
+ },
10848
+ enableSorting: true,
10849
+ sortAscLabel: "Oldest first",
10850
+ sortDescLabel: "Newest first"
10851
+ }),
10852
+ columnHelper.accessor("created_at", {
10853
+ header: "Created",
10854
+ cell: ({ getValue }) => {
10855
+ return /* @__PURE__ */ jsx(
10856
+ Tooltip,
10857
+ {
10858
+ content: getFullDate({ date: getValue(), includeTime: true }),
10859
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10860
+ }
10861
+ );
10862
+ },
10863
+ enableSorting: true,
10864
+ sortAscLabel: "Oldest first",
10865
+ sortDescLabel: "Newest first"
10866
+ })
11109
10867
  ];
11110
- }
11111
- return Object.entries(metadata).map(([key, value]) => {
11112
- if (!EDITABLE_TYPES.includes(typeof value)) {
11113
- return {
11114
- key,
11115
- value,
11116
- disabled: true
11117
- };
11118
- }
11119
- let stringValue = value;
11120
- if (typeof value !== "string") {
11121
- stringValue = JSON.stringify(value);
11122
- }
11123
- return {
11124
- key,
11125
- value: stringValue,
11126
- original_key: key
11127
- };
10868
+ }, []);
10869
+ };
10870
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10871
+ const { setIsOpen } = useStackedModal();
10872
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10873
+ const form = useForm({
10874
+ defaultValues: {
10875
+ title: "",
10876
+ quantity: 1,
10877
+ unit_price: ""
10878
+ },
10879
+ resolver: zodResolver(customItemSchema)
11128
10880
  });
11129
- }
11130
- function parseValues(values) {
11131
- const metadata = values.metadata;
11132
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11133
- if (isEmpty) {
11134
- return null;
11135
- }
11136
- const update = {};
11137
- metadata.forEach((field) => {
11138
- let key = field.key;
11139
- let value = field.value;
11140
- const disabled = field.disabled;
11141
- if (!key || !value) {
11142
- return;
11143
- }
11144
- if (disabled) {
11145
- update[key] = value;
11146
- return;
11147
- }
11148
- key = key.trim();
11149
- value = value.trim();
11150
- if (value === "true") {
11151
- update[key] = true;
11152
- } else if (value === "false") {
11153
- update[key] = false;
11154
- } else {
11155
- const parsedNumber = parseFloat(value);
11156
- if (!isNaN(parsedNumber)) {
11157
- update[key] = parsedNumber;
11158
- } else {
11159
- update[key] = value;
10881
+ const onSubmit = form.handleSubmit(async (data) => {
10882
+ await addItems(
10883
+ {
10884
+ items: [
10885
+ {
10886
+ title: data.title,
10887
+ quantity: data.quantity,
10888
+ unit_price: convertNumber(data.unit_price)
10889
+ }
10890
+ ]
10891
+ },
10892
+ {
10893
+ onSuccess: () => {
10894
+ setIsOpen(STACKED_MODAL_ID, false);
10895
+ },
10896
+ onError: (e) => {
10897
+ toast.error(e.message);
10898
+ }
11160
10899
  }
11161
- }
10900
+ );
11162
10901
  });
11163
- return update;
11164
- }
11165
- function getHasUneditableRows(metadata) {
11166
- if (!metadata) {
11167
- return false;
11168
- }
11169
- return Object.values(metadata).some(
11170
- (value) => !EDITABLE_TYPES.includes(typeof value)
11171
- );
11172
- }
10902
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10903
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10904
+ /* @__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: [
10905
+ /* @__PURE__ */ jsxs("div", { children: [
10906
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10907
+ /* @__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." }) })
10908
+ ] }),
10909
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10910
+ /* @__PURE__ */ jsx(
10911
+ Form$2.Field,
10912
+ {
10913
+ control: form.control,
10914
+ name: "title",
10915
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10916
+ /* @__PURE__ */ jsxs("div", { children: [
10917
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10918
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10919
+ ] }),
10920
+ /* @__PURE__ */ jsxs("div", { children: [
10921
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10922
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10923
+ ] })
10924
+ ] }) })
10925
+ }
10926
+ ),
10927
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10928
+ /* @__PURE__ */ jsx(
10929
+ Form$2.Field,
10930
+ {
10931
+ control: form.control,
10932
+ name: "unit_price",
10933
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10934
+ /* @__PURE__ */ jsxs("div", { children: [
10935
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10936
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10937
+ ] }),
10938
+ /* @__PURE__ */ jsxs("div", { children: [
10939
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10940
+ CurrencyInput,
10941
+ {
10942
+ symbol: getNativeSymbol(currencyCode),
10943
+ code: currencyCode,
10944
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10945
+ ...field
10946
+ }
10947
+ ) }),
10948
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10949
+ ] })
10950
+ ] }) })
10951
+ }
10952
+ ),
10953
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10954
+ /* @__PURE__ */ jsx(
10955
+ Form$2.Field,
10956
+ {
10957
+ control: form.control,
10958
+ name: "quantity",
10959
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10960
+ /* @__PURE__ */ jsxs("div", { children: [
10961
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10962
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10963
+ ] }),
10964
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10965
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10966
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10967
+ ] })
10968
+ ] }) })
10969
+ }
10970
+ )
10971
+ ] }) }) }),
10972
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10973
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10974
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10975
+ ] }) })
10976
+ ] }) }) });
10977
+ };
10978
+ const customItemSchema = objectType({
10979
+ title: stringType().min(1),
10980
+ quantity: numberType(),
10981
+ unit_price: unionType([numberType(), stringType()])
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();
@@ -11510,49 +11320,252 @@ const SalesChannelForm = ({ order }) => {
11510
11320
  }
11511
11321
  ) });
11512
11322
  };
11513
- const SalesChannelField = ({ control, order }) => {
11514
- const salesChannels = useComboboxData({
11515
- queryFn: async (params) => {
11516
- return await sdk.admin.salesChannel.list(params);
11517
- },
11518
- queryKey: ["sales-channels"],
11519
- getOptions: (data) => {
11520
- return data.sales_channels.map((salesChannel) => ({
11521
- label: salesChannel.name,
11522
- value: salesChannel.id
11523
- }));
11524
- },
11525
- defaultValue: order.sales_channel_id || void 0
11526
- });
11527
- return /* @__PURE__ */ jsx(
11528
- Form$2.Field,
11529
- {
11530
- control,
11531
- name: "sales_channel_id",
11532
- render: ({ field }) => {
11533
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
- Combobox,
11537
- {
11538
- options: salesChannels.options,
11539
- fetchNextPage: salesChannels.fetchNextPage,
11540
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
- searchValue: salesChannels.searchValue,
11542
- onSearchValueChange: salesChannels.onSearchValueChange,
11543
- placeholder: "Select sales channel",
11544
- ...field
11545
- }
11546
- ) }),
11547
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
- ] });
11549
- }
11550
- }
11551
- );
11552
- };
11553
- const schema$2 = objectType({
11554
- sales_channel_id: stringType().min(1)
11555
- });
11323
+ const SalesChannelField = ({ control, order }) => {
11324
+ const salesChannels = useComboboxData({
11325
+ queryFn: async (params) => {
11326
+ return await sdk.admin.salesChannel.list(params);
11327
+ },
11328
+ queryKey: ["sales-channels"],
11329
+ getOptions: (data) => {
11330
+ return data.sales_channels.map((salesChannel) => ({
11331
+ label: salesChannel.name,
11332
+ value: salesChannel.id
11333
+ }));
11334
+ },
11335
+ defaultValue: order.sales_channel_id || void 0
11336
+ });
11337
+ return /* @__PURE__ */ jsx(
11338
+ Form$2.Field,
11339
+ {
11340
+ control,
11341
+ name: "sales_channel_id",
11342
+ render: ({ field }) => {
11343
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11344
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11345
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11346
+ Combobox,
11347
+ {
11348
+ options: salesChannels.options,
11349
+ fetchNextPage: salesChannels.fetchNextPage,
11350
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11351
+ searchValue: salesChannels.searchValue,
11352
+ onSearchValueChange: salesChannels.onSearchValueChange,
11353
+ placeholder: "Select sales channel",
11354
+ ...field
11355
+ }
11356
+ ) }),
11357
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11358
+ ] });
11359
+ }
11360
+ }
11361
+ );
11362
+ };
11363
+ const schema$3 = objectType({
11364
+ sales_channel_id: stringType().min(1)
11365
+ });
11366
+ const ShippingAddress = () => {
11367
+ const { id } = useParams();
11368
+ const { order, isPending, isError, error } = useOrder(id, {
11369
+ fields: "+shipping_address"
11370
+ });
11371
+ if (isError) {
11372
+ throw error;
11373
+ }
11374
+ const isReady = !isPending && !!order;
11375
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11376
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11377
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11378
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11379
+ ] }),
11380
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11381
+ ] });
11382
+ };
11383
+ const ShippingAddressForm = ({ order }) => {
11384
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11385
+ const form = useForm({
11386
+ defaultValues: {
11387
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11388
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11389
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11390
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11391
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11392
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11393
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11394
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11395
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11396
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11397
+ },
11398
+ resolver: zodResolver(schema$2)
11399
+ });
11400
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11401
+ const { handleSuccess } = useRouteModal();
11402
+ const onSubmit = form.handleSubmit(async (data) => {
11403
+ await mutateAsync(
11404
+ {
11405
+ shipping_address: {
11406
+ first_name: data.first_name,
11407
+ last_name: data.last_name,
11408
+ company: data.company,
11409
+ address_1: data.address_1,
11410
+ address_2: data.address_2,
11411
+ city: data.city,
11412
+ province: data.province,
11413
+ country_code: data.country_code,
11414
+ postal_code: data.postal_code,
11415
+ phone: data.phone
11416
+ }
11417
+ },
11418
+ {
11419
+ onSuccess: () => {
11420
+ handleSuccess();
11421
+ },
11422
+ onError: (error) => {
11423
+ toast.error(error.message);
11424
+ }
11425
+ }
11426
+ );
11427
+ });
11428
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11429
+ KeyboundForm,
11430
+ {
11431
+ className: "flex flex-1 flex-col overflow-hidden",
11432
+ onSubmit,
11433
+ children: [
11434
+ /* @__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: [
11435
+ /* @__PURE__ */ jsx(
11436
+ Form$2.Field,
11437
+ {
11438
+ control: form.control,
11439
+ name: "country_code",
11440
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11441
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11442
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11443
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11444
+ ] })
11445
+ }
11446
+ ),
11447
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11448
+ /* @__PURE__ */ jsx(
11449
+ Form$2.Field,
11450
+ {
11451
+ control: form.control,
11452
+ name: "first_name",
11453
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11454
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11455
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11456
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11457
+ ] })
11458
+ }
11459
+ ),
11460
+ /* @__PURE__ */ jsx(
11461
+ Form$2.Field,
11462
+ {
11463
+ control: form.control,
11464
+ name: "last_name",
11465
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11466
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11467
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11468
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11469
+ ] })
11470
+ }
11471
+ )
11472
+ ] }),
11473
+ /* @__PURE__ */ jsx(
11474
+ Form$2.Field,
11475
+ {
11476
+ control: form.control,
11477
+ name: "company",
11478
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11479
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11480
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11481
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11482
+ ] })
11483
+ }
11484
+ ),
11485
+ /* @__PURE__ */ jsx(
11486
+ Form$2.Field,
11487
+ {
11488
+ control: form.control,
11489
+ name: "address_1",
11490
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11491
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11492
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11493
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11494
+ ] })
11495
+ }
11496
+ ),
11497
+ /* @__PURE__ */ jsx(
11498
+ Form$2.Field,
11499
+ {
11500
+ control: form.control,
11501
+ name: "address_2",
11502
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11503
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11504
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11505
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11506
+ ] })
11507
+ }
11508
+ ),
11509
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11510
+ /* @__PURE__ */ jsx(
11511
+ Form$2.Field,
11512
+ {
11513
+ control: form.control,
11514
+ name: "postal_code",
11515
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11516
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11517
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11518
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11519
+ ] })
11520
+ }
11521
+ ),
11522
+ /* @__PURE__ */ jsx(
11523
+ Form$2.Field,
11524
+ {
11525
+ control: form.control,
11526
+ name: "city",
11527
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11528
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11529
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11530
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11531
+ ] })
11532
+ }
11533
+ )
11534
+ ] }),
11535
+ /* @__PURE__ */ jsx(
11536
+ Form$2.Field,
11537
+ {
11538
+ control: form.control,
11539
+ name: "province",
11540
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11541
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11542
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11543
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11544
+ ] })
11545
+ }
11546
+ ),
11547
+ /* @__PURE__ */ jsx(
11548
+ Form$2.Field,
11549
+ {
11550
+ control: form.control,
11551
+ name: "phone",
11552
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11553
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11554
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11555
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11556
+ ] })
11557
+ }
11558
+ )
11559
+ ] }) }),
11560
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11561
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11562
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11563
+ ] }) })
11564
+ ]
11565
+ }
11566
+ ) });
11567
+ };
11568
+ const schema$2 = addressSchema;
11556
11569
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
11570
  const Shipping = () => {
11558
11571
  var _a;
@@ -12343,226 +12356,23 @@ const CustomAmountField = ({
12343
12356
  render: ({ field: { onChange, ...field } }) => {
12344
12357
  return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
12358
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12348
- ] }),
12349
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
- CurrencyInput,
12351
- {
12352
- ...field,
12353
- onValueChange: (value) => onChange(value),
12354
- symbol: getNativeSymbol(currencyCode),
12355
- code: currencyCode
12356
- }
12357
- ) })
12358
- ] });
12359
- }
12360
- }
12361
- );
12362
- };
12363
- const ShippingAddress = () => {
12364
- const { id } = useParams();
12365
- const { order, isPending, isError, error } = useOrder(id, {
12366
- fields: "+shipping_address"
12367
- });
12368
- if (isError) {
12369
- throw error;
12370
- }
12371
- const isReady = !isPending && !!order;
12372
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12373
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12374
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12376
- ] }),
12377
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12378
- ] });
12379
- };
12380
- const ShippingAddressForm = ({ order }) => {
12381
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12382
- const form = useForm({
12383
- defaultValues: {
12384
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
- },
12395
- resolver: zodResolver(schema$1)
12396
- });
12397
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
- const { handleSuccess } = useRouteModal();
12399
- const onSubmit = form.handleSubmit(async (data) => {
12400
- await mutateAsync(
12401
- {
12402
- shipping_address: {
12403
- first_name: data.first_name,
12404
- last_name: data.last_name,
12405
- company: data.company,
12406
- address_1: data.address_1,
12407
- address_2: data.address_2,
12408
- city: data.city,
12409
- province: data.province,
12410
- country_code: data.country_code,
12411
- postal_code: data.postal_code,
12412
- phone: data.phone
12413
- }
12414
- },
12415
- {
12416
- onSuccess: () => {
12417
- handleSuccess();
12418
- },
12419
- onError: (error) => {
12420
- toast.error(error.message);
12421
- }
12422
- }
12423
- );
12424
- });
12425
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12426
- KeyboundForm,
12427
- {
12428
- className: "flex flex-1 flex-col overflow-hidden",
12429
- onSubmit,
12430
- children: [
12431
- /* @__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: [
12432
- /* @__PURE__ */ jsx(
12433
- Form$2.Field,
12434
- {
12435
- control: form.control,
12436
- name: "country_code",
12437
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
- ] })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
- /* @__PURE__ */ jsx(
12446
- Form$2.Field,
12447
- {
12448
- control: form.control,
12449
- name: "first_name",
12450
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
- ] })
12455
- }
12456
- ),
12457
- /* @__PURE__ */ jsx(
12458
- Form$2.Field,
12459
- {
12460
- control: form.control,
12461
- name: "last_name",
12462
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
- ] })
12467
- }
12468
- )
12469
- ] }),
12470
- /* @__PURE__ */ jsx(
12471
- Form$2.Field,
12472
- {
12473
- control: form.control,
12474
- name: "company",
12475
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
- ] })
12480
- }
12481
- ),
12482
- /* @__PURE__ */ jsx(
12483
- Form$2.Field,
12484
- {
12485
- control: form.control,
12486
- name: "address_1",
12487
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
- ] })
12492
- }
12493
- ),
12494
- /* @__PURE__ */ jsx(
12495
- Form$2.Field,
12496
- {
12497
- control: form.control,
12498
- name: "address_2",
12499
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
- ] })
12504
- }
12505
- ),
12506
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
- /* @__PURE__ */ jsx(
12508
- Form$2.Field,
12509
- {
12510
- control: form.control,
12511
- name: "postal_code",
12512
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
- ] })
12517
- }
12518
- ),
12519
- /* @__PURE__ */ jsx(
12520
- Form$2.Field,
12521
- {
12522
- control: form.control,
12523
- name: "city",
12524
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
- ] })
12529
- }
12530
- )
12359
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12360
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12531
12361
  ] }),
12532
- /* @__PURE__ */ jsx(
12533
- Form$2.Field,
12534
- {
12535
- control: form.control,
12536
- name: "province",
12537
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
- ] })
12542
- }
12543
- ),
12544
- /* @__PURE__ */ jsx(
12545
- Form$2.Field,
12362
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12363
+ CurrencyInput,
12546
12364
  {
12547
- control: form.control,
12548
- name: "phone",
12549
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
- ] })
12365
+ ...field,
12366
+ onValueChange: (value) => onChange(value),
12367
+ symbol: getNativeSymbol(currencyCode),
12368
+ code: currencyCode
12554
12369
  }
12555
- )
12556
- ] }) }),
12557
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
- ] }) })
12561
- ]
12370
+ ) })
12371
+ ] });
12372
+ }
12562
12373
  }
12563
- ) });
12374
+ );
12564
12375
  };
12565
- const schema$1 = 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: Items,
13076
- path: "/draft-orders/:id/items"
13077
- },
13078
13070
  {
13079
13071
  Component: Metadata,
13080
13072
  path: "/draft-orders/:id/metadata"
13081
13073
  },
13074
+ {
13075
+ Component: Items,
13076
+ path: "/draft-orders/:id/items"
13077
+ },
13082
13078
  {
13083
13079
  Component: Promotions,
13084
13080
  path: "/draft-orders/:id/promotions"
@@ -13087,17 +13083,21 @@ const routeModule = {
13087
13083
  Component: SalesChannel,
13088
13084
  path: "/draft-orders/:id/sales-channel"
13089
13085
  },
13090
- {
13091
- Component: Shipping,
13092
- path: "/draft-orders/:id/shipping"
13093
- },
13094
13086
  {
13095
13087
  Component: ShippingAddress,
13096
13088
  path: "/draft-orders/:id/shipping-address"
13097
13089
  },
13090
+ {
13091
+ Component: Shipping,
13092
+ path: "/draft-orders/:id/shipping"
13093
+ },
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
  }