@medusajs/draft-order 2.14.1 → 2.14.2-preview-20260426063241

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.
@@ -9899,196 +9899,6 @@ const ID = () => {
9899
9899
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9900
9900
  ] });
9901
9901
  };
9902
- const BillingAddress = () => {
9903
- const { id } = reactRouterDom.useParams();
9904
- const { order, isPending, isError, error } = useOrder(id, {
9905
- fields: "+billing_address"
9906
- });
9907
- if (isError) {
9908
- throw error;
9909
- }
9910
- const isReady = !isPending && !!order;
9911
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9912
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9913
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9914
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9915
- ] }),
9916
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9917
- ] });
9918
- };
9919
- const BillingAddressForm = ({ order }) => {
9920
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9921
- const form = reactHookForm.useForm({
9922
- defaultValues: {
9923
- first_name: ((_a2 = order.billing_address) == null ? void 0 : _a2.first_name) ?? "",
9924
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9925
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9926
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9927
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9928
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9929
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9930
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9931
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9932
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9933
- },
9934
- resolver: zod.zodResolver(schema$5)
9935
- });
9936
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9937
- const { handleSuccess } = useRouteModal();
9938
- const onSubmit = form.handleSubmit(async (data) => {
9939
- await mutateAsync(
9940
- { billing_address: data },
9941
- {
9942
- onSuccess: () => {
9943
- handleSuccess();
9944
- },
9945
- onError: (error) => {
9946
- ui.toast.error(error.message);
9947
- }
9948
- }
9949
- );
9950
- });
9951
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9952
- KeyboundForm,
9953
- {
9954
- className: "flex flex-1 flex-col overflow-hidden",
9955
- onSubmit,
9956
- children: [
9957
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9958
- /* @__PURE__ */ jsxRuntime.jsx(
9959
- Form$2.Field,
9960
- {
9961
- control: form.control,
9962
- name: "country_code",
9963
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9964
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9965
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9966
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9967
- ] })
9968
- }
9969
- ),
9970
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9971
- /* @__PURE__ */ jsxRuntime.jsx(
9972
- Form$2.Field,
9973
- {
9974
- control: form.control,
9975
- name: "first_name",
9976
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9977
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9978
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9979
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9980
- ] })
9981
- }
9982
- ),
9983
- /* @__PURE__ */ jsxRuntime.jsx(
9984
- Form$2.Field,
9985
- {
9986
- control: form.control,
9987
- name: "last_name",
9988
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9989
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9990
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9992
- ] })
9993
- }
9994
- )
9995
- ] }),
9996
- /* @__PURE__ */ jsxRuntime.jsx(
9997
- Form$2.Field,
9998
- {
9999
- control: form.control,
10000
- name: "company",
10001
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10002
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
10003
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10004
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10005
- ] })
10006
- }
10007
- ),
10008
- /* @__PURE__ */ jsxRuntime.jsx(
10009
- Form$2.Field,
10010
- {
10011
- control: form.control,
10012
- name: "address_1",
10013
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10014
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
10015
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10016
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10017
- ] })
10018
- }
10019
- ),
10020
- /* @__PURE__ */ jsxRuntime.jsx(
10021
- Form$2.Field,
10022
- {
10023
- control: form.control,
10024
- name: "address_2",
10025
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10028
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10029
- ] })
10030
- }
10031
- ),
10032
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10033
- /* @__PURE__ */ jsxRuntime.jsx(
10034
- Form$2.Field,
10035
- {
10036
- control: form.control,
10037
- name: "postal_code",
10038
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10039
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
10040
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10041
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10042
- ] })
10043
- }
10044
- ),
10045
- /* @__PURE__ */ jsxRuntime.jsx(
10046
- Form$2.Field,
10047
- {
10048
- control: form.control,
10049
- name: "city",
10050
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10051
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
10052
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10053
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10054
- ] })
10055
- }
10056
- )
10057
- ] }),
10058
- /* @__PURE__ */ jsxRuntime.jsx(
10059
- Form$2.Field,
10060
- {
10061
- control: form.control,
10062
- name: "province",
10063
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10064
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10065
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10066
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10067
- ] })
10068
- }
10069
- ),
10070
- /* @__PURE__ */ jsxRuntime.jsx(
10071
- Form$2.Field,
10072
- {
10073
- control: form.control,
10074
- name: "phone",
10075
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10076
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
10077
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10078
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10079
- ] })
10080
- }
10081
- )
10082
- ] }) }),
10083
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10084
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10085
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10086
- ] }) })
10087
- ]
10088
- }
10089
- ) });
10090
- };
10091
- const schema$5 = addressSchema;
10092
9902
  const CustomItems = () => {
10093
9903
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10094
9904
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -10097,7 +9907,7 @@ const CustomItems = () => {
10097
9907
  };
10098
9908
  const CustomItemsForm = () => {
10099
9909
  const form = reactHookForm.useForm({
10100
- resolver: zod.zodResolver(schema$4)
9910
+ resolver: zod.zodResolver(schema$5)
10101
9911
  });
10102
9912
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10103
9913
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -10107,7 +9917,7 @@ const CustomItemsForm = () => {
10107
9917
  ] }) })
10108
9918
  ] }) });
10109
9919
  };
10110
- const schema$4 = object({
9920
+ const schema$5 = object({
10111
9921
  email: string().email()
10112
9922
  });
10113
9923
  const Email = () => {
@@ -10132,7 +9942,7 @@ const EmailForm = ({ order }) => {
10132
9942
  defaultValues: {
10133
9943
  email: order.email ?? ""
10134
9944
  },
10135
- resolver: zod.zodResolver(schema$3)
9945
+ resolver: zod.zodResolver(schema$4)
10136
9946
  });
10137
9947
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10138
9948
  const { handleSuccess } = useRouteModal();
@@ -10175,7 +9985,7 @@ const EmailForm = ({ order }) => {
10175
9985
  }
10176
9986
  ) });
10177
9987
  };
10178
- const schema$3 = object({
9988
+ const schema$4 = object({
10179
9989
  email: string().email()
10180
9990
  });
10181
9991
  const NumberInput = React.forwardRef(
@@ -11807,7 +11617,7 @@ const SalesChannelForm = ({ order }) => {
11807
11617
  defaultValues: {
11808
11618
  sales_channel_id: order.sales_channel_id || ""
11809
11619
  },
11810
- resolver: zod.zodResolver(schema$2)
11620
+ resolver: zod.zodResolver(schema$3)
11811
11621
  });
11812
11622
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11813
11623
  const { handleSuccess } = useRouteModal();
@@ -11882,1495 +11692,1685 @@ const SalesChannelField = ({ control, order }) => {
11882
11692
  }
11883
11693
  );
11884
11694
  };
11885
- const schema$2 = object({
11695
+ const schema$3 = object({
11886
11696
  sales_channel_id: string().min(1)
11887
11697
  });
11888
- const ShippingAddress = () => {
11698
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11699
+ const Shipping = () => {
11700
+ var _a2;
11889
11701
  const { id } = reactRouterDom.useParams();
11890
11702
  const { order, isPending, isError, error } = useOrder(id, {
11891
- fields: "+shipping_address"
11703
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11892
11704
  });
11705
+ const {
11706
+ order: preview,
11707
+ isPending: isPreviewPending,
11708
+ isError: isPreviewError,
11709
+ error: previewError
11710
+ } = useOrderPreview(id);
11711
+ useInitiateOrderEdit({ preview });
11712
+ const { onCancel } = useCancelOrderEdit({ preview });
11893
11713
  if (isError) {
11894
11714
  throw error;
11895
11715
  }
11896
- const isReady = !isPending && !!order;
11897
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11898
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11899
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11900
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11901
- ] }),
11902
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11903
- ] });
11716
+ if (isPreviewError) {
11717
+ throw previewError;
11718
+ }
11719
+ const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
11720
+ const isReady = preview && !isPreviewPending && order && !isPending;
11721
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11722
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11723
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11724
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11725
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11726
+ ] }) }) }),
11727
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11728
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11729
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11730
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11731
+ ] }) });
11904
11732
  };
11905
- const ShippingAddressForm = ({ order }) => {
11906
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11907
- const form = reactHookForm.useForm({
11908
- defaultValues: {
11909
- first_name: ((_a2 = order.shipping_address) == null ? void 0 : _a2.first_name) ?? "",
11910
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11911
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11912
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11913
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11914
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11915
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11916
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11917
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11918
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11919
- },
11920
- resolver: zod.zodResolver(schema$1)
11921
- });
11922
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11923
- const { handleSuccess } = useRouteModal();
11924
- const onSubmit = form.handleSubmit(async (data) => {
11925
- await mutateAsync(
11926
- {
11927
- shipping_address: {
11928
- first_name: data.first_name,
11929
- last_name: data.last_name,
11930
- company: data.company,
11931
- address_1: data.address_1,
11932
- address_2: data.address_2,
11933
- city: data.city,
11934
- province: data.province,
11935
- country_code: data.country_code,
11936
- postal_code: data.postal_code,
11937
- phone: data.phone
11938
- }
11733
+ const ShippingForm = ({ preview, order }) => {
11734
+ var _a2;
11735
+ const { setIsOpen } = useStackedModal();
11736
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11737
+ const [data, setData] = React.useState(null);
11738
+ const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
11739
+ const { shipping_options } = useShippingOptions(
11740
+ {
11741
+ id: appliedShippingOptionIds,
11742
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11743
+ },
11744
+ {
11745
+ enabled: appliedShippingOptionIds.length > 0
11746
+ }
11747
+ );
11748
+ const uniqueShippingProfiles = React.useMemo(() => {
11749
+ const profiles = /* @__PURE__ */ new Map();
11750
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11751
+ profiles.set(profile.id, profile);
11752
+ });
11753
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11754
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11755
+ });
11756
+ return Array.from(profiles.values());
11757
+ }, [order.items, shipping_options]);
11758
+ const { handleSuccess } = useRouteModal();
11759
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11760
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11761
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11762
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11763
+ const onSubmit = async () => {
11764
+ setIsSubmitting(true);
11765
+ let requestSucceeded = false;
11766
+ await requestOrderEdit(void 0, {
11767
+ onError: (e) => {
11768
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11939
11769
  },
11940
- {
11941
- onSuccess: () => {
11942
- handleSuccess();
11943
- },
11944
- onError: (error) => {
11945
- ui.toast.error(error.message);
11770
+ onSuccess: () => {
11771
+ requestSucceeded = true;
11772
+ }
11773
+ });
11774
+ if (!requestSucceeded) {
11775
+ setIsSubmitting(false);
11776
+ return;
11777
+ }
11778
+ await confirmOrderEdit(void 0, {
11779
+ onError: (e) => {
11780
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11781
+ },
11782
+ onSuccess: () => {
11783
+ handleSuccess();
11784
+ },
11785
+ onSettled: () => {
11786
+ setIsSubmitting(false);
11787
+ }
11788
+ });
11789
+ };
11790
+ const onKeydown = React.useCallback(
11791
+ (e) => {
11792
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11793
+ if (data || isSubmitting) {
11794
+ return;
11946
11795
  }
11796
+ onSubmit();
11947
11797
  }
11948
- );
11949
- });
11950
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11951
- KeyboundForm,
11952
- {
11953
- className: "flex flex-1 flex-col overflow-hidden",
11954
- onSubmit,
11955
- children: [
11956
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11957
- /* @__PURE__ */ jsxRuntime.jsx(
11958
- Form$2.Field,
11959
- {
11960
- control: form.control,
11961
- name: "country_code",
11962
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11963
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11964
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11965
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11966
- ] })
11967
- }
11968
- ),
11969
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11798
+ },
11799
+ [data, isSubmitting, onSubmit]
11800
+ );
11801
+ React.useEffect(() => {
11802
+ document.addEventListener("keydown", onKeydown);
11803
+ return () => {
11804
+ document.removeEventListener("keydown", onKeydown);
11805
+ };
11806
+ }, [onKeydown]);
11807
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11808
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11809
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11810
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11811
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11812
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11813
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11814
+ ] }),
11815
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11816
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11817
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11970
11818
  /* @__PURE__ */ jsxRuntime.jsx(
11971
- Form$2.Field,
11819
+ ui.Text,
11972
11820
  {
11973
- control: form.control,
11974
- name: "first_name",
11975
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11976
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11977
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11978
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11979
- ] })
11821
+ size: "xsmall",
11822
+ weight: "plus",
11823
+ className: "text-ui-fg-muted",
11824
+ children: "Shipping profile"
11980
11825
  }
