@medusajs/draft-order 2.15.2-snapshot-20260512173359 → 2.15.2

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.
@@ -10089,6 +10089,27 @@ const BillingAddressForm = ({ order }) => {
10089
10089
  ) });
10090
10090
  };
10091
10091
  const schema$5 = addressSchema;
10092
+ const CustomItems = () => {
10093
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10094
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
10095
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
10096
+ ] });
10097
+ };
10098
+ const CustomItemsForm = () => {
10099
+ const form = reactHookForm.useForm({
10100
+ resolver: zod.zodResolver(schema$4)
10101
+ });
10102
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10103
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
10104
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10105
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10106
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
10107
+ ] }) })
10108
+ ] }) });
10109
+ };
10110
+ const schema$4 = object({
10111
+ email: string().email()
10112
+ });
10092
10113
  const Email = () => {
10093
10114
  const { id } = reactRouterDom.useParams();
10094
10115
  const { order, isPending, isError, error } = useOrder(id, {
@@ -10111,7 +10132,7 @@ const EmailForm = ({ order }) => {
10111
10132
  defaultValues: {
10112
10133
  email: order.email ?? ""
10113
10134
  },
10114
- resolver: zod.zodResolver(schema$4)
10135
+ resolver: zod.zodResolver(schema$3)
10115
10136
  });
10116
10137
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10117
10138
  const { handleSuccess } = useRouteModal();
@@ -10154,27 +10175,6 @@ const EmailForm = ({ order }) => {
10154
10175
  }
10155
10176
  ) });
10156
10177
  };
10157
- const schema$4 = object({
10158
- email: string().email()
10159
- });
10160
- const CustomItems = () => {
10161
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10162
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
10163
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
10164
- ] });
10165
- };
10166
- const CustomItemsForm = () => {
10167
- const form = reactHookForm.useForm({
10168
- resolver: zod.zodResolver(schema$3)
10169
- });
10170
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10171
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
10172
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10173
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10174
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
10175
- ] }) })
10176
- ] }) });
10177
- };
10178
10178
  const schema$3 = object({
10179
10179
  email: string().email()
10180
10180
  });
@@ -11885,821 +11885,142 @@ const SalesChannelField = ({ control, order }) => {
11885
11885
  const schema$2 = object({
11886
11886
  sales_channel_id: string().min(1)
11887
11887
  });
11888
- const ShippingAddress = () => {
11888
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11889
+ const Shipping = () => {
11890
+ var _a2;
11889
11891
  const { id } = reactRouterDom.useParams();
11890
11892
  const { order, isPending, isError, error } = useOrder(id, {
11891
- fields: "+shipping_address"
11893
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11892
11894
  });
11895
+ const {
11896
+ order: preview,
11897
+ isPending: isPreviewPending,
11898
+ isError: isPreviewError,
11899
+ error: previewError
11900
+ } = useOrderPreview(id);
11901
+ useInitiateOrderEdit({ preview });
11902
+ const { onCancel } = useCancelOrderEdit({ preview });
11893
11903
  if (isError) {
11894
11904
  throw error;
11895
11905
  }
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
- ] });
11906
+ if (isPreviewError) {
11907
+ throw previewError;
11908
+ }
11909
+ const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
11910
+ const isReady = preview && !isPreviewPending && order && !isPending;
11911
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11912
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11913
+ /* @__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: [
11914
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11915
+ /* @__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." }) })
11916
+ ] }) }) }),
11917
+ /* @__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" }) }) })
11918
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11919
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11920
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11921
+ ] }) });
11904
11922
  };
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) ?? ""
11923
+ const ShippingForm = ({ preview, order }) => {
11924
+ var _a2;
11925
+ const { setIsOpen } = useStackedModal();
11926
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11927
+ const [data, setData] = React.useState(null);
11928
+ const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
11929
+ const { shipping_options } = useShippingOptions(
11930
+ {
11931
+ id: appliedShippingOptionIds,
11932
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11919
11933
  },
11920
- resolver: zod.zodResolver(schema$1)
11921
- });
11922
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11934
+ {
11935
+ enabled: appliedShippingOptionIds.length > 0
11936
+ }
11937
+ );
11938
+ const uniqueShippingProfiles = React.useMemo(() => {
11939
+ const profiles = /* @__PURE__ */ new Map();
11940
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11941
+ profiles.set(profile.id, profile);
11942
+ });
11943
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11944
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11945
+ });
11946
+ return Array.from(profiles.values());
11947
+ }, [order.items, shipping_options]);
11923
11948
  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
- }
11949
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11950
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11951
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11952
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11953
+ const onSubmit = async () => {
11954
+ setIsSubmitting(true);
11955
+ let requestSucceeded = false;
11956
+ await requestOrderEdit(void 0, {
11957
+ onError: (e) => {
11958
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11939
11959
  },
11940
- {
11941
- onSuccess: () => {
11942
- handleSuccess();
11943
- },
11944
- onError: (error) => {
11945
- ui.toast.error(error.message);
11960
+ onSuccess: () => {
11961
+ requestSucceeded = true;
11962
+ }
11963
+ });
11964
+ if (!requestSucceeded) {
11965
+ setIsSubmitting(false);
11966
+ return;
11967
+ }
11968
+ await confirmOrderEdit(void 0, {
11969
+ onError: (e) => {
11970
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11971
+ },
11972
+ onSuccess: () => {
11973
+ handleSuccess();
11974
+ },
11975
+ onSettled: () => {
11976
+ setIsSubmitting(false);
11977
+ }
11978
+ });
11979
+ };
11980
+ const onKeydown = React.useCallback(
11981
+ (e) => {
11982
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11983
+ if (data || isSubmitting) {
11984
+ return;
11946
11985
  }
11986
+ onSubmit();
11947
11987
  }
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: [
11988
+ },
11989
+ [data, isSubmitting, onSubmit]
11990
+ );
11991
+ React.useEffect(() => {
11992
+ document.addEventListener("keydown", onKeydown);
11993
+ return () => {
11994
+ document.removeEventListener("keydown", onKeydown);
11995
+ };
11996
+ }, [onKeydown]);
11997
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11998
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11999
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12000
+ /* @__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: [
12001
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12002
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12003
+ /* @__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." }) })
12004
+ ] }),
12005
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12006
+ /* @__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: [
12007
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11970
12008
  /* @__PURE__ */ jsxRuntime.jsx(
11971
- Form$2.Field,
12009
+ ui.Text,
11972
12010
  {
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
- ] })
12011
+ size: "xsmall",
12012
+ weight: "plus",
12013
+ className: "text-ui-fg-muted",
12014
+ children: "Shipping profile"
11980
12015
  }
11981
12016
  ),
11982
12017
  /* @__PURE__ */ jsxRuntime.jsx(
11983
- Form$2.Field,
12018
+ ui.Text,
11984
12019
  {
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
- ] })
11992
- }
11993
- )
11994
- ] }),
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,
12046
- {
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" })
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)
12115
- });
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 },
12126
- {
12127
- onSuccess: () => {
12128
- ui.toast.success("Customer updated");
12129
- handleSuccess();
12130
- },
12131
- onError: (error) => {
12132
- ui.toast.error(error.message);
12133
- }
12134
- }
12135
- );
12136
- });
12137
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12138
- KeyboundForm,
12139
- {
12140
- className: "flex flex-1 flex-col overflow-hidden",
12141
- onSubmit,
12142
- 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
- ] })
12154
- ] }),
12155
- /* @__PURE__ */ jsxRuntime.jsx(
12156
- CustomerField,
12157
- {
12158
- control: form.control,
12159
- currentCustomerId: order.customer_id
12160
- }
12161
- )
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
- ] }) })
12167
- ]
12168
- }
12169
- ) });
12170
- };
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
- ] })
12214
- }
12215
- );
12216
- };
12217
- const Illustration = () => {
12218
- return /* @__PURE__ */ jsxRuntime.jsxs(
12219
- "svg",
12220
- {
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",
12552
- {
12553
- width: "12",
12554
- height: "12",
12555
- fill: "white",
12556
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12557
- }
12558
- ) })
12559
- ] })
12560
- ]
12561
- }
12562
- );
12563
- };
12564
- const schema = object({
12565
- customer_id: string().min(1)
12566
- });
12567
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12568
- const Shipping = () => {
12569
- 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"
12573
- });
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
- },
12613
- {
12614
- enabled: appliedShippingOptionIds.length > 0
12615
- }
12616
- );
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;
12641
- }
12642
- });
12643
- if (!requestSucceeded) {
12644
- setIsSubmitting(false);
12645
- return;
12646
- }
12647
- await confirmOrderEdit(void 0, {
12648
- onError: (e) => {
12649
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12650
- },
12651
- onSuccess: () => {
12652
- handleSuccess();
12653
- },
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;
12664
- }
12665
- onSubmit();
12666
- }
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: [
12687
- /* @__PURE__ */ jsxRuntime.jsx(
12688
- ui.Text,
12689
- {
12690
- size: "xsmall",
12691
- weight: "plus",
12692
- className: "text-ui-fg-muted",
12693
- children: "Shipping profile"
12694
- }
12695
- ),
12696
- /* @__PURE__ */ jsxRuntime.jsx(
12697
- ui.Text,
12698
- {
12699
- size: "xsmall",
12700
- weight: "plus",
12701
- className: "text-ui-fg-muted",
12702
- children: "Action"
12020
+ size: "xsmall",
12021
+ weight: "plus",
12022
+ className: "text-ui-fg-muted",
12023
+ children: "Action"
12703
12024
  }
12704
12025
  )
12705
12026
  ] }),
@@ -12952,425 +12273,1104 @@ const ShippingForm = ({ preview, order }) => {
12952
12273
  );
12953
12274
  }) })
12954
12275
  ] }) })