11981
11826
  ),
11982
11827
  /* @__PURE__ */ jsxRuntime.jsx(
11983
- Form$2.Field,
11828
+ ui.Text,
11984
11829
  {
11985
- control: form.control,
11986
- name: "last_name",
11987
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11988
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11989
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11990
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11991
- ] })
11830
+ size: "xsmall",
11831
+ weight: "plus",
11832
+ className: "text-ui-fg-muted",
11833
+ children: "Action"
11992
11834
  }
11993
11835
  )
11994
11836
  ] }),
11995
- /* @__PURE__ */ jsxRuntime.jsx(
11996
- Form$2.Field,
11997
- {
11998
- control: form.control,
11999
- name: "company",
12000
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12001
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12002
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12003
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12004
- ] })
12005
- }
12006
- ),
12007
- /* @__PURE__ */ jsxRuntime.jsx(
12008
- Form$2.Field,
12009
- {
12010
- control: form.control,
12011
- name: "address_1",
12012
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12013
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12014
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12015
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12016
- ] })
12017
- }
12018
- ),
12019
- /* @__PURE__ */ jsxRuntime.jsx(
12020
- Form$2.Field,
12021
- {
12022
- control: form.control,
12023
- name: "address_2",
12024
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12028
- ] })
12029
- }
12030
- ),
12031
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12032
- /* @__PURE__ */ jsxRuntime.jsx(
12033
- Form$2.Field,
12034
- {
12035
- control: form.control,
12036
- name: "postal_code",
12037
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12038
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12039
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12040
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12041
- ] })
12042
- }
12043
- ),
12044
- /* @__PURE__ */ jsxRuntime.jsx(
12045
- Form$2.Field,
11837
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11838
+ var _a3, _b, _c, _d, _e, _f, _g;
11839
+ const items = getItemsWithShippingProfile(
11840
+ profile.id,
11841
+ order.items
11842
+ );
11843
+ const hasItems = items.length > 0;
11844
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11845
+ (option) => option.shipping_profile_id === profile.id
11846
+ );
11847
+ const shippingMethod = preview.shipping_methods.find(
11848
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11849
+ );
11850
+ const addShippingMethodAction = (_a3 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a3.find(
11851
+ (action) => action.action === "SHIPPING_ADD"
11852
+ );
11853
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11854
+ radixUi.Accordion.Item,
12046
11855
  {
12047
- control: form.control,
12048
- name: "city",
12049
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12050
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12051
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12052
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12053
- ] })
12054
- }
12055
- )
12056
- ] }),
12057
- /* @__PURE__ */ jsxRuntime.jsx(
12058
- Form$2.Field,
12059
- {
12060
- control: form.control,
12061
- name: "province",
12062
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12063
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12064
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12065
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12066
- ] })
12067
- }
12068
- ),
12069
- /* @__PURE__ */ jsxRuntime.jsx(
12070
- Form$2.Field,
12071
- {
12072
- control: form.control,
12073
- name: "phone",
12074
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12075
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12076
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12077
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12078
- ] })
12079
- }
12080
- )
12081
- ] }) }),
12082
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12083
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12084
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11856
+ value: profile.id,
11857
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11858
+ children: [
11859
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11860
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11861
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11862
+ ui.IconButton,
11863
+ {
11864
+ size: "2xsmall",
11865
+ variant: "transparent",
11866
+ className: "group/trigger",
11867
+ disabled: !hasItems,
11868
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11869
+ }
11870
+ ) }),
11871
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11872
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11873
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
11874
+ /* @__PURE__ */ jsxRuntime.jsx(
11875
+ ui.Text,
11876
+ {
11877
+ size: "small",
11878
+ weight: "plus",
11879
+ leading: "compact",
11880
+ children: profile.name
11881
+ }
11882
+ ),
11883
+ /* @__PURE__ */ jsxRuntime.jsxs(
11884
+ ui.Text,
11885
+ {
11886
+ size: "small",
11887
+ leading: "compact",
11888
+ className: "text-ui-fg-subtle",
11889
+ children: [
11890
+ items.length,
11891
+ " ",
11892
+ pluralize(items.length, "items", "item")
11893
+ ]
11894
+ }
11895
+ )
11896
+ ] })
11897
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11898
+ /* @__PURE__ */ jsxRuntime.jsx(
11899
+ ui.Tooltip,
11900
+ {
11901
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11902
+ var _a4, _b2, _c2;
11903
+ return /* @__PURE__ */ jsxRuntime.jsx(
11904
+ "li",
11905
+ {
11906
+ children: `${item.quantity}x ${(_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11907
+ },
11908
+ item.id
11909
+ );
11910
+ }) }),
11911
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11912
+ ui.Badge,
11913
+ {
11914
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11915
+ size: "xsmall",
11916
+ children: [
11917
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11918
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11919
+ items.reduce(
11920
+ (acc, item) => acc + item.quantity,
11921
+ 0
11922
+ ),
11923
+ "x",
11924
+ " ",
11925
+ pluralize(items.length, "items", "item")
11926
+ ] })
11927
+ ]
11928
+ }
11929
+ )
11930
+ }
11931
+ ),
11932
+ /* @__PURE__ */ jsxRuntime.jsx(
11933
+ ui.Tooltip,
11934
+ {
11935
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11936
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11937
+ ui.Badge,
11938
+ {
11939
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11940
+ size: "xsmall",
11941
+ children: [
11942
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11943
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11944
+ ]
11945
+ }
11946
+ )
11947
+ }
11948
+ ),
11949
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11950
+ ui.Badge,
11951
+ {
11952
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11953
+ size: "xsmall",
11954
+ children: [
11955
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11956
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11957
+ ]
11958
+ }
11959
+ ) })
11960
+ ] })
11961
+ ] }),
11962
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11963
+ ActionMenu,
11964
+ {
11965
+ groups: [
11966
+ {
11967
+ actions: [
11968
+ hasItems ? {
11969
+ label: "Edit shipping option",
11970
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11971
+ onClick: () => {
11972
+ setIsOpen(
11973
+ STACKED_FOCUS_MODAL_ID,
11974
+ true
11975
+ );
11976
+ setData({
11977
+ shippingProfileId: profile.id,
11978
+ shippingOption,
11979
+ shippingMethod
11980
+ });
11981
+ }
11982
+ } : void 0,
11983
+ {
11984
+ label: "Remove shipping option",
11985
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11986
+ onClick: () => {
11987
+ if (shippingMethod) {
11988
+ if (addShippingMethodAction) {
11989
+ removeActionShippingMethod(
11990
+ addShippingMethodAction.id
11991
+ );
11992
+ } else {
11993
+ removeShippingMethod(
11994
+ shippingMethod.id
11995
+ );
11996
+ }
11997
+ }
11998
+ }
11999
+ }
12000
+ ].filter(Boolean)
12001
+ }
12002
+ ]
12003
+ }
12004
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12005
+ StackedModalTrigger,
12006
+ {
12007
+ shippingProfileId: profile.id,
12008
+ shippingOption,
12009
+ shippingMethod,
12010
+ setData,
12011
+ children: "Add shipping option"
12012
+ }
12013
+ )
12014
+ ] }),
12015
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12016
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12017
+ items.map((item, idx) => {
12018
+ var _a4, _b2, _c2, _d2, _e2;
12019
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12020
+ /* @__PURE__ */ jsxRuntime.jsxs(
12021
+ "div",
12022
+ {
12023
+ className: "flex items-center gap-x-3 px-3",
12024
+ children: [
12025
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12026
+ ui.Divider,
12027
+ {
12028
+ variant: "dashed",
12029
+ orientation: "vertical"
12030
+ }
12031
+ ) }),
12032
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12033
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12034
+ ui.Text,
12035
+ {
12036
+ size: "small",
12037
+ leading: "compact",
12038
+ className: "text-ui-fg-subtle",
12039
+ children: [
12040
+ item.quantity,
12041
+ "x"
12042
+ ]
12043
+ }
12044
+ ) }),
12045
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12046
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12047
+ /* @__PURE__ */ jsxRuntime.jsxs(
12048
+ ui.Text,
12049
+ {
12050
+ size: "small",
12051
+ leading: "compact",
12052
+ weight: "plus",
12053
+ children: [
12054
+ (_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title,
12055
+ " (",
12056
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12057
+ ")"
12058
+ ]
12059
+ }
12060
+ ),
12061
+ /* @__PURE__ */ jsxRuntime.jsx(
12062
+ ui.Text,
12063
+ {
12064
+ size: "small",
12065
+ leading: "compact",
12066
+ className: "text-ui-fg-subtle",
12067
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12068
+ }
12069
+ )
12070
+ ] })
12071
+ ] })
12072
+ ]
12073
+ },
12074
+ item.id
12075
+ ),
12076
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12077
+ ] }, item.id);
12078
+ })
12079
+ ] })
12080
+ ]
12081
+ },
12082
+ profile.id
12083
+ );
12084
+ }) })
12085
12085
  ] }) })
12086
- ]
12087
- }
12088
- ) });
12089
- };
12090
- const schema$1 = addressSchema;
12091
- const TransferOwnership = () => {
12092
- const { id } = reactRouterDom.useParams();
12093
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12094
- fields: "id,customer_id,customer.*"
12095
- });
12096
- if (isError) {
12097
- throw error;
12098
- }
12099
- const isReady = !isPending && !!draft_order;
12100
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12101
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12102
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12103
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12104
- ] }),
12105
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12106
- ] });
12107
- };
12108
- const TransferOwnershipForm = ({ order }) => {
12109
- var _a2, _b;
12110
- const form = reactHookForm.useForm({
12111
- defaultValues: {
12112
- customer_id: order.customer_id || ""
12113
- },
12114
- resolver: zod.zodResolver(schema)
12086
+ ] }) }),
12087
+ /* @__PURE__ */ jsxRuntime.jsx(
12088
+ StackedFocusModal,
12089
+ {
12090
+ id: STACKED_FOCUS_MODAL_ID,
12091
+ onOpenChangeCallback: (open) => {
12092
+ if (!open) {
12093
+ setData(null);
12094
+ }
12095
+ return open;
12096
+ },
12097
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12098
+ }
12099
+ )
12100
+ ] }),
12101
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12102
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12103
+ /* @__PURE__ */ jsxRuntime.jsx(
12104
+ ui.Button,
12105
+ {
12106
+ size: "small",
12107
+ type: "button",
12108
+ isLoading: isSubmitting,
12109
+ onClick: onSubmit,
12110
+ children: "Save"
12111
+ }
12112
+ )
12113
+ ] }) })
12114
+ ] });
12115
+ };
12116
+ const StackedModalTrigger = ({
12117
+ shippingProfileId,
12118
+ shippingOption,
12119
+ shippingMethod,
12120
+ setData,
12121
+ children
12122
+ }) => {
12123
+ const { setIsOpen, getIsOpen } = useStackedModal();
12124
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12125
+ const onToggle = () => {
12126
+ if (isOpen) {
12127
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12128
+ setData(null);
12129
+ } else {
12130
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12131
+ setData({
12132
+ shippingProfileId,
12133
+ shippingOption,
12134
+ shippingMethod
12135
+ });
12136
+ }
12137
+ };
12138
+ return /* @__PURE__ */ jsxRuntime.jsx(
12139
+ ui.Button,
12140
+ {
12141
+ size: "small",
12142
+ variant: "secondary",
12143
+ onClick: onToggle,
12144
+ className: "text-ui-fg-primary shrink-0",
12145
+ children
12146
+ }
12147
+ );
12148
+ };
12149
+ const ShippingProfileForm = ({
12150
+ data,
12151
+ order,
12152
+ preview
12153
+ }) => {
12154
+ var _a2, _b, _c, _d, _e, _f;
12155
+ const { setIsOpen } = useStackedModal();
12156
+ const form = reactHookForm.useForm({
12157
+ resolver: zod.zodResolver(shippingMethodSchema),
12158
+ defaultValues: {
12159
+ location_id: (_d = (_c = (_b = (_a2 = data.shippingOption) == null ? void 0 : _a2.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12160
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12161
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12162
+ }
12115
12163
  });
12116
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12117
- const { handleSuccess } = useRouteModal();
12118
- const name = [(_a2 = order.customer) == null ? void 0 : _a2.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12119
- const currentCustomer = order.customer ? {
12120
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12121
- value: order.customer.id
12122
- } : null;
12123
- const onSubmit = form.handleSubmit(async (data) => {
12124
- await mutateAsync(
12125
- { customer_id: data.customer_id },
12164
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12165
+ const {
12166
+ mutateAsync: updateShippingMethod,
12167
+ isPending: isUpdatingShippingMethod
12168
+ } = useDraftOrderUpdateShippingMethod(order.id);
12169
+ const onSubmit = form.handleSubmit(async (values) => {
12170
+ if (isEqual__default.default(values, form.formState.defaultValues)) {
12171
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12172
+ return;
12173
+ }
12174
+ if (data.shippingMethod) {
12175
+ await updateShippingMethod(
12176
+ {
12177
+ method_id: data.shippingMethod.id,
12178
+ shipping_option_id: values.shipping_option_id,
12179
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12180
+ },
12181
+ {
12182
+ onError: (e) => {
12183
+ ui.toast.error(e.message);
12184
+ },
12185
+ onSuccess: () => {
12186
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12187
+ }
12188
+ }
12189
+ );
12190
+ return;
12191
+ }
12192
+ await addShippingMethod(
12126
12193
  {
12127
- onSuccess: () => {
12128
- ui.toast.success("Customer updated");
12129
- handleSuccess();
12194
+ shipping_option_id: values.shipping_option_id,
12195
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12196
+ },
12197
+ {
12198
+ onError: (e) => {
12199
+ ui.toast.error(e.message);
12130
12200
  },
12131
- onError: (error) => {
12132
- ui.toast.error(error.message);
12201
+ onSuccess: () => {
12202
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12133
12203
  }
12134
12204
  }
12135
12205
  );
12136
12206
  });
12137
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12207
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12138
12208
  KeyboundForm,
12139
12209
  {
12140
- className: "flex flex-1 flex-col overflow-hidden",
12210
+ className: "flex h-full flex-col overflow-hidden",
12141
12211
  onSubmit,
12142
12212
  children: [
12143
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12144
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12145
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12146
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12147
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12148
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12149
- ] }),
12150
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12151
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12152
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12153
- ] })
12213
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12214
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12215
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12216
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12217
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12154
12218
  ] }),
12219
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12155
12220
  /* @__PURE__ */ jsxRuntime.jsx(
12156
- CustomerField,
12221
+ LocationField,
12157
12222
  {
12158
12223
  control: form.control,
12159
- currentCustomerId: order.customer_id
12224
+ setValue: form.setValue
12225
+ }
12226
+ ),
12227
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12228
+ /* @__PURE__ */ jsxRuntime.jsx(
12229
+ ShippingOptionField,
12230
+ {
12231
+ shippingProfileId: data.shippingProfileId,
12232
+ preview,
12233
+ control: form.control
12234
+ }
12235
+ ),
12236
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12237
+ /* @__PURE__ */ jsxRuntime.jsx(
12238
+ CustomAmountField,
12239
+ {
12240
+ control: form.control,
12241
+ currencyCode: order.currency_code
12242
+ }
12243
+ ),
12244
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12245
+ /* @__PURE__ */ jsxRuntime.jsx(
12246
+ ItemsPreview,
12247
+ {
12248
+ order,
12249
+ shippingProfileId: data.shippingProfileId
12250
+ }
12251
+ )
12252
+ ] }) }) }),
12253
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12254
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12255
+ /* @__PURE__ */ jsxRuntime.jsx(
12256
+ ui.Button,
12257
+ {
12258
+ size: "small",
12259
+ type: "submit",
12260
+ isLoading: isPending || isUpdatingShippingMethod,
12261
+ children: data.shippingMethod ? "Update" : "Add"
12160
12262
  }
12161
12263
  )
12162
- ] }),
12163
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12164
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12165
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12166
12264
  ] }) })
12167
12265
  ]
12168
12266
  }
12169
- ) });
12267
+ ) }) });
12170
12268
  };
12171
- const CustomerField = ({ control, currentCustomerId }) => {
12172
- const customers = useComboboxData({
12173
- queryFn: async (params) => {
12174
- return await sdk.admin.customer.list({
12175
- ...params,
12176
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12177
- });
12178
- },
12179
- queryKey: ["customers"],
12180
- getOptions: (data) => {
12181
- return data.customers.map((customer) => {
12182
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12183
- return {
12184
- label: name ? `${name} (${customer.email})` : customer.email,
12185
- value: customer.id
12186
- };
12187
- });
12188
- }
12189
- });
12190
- return /* @__PURE__ */ jsxRuntime.jsx(
12191
- Form$2.Field,
12192
- {
12193
- name: "customer_id",
12194
- control,
12195
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12196
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12197
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12198
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12199
- ] }),
12200
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12201
- Combobox,
12202
- {
12203
- options: customers.options,
12204
- fetchNextPage: customers.fetchNextPage,
12205
- isFetchingNextPage: customers.isFetchingNextPage,
12206
- searchValue: customers.searchValue,
12207
- onSearchValueChange: customers.onSearchValueChange,
12208
- placeholder: "Select customer",
12209
- ...field
12210
- }
12211
- ) }),
12212
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12213
- ] })
12269
+ const shippingMethodSchema = object({
12270
+ location_id: string(),
12271
+ shipping_option_id: string(),
12272
+ custom_amount: union([number(), string()]).optional()
12273
+ });
12274
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12275
+ const matches = order.items.filter(
12276
+ (item) => {
12277
+ var _a2, _b, _c;
12278
+ return ((_c = (_b = (_a2 = item.variant) == null ? void 0 : _a2.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12214
12279
  }
12215
12280
  );
12216
- };
12217
- const Illustration = () => {
12218
- return /* @__PURE__ */ jsxRuntime.jsxs(
12219
- "svg",
12281
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12282
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12283
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12284
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12285
+ ] }) }),
12286
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12287
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12288
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12289
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12290
+ ] }),
12291
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12292
+ "div",
12293
+ {
12294
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12295
+ children: [
12296
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12297
+ /* @__PURE__ */ jsxRuntime.jsx(
12298
+ Thumbnail,
12299
+ {
12300
+ thumbnail: item.thumbnail,
12301
+ alt: item.product_title ?? void 0
12302
+ }
12303
+ ),
12304
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12305
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12306
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12307
+ /* @__PURE__ */ jsxRuntime.jsxs(
12308
+ ui.Text,
12309
+ {
12310
+ size: "small",
12311
+ leading: "compact",
12312
+ className: "text-ui-fg-subtle",
12313
+ children: [
12314
+ "(",
12315
+ item.variant_title,
12316
+ ")"
12317
+ ]
12318
+ }
12319
+ )
12320
+ ] }),
12321
+ /* @__PURE__ */ jsxRuntime.jsx(
12322
+ ui.Text,
12323
+ {
12324
+ size: "small",
12325
+ leading: "compact",
12326
+ className: "text-ui-fg-subtle",
12327
+ children: item.variant_sku
12328
+ }
12329
+ )
12330
+ ] })
12331
+ ] }),
12332
+ /* @__PURE__ */ jsxRuntime.jsxs(
12333
+ ui.Text,
12334
+ {
12335
+ size: "small",
12336
+ leading: "compact",
12337
+ className: "text-ui-fg-subtle",
12338
+ children: [
12339
+ item.quantity,
12340
+ "x"
12341
+ ]
12342
+ }
12343
+ )
12344
+ ]
12345
+ },
12346
+ item.id
12347
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12348
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12349
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12350
+ 'No items found for "',
12351
+ query,
12352
+ '".'
12353
+ ] })
12354
+ ] }) })
12355
+ ] })
12356
+ ] });
12357
+ };
12358
+ const LocationField = ({ control, setValue }) => {
12359
+ const locations = useComboboxData({
12360
+ queryKey: ["locations"],
12361
+ queryFn: async (params) => {
12362
+ return await sdk.admin.stockLocation.list(params);
12363
+ },
12364
+ getOptions: (data) => {
12365
+ return data.stock_locations.map((location) => ({
12366
+ label: location.name,
12367
+ value: location.id
12368
+ }));
12369
+ }
12370
+ });
12371
+ return /* @__PURE__ */ jsxRuntime.jsx(
12372
+ Form$2.Field,
12220
12373
  {
12221
- width: "280",
12222
- height: "180",
12223
- viewBox: "0 0 280 180",
12224
- fill: "none",
12225
- xmlns: "http://www.w3.org/2000/svg",
12226
- children: [
12227
- /* @__PURE__ */ jsxRuntime.jsx(
12228
- "rect",
12229
- {
12230
- x: "0.00428286",
12231
- y: "-0.742904",
12232
- width: "33.5",
12233
- height: "65.5",
12234
- rx: "6.75",
12235
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12236
- fill: "#D4D4D8",
12237
- stroke: "#52525B",
12238
- strokeWidth: "1.5"
12239
- }
12240
- ),
12241
- /* @__PURE__ */ jsxRuntime.jsx(
12242
- "rect",
12243
- {
12244
- x: "0.00428286",
12245
- y: "-0.742904",
12246
- width: "33.5",
12247
- height: "65.5",
12248
- rx: "6.75",
12249
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12250
- fill: "white",
12251
- stroke: "#52525B",
12252
- strokeWidth: "1.5"
12253
- }
12254
- ),
12255
- /* @__PURE__ */ jsxRuntime.jsx(
12256
- "path",
12257
- {
12258
- d: "M180.579 107.142L179.126 107.959",
12259
- stroke: "#52525B",
12260
- strokeWidth: "1.5",
12261
- strokeLinecap: "round",
12262
- strokeLinejoin: "round"
12263
- }
12264
- ),
12265
- /* @__PURE__ */ jsxRuntime.jsx(
12266
- "path",
12267
- {
12268
- opacity: "0.88",
12269
- d: "M182.305 109.546L180.257 109.534",
12270
- stroke: "#52525B",
12271
- strokeWidth: "1.5",
12272
- strokeLinecap: "round",
12273
- strokeLinejoin: "round"
12274
- }
12275
- ),
12276
- /* @__PURE__ */ jsxRuntime.jsx(
12277
- "path",
12278
- {
12279
- opacity: "0.75",
12280
- d: "M180.551 111.93L179.108 111.096",
12281
- stroke: "#52525B",
12282
- strokeWidth: "1.5",
12283
- strokeLinecap: "round",
12284
- strokeLinejoin: "round"
12285
- }
12286
- ),
12287
- /* @__PURE__ */ jsxRuntime.jsx(
12288
- "path",
12289
- {
12290
- opacity: "0.63",
12291
- d: "M176.347 112.897L176.354 111.73",
12292
- stroke: "#52525B",
12293
- strokeWidth: "1.5",
12294
- strokeLinecap: "round",
12295
- strokeLinejoin: "round"
12296
- }
12297
- ),
12298
- /* @__PURE__ */ jsxRuntime.jsx(
12299
- "path",
12300
- {
12301
- opacity: "0.5",
12302
- d: "M172.153 111.881L173.606 111.064",
12303
- stroke: "#52525B",
12304
- strokeWidth: "1.5",
12305
- strokeLinecap: "round",
12306
- strokeLinejoin: "round"
12307
- }
12308
- ),
12309
- /* @__PURE__ */ jsxRuntime.jsx(
12310
- "path",
12311
- {
12312
- opacity: "0.38",
12313
- d: "M170.428 109.478L172.476 109.489",
12314
- stroke: "#52525B",
12315
- strokeWidth: "1.5",
12316
- strokeLinecap: "round",
12317
- strokeLinejoin: "round"
12318
- }
12319
- ),
12320
- /* @__PURE__ */ jsxRuntime.jsx(
12321
- "path",
12322
- {
12323
- opacity: "0.25",
12324
- d: "M172.181 107.094L173.624 107.928",
12325
- stroke: "#52525B",
12326
- strokeWidth: "1.5",
12327
- strokeLinecap: "round",
12328
- strokeLinejoin: "round"
12329
- }
12330
- ),
12331
- /* @__PURE__ */ jsxRuntime.jsx(
12332
- "path",
12333
- {
12334
- opacity: "0.13",
12335
- d: "M176.386 106.126L176.379 107.294",
12336
- stroke: "#52525B",
12337
- strokeWidth: "1.5",
12338
- strokeLinecap: "round",
12339
- strokeLinejoin: "round"
12340
- }
12341
- ),
12342
- /* @__PURE__ */ jsxRuntime.jsx(
12343
- "rect",
12344
- {
12345
- width: "12",
12346
- height: "3",
12347
- rx: "1.5",
12348
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12349
- fill: "#D4D4D8"
12350
- }
12351
- ),
12352
- /* @__PURE__ */ jsxRuntime.jsx(
12353
- "rect",
12354
- {
12355
- x: "0.00428286",
12356
- y: "-0.742904",
12357
- width: "33.5",
12358
- height: "65.5",
12359
- rx: "6.75",
12360
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12361
- fill: "#D4D4D8",
12362
- stroke: "#52525B",
12363
- strokeWidth: "1.5"
12364
- }
12365
- ),
12366
- /* @__PURE__ */ jsxRuntime.jsx(
12367
- "rect",
12368
- {
12369
- x: "0.00428286",
12370
- y: "-0.742904",
12371
- width: "33.5",
12372
- height: "65.5",
12373
- rx: "6.75",
12374
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12375
- fill: "white",
12376
- stroke: "#52525B",
12377
- strokeWidth: "1.5"
12378
- }
12379
- ),
12380
- /* @__PURE__ */ jsxRuntime.jsx(
12381
- "rect",
12382
- {
12383
- width: "12",
12384
- height: "3",
12385
- rx: "1.5",
12386
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12387
- fill: "#D4D4D8"
12388
- }
12389
- ),
12390
- /* @__PURE__ */ jsxRuntime.jsx(
12391
- "rect",
12392
- {
12393
- width: "17",
12394
- height: "3",
12395
- rx: "1.5",
12396
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12397
- fill: "#D4D4D8"
12398
- }
12399
- ),
12400
- /* @__PURE__ */ jsxRuntime.jsx(
12401
- "rect",
12402
- {
12403
- width: "12",
12404
- height: "3",
12405
- rx: "1.5",
12406
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12407
- fill: "#D4D4D8"
12408
- }
12409
- ),
12410
- /* @__PURE__ */ jsxRuntime.jsx(
12411
- "path",
12412
- {
12413
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12414
- fill: "#A1A1AA"
12415
- }
12416
- ),
12417
- /* @__PURE__ */ jsxRuntime.jsx(
12418
- "rect",
12419
- {
12420
- width: "17",
12421
- height: "3",
12422
- rx: "1.5",
12423
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12424
- fill: "#A1A1AA"
12425
- }
12426
- ),
12427
- /* @__PURE__ */ jsxRuntime.jsx(
12428
- "rect",
12429
- {
12430
- width: "12",
12431
- height: "3",
12432
- rx: "1.5",
12433
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12434
- fill: "#A1A1AA"
12435
- }
12436
- ),
12437
- /* @__PURE__ */ jsxRuntime.jsx(
12438
- "path",
12439
- {
12440
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12441
- fill: "#52525B"
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12445
- "path",
12446
- {
12447
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12448
- stroke: "#A1A1AA",
12449
- strokeWidth: "1.5",
12450
- strokeLinecap: "round",
12451
- strokeLinejoin: "round"
12452
- }
12453
- ) }),
12454
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12455
- "path",
12456
- {
12457
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12458
- stroke: "#A1A1AA",
12459
- strokeWidth: "1.5",
12460
- strokeLinecap: "round",
12461
- strokeLinejoin: "round"
12462
- }
12463
- ) }),
12464
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12465
- "path",
12466
- {
12467
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12468
- stroke: "#A1A1AA",
12469
- strokeWidth: "1.5",
12470
- strokeLinecap: "round",
12471
- strokeLinejoin: "round"
12472
- }
12473
- ) }),
12474
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12475
- "path",
12476
- {
12477
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12478
- stroke: "#A1A1AA",
12479
- strokeWidth: "1.5",
12480
- strokeLinecap: "round",
12481
- strokeLinejoin: "round"
12482
- }
12483
- ) }),
12484
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12485
- "path",
12486
- {
12487
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12488
- stroke: "#A1A1AA",
12489
- strokeWidth: "1.5",
12490
- strokeLinecap: "round",
12491
- strokeLinejoin: "round"
12492
- }
12493
- ) }),
12494
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12495
- "path",
12496
- {
12497
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12498
- stroke: "#A1A1AA",
12499
- strokeWidth: "1.5",
12500
- strokeLinecap: "round",
12501
- strokeLinejoin: "round"
12502
- }
12503
- ) }),
12504
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12505
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12506
- "rect",
12507
- {
12508
- width: "12",
12509
- height: "12",
12510
- fill: "white",
12511
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12512
- }
12513
- ) }),
12514
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12515
- "rect",
12516
- {
12517
- width: "12",
12518
- height: "12",
12519
- fill: "white",
12520
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12521
- }
12522
- ) }),
12523
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12524
- "rect",
12525
- {
12526
- width: "12",
12527
- height: "12",
12528
- fill: "white",
12529
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12530
- }
12531
- ) }),
12532
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12533
- "rect",
12534
- {
12535
- width: "12",
12536
- height: "12",
12537
- fill: "white",
12538
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12539
- }
12540
- ) }),
12541
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12542
- "rect",
12543
- {
12544
- width: "12",
12545
- height: "12",
12546
- fill: "white",
12547
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12548
- }
12549
- ) }),
12550
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12551
- "rect",
12374
+ control,
12375
+ name: "location_id",
12376
+ render: ({ field: { onChange, ...field } }) => {
12377
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12378
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12380
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12381
+ ] }),
12382
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12383
+ Combobox,
12552
12384
  {
12553
- width: "12",
12554
- height: "12",
12555
- fill: "white",
12556
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12385
+ options: locations.options,
12386
+ fetchNextPage: locations.fetchNextPage,
12387
+ isFetchingNextPage: locations.isFetchingNextPage,
12388
+ searchValue: locations.searchValue,
12389
+ onSearchValueChange: locations.onSearchValueChange,
12390
+ placeholder: "Select location",
12391
+ onChange: (value) => {
12392
+ setValue("shipping_option_id", "", {
12393
+ shouldDirty: true,
12394
+ shouldTouch: true
12395
+ });
12396
+ onChange(value);
12397
+ },
12398
+ ...field
12557
12399
  }
12558
12400
  ) })
12559
- ] })
12560
- ]
12401
+ ] }) });
12402
+ }
12561
12403
  }
12562
12404
  );
12563
12405
  };
12564
- const schema = object({
12565
- customer_id: string().min(1)
12566
- });
12567
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12568
- const Shipping = () => {
12406
+ const ShippingOptionField = ({
12407
+ shippingProfileId,
12408
+ preview,
12409
+ control
12410
+ }) => {
12569
12411
  var _a2;
12570
- const { id } = reactRouterDom.useParams();
12571
- const { order, isPending, isError, error } = useOrder(id, {
12572
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12412
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12413
+ const shippingOptions = useComboboxData({
12414
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12415
+ queryFn: async (params) => {
12416
+ return await sdk.admin.shippingOption.list({
12417
+ ...params,
12418
+ stock_location_id: locationId,
12419
+ shipping_profile_id: shippingProfileId
12420
+ });
12421
+ },
12422
+ getOptions: (data) => {
12423
+ return data.shipping_options.map((option) => {
12424
+ var _a3;
12425
+ if ((_a3 = option.rules) == null ? void 0 : _a3.find(
12426
+ (r) => r.attribute === "is_return" && r.value === "true"
12427
+ )) {
12428
+ return void 0;
12429
+ }
12430
+ return {
12431
+ label: option.name,
12432
+ value: option.id
12433
+ };
12434
+ }).filter(Boolean);
12435
+ },
12436
+ enabled: !!locationId && !!shippingProfileId,
12437
+ defaultValue: ((_a2 = preview.shipping_methods[0]) == null ? void 0 : _a2.shipping_option_id) || void 0
12573
12438
  });
12574
- const {
12575
- order: preview,
12576
- isPending: isPreviewPending,
12577
- isError: isPreviewError,
12578
- error: previewError
12579
- } = useOrderPreview(id);
12580
- useInitiateOrderEdit({ preview });
12581
- const { onCancel } = useCancelOrderEdit({ preview });
12582
- if (isError) {
12583
- throw error;
12584
- }
12585
- if (isPreviewError) {
12586
- throw previewError;
12587
- }
12588
- const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
12589
- const isReady = preview && !isPreviewPending && order && !isPending;
12590
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12591
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12592
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12593
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12594
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12595
- ] }) }) }),
12596
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12597
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12598
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12599
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12600
- ] }) });
12601
- };
12602
- const ShippingForm = ({ preview, order }) => {
12603
- var _a2;
12604
- const { setIsOpen } = useStackedModal();
12605
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12606
- const [data, setData] = React.useState(null);
12607
- const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
12608
- const { shipping_options } = useShippingOptions(
12609
- {
12610
- id: appliedShippingOptionIds,
12611
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12612
- },
12439
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12440
+ return /* @__PURE__ */ jsxRuntime.jsx(
12441
+ Form$2.Field,
12613
12442
  {
12614
- enabled: appliedShippingOptionIds.length > 0
12443
+ control,
12444
+ name: "shipping_option_id",
12445
+ render: ({ field }) => {
12446
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12447
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12448
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12449
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12450
+ ] }),
12451
+ /* @__PURE__ */ jsxRuntime.jsx(
12452
+ ConditionalTooltip,
12453
+ {
12454
+ content: tooltipContent,
12455
+ showTooltip: !locationId || !shippingProfileId,
12456
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12457
+ Combobox,
12458
+ {
12459
+ options: shippingOptions.options,
12460
+ fetchNextPage: shippingOptions.fetchNextPage,
12461
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12462
+ searchValue: shippingOptions.searchValue,
12463
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12464
+ placeholder: "Select shipping option",
12465
+ ...field,
12466
+ disabled: !locationId || !shippingProfileId
12467
+ }
12468
+ ) }) })
12469
+ }
12470
+ )
12471
+ ] }) });
12472
+ }
12615
12473
  }
12616
12474
  );
12617
- const uniqueShippingProfiles = React.useMemo(() => {
12618
- const profiles = /* @__PURE__ */ new Map();
12619
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12620
- profiles.set(profile.id, profile);
12621
- });
12622
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12623
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12624
- });
12625
- return Array.from(profiles.values());
12626
- }, [order.items, shipping_options]);
12627
- const { handleSuccess } = useRouteModal();
12628
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12629
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12630
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12631
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12632
- const onSubmit = async () => {
12633
- setIsSubmitting(true);
12634
- let requestSucceeded = false;
12635
- await requestOrderEdit(void 0, {
12636
- onError: (e) => {
12637
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12638
- },
12639
- onSuccess: () => {
12640
- requestSucceeded = true;
12475
+ };
12476
+ const CustomAmountField = ({
12477
+ control,
12478
+ currencyCode
12479
+ }) => {
12480
+ return /* @__PURE__ */ jsxRuntime.jsx(
12481
+ Form$2.Field,
12482
+ {
12483
+ control,
12484
+ name: "custom_amount",
12485
+ render: ({ field: { onChange, ...field } }) => {
12486
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12487
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12488
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12489
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12490
+ ] }),
12491
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12492
+ ui.CurrencyInput,
12493
+ {
12494
+ ...field,
12495
+ onValueChange: (value) => onChange(value),
12496
+ symbol: getNativeSymbol(currencyCode),
12497
+ code: currencyCode
12498
+ }
12499
+ ) })
12500
+ ] });
12641
12501
  }
12642
- });
12643
- if (!requestSucceeded) {
12644
- setIsSubmitting(false);
12645
- return;
12646
12502
  }
12647
- await confirmOrderEdit(void 0, {
12648
- onError: (e) => {
12649
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12650
- },
12651
- onSuccess: () => {
12652
- handleSuccess();
12503
+ );
12504
+ };
12505
+ const ShippingAddress = () => {
12506
+ const { id } = reactRouterDom.useParams();
12507
+ const { order, isPending, isError, error } = useOrder(id, {
12508
+ fields: "+shipping_address"
12509
+ });
12510
+ if (isError) {
12511
+ throw error;
12512
+ }
12513
+ const isReady = !isPending && !!order;
12514
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12515
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12516
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12517
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12518
+ ] }),
12519
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12520
+ ] });
12521
+ };
12522
+ const ShippingAddressForm = ({ order }) => {
12523
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12524
+ const form = reactHookForm.useForm({
12525
+ defaultValues: {
12526
+ first_name: ((_a2 = order.shipping_address) == null ? void 0 : _a2.first_name) ?? "",
12527
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12528
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12529
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12530
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12531
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12532
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12533
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12534
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12535
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12536
+ },
12537
+ resolver: zod.zodResolver(schema$2)
12538
+ });
12539
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12540
+ const { handleSuccess } = useRouteModal();
12541
+ const onSubmit = form.handleSubmit(async (data) => {
12542
+ await mutateAsync(
12543
+ {
12544
+ shipping_address: {
12545
+ first_name: data.first_name,
12546
+ last_name: data.last_name,
12547
+ company: data.company,
12548
+ address_1: data.address_1,
12549
+ address_2: data.address_2,
12550
+ city: data.city,
12551
+ province: data.province,
12552
+ country_code: data.country_code,
12553
+ postal_code: data.postal_code,
12554
+ phone: data.phone
12555
+ }
12653
12556
  },
12654
- onSettled: () => {
12655
- setIsSubmitting(false);
12656
- }
12657
- });
12658
- };
12659
- const onKeydown = React.useCallback(
12660
- (e) => {
12661
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12662
- if (data || isSubmitting) {
12663
- return;
12557
+ {
12558
+ onSuccess: () => {
12559
+ handleSuccess();
12560
+ },
12561
+ onError: (error) => {
12562
+ ui.toast.error(error.message);
12664
12563
  }
12665
- onSubmit();
12666
12564
  }
12667
- },
12668
- [data, isSubmitting, onSubmit]
12669
- );
12670
- React.useEffect(() => {
12671
- document.addEventListener("keydown", onKeydown);
12672
- return () => {
12673
- document.removeEventListener("keydown", onKeydown);
12674
- };
12675
- }, [onKeydown]);
12676
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12677
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12678
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12679
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12680
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12681
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12682
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12683
- ] }),
12684
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12685
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12686
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
12565
+ );
12566
+ });
12567
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12568
+ KeyboundForm,
12569
+ {
12570
+ className: "flex flex-1 flex-col overflow-hidden",
12571
+ onSubmit,
12572
+ children: [
12573
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12574
+ /* @__PURE__ */ jsxRuntime.jsx(
12575
+ Form$2.Field,
12576
+ {
12577
+ control: form.control,
12578
+ name: "country_code",
12579
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12580
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12581
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12582
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12583
+ ] })
12584
+ }
12585
+ ),
12586
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12687
12587
  /* @__PURE__ */ jsxRuntime.jsx(
12688
- ui.Text,
12588
+ Form$2.Field,
12689
12589
  {
12690
- size: "xsmall",
12691
- weight: "plus",
12692
- className: "text-ui-fg-muted",
12693
- children: "Shipping profile"
12590
+ control: form.control,
12591
+ name: "first_name",
12592
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12593
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12594
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12595
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12596
+ ] })
12694
12597
  }
12695
12598
  ),
12696
12599
  /* @__PURE__ */ jsxRuntime.jsx(
12697
- ui.Text,
12600
+ Form$2.Field,
12698
12601
  {
12699
- size: "xsmall",
12700
- weight: "plus",
12701
- className: "text-ui-fg-muted",
12702
- children: "Action"
12602
+ control: form.control,
12603
+ name: "last_name",
12604
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12605
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12606
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12607
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12608
+ ] })
12703
12609
  }
12704
12610
  )
12705
12611
  ] }),
12706
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12707
- var _a3, _b, _c, _d, _e, _f, _g;
12708
- const items = getItemsWithShippingProfile(
12709
- profile.id,
12710
- order.items
12711
- );
12712
- const hasItems = items.length > 0;
12713
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12714
- (option) => option.shipping_profile_id === profile.id
12715
- );
12716
- const shippingMethod = preview.shipping_methods.find(
12717
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12718
- );
12719
- const addShippingMethodAction = (_a3 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a3.find(
12720
- (action) => action.action === "SHIPPING_ADD"
12721
- );
12722
- return /* @__PURE__ */ jsxRuntime.jsxs(
12723
- radixUi.Accordion.Item,
12612
+ /* @__PURE__ */ jsxRuntime.jsx(
12613
+ Form$2.Field,
12614
+ {
12615
+ control: form.control,
12616
+ name: "company",
12617
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12618
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12619
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12620
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12621
+ ] })
12622
+ }
12623
+ ),
12624
+ /* @__PURE__ */ jsxRuntime.jsx(
12625
+ Form$2.Field,
12626
+ {
12627
+ control: form.control,
12628
+ name: "address_1",
12629
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12630
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12631
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12632
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12633
+ ] })
12634
+ }
12635
+ ),
12636
+ /* @__PURE__ */ jsxRuntime.jsx(
12637
+ Form$2.Field,
12638
+ {
12639
+ control: form.control,
12640
+ name: "address_2",
12641
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12642
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12643
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12644
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12645
+ ] })
12646
+ }
12647
+ ),
12648
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12649
+ /* @__PURE__ */ jsxRuntime.jsx(
12650
+ Form$2.Field,
12724
12651
  {
12725
- value: profile.id,
12726
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12727
- children: [
12728
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
12729
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
12730
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12731
- ui.IconButton,
12732
- {
12733
- size: "2xsmall",
12734
- variant: "transparent",
12735
- className: "group/trigger",
12736
- disabled: !hasItems,
12737
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
12738
- }
12739
- ) }),
12740
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12741
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
12742
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
12743
- /* @__PURE__ */ jsxRuntime.jsx(
12744
- ui.Text,
12745
- {
12746
- size: "small",
12747
- weight: "plus",
12748
- leading: "compact",
12749
- children: profile.name
12750
- }
12751
- ),
12752
- /* @__PURE__ */ jsxRuntime.jsxs(
12753
- ui.Text,
12754
- {
12755
- size: "small",
12756
- leading: "compact",
12757
- className: "text-ui-fg-subtle",
12758
- children: [
12759
- items.length,
12760
- " ",
12761
- pluralize(items.length, "items", "item")
12762
- ]
12763
- }
12764
- )
12765
- ] })
12766
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
12767
- /* @__PURE__ */ jsxRuntime.jsx(
12768
- ui.Tooltip,
12769
- {
12770
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12771
- var _a4, _b2, _c2;
12772
- return /* @__PURE__ */ jsxRuntime.jsx(
12773
- "li",
12774
- {
12775
- children: `${item.quantity}x ${(_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12776
- },
12777
- item.id
12778
- );
12779
- }) }),
12780
- children: /* @__PURE__ */ jsxRuntime.jsxs(
12781
- ui.Badge,
12782
- {
12783
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12784
- size: "xsmall",
12785
- children: [
12786
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12787
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12788
- items.reduce(
12789
- (acc, item) => acc + item.quantity,
12790
- 0
12791
- ),
12792
- "x",
12793
- " ",
12794
- pluralize(items.length, "items", "item")
12795
- ] })
12796
- ]
12797
- }
12798
- )
12799
- }
12800
- ),
12801
- /* @__PURE__ */ jsxRuntime.jsx(
12802
- ui.Tooltip,
12803
- {
12804
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12805
- children: /* @__PURE__ */ jsxRuntime.jsxs(
12806
- ui.Badge,
12807
- {
12808
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12809
- size: "xsmall",
12810
- children: [
12811
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12812
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12813
- ]
12814
- }
12815
- )
12816
- }
12817
- ),
12818
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12819
- ui.Badge,
12820
- {
12821
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12822
- size: "xsmall",
12823
- children: [
12824
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12825
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12826
- ]
12827
- }
12828
- ) })
12829
- ] })
12830
- ] }),
12831
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12832
- ActionMenu,
12833
- {
12834
- groups: [
12835
- {
12836
- actions: [
12837
- hasItems ? {
12838
- label: "Edit shipping option",
12839
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12840
- onClick: () => {
12841
- setIsOpen(
12842
- STACKED_FOCUS_MODAL_ID,
12843
- true
12844
- );
12845
- setData({
12846
- shippingProfileId: profile.id,
12847
- shippingOption,
12848
- shippingMethod
12849
- });
12850
- }
12851
- } : void 0,
12852
- {
12853
- label: "Remove shipping option",
12854
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12855
- onClick: () => {
12856
- if (shippingMethod) {
12857
- if (addShippingMethodAction) {
12858
- removeActionShippingMethod(
12859
- addShippingMethodAction.id
12860
- );
12861
- } else {
12862
- removeShippingMethod(
12863
- shippingMethod.id
12864
- );
12865
- }
12866
- }
12867
- }
12868
- }
12869
- ].filter(Boolean)
12870
- }
12871
- ]
12872
- }
12873
- ) : /* @__PURE__ */ jsxRuntime.jsx(
12874
- StackedModalTrigger,
12875
- {
12876
- shippingProfileId: profile.id,
12877
- shippingOption,
12878
- shippingMethod,
12879
- setData,
12880
- children: "Add shipping option"
12881
- }
12882
- )
12883
- ] }),
12884
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12885
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12886
- items.map((item, idx) => {
12887
- var _a4, _b2, _c2, _d2, _e2;
12888
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12889
- /* @__PURE__ */ jsxRuntime.jsxs(
12890
- "div",
12891
- {
12892
- className: "flex items-center gap-x-3 px-3",
12893
- children: [
12894
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12895
- ui.Divider,
12896
- {
12897
- variant: "dashed",
12898
- orientation: "vertical"
12899
- }
12900
- ) }),
12901
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12902
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12903
- ui.Text,
12904
- {
12905
- size: "small",
12906
- leading: "compact",
12907
- className: "text-ui-fg-subtle",
12908
- children: [
12909
- item.quantity,
12910
- "x"
12911
- ]
12912
- }
12913
- ) }),
12914
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12915
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12916
- /* @__PURE__ */ jsxRuntime.jsxs(
12917
- ui.Text,
12918
- {
12919
- size: "small",
12920
- leading: "compact",
12921
- weight: "plus",
12922
- children: [
12923
- (_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title,
12924
- " (",
12925
- (_c2 = item.variant) == null ? void 0 : _c2.title,
12926
- ")"
12927
- ]
12928
- }
12929
- ),
12930
- /* @__PURE__ */ jsxRuntime.jsx(
12931
- ui.Text,
12932
- {
12933
- size: "small",
12934
- leading: "compact",
12935
- className: "text-ui-fg-subtle",
12936
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12937
- }
12938
- )
12939
- ] })
12940
- ] })
12941
- ]
12942
- },
12943
- item.id
12944
- ),
12945
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12946
- ] }, item.id);
12947
- })
12948
- ] })
12949
- ]
12950
- },
12951
- profile.id
12952
- );
12953
- }) })
12954
- ] }) })
12955
- ] }) }),
12956
- /* @__PURE__ */ jsxRuntime.jsx(
12957
- StackedFocusModal,
12958
- {
12959
- id: STACKED_FOCUS_MODAL_ID,
12960
- onOpenChangeCallback: (open) => {
12961
- if (!open) {
12962
- setData(null);
12652
+ control: form.control,
12653
+ name: "postal_code",
12654
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12655
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12656
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12657
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12658
+ ] })
12659
+ }
12660
+ ),
12661
+ /* @__PURE__ */ jsxRuntime.jsx(
12662
+ Form$2.Field,
12663
+ {
12664
+ control: form.control,
12665
+ name: "city",
12666
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12667
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12668
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12669
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12670
+ ] })
12671
+ }
12672
+ )
12673
+ ] }),
12674
+ /* @__PURE__ */ jsxRuntime.jsx(
12675
+ Form$2.Field,
12676
+ {
12677
+ control: form.control,
12678
+ name: "province",
12679
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12680
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12681
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12682
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12683
+ ] })
12684
+ }
12685
+ ),
12686
+ /* @__PURE__ */ jsxRuntime.jsx(
12687
+ Form$2.Field,
12688
+ {
12689
+ control: form.control,
12690
+ name: "phone",
12691
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12692
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12693
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12694
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12695
+ ] })
12963
12696
  }