12955
- ] }) }),
12956
- /* @__PURE__ */ jsxRuntime.jsx(
12957
- StackedFocusModal,
12276
+ ] }) }),
12277
+ /* @__PURE__ */ jsxRuntime.jsx(
12278
+ StackedFocusModal,
12279
+ {
12280
+ id: STACKED_FOCUS_MODAL_ID,
12281
+ onOpenChangeCallback: (open) => {
12282
+ if (!open) {
12283
+ setData(null);
12284
+ }
12285
+ return open;
12286
+ },
12287
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12288
+ }
12289
+ )
12290
+ ] }),
12291
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12292
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12293
+ /* @__PURE__ */ jsxRuntime.jsx(
12294
+ ui.Button,
12295
+ {
12296
+ size: "small",
12297
+ type: "button",
12298
+ isLoading: isSubmitting,
12299
+ onClick: onSubmit,
12300
+ children: "Save"
12301
+ }
12302
+ )
12303
+ ] }) })
12304
+ ] });
12305
+ };
12306
+ const StackedModalTrigger = ({
12307
+ shippingProfileId,
12308
+ shippingOption,
12309
+ shippingMethod,
12310
+ setData,
12311
+ children
12312
+ }) => {
12313
+ const { setIsOpen, getIsOpen } = useStackedModal();
12314
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12315
+ const onToggle = () => {
12316
+ if (isOpen) {
12317
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12318
+ setData(null);
12319
+ } else {
12320
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12321
+ setData({
12322
+ shippingProfileId,
12323
+ shippingOption,
12324
+ shippingMethod
12325
+ });
12326
+ }
12327
+ };
12328
+ return /* @__PURE__ */ jsxRuntime.jsx(
12329
+ ui.Button,
12330
+ {
12331
+ size: "small",
12332
+ variant: "secondary",
12333
+ onClick: onToggle,
12334
+ className: "text-ui-fg-primary shrink-0",
12335
+ children
12336
+ }
12337
+ );
12338
+ };
12339
+ const ShippingProfileForm = ({
12340
+ data,
12341
+ order,
12342
+ preview
12343
+ }) => {
12344
+ var _a2, _b, _c, _d, _e, _f;
12345
+ const { setIsOpen } = useStackedModal();
12346
+ const form = reactHookForm.useForm({
12347
+ resolver: zod.zodResolver(shippingMethodSchema),
12348
+ defaultValues: {
12349
+ 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,
12350
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12351
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12352
+ }
12353
+ });
12354
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12355
+ const {
12356
+ mutateAsync: updateShippingMethod,
12357
+ isPending: isUpdatingShippingMethod
12358
+ } = useDraftOrderUpdateShippingMethod(order.id);
12359
+ const onSubmit = form.handleSubmit(async (values) => {
12360
+ if (isEqual__default.default(values, form.formState.defaultValues)) {
12361
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12362
+ return;
12363
+ }
12364
+ if (data.shippingMethod) {
12365
+ await updateShippingMethod(
12366
+ {
12367
+ method_id: data.shippingMethod.id,
12368
+ shipping_option_id: values.shipping_option_id,
12369
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12370
+ },
12371
+ {
12372
+ onError: (e) => {
12373
+ ui.toast.error(e.message);
12374
+ },
12375
+ onSuccess: () => {
12376
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12377
+ }
12378
+ }
12379
+ );
12380
+ return;
12381
+ }
12382
+ await addShippingMethod(
12383
+ {
12384
+ shipping_option_id: values.shipping_option_id,
12385
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12386
+ },
12387
+ {
12388
+ onError: (e) => {
12389
+ ui.toast.error(e.message);
12390
+ },
12391
+ onSuccess: () => {
12392
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12393
+ }
12394
+ }
12395
+ );
12396
+ });
12397
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12398
+ KeyboundForm,
12399
+ {
12400
+ className: "flex h-full flex-col overflow-hidden",
12401
+ onSubmit,
12402
+ children: [
12403
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12404
+ /* @__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: [
12405
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12406
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12407
+ /* @__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." }) })
12408
+ ] }),
12409
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12410
+ /* @__PURE__ */ jsxRuntime.jsx(
12411
+ LocationField,
12412
+ {
12413
+ control: form.control,
12414
+ setValue: form.setValue
12415
+ }
12416
+ ),
12417
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12418
+ /* @__PURE__ */ jsxRuntime.jsx(
12419
+ ShippingOptionField,
12420
+ {
12421
+ shippingProfileId: data.shippingProfileId,
12422
+ preview,
12423
+ control: form.control
12424
+ }
12425
+ ),
12426
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12427
+ /* @__PURE__ */ jsxRuntime.jsx(
12428
+ CustomAmountField,
12429
+ {
12430
+ control: form.control,
12431
+ currencyCode: order.currency_code
12432
+ }
12433
+ ),
12434
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12435
+ /* @__PURE__ */ jsxRuntime.jsx(
12436
+ ItemsPreview,
12437
+ {
12438
+ order,
12439
+ shippingProfileId: data.shippingProfileId
12440
+ }
12441
+ )
12442
+ ] }) }) }),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(
12446
+ ui.Button,
12447
+ {
12448
+ size: "small",
12449
+ type: "submit",
12450
+ isLoading: isPending || isUpdatingShippingMethod,
12451
+ children: data.shippingMethod ? "Update" : "Add"
12452
+ }
12453
+ )
12454
+ ] }) })
12455
+ ]
12456
+ }
12457
+ ) }) });
12458
+ };
12459
+ const shippingMethodSchema = object({
12460
+ location_id: string(),
12461
+ shipping_option_id: string(),
12462
+ custom_amount: union([number(), string()]).optional()
12463
+ });
12464
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12465
+ const matches = order.items.filter(
12466
+ (item) => {
12467
+ var _a2, _b, _c;
12468
+ return ((_c = (_b = (_a2 = item.variant) == null ? void 0 : _a2.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12469
+ }
12470
+ );
12471
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12472
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12473
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12474
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12475
+ ] }) }),
12476
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12477
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12478
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12479
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12480
+ ] }),
12481
+ /* @__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(
12482
+ "div",
12958
12483
  {
12959
- id: STACKED_FOCUS_MODAL_ID,
12960
- onOpenChangeCallback: (open) => {
12961
- if (!open) {
12962
- setData(null);
12484
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12485
+ children: [
12486
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12487
+ /* @__PURE__ */ jsxRuntime.jsx(
12488
+ Thumbnail,
12489
+ {
12490
+ thumbnail: item.thumbnail,
12491
+ alt: item.product_title ?? void 0
12492
+ }
12493
+ ),
12494
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12495
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12496
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12497
+ /* @__PURE__ */ jsxRuntime.jsxs(
12498
+ ui.Text,
12499
+ {
12500
+ size: "small",
12501
+ leading: "compact",
12502
+ className: "text-ui-fg-subtle",
12503
+ children: [
12504
+ "(",
12505
+ item.variant_title,
12506
+ ")"
12507
+ ]
12508
+ }
12509
+ )
12510
+ ] }),
12511
+ /* @__PURE__ */ jsxRuntime.jsx(
12512
+ ui.Text,
12513
+ {
12514
+ size: "small",
12515
+ leading: "compact",
12516
+ className: "text-ui-fg-subtle",
12517
+ children: item.variant_sku
12518
+ }
12519
+ )
12520
+ ] })
12521
+ ] }),
12522
+ /* @__PURE__ */ jsxRuntime.jsxs(
12523
+ ui.Text,
12524
+ {
12525
+ size: "small",
12526
+ leading: "compact",
12527
+ className: "text-ui-fg-subtle",
12528
+ children: [
12529
+ item.quantity,
12530
+ "x"
12531
+ ]
12532
+ }
12533
+ )
12534
+ ]
12535
+ },
12536
+ item.id
12537
+ )) : /* @__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: [
12538
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12539
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12540
+ 'No items found for "',
12541
+ query,
12542
+ '".'
12543
+ ] })
12544
+ ] }) })
12545
+ ] })
12546
+ ] });
12547
+ };
12548
+ const LocationField = ({ control, setValue }) => {
12549
+ const locations = useComboboxData({
12550
+ queryKey: ["locations"],
12551
+ queryFn: async (params) => {
12552
+ return await sdk.admin.stockLocation.list(params);
12553
+ },
12554
+ getOptions: (data) => {
12555
+ return data.stock_locations.map((location) => ({
12556
+ label: location.name,
12557
+ value: location.id
12558
+ }));
12559
+ }
12560
+ });
12561
+ return /* @__PURE__ */ jsxRuntime.jsx(
12562
+ Form$2.Field,
12563
+ {
12564
+ control,
12565
+ name: "location_id",
12566
+ render: ({ field: { onChange, ...field } }) => {
12567
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12568
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12569
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12570
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12571
+ ] }),
12572
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12573
+ Combobox,
12574
+ {
12575
+ options: locations.options,
12576
+ fetchNextPage: locations.fetchNextPage,
12577
+ isFetchingNextPage: locations.isFetchingNextPage,
12578
+ searchValue: locations.searchValue,
12579
+ onSearchValueChange: locations.onSearchValueChange,
12580
+ placeholder: "Select location",
12581
+ onChange: (value) => {
12582
+ setValue("shipping_option_id", "", {
12583
+ shouldDirty: true,
12584
+ shouldTouch: true
12585
+ });
12586
+ onChange(value);
12587
+ },
12588
+ ...field
12589
+ }
12590
+ ) })
12591
+ ] }) });
12592
+ }
12593
+ }
12594
+ );
12595
+ };
12596
+ const ShippingOptionField = ({
12597
+ shippingProfileId,
12598
+ preview,
12599
+ control
12600
+ }) => {
12601
+ var _a2;
12602
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12603
+ const shippingOptions = useComboboxData({
12604
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12605
+ queryFn: async (params) => {
12606
+ return await sdk.admin.shippingOption.list({
12607
+ ...params,
12608
+ stock_location_id: locationId,
12609
+ shipping_profile_id: shippingProfileId
12610
+ });
12611
+ },
12612
+ getOptions: (data) => {
12613
+ return data.shipping_options.map((option) => {
12614
+ var _a3;
12615
+ if ((_a3 = option.rules) == null ? void 0 : _a3.find(
12616
+ (r) => r.attribute === "is_return" && r.value === "true"
12617
+ )) {
12618
+ return void 0;
12619
+ }
12620
+ return {
12621
+ label: option.name,
12622
+ value: option.id
12623
+ };
12624
+ }).filter(Boolean);
12625
+ },
12626
+ enabled: !!locationId && !!shippingProfileId,
12627
+ defaultValue: ((_a2 = preview.shipping_methods[0]) == null ? void 0 : _a2.shipping_option_id) || void 0
12628
+ });
12629
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12630
+ return /* @__PURE__ */ jsxRuntime.jsx(
12631
+ Form$2.Field,
12632
+ {
12633
+ control,
12634
+ name: "shipping_option_id",
12635
+ render: ({ field }) => {
12636
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12637
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12640
+ ] }),
12641
+ /* @__PURE__ */ jsxRuntime.jsx(
12642
+ ConditionalTooltip,
12643
+ {
12644
+ content: tooltipContent,
12645
+ showTooltip: !locationId || !shippingProfileId,
12646
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12647
+ Combobox,
12648
+ {
12649
+ options: shippingOptions.options,
12650
+ fetchNextPage: shippingOptions.fetchNextPage,
12651
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12652
+ searchValue: shippingOptions.searchValue,
12653
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12654
+ placeholder: "Select shipping option",
12655
+ ...field,
12656
+ disabled: !locationId || !shippingProfileId
12657
+ }
12658
+ ) }) })
12659
+ }
12660
+ )
12661
+ ] }) });
12662
+ }
12663
+ }
12664
+ );
12665
+ };
12666
+ const CustomAmountField = ({
12667
+ control,
12668
+ currencyCode
12669
+ }) => {
12670
+ return /* @__PURE__ */ jsxRuntime.jsx(
12671
+ Form$2.Field,
12672
+ {
12673
+ control,
12674
+ name: "custom_amount",
12675
+ render: ({ field: { onChange, ...field } }) => {
12676
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12677
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12679
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12680
+ ] }),
12681
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12682
+ ui.CurrencyInput,
12683
+ {
12684
+ ...field,
12685
+ onValueChange: (value) => onChange(value),
12686
+ symbol: getNativeSymbol(currencyCode),
12687
+ code: currencyCode
12963
12688
  }
12964
- return open;
12965
- },
12966
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12967
- }
12968
- )
12689
+ ) })
12690
+ ] });
12691
+ }
12692
+ }
12693
+ );
12694
+ };
12695
+ const ShippingAddress = () => {
12696
+ const { id } = reactRouterDom.useParams();
12697
+ const { order, isPending, isError, error } = useOrder(id, {
12698
+ fields: "+shipping_address"
12699
+ });
12700
+ if (isError) {
12701
+ throw error;
12702
+ }
12703
+ const isReady = !isPending && !!order;
12704
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12705
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12706
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12707
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12969
12708
  ] }),
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
- ] }) })
12709
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12983
12710
  ] });
12984
12711
  };
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
13004
- });
13005
- }
13006
- };
13007
- return /* @__PURE__ */ jsxRuntime.jsx(
13008
- ui.Button,
12712
+ const ShippingAddressForm = ({ order }) => {
12713
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12714
+ const form = reactHookForm.useForm({
12715
+ defaultValues: {
12716
+ first_name: ((_a2 = order.shipping_address) == null ? void 0 : _a2.first_name) ?? "",
12717
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12718
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12719
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12720
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12721
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12722
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12723
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12724
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12725
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12726
+ },
12727
+ resolver: zod.zodResolver(schema$1)
12728
+ });
12729
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12730
+ const { handleSuccess } = useRouteModal();
12731
+ const onSubmit = form.handleSubmit(async (data) => {
12732
+ await mutateAsync(
12733
+ {
12734
+ shipping_address: {
12735
+ first_name: data.first_name,
12736
+ last_name: data.last_name,
12737
+ company: data.company,
12738
+ address_1: data.address_1,
12739
+ address_2: data.address_2,
12740
+ city: data.city,
12741
+ province: data.province,
12742
+ country_code: data.country_code,
12743
+ postal_code: data.postal_code,
12744
+ phone: data.phone
12745
+ }
12746
+ },
12747
+ {
12748
+ onSuccess: () => {
12749
+ handleSuccess();
12750
+ },
12751
+ onError: (error) => {
12752
+ ui.toast.error(error.message);
12753
+ }
12754
+ }
12755
+ );
12756
+ });
12757
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12758
+ KeyboundForm,
13009
12759
  {
13010
- size: "small",
13011
- variant: "secondary",
13012
- onClick: onToggle,
13013
- className: "text-ui-fg-primary shrink-0",
13014
- children
12760
+ className: "flex flex-1 flex-col overflow-hidden",
12761
+ onSubmit,
12762
+ children: [
12763
+ /* @__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: [
12764
+ /* @__PURE__ */ jsxRuntime.jsx(
12765
+ Form$2.Field,
12766
+ {
12767
+ control: form.control,
12768
+ name: "country_code",
12769
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12770
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12771
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12772
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12773
+ ] })
12774
+ }
12775
+ ),
12776
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12777
+ /* @__PURE__ */ jsxRuntime.jsx(
12778
+ Form$2.Field,
12779
+ {
12780
+ control: form.control,
12781
+ name: "first_name",
12782
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12783
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12784
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12785
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12786
+ ] })
12787
+ }
12788
+ ),
12789
+ /* @__PURE__ */ jsxRuntime.jsx(
12790
+ Form$2.Field,
12791
+ {
12792
+ control: form.control,
12793
+ name: "last_name",
12794
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12795
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12796
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12797
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12798
+ ] })
12799
+ }
12800
+ )
12801
+ ] }),
12802
+ /* @__PURE__ */ jsxRuntime.jsx(
12803
+ Form$2.Field,
12804
+ {
12805
+ control: form.control,
12806
+ name: "company",
12807
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12808
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12809
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12810
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12811
+ ] })
12812
+ }
12813
+ ),
12814
+ /* @__PURE__ */ jsxRuntime.jsx(
12815
+ Form$2.Field,
12816
+ {
12817
+ control: form.control,
12818
+ name: "address_1",
12819
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12820
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12821
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12822
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12823
+ ] })
12824
+ }
12825
+ ),
12826
+ /* @__PURE__ */ jsxRuntime.jsx(
12827
+ Form$2.Field,
12828
+ {
12829
+ control: form.control,
12830
+ name: "address_2",
12831
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12832
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12833
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12834
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12835
+ ] })
12836
+ }
12837
+ ),
12838
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12839
+ /* @__PURE__ */ jsxRuntime.jsx(
12840
+ Form$2.Field,
12841
+ {
12842
+ control: form.control,
12843
+ name: "postal_code",
12844
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12845
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12846
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12847
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12848
+ ] })
12849
+ }
12850
+ ),
12851
+ /* @__PURE__ */ jsxRuntime.jsx(
12852
+ Form$2.Field,
12853
+ {
12854
+ control: form.control,
12855
+ name: "city",
12856
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12857
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12858
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12859
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12860
+ ] })
12861
+ }
12862
+ )
12863
+ ] }),
12864
+ /* @__PURE__ */ jsxRuntime.jsx(
12865
+ Form$2.Field,
12866
+ {
12867
+ control: form.control,
12868
+ name: "province",
12869
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12870
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12871
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12872
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12873
+ ] })
12874
+ }
12875
+ ),
12876
+ /* @__PURE__ */ jsxRuntime.jsx(
12877
+ Form$2.Field,
12878
+ {
12879
+ control: form.control,
12880
+ name: "phone",
12881
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12882
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12883
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12884
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12885
+ ] })
12886
+ }
12887
+ )
12888
+ ] }) }),
12889
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12890
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12891
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12892
+ ] }) })
12893
+ ]
13015
12894
  }