12964
- return open;
12965
- },
12966
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12967
- }
12968
- )
12697
+ )
12698
+ ] }) }),
12699
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12700
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12701
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12702
+ ] }) })
12703
+ ]
12704
+ }
12705
+ ) });
12706
+ };
12707
+ const schema$2 = addressSchema;
12708
+ const TransferOwnership = () => {
12709
+ const { id } = reactRouterDom.useParams();
12710
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12711
+ fields: "id,customer_id,customer.*"
12712
+ });
12713
+ if (isError) {
12714
+ throw error;
12715
+ }
12716
+ const isReady = !isPending && !!draft_order;
12717
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12718
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12719
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12720
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12969
12721
  ] }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12971
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12972
- /* @__PURE__ */ jsxRuntime.jsx(
12973
- ui.Button,
12974
- {
12975
- size: "small",
12976
- type: "button",
12977
- isLoading: isSubmitting,
12978
- onClick: onSubmit,
12979
- children: "Save"
12980
- }
12981
- )
12982
- ] }) })
12722
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12983
12723
  ] });
12984
12724
  };
12985
- const StackedModalTrigger = ({
12986
- shippingProfileId,
12987
- shippingOption,
12988
- shippingMethod,
12989
- setData,
12990
- children
12991
- }) => {
12992
- const { setIsOpen, getIsOpen } = useStackedModal();
12993
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12994
- const onToggle = () => {
12995
- if (isOpen) {
12996
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12997
- setData(null);
12998
- } else {
12999
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
13000
- setData({
13001
- shippingProfileId,
13002
- shippingOption,
13003
- shippingMethod
12725
+ const TransferOwnershipForm = ({ order }) => {
12726
+ var _a2, _b;
12727
+ const form = reactHookForm.useForm({
12728
+ defaultValues: {
12729
+ customer_id: order.customer_id || ""
12730
+ },
12731
+ resolver: zod.zodResolver(schema$1)
12732
+ });
12733
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12734
+ const { handleSuccess } = useRouteModal();
12735
+ const name = [(_a2 = order.customer) == null ? void 0 : _a2.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12736
+ const currentCustomer = order.customer ? {
12737
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12738
+ value: order.customer.id
12739
+ } : null;
12740
+ const onSubmit = form.handleSubmit(async (data) => {
12741
+ await mutateAsync(
12742
+ { customer_id: data.customer_id },
12743
+ {
12744
+ onSuccess: () => {
12745
+ ui.toast.success("Customer updated");
12746
+ handleSuccess();
12747
+ },
12748
+ onError: (error) => {
12749
+ ui.toast.error(error.message);
12750
+ }
12751
+ }
12752
+ );
12753
+ });
12754
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12755
+ KeyboundForm,
12756
+ {
12757
+ className: "flex flex-1 flex-col overflow-hidden",
12758
+ onSubmit,
12759
+ children: [
12760
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12761
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12762
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12763
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12764
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12765
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12766
+ ] }),
12767
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12768
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12769
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12770
+ ] })
12771
+ ] }),
12772
+ /* @__PURE__ */ jsxRuntime.jsx(
12773
+ CustomerField,
12774
+ {
12775
+ control: form.control,
12776
+ currentCustomerId: order.customer_id
12777
+ }
12778
+ )
12779
+ ] }),
12780
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12781
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12782
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12783
+ ] }) })
12784
+ ]
12785
+ }
12786
+ ) });
12787
+ };
12788
+ const CustomerField = ({ control, currentCustomerId }) => {
12789
+ const customers = useComboboxData({
12790
+ queryFn: async (params) => {
12791
+ return await sdk.admin.customer.list({
12792
+ ...params,
12793
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12794
+ });
12795
+ },
12796
+ queryKey: ["customers"],
12797
+ getOptions: (data) => {
12798
+ return data.customers.map((customer) => {
12799
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12800
+ return {
12801
+ label: name ? `${name} (${customer.email})` : customer.email,
12802
+ value: customer.id
12803
+ };
13004
12804
  });
13005
12805
  }
13006
- };
12806
+ });
13007
12807
  return /* @__PURE__ */ jsxRuntime.jsx(
13008
- ui.Button,
12808
+ Form$2.Field,
13009
12809
  {
13010
- size: "small",
13011
- variant: "secondary",
13012
- onClick: onToggle,
13013
- className: "text-ui-fg-primary shrink-0",
13014
- children
12810
+ name: "customer_id",
12811
+ control,
12812
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12813
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12814
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12815
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12816
+ ] }),
12817
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12818
+ Combobox,
12819
+ {
12820
+ options: customers.options,
12821
+ fetchNextPage: customers.fetchNextPage,
12822
+ isFetchingNextPage: customers.isFetchingNextPage,
12823
+ searchValue: customers.searchValue,
12824
+ onSearchValueChange: customers.onSearchValueChange,
12825
+ placeholder: "Select customer",
12826
+ ...field
12827
+ }
12828
+ ) }),
12829
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12830
+ ] })
13015
12831
  }