13016
- );
12895
+ ) });
13017
12896
  };
13018
- const ShippingProfileForm = ({
13019
- data,
13020
- order,
13021
- preview
13022
- }) => {
13023
- var _a2, _b, _c, _d, _e, _f;
13024
- const { setIsOpen } = useStackedModal();
12897
+ const schema$1 = addressSchema;
12898
+ const TransferOwnership = () => {
12899
+ const { id } = reactRouterDom.useParams();
12900
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12901
+ fields: "id,customer_id,customer.*"
12902
+ });
12903
+ if (isError) {
12904
+ throw error;
12905
+ }
12906
+ const isReady = !isPending && !!draft_order;
12907
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12908
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12909
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12910
+ /* @__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" }) })
12911
+ ] }),
12912
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12913
+ ] });
12914
+ };
12915
+ const TransferOwnershipForm = ({ order }) => {
12916
+ var _a2, _b;
13025
12917
  const form = reactHookForm.useForm({
13026
- resolver: zod.zodResolver(shippingMethodSchema),
13027
12918
  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
- }
12919
+ customer_id: order.customer_id || ""
12920
+ },
12921
+ resolver: zod.zodResolver(schema)
13032
12922
  });
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);
13056
- }
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
- },
12923
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12924
+ const { handleSuccess } = useRouteModal();
12925
+ const name = [(_a2 = order.customer) == null ? void 0 : _a2.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12926
+ const currentCustomer = order.customer ? {
12927
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12928
+ value: order.customer.id
12929
+ } : null;
12930
+ const onSubmit = form.handleSubmit(async (data) => {
12931
+ await mutateAsync(
12932
+ { customer_id: data.customer_id },
13066
12933
  {
13067
- onError: (e) => {
13068
- ui.toast.error(e.message);
13069
- },
13070
12934
  onSuccess: () => {
13071
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12935
+ ui.toast.success("Customer updated");
12936
+ handleSuccess();
12937
+ },
12938
+ onError: (error) => {
12939
+ ui.toast.error(error.message);
13072
12940
  }
13073
12941
  }
13074
12942
  );
13075
12943
  });
13076
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12944
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13077
12945
  KeyboundForm,
13078
12946
  {
13079
- className: "flex h-full flex-col overflow-hidden",
12947
+ className: "flex flex-1 flex-col overflow-hidden",
13080
12948
  onSubmit,
13081
12949
  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." }) })
12950
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12951
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12952
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12953
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12954
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12955
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12956
+ ] }),
12957
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12960
+ ] })
13087
12961
  ] }),
13088
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13089
- /* @__PURE__ */ jsxRuntime.jsx(
13090
- LocationField,
13091
- {
13092
- control: form.control,
13093
- setValue: form.setValue
13094
- }
13095
- ),
13096
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13097
- /* @__PURE__ */ jsxRuntime.jsx(
13098
- ShippingOptionField,
13099
- {
13100
- shippingProfileId: data.shippingProfileId,
13101
- preview,
13102
- control: form.control
13103
- }
13104
- ),
13105
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13106
12962
  /* @__PURE__ */ jsxRuntime.jsx(
13107
- CustomAmountField,
12963
+ CustomerField,
13108
12964
  {
13109
12965
  control: form.control,
13110
- currencyCode: order.currency_code
13111
- }
13112
- ),
13113
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13114
- /* @__PURE__ */ jsxRuntime.jsx(
13115
- ItemsPreview,
13116
- {
13117
- order,
13118
- shippingProfileId: data.shippingProfileId
13119
- }
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,
13126
- {
13127
- size: "small",
13128
- type: "submit",
13129
- isLoading: isPending || isUpdatingShippingMethod,
13130
- children: data.shippingMethod ? "Update" : "Add"
12966
+ currentCustomerId: order.customer_id
13131
12967
  }
13132
12968
  )
12969
+ ] }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12971
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13133
12973
  ] }) })
13134
12974
  ]
13135
12975
  }
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
- ] });
12976
+ ) });
13226
12977
  };
13227
- const LocationField = ({ control, setValue }) => {
13228
- const locations = useComboboxData({
13229
- queryKey: ["locations"],
12978
+ const CustomerField = ({ control, currentCustomerId }) => {
12979
+ const customers = useComboboxData({
13230
12980
  queryFn: async (params) => {
13231
- return await sdk.admin.stockLocation.list(params);
12981
+ return await sdk.admin.customer.list({
12982
+ ...params,
12983
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12984
+ });
13232
12985
  },
12986
+ queryKey: ["customers"],
13233
12987
  getOptions: (data) => {
13234
- return data.stock_locations.map((location) => ({
13235
- label: location.name,
13236
- value: location.id
13237
- }));
12988
+ return data.customers.map((customer) => {
12989
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12990
+ return {
12991
+ label: name ? `${name} (${customer.email})` : customer.email,
12992
+ value: customer.id
12993
+ };
12994
+ });
13238
12995
  }
13239
12996
  });
13240
12997
  return /* @__PURE__ */ jsxRuntime.jsx(
13241
12998
  Form$2.Field,
13242
12999
  {
13000
+ name: "customer_id",
13243
13001
  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,
13002
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
13003
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13004
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
13005
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
13006
+ ] }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13008
+ Combobox,
13009
+ {
13010
+ options: customers.options,
13011
+ fetchNextPage: customers.fetchNextPage,
13012
+ isFetchingNextPage: customers.isFetchingNextPage,
13013
+ searchValue: customers.searchValue,
13014
+ onSearchValueChange: customers.onSearchValueChange,
13015
+ placeholder: "Select customer",
13016
+ ...field
13017
+ }
13018
+ ) }),
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13020
+ ] })
13021
+ }
13022
+ );
13023
+ };
13024
+ const Illustration = () => {
13025
+ return /* @__PURE__ */ jsxRuntime.jsxs(
13026
+ "svg",
13027
+ {
13028
+ width: "280",
13029
+ height: "180",
13030
+ viewBox: "0 0 280 180",
13031
+ fill: "none",
13032
+ xmlns: "http://www.w3.org/2000/svg",
13033
+ children: [
13034
+ /* @__PURE__ */ jsxRuntime.jsx(
13035
+ "rect",
13036
+ {
13037
+ x: "0.00428286",
13038
+ y: "-0.742904",
13039
+ width: "33.5",
13040
+ height: "65.5",
13041
+ rx: "6.75",
13042
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
13043
+ fill: "#D4D4D8",
13044
+ stroke: "#52525B",
13045
+ strokeWidth: "1.5"
13046
+ }
13047
+ ),
13048
+ /* @__PURE__ */ jsxRuntime.jsx(
13049
+ "rect",
13050
+ {
13051
+ x: "0.00428286",
13052
+ y: "-0.742904",
13053
+ width: "33.5",
13054
+ height: "65.5",
13055
+ rx: "6.75",
13056
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
13057
+ fill: "white",
13058
+ stroke: "#52525B",
13059
+ strokeWidth: "1.5"
13060
+ }
13061
+ ),
13062
+ /* @__PURE__ */ jsxRuntime.jsx(
13063
+ "path",
13064
+ {
13065
+ d: "M180.579 107.142L179.126 107.959",
13066
+ stroke: "#52525B",
13067
+ strokeWidth: "1.5",
13068
+ strokeLinecap: "round",
13069
+ strokeLinejoin: "round"
13070
+ }
13071
+ ),
13072
+ /* @__PURE__ */ jsxRuntime.jsx(
13073
+ "path",
13074
+ {
13075
+ opacity: "0.88",
13076
+ d: "M182.305 109.546L180.257 109.534",
13077
+ stroke: "#52525B",
13078
+ strokeWidth: "1.5",
13079
+ strokeLinecap: "round",
13080
+ strokeLinejoin: "round"
13081
+ }
13082
+ ),
13083
+ /* @__PURE__ */ jsxRuntime.jsx(
13084
+ "path",
13085
+ {
13086
+ opacity: "0.75",
13087
+ d: "M180.551 111.93L179.108 111.096",
13088
+ stroke: "#52525B",
13089
+ strokeWidth: "1.5",
13090
+ strokeLinecap: "round",
13091
+ strokeLinejoin: "round"
13092
+ }
13093
+ ),
13094
+ /* @__PURE__ */ jsxRuntime.jsx(
13095
+ "path",
13096
+ {
13097
+ opacity: "0.63",
13098
+ d: "M176.347 112.897L176.354 111.73",
13099
+ stroke: "#52525B",
13100
+ strokeWidth: "1.5",
13101
+ strokeLinecap: "round",
13102
+ strokeLinejoin: "round"
13103
+ }
13104
+ ),
13105
+ /* @__PURE__ */ jsxRuntime.jsx(
13106
+ "path",
13107
+ {
13108
+ opacity: "0.5",
13109
+ d: "M172.153 111.881L173.606 111.064",
13110
+ stroke: "#52525B",
13111
+ strokeWidth: "1.5",
13112
+ strokeLinecap: "round",
13113
+ strokeLinejoin: "round"
13114
+ }
13115
+ ),
13116
+ /* @__PURE__ */ jsxRuntime.jsx(
13117
+ "path",
13118
+ {
13119
+ opacity: "0.38",
13120
+ d: "M170.428 109.478L172.476 109.489",
13121
+ stroke: "#52525B",
13122
+ strokeWidth: "1.5",
13123
+ strokeLinecap: "round",
13124
+ strokeLinejoin: "round"
13125
+ }
13126
+ ),
13127
+ /* @__PURE__ */ jsxRuntime.jsx(
13128
+ "path",
13129
+ {
13130
+ opacity: "0.25",
13131
+ d: "M172.181 107.094L173.624 107.928",
13132
+ stroke: "#52525B",
13133
+ strokeWidth: "1.5",
13134
+ strokeLinecap: "round",
13135
+ strokeLinejoin: "round"
13136
+ }
13137
+ ),
13138
+ /* @__PURE__ */ jsxRuntime.jsx(
13139
+ "path",
13140
+ {
13141
+ opacity: "0.13",
13142
+ d: "M176.386 106.126L176.379 107.294",
13143
+ stroke: "#52525B",
13144
+ strokeWidth: "1.5",
13145
+ strokeLinecap: "round",
13146
+ strokeLinejoin: "round"
13147
+ }
13148
+ ),
13149
+ /* @__PURE__ */ jsxRuntime.jsx(
13150
+ "rect",
13151
+ {
13152
+ width: "12",
13153
+ height: "3",
13154
+ rx: "1.5",
13155
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
13156
+ fill: "#D4D4D8"
13157
+ }
13158
+ ),
13159
+ /* @__PURE__ */ jsxRuntime.jsx(
13160
+ "rect",
13161
+ {
13162
+ x: "0.00428286",
13163
+ y: "-0.742904",
13164
+ width: "33.5",
13165
+ height: "65.5",
13166
+ rx: "6.75",
13167
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
13168
+ fill: "#D4D4D8",
13169
+ stroke: "#52525B",
13170
+ strokeWidth: "1.5"
13171
+ }
13172
+ ),
13173
+ /* @__PURE__ */ jsxRuntime.jsx(
13174
+ "rect",
13175
+ {
13176
+ x: "0.00428286",
13177
+ y: "-0.742904",
13178
+ width: "33.5",
13179
+ height: "65.5",
13180
+ rx: "6.75",
13181
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
13182
+ fill: "white",
13183
+ stroke: "#52525B",
13184
+ strokeWidth: "1.5"
13185
+ }
13186
+ ),
13187
+ /* @__PURE__ */ jsxRuntime.jsx(
13188
+ "rect",
13189
+ {
13190
+ width: "12",
13191
+ height: "3",
13192
+ rx: "1.5",
13193
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
13194
+ fill: "#D4D4D8"
13195
+ }
13196
+ ),
13197
+ /* @__PURE__ */ jsxRuntime.jsx(
13198
+ "rect",
13199
+ {
13200
+ width: "17",
13201
+ height: "3",
13202
+ rx: "1.5",
13203
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
13204
+ fill: "#D4D4D8"
13205
+ }
13206
+ ),
13207
+ /* @__PURE__ */ jsxRuntime.jsx(
13208
+ "rect",
13209
+ {
13210
+ width: "12",
13211
+ height: "3",
13212
+ rx: "1.5",
13213
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
13214
+ fill: "#D4D4D8"
13215
+ }
13216
+ ),
13217
+ /* @__PURE__ */ jsxRuntime.jsx(
13218
+ "path",
13219
+ {
13220
+ 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",
13221
+ fill: "#A1A1AA"
13222
+ }
13223
+ ),
13224
+ /* @__PURE__ */ jsxRuntime.jsx(
13225
+ "rect",
13226
+ {
13227
+ width: "17",
13228
+ height: "3",
13229
+ rx: "1.5",
13230
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
13231
+ fill: "#A1A1AA"
13232
+ }
13233
+ ),
13234
+ /* @__PURE__ */ jsxRuntime.jsx(
13235
+ "rect",
13236
+ {
13237
+ width: "12",
13238
+ height: "3",
13239
+ rx: "1.5",
13240
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
13241
+ fill: "#A1A1AA"
13242
+ }
13243
+ ),
13244
+ /* @__PURE__ */ jsxRuntime.jsx(
13245
+ "path",
13246
+ {
13247
+ 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",
13248
+ fill: "#52525B"
13249
+ }
13250
+ ),
13251
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13252
+ "path",
13253
+ {
13254
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
13255
+ stroke: "#A1A1AA",
13256
+ strokeWidth: "1.5",
13257
+ strokeLinecap: "round",
13258
+ strokeLinejoin: "round"
13259
+ }
13260
+ ) }),
13261
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13262
+ "path",
13263
+ {
13264
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
13265
+ stroke: "#A1A1AA",
13266
+ strokeWidth: "1.5",
13267
+ strokeLinecap: "round",
13268
+ strokeLinejoin: "round"
13269
+ }
13270
+ ) }),
13271
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13272
+ "path",
13273
+ {
13274
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
13275
+ stroke: "#A1A1AA",
13276
+ strokeWidth: "1.5",
13277
+ strokeLinecap: "round",
13278
+ strokeLinejoin: "round"
13279
+ }
13280
+ ) }),
13281
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13282
+ "path",
13283
+ {
13284
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
13285
+ stroke: "#A1A1AA",
13286
+ strokeWidth: "1.5",
13287
+ strokeLinecap: "round",
13288
+ strokeLinejoin: "round"
13289
+ }
13290
+ ) }),
13291
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13292
+ "path",
13293
+ {
13294
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
13295
+ stroke: "#A1A1AA",
13296
+ strokeWidth: "1.5",
13297
+ strokeLinecap: "round",
13298
+ strokeLinejoin: "round"
13299
+ }
13300
+ ) }),
13301
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13302
+ "path",
13303
+ {
13304
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
13305
+ stroke: "#A1A1AA",
13306
+ strokeWidth: "1.5",
13307
+ strokeLinecap: "round",
13308
+ strokeLinejoin: "round"
13309
+ }
13310
+ ) }),
13311
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
13312
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13313
+ "rect",
13253
13314
  {
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
13315
+ width: "12",
13316
+ height: "12",
13317
+ fill: "white",
13318
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
13268
13319
  }