13016
12832
  );
13017
12833
  };
13018
- const ShippingProfileForm = ({
13019
- data,
13020
- order,
13021
- preview
13022
- }) => {
13023
- var _a2, _b, _c, _d, _e, _f;
13024
- const { setIsOpen } = useStackedModal();
13025
- const form = reactHookForm.useForm({
13026
- resolver: zod.zodResolver(shippingMethodSchema),
13027
- defaultValues: {
13028
- location_id: (_d = (_c = (_b = (_a2 = data.shippingOption) == null ? void 0 : _a2.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
13029
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
13030
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
13031
- }
13032
- });
13033
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
13034
- const {
13035
- mutateAsync: updateShippingMethod,
13036
- isPending: isUpdatingShippingMethod
13037
- } = useDraftOrderUpdateShippingMethod(order.id);
13038
- const onSubmit = form.handleSubmit(async (values) => {
13039
- if (isEqual__default.default(values, form.formState.defaultValues)) {
13040
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
13041
- return;
13042
- }
13043
- if (data.shippingMethod) {
13044
- await updateShippingMethod(
13045
- {
13046
- method_id: data.shippingMethod.id,
13047
- shipping_option_id: values.shipping_option_id,
13048
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
13049
- },
13050
- {
13051
- onError: (e) => {
13052
- ui.toast.error(e.message);
13053
- },
13054
- onSuccess: () => {
13055
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12834
+ const Illustration = () => {
12835
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12836
+ "svg",
12837
+ {
12838
+ width: "280",
12839
+ height: "180",
12840
+ viewBox: "0 0 280 180",
12841
+ fill: "none",
12842
+ xmlns: "http://www.w3.org/2000/svg",
12843
+ children: [
12844
+ /* @__PURE__ */ jsxRuntime.jsx(
12845
+ "rect",
12846
+ {
12847
+ x: "0.00428286",
12848
+ y: "-0.742904",
12849
+ width: "33.5",
12850
+ height: "65.5",
12851
+ rx: "6.75",
12852
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12853
+ fill: "#D4D4D8",
12854
+ stroke: "#52525B",
12855
+ strokeWidth: "1.5"
12856
+ }
12857
+ ),
12858
+ /* @__PURE__ */ jsxRuntime.jsx(
12859
+ "rect",
12860
+ {
12861
+ x: "0.00428286",
12862
+ y: "-0.742904",
12863
+ width: "33.5",
12864
+ height: "65.5",
12865
+ rx: "6.75",
12866
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12867
+ fill: "white",
12868
+ stroke: "#52525B",
12869
+ strokeWidth: "1.5"
12870
+ }
12871
+ ),
12872
+ /* @__PURE__ */ jsxRuntime.jsx(
12873
+ "path",
12874
+ {
12875
+ d: "M180.579 107.142L179.126 107.959",
12876
+ stroke: "#52525B",
12877
+ strokeWidth: "1.5",
12878
+ strokeLinecap: "round",
12879
+ strokeLinejoin: "round"
13056
12880
  }
13057
- }
13058
- );
13059
- return;
13060
- }
13061
- await addShippingMethod(
13062
- {
13063
- shipping_option_id: values.shipping_option_id,
13064
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
13065
- },
13066
- {
13067
- onError: (e) => {
13068
- ui.toast.error(e.message);
13069
- },
13070
- onSuccess: () => {
13071
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
13072
- }
13073
- }
13074
- );
13075
- });
13076
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13077
- KeyboundForm,
13078
- {
13079
- className: "flex h-full flex-col overflow-hidden",
13080
- onSubmit,
13081
- children: [
13082
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
13083
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
13084
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13085
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
13086
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
13087
- ] }),
13088
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13089
- /* @__PURE__ */ jsxRuntime.jsx(
13090
- LocationField,
12881
+ ),
12882
+ /* @__PURE__ */ jsxRuntime.jsx(
12883
+ "path",
12884
+ {
12885
+ opacity: "0.88",
12886
+ d: "M182.305 109.546L180.257 109.534",
12887
+ stroke: "#52525B",
12888
+ strokeWidth: "1.5",
12889
+ strokeLinecap: "round",
12890
+ strokeLinejoin: "round"
12891
+ }
12892
+ ),
12893
+ /* @__PURE__ */ jsxRuntime.jsx(
12894
+ "path",
12895
+ {
12896
+ opacity: "0.75",
12897
+ d: "M180.551 111.93L179.108 111.096",
12898
+ stroke: "#52525B",
12899
+ strokeWidth: "1.5",
12900
+ strokeLinecap: "round",
12901
+ strokeLinejoin: "round"
12902
+ }
12903
+ ),
12904
+ /* @__PURE__ */ jsxRuntime.jsx(
12905
+ "path",
12906
+ {
12907
+ opacity: "0.63",
12908
+ d: "M176.347 112.897L176.354 111.73",
12909
+ stroke: "#52525B",
12910
+ strokeWidth: "1.5",
12911
+ strokeLinecap: "round",
12912
+ strokeLinejoin: "round"
12913
+ }
12914
+ ),
12915
+ /* @__PURE__ */ jsxRuntime.jsx(
12916
+ "path",
12917
+ {
12918
+ opacity: "0.5",
12919
+ d: "M172.153 111.881L173.606 111.064",
12920
+ stroke: "#52525B",
12921
+ strokeWidth: "1.5",
12922
+ strokeLinecap: "round",
12923
+ strokeLinejoin: "round"
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ "path",
12928
+ {
12929
+ opacity: "0.38",
12930
+ d: "M170.428 109.478L172.476 109.489",
12931
+ stroke: "#52525B",
12932
+ strokeWidth: "1.5",
12933
+ strokeLinecap: "round",
12934
+ strokeLinejoin: "round"
12935
+ }
12936
+ ),
12937
+ /* @__PURE__ */ jsxRuntime.jsx(
12938
+ "path",
12939
+ {
12940
+ opacity: "0.25",
12941
+ d: "M172.181 107.094L173.624 107.928",
12942
+ stroke: "#52525B",
12943
+ strokeWidth: "1.5",
12944
+ strokeLinecap: "round",
12945
+ strokeLinejoin: "round"
12946
+ }
12947
+ ),
12948
+ /* @__PURE__ */ jsxRuntime.jsx(
12949
+ "path",
12950
+ {
12951
+ opacity: "0.13",
12952
+ d: "M176.386 106.126L176.379 107.294",
12953
+ stroke: "#52525B",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12957
+ }
12958
+ ),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(
12960
+ "rect",
12961
+ {
12962
+ width: "12",
12963
+ height: "3",
12964
+ rx: "1.5",
12965
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12966
+ fill: "#D4D4D8"
12967
+ }
12968
+ ),
12969
+ /* @__PURE__ */ jsxRuntime.jsx(
12970
+ "rect",
12971
+ {
12972
+ x: "0.00428286",
12973
+ y: "-0.742904",
12974
+ width: "33.5",
12975
+ height: "65.5",
12976
+ rx: "6.75",
12977
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12978
+ fill: "#D4D4D8",
12979
+ stroke: "#52525B",
12980
+ strokeWidth: "1.5"
12981
+ }
12982
+ ),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(
12984
+ "rect",
12985
+ {
12986
+ x: "0.00428286",
12987
+ y: "-0.742904",
12988
+ width: "33.5",
12989
+ height: "65.5",
12990
+ rx: "6.75",
12991
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12992
+ fill: "white",
12993
+ stroke: "#52525B",
12994
+ strokeWidth: "1.5"
12995
+ }
12996
+ ),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(
12998
+ "rect",
12999
+ {
13000
+ width: "12",
13001
+ height: "3",
13002
+ rx: "1.5",
13003
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
13004
+ fill: "#D4D4D8"
13005
+ }
13006
+ ),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(
13008
+ "rect",
13009
+ {
13010
+ width: "17",
13011
+ height: "3",
13012
+ rx: "1.5",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
13014
+ fill: "#D4D4D8"
13015
+ }
13016
+ ),
13017
+ /* @__PURE__ */ jsxRuntime.jsx(
13018
+ "rect",
13019
+ {
13020
+ width: "12",
13021
+ height: "3",
13022
+ rx: "1.5",
13023
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
13024
+ fill: "#D4D4D8"
13025
+ }
13026
+ ),
13027
+ /* @__PURE__ */ jsxRuntime.jsx(
13028
+ "path",
13029
+ {
13030
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
13031
+ fill: "#A1A1AA"
13032
+ }
13033
+ ),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(
13035
+ "rect",
13036
+ {
13037
+ width: "17",
13038
+ height: "3",
13039
+ rx: "1.5",
13040
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
13041
+ fill: "#A1A1AA"
13042
+ }
13043
+ ),
13044
+ /* @__PURE__ */ jsxRuntime.jsx(
13045
+ "rect",
13046
+ {
13047
+ width: "12",
13048
+ height: "3",
13049
+ rx: "1.5",
13050
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
13051
+ fill: "#A1A1AA"
13052
+ }
13053
+ ),
13054
+ /* @__PURE__ */ jsxRuntime.jsx(
13055
+ "path",
13056
+ {
13057
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
13058
+ fill: "#52525B"
13059
+ }
13060
+ ),
13061
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13062
+ "path",
13063
+ {
13064
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
13065
+ stroke: "#A1A1AA",
13066
+ strokeWidth: "1.5",
13067
+ strokeLinecap: "round",
13068
+ strokeLinejoin: "round"
13069
+ }
13070
+ ) }),
13071
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13072
+ "path",
13073
+ {
13074
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
13075
+ stroke: "#A1A1AA",
13076
+ strokeWidth: "1.5",
13077
+ strokeLinecap: "round",
13078
+ strokeLinejoin: "round"
13079
+ }
13080
+ ) }),
13081
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13082
+ "path",
13083
+ {
13084
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
13085
+ stroke: "#A1A1AA",
13086
+ strokeWidth: "1.5",
13087
+ strokeLinecap: "round",
13088
+ strokeLinejoin: "round"
13089
+ }
13090
+ ) }),
13091
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13092
+ "path",
13093
+ {
13094
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
13095
+ stroke: "#A1A1AA",
13096
+ strokeWidth: "1.5",
13097
+ strokeLinecap: "round",
13098
+ strokeLinejoin: "round"
13099
+ }
13100
+ ) }),
13101
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13102
+ "path",
13103
+ {
13104
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
13105
+ stroke: "#A1A1AA",
13106
+ strokeWidth: "1.5",
13107
+ strokeLinecap: "round",
13108
+ strokeLinejoin: "round"
13109
+ }
13110
+ ) }),
13111
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13112
+ "path",
13113
+ {
13114
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
13115
+ stroke: "#A1A1AA",
13116
+ strokeWidth: "1.5",
13117
+ strokeLinecap: "round",
13118
+ strokeLinejoin: "round"
13119
+ }
13120
+ ) }),
13121
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
13122
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13123
+ "rect",
13091
13124
  {
13092
- control: form.control,
13093
- setValue: form.setValue
13125
+ width: "12",
13126
+ height: "12",
13127
+ fill: "white",
13128
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
13094
13129
  }
13095
- ),
13096
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13097
- /* @__PURE__ */ jsxRuntime.jsx(
13098
- ShippingOptionField,
13130
+ ) }),
13131
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13132
+ "rect",
13099
13133
  {
13100
- shippingProfileId: data.shippingProfileId,
13101
- preview,
13102
- control: form.control
13134
+ width: "12",
13135
+ height: "12",
13136
+ fill: "white",
13137
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13103
13138
  }
13104
- ),
13105
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13106
- /* @__PURE__ */ jsxRuntime.jsx(
13107
- CustomAmountField,
13139
+ ) }),
13140
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13141
+ "rect",
13108
13142
  {
13109
- control: form.control,
13110
- currencyCode: order.currency_code
13143
+ width: "12",
13144
+ height: "12",
13145
+ fill: "white",
13146
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13111
13147
  }
13112
- ),
13113
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13114
- /* @__PURE__ */ jsxRuntime.jsx(
13115
- ItemsPreview,
13148
+ ) }),
13149
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13150
+ "rect",
13116
13151
  {
13117
- order,
13118
- shippingProfileId: data.shippingProfileId
13152
+ width: "12",
13153
+ height: "12",
13154
+ fill: "white",
13155
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13119
13156
  }
13120
- )
13121
- ] }) }) }),
13122
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
13123
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13124
- /* @__PURE__ */ jsxRuntime.jsx(
13125
- ui.Button,
13157
+ ) }),
13158
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13159
+ "rect",
13126
13160
  {
13127
- size: "small",
13128
- type: "submit",
13129
- isLoading: isPending || isUpdatingShippingMethod,
13130
- children: data.shippingMethod ? "Update" : "Add"
13161
+ width: "12",
13162
+ height: "12",
13163
+ fill: "white",
13164
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13131
13165
  }