13269
- ) })
13270
- ] }) });
13271
- }
13272
- }
13273
- );
13274
- };
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
- });
13290
- },
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;
13298
- }
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
13307
- });
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,
13311
- {
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." })
13319
- ] }),
13320
- /* @__PURE__ */ jsxRuntime.jsx(
13321
- ConditionalTooltip,
13320
+ ) }),
13321
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13322
+ "rect",
13322
13323
  {
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
- ) }) })
13324
+ width: "12",
13325
+ height: "12",
13326
+ fill: "white",
13327
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13338
13328
  }
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." })
13359
- ] }),
13360
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13361
- ui.CurrencyInput,
13329
+ ) }),
13330
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13331
+ "rect",
13362
13332
  {
13363
- ...field,
13364
- onValueChange: (value) => onChange(value),
13365
- symbol: getNativeSymbol(currencyCode),
13366
- code: currencyCode
13333
+ width: "12",
13334
+ height: "12",
13335
+ fill: "white",
13336
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13337
+ }
13338
+ ) }),
13339
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13340
+ "rect",
13341
+ {
13342
+ width: "12",
13343
+ height: "12",
13344
+ fill: "white",
13345
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13346
+ }
13347
+ ) }),
13348
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13349
+ "rect",
13350
+ {
13351
+ width: "12",
13352
+ height: "12",
13353
+ fill: "white",
13354
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13355
+ }
13356
+ ) }),
13357
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13358
+ "rect",
13359
+ {
13360
+ width: "12",
13361
+ height: "12",
13362
+ fill: "white",
13363
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13367
13364
  }