13132
- )
13133
- ] }) })
13134
- ]
13135
- }
13136
- ) }) });
13137
- };
13138
- const shippingMethodSchema = object({
13139
- location_id: string(),
13140
- shipping_option_id: string(),
13141
- custom_amount: union([number(), string()]).optional()
13142
- });
13143
- const ItemsPreview = ({ order, shippingProfileId }) => {
13144
- const matches = order.items.filter(
13145
- (item) => {
13146
- var _a2, _b, _c;
13147
- return ((_c = (_b = (_a2 = item.variant) == null ? void 0 : _a2.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
13148
- }
13149
- );
13150
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
13151
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13152
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
13153
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
13154
- ] }) }),
13155
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
13156
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
13157
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
13158
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
13159
- ] }),
13160
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
13161
- "div",
13162
- {
13163
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
13164
- children: [
13165
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
13166
- /* @__PURE__ */ jsxRuntime.jsx(
13167
- Thumbnail,
13168
- {
13169
- thumbnail: item.thumbnail,
13170
- alt: item.product_title ?? void 0
13171
- }
13172
- ),
13173
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13174
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
13175
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
13176
- /* @__PURE__ */ jsxRuntime.jsxs(
13177
- ui.Text,
13178
- {
13179
- size: "small",
13180
- leading: "compact",
13181
- className: "text-ui-fg-subtle",
13182
- children: [
13183
- "(",
13184
- item.variant_title,
13185
- ")"
13186
- ]
13187
- }
13188
- )
13189
- ] }),
13190
- /* @__PURE__ */ jsxRuntime.jsx(
13191
- ui.Text,
13192
- {
13193
- size: "small",
13194
- leading: "compact",
13195
- className: "text-ui-fg-subtle",
13196
- children: item.variant_sku
13197
- }
13198
- )
13199
- ] })
13200
- ] }),
13201
- /* @__PURE__ */ jsxRuntime.jsxs(
13202
- ui.Text,
13203
- {
13204
- size: "small",
13205
- leading: "compact",
13206
- className: "text-ui-fg-subtle",
13207
- children: [
13208
- item.quantity,
13209
- "x"
13210
- ]
13211
- }
13212
- )
13213
- ]
13214
- },
13215
- item.id
13216
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
13217
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
13218
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
13219
- 'No items found for "',
13220
- query,
13221
- '".'
13222
- ] })
13223
- ] }) })
13224
- ] })
13225
- ] });
13226
- };
13227
- const LocationField = ({ control, setValue }) => {
13228
- const locations = useComboboxData({
13229
- queryKey: ["locations"],
13230
- queryFn: async (params) => {
13231
- return await sdk.admin.stockLocation.list(params);
13232
- },
13233
- getOptions: (data) => {
13234
- return data.stock_locations.map((location) => ({
13235
- label: location.name,
13236
- value: location.id
13237
- }));
13238
- }
13239
- });
13240
- return /* @__PURE__ */ jsxRuntime.jsx(
13241
- Form$2.Field,
13242
- {
13243
- control,
13244
- name: "location_id",
13245
- render: ({ field: { onChange, ...field } }) => {
13246
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13247
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13248
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
13249
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
13250
- ] }),
13251
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13252
- Combobox,
13166
+ ) }),
13167
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13168
+ "rect",
13253
13169
  {
13254
- options: locations.options,
13255
- fetchNextPage: locations.fetchNextPage,
13256
- isFetchingNextPage: locations.isFetchingNextPage,
13257
- searchValue: locations.searchValue,
13258
- onSearchValueChange: locations.onSearchValueChange,
13259
- placeholder: "Select location",
13260
- onChange: (value) => {
13261
- setValue("shipping_option_id", "", {
13262
- shouldDirty: true,
13263
- shouldTouch: true
13264
- });
13265
- onChange(value);
13266
- },
13267
- ...field
13170
+ width: "12",
13171
+ height: "12",
13172
+ fill: "white",
13173
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13268
13174
  }
13269
13175
  ) })
13270
- ] }) });
13271
- }
13176
+ ] })
13177
+ ]
13272
13178
  }
13273
13179
  );
13274
13180
  };
13275
- const ShippingOptionField = ({
13276
- shippingProfileId,
13277
- preview,
13278
- control
13279
- }) => {
13280
- var _a2;
13281
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
13282
- const shippingOptions = useComboboxData({
13283
- queryKey: ["shipping_options", locationId, shippingProfileId],
13284
- queryFn: async (params) => {
13285
- return await sdk.admin.shippingOption.list({
13286
- ...params,
13287
- stock_location_id: locationId,
13288
- shipping_profile_id: shippingProfileId
13289
- });
13181
+ const schema$1 = object({
13182
+ customer_id: string().min(1)
13183
+ });
13184
+ const BillingAddress = () => {
13185
+ const { id } = reactRouterDom.useParams();
13186
+ const { order, isPending, isError, error } = useOrder(id, {
13187
+ fields: "+billing_address"
13188
+ });
13189
+ if (isError) {
13190
+ throw error;
13191
+ }
13192
+ const isReady = !isPending && !!order;
13193
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13194
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
13195
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
13196
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
13197
+ ] }),
13198
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
13199
+ ] });
13200
+ };
13201
+ const BillingAddressForm = ({ order }) => {
13202
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
13203
+ const form = reactHookForm.useForm({
13204
+ defaultValues: {
13205
+ first_name: ((_a2 = order.billing_address) == null ? void 0 : _a2.first_name) ?? "",
13206
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
13207
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
13208
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
13209
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
13210
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
13211
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
13212
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
13213
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
13214
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
13290
13215
  },
13291
- getOptions: (data) => {
13292
- return data.shipping_options.map((option) => {
13293
- var _a3;
13294
- if ((_a3 = option.rules) == null ? void 0 : _a3.find(
13295
- (r) => r.attribute === "is_return" && r.value === "true"
13296
- )) {
13297
- return void 0;
13216
+ resolver: zod.zodResolver(schema)
13217
+ });
13218
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
13219
+ const { handleSuccess } = useRouteModal();
13220
+ const onSubmit = form.handleSubmit(async (data) => {
13221
+ await mutateAsync(
13222
+ { billing_address: data },
13223
+ {
13224
+ onSuccess: () => {
13225
+ handleSuccess();
13226
+ },
13227
+ onError: (error) => {
13228
+ ui.toast.error(error.message);
13298
13229
  }
13299
- return {
13300
- label: option.name,
13301
- value: option.id
13302
- };
13303
- }).filter(Boolean);
13304
- },
13305
- enabled: !!locationId && !!shippingProfileId,
13306
- defaultValue: ((_a2 = preview.shipping_methods[0]) == null ? void 0 : _a2.shipping_option_id) || void 0
13230
+ }
13231
+ );
13307
13232
  });
13308
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
13309
- return /* @__PURE__ */ jsxRuntime.jsx(
13310
- Form$2.Field,
13233
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13234
+ KeyboundForm,
13311
13235
  {
13312
- control,
13313
- name: "shipping_option_id",
13314
- render: ({ field }) => {
13315
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13316
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13317
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
13318
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
13236
+ className: "flex flex-1 flex-col overflow-hidden",
13237
+ onSubmit,
13238
+ children: [
13239
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
13240
+ /* @__PURE__ */ jsxRuntime.jsx(
13241
+ Form$2.Field,
13242
+ {
13243
+ control: form.control,
13244
+ name: "country_code",
13245
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13246
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
13247
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
13248
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13249
+ ] })
13250
+ }
13251
+ ),
13252
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
13253
+ /* @__PURE__ */ jsxRuntime.jsx(
13254
+ Form$2.Field,
13255
+ {
13256
+ control: form.control,
13257
+ name: "first_name",
13258
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13259
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
13260
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13261
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13262
+ ] })
13263
+ }
13264
+ ),
13265
+ /* @__PURE__ */ jsxRuntime.jsx(
13266
+ Form$2.Field,
13267
+ {
13268
+ control: form.control,
13269
+ name: "last_name",
13270
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13271
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
13272
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13273
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13274
+ ] })
13275
+ }
13276
+ )
13319
13277
  ] }),