13368
13365
  ) })
13369
- ] });
13370
- }
13366
+ ] })
13367
+ ]
13371
13368
  }
13372
13369
  );
13373
13370
  };
13371
+ const schema = object({
13372
+ customer_id: string().min(1)
13373
+ });
13374
13374
  const widgetModule = { widgets: [] };
13375
13375
  const routeModule = {
13376
13376
  routes: [
@@ -13395,14 +13395,14 @@ const routeModule = {
13395
13395
  Component: BillingAddress,
13396
13396
  path: "/draft-orders/:id/billing-address"
13397
13397
  },
13398
- {
13399
- Component: Email,
13400
- path: "/draft-orders/:id/email"
13401
- },
13402
13398
  {
13403
13399
  Component: CustomItems,
13404
13400
  path: "/draft-orders/:id/custom-items"
13405
13401
  },
13402
+ {
13403
+ Component: Email,
13404
+ path: "/draft-orders/:id/email"
13405
+ },
13406
13406
  {
13407
13407
  Component: Items,
13408
13408
  path: "/draft-orders/:id/items"
@@ -13419,6 +13419,10 @@ const routeModule = {
13419
13419
  Component: SalesChannel,
13420
13420
  path: "/draft-orders/:id/sales-channel"
13421
13421
  },
13422
+ {
13423
+ Component: Shipping,
13424
+ path: "/draft-orders/:id/shipping"
13425
+ },
13422
13426
  {
13423
13427
  Component: ShippingAddress,
13424
13428
  path: "/draft-orders/:id/shipping-address"
@@ -13426,10 +13430,6 @@ const routeModule = {
13426
13430
  {
13427
13431
  Component: TransferOwnership,
13428
13432
  path: "/draft-orders/:id/transfer-ownership"
13429
- },
13430
- {
13431
- Component: Shipping,
13432
- path: "/draft-orders/:id/shipping"
13433
13433
  }
13434
13434
  ]
13435
13435
  }