13320
13278
  /* @__PURE__ */ jsxRuntime.jsx(
13321
- ConditionalTooltip,
13279
+ Form$2.Field,
13322
13280
  {
13323
- content: tooltipContent,
13324
- showTooltip: !locationId || !shippingProfileId,
13325
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13326
- Combobox,
13327
- {
13328
- options: shippingOptions.options,
13329
- fetchNextPage: shippingOptions.fetchNextPage,
13330
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
13331
- searchValue: shippingOptions.searchValue,
13332
- onSearchValueChange: shippingOptions.onSearchValueChange,
13333
- placeholder: "Select shipping option",
13334
- ...field,
13335
- disabled: !locationId || !shippingProfileId
13336
- }
13337
- ) }) })
13281
+ control: form.control,
13282
+ name: "company",
13283
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13284
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
13285
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13286
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13287
+ ] })
13338
13288
  }
13339
- )
13340
- ] }) });
13341
- }
13342
- }
13343
- );
13344
- };
13345
- const CustomAmountField = ({
13346
- control,
13347
- currencyCode
13348
- }) => {
13349
- return /* @__PURE__ */ jsxRuntime.jsx(
13350
- Form$2.Field,
13351
- {
13352
- control,
13353
- name: "custom_amount",
13354
- render: ({ field: { onChange, ...field } }) => {
13355
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13356
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13357
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13358
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13289
+ ),
13290
+ /* @__PURE__ */ jsxRuntime.jsx(
13291
+ Form$2.Field,
13292
+ {
13293
+ control: form.control,
13294
+ name: "address_1",
13295
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13296
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
13297
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13298
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13299
+ ] })
13300
+ }
13301
+ ),
13302
+ /* @__PURE__ */ jsxRuntime.jsx(
13303
+ Form$2.Field,
13304
+ {
13305
+ control: form.control,
13306
+ name: "address_2",
13307
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13308
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
13309
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13310
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13311
+ ] })
13312
+ }
13313
+ ),
13314
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
13315
+ /* @__PURE__ */ jsxRuntime.jsx(
13316
+ Form$2.Field,
13317
+ {
13318
+ control: form.control,
13319
+ name: "postal_code",
13320
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13321
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
13322
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13323
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13324
+ ] })
13325
+ }
13326
+ ),
13327
+ /* @__PURE__ */ jsxRuntime.jsx(
13328
+ Form$2.Field,
13329
+ {
13330
+ control: form.control,
13331
+ name: "city",
13332
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13333
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13334
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13335
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13336
+ ] })
13337
+ }
13338
+ )
13359
13339
  ] }),
13360
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13361
- ui.CurrencyInput,
13340
+ /* @__PURE__ */ jsxRuntime.jsx(
13341
+ Form$2.Field,
13362
13342
  {
13363
- ...field,
13364
- onValueChange: (value) => onChange(value),
13365
- symbol: getNativeSymbol(currencyCode),
13366
- code: currencyCode
13343
+ control: form.control,
13344
+ name: "province",
13345
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13346
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13347
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13348
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13349
+ ] })
13367
13350
  }
13368
- ) })
13369
- ] });
13370
- }
13351
+ ),
13352
+ /* @__PURE__ */ jsxRuntime.jsx(
13353
+ Form$2.Field,
13354
+ {
13355
+ control: form.control,
13356
+ name: "phone",
13357
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13358
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13359
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13360
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13361
+ ] })
13362
+ }
13363
+ )
13364
+ ] }) }),
13365
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13366
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13367
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13368
+ ] }) })
13369
+ ]
13371
13370
  }
13372
- );
13371
+ ) });
13373
13372
  };
13373
+ const schema = addressSchema;
13374
13374
  const widgetModule = { widgets: [] };
13375
13375
  const routeModule = {
13376
13376
  routes: [
@@ -13391,10 +13391,6 @@ const routeModule = {
13391
13391
  handle,
13392
13392
  loader,
13393
13393
  children: [
13394
- {
13395
- Component: BillingAddress,
13396
- path: "/draft-orders/:id/billing-address"
13397
- },
13398
13394
  {
13399
13395
  Component: CustomItems,
13400
13396
  path: "/draft-orders/:id/custom-items"
@@ -13419,6 +13415,10 @@ const routeModule = {
13419
13415
  Component: SalesChannel,
13420
13416
  path: "/draft-orders/:id/sales-channel"
13421
13417
  },
13418
+ {
13419
+ Component: Shipping,
13420
+ path: "/draft-orders/:id/shipping"
13421
+ },
13422
13422
  {
13423
13423
  Component: ShippingAddress,
13424
13424
  path: "/draft-orders/:id/shipping-address"
@@ -13428,8 +13428,8 @@ const routeModule = {
13428
13428
  path: "/draft-orders/:id/transfer-ownership"
13429
13429
  },
13430
13430
  {
13431
- Component: Shipping,
13432
- path: "/draft-orders/:id/shipping"
13431
+ Component: BillingAddress,
13432
+ path: "/draft-orders/:id/billing-address"
13433
13433
  }
13434
13434
  ]
13435
13435
  }