@medusajs/draft-order 2.10.0-preview-20250828060153 → 2.10.0-preview-20250828090201

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.
@@ -9750,74 +9750,6 @@ const BillingAddressForm = ({ order }) => {
9750
9750
  ) });
9751
9751
  };
9752
9752
  const schema$5 = addressSchema;
9753
- const Email = () => {
9754
- const { id } = reactRouterDom.useParams();
9755
- const { order, isPending, isError, error } = useOrder(id, {
9756
- fields: "+email"
9757
- });
9758
- if (isError) {
9759
- throw error;
9760
- }
9761
- const isReady = !isPending && !!order;
9762
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9763
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9764
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9765
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9766
- ] }),
9767
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9768
- ] });
9769
- };
9770
- const EmailForm = ({ order }) => {
9771
- const form = reactHookForm.useForm({
9772
- defaultValues: {
9773
- email: order.email ?? ""
9774
- },
9775
- resolver: zod.zodResolver(schema$4)
9776
- });
9777
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9778
- const { handleSuccess } = useRouteModal();
9779
- const onSubmit = form.handleSubmit(async (data) => {
9780
- await mutateAsync(
9781
- { email: data.email },
9782
- {
9783
- onSuccess: () => {
9784
- handleSuccess();
9785
- },
9786
- onError: (error) => {
9787
- ui.toast.error(error.message);
9788
- }
9789
- }
9790
- );
9791
- });
9792
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9793
- KeyboundForm,
9794
- {
9795
- className: "flex flex-1 flex-col overflow-hidden",
9796
- onSubmit,
9797
- children: [
9798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9799
- Form$2.Field,
9800
- {
9801
- control: form.control,
9802
- name: "email",
9803
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9804
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9805
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9806
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9807
- ] })
9808
- }
9809
- ) }),
9810
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9811
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9812
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9813
- ] }) })
9814
- ]
9815
- }
9816
- ) });
9817
- };
9818
- const schema$4 = objectType({
9819
- email: stringType().email()
9820
- });
9821
9753
  const CustomItems = () => {
9822
9754
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9823
9755
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9826,7 +9758,7 @@ const CustomItems = () => {
9826
9758
  };
9827
9759
  const CustomItemsForm = () => {
9828
9760
  const form = reactHookForm.useForm({
9829
- resolver: zod.zodResolver(schema$3)
9761
+ resolver: zod.zodResolver(schema$4)
9830
9762
  });
9831
9763
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9832
9764
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9836,7 +9768,7 @@ const CustomItemsForm = () => {
9836
9768
  ] }) })
9837
9769
  ] }) });
9838
9770
  };
9839
- const schema$3 = objectType({
9771
+ const schema$4 = objectType({
9840
9772
  email: stringType().email()
9841
9773
  });
9842
9774
  const NumberInput = React.forwardRef(
@@ -10813,6 +10745,74 @@ const customItemSchema = objectType({
10813
10745
  quantity: numberType(),
10814
10746
  unit_price: unionType([numberType(), stringType()])
10815
10747
  });
10748
+ const Email = () => {
10749
+ const { id } = reactRouterDom.useParams();
10750
+ const { order, isPending, isError, error } = useOrder(id, {
10751
+ fields: "+email"
10752
+ });
10753
+ if (isError) {
10754
+ throw error;
10755
+ }
10756
+ const isReady = !isPending && !!order;
10757
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10758
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10759
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10760
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10761
+ ] }),
10762
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10763
+ ] });
10764
+ };
10765
+ const EmailForm = ({ order }) => {
10766
+ const form = reactHookForm.useForm({
10767
+ defaultValues: {
10768
+ email: order.email ?? ""
10769
+ },
10770
+ resolver: zod.zodResolver(schema$3)
10771
+ });
10772
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10773
+ const { handleSuccess } = useRouteModal();
10774
+ const onSubmit = form.handleSubmit(async (data) => {
10775
+ await mutateAsync(
10776
+ { email: data.email },
10777
+ {
10778
+ onSuccess: () => {
10779
+ handleSuccess();
10780
+ },
10781
+ onError: (error) => {
10782
+ ui.toast.error(error.message);
10783
+ }
10784
+ }
10785
+ );
10786
+ });
10787
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10788
+ KeyboundForm,
10789
+ {
10790
+ className: "flex flex-1 flex-col overflow-hidden",
10791
+ onSubmit,
10792
+ children: [
10793
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10794
+ Form$2.Field,
10795
+ {
10796
+ control: form.control,
10797
+ name: "email",
10798
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10799
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10800
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10801
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10802
+ ] })
10803
+ }
10804
+ ) }),
10805
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10806
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10807
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10808
+ ] }) })
10809
+ ]
10810
+ }
10811
+ ) });
10812
+ };
10813
+ const schema$3 = objectType({
10814
+ email: stringType().email()
10815
+ });
10816
10816
  const InlineTip = React.forwardRef(
10817
10817
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10818
10818
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11546,283 +11546,80 @@ const SalesChannelField = ({ control, order }) => {
11546
11546
  const schema$2 = objectType({
11547
11547
  sales_channel_id: stringType().min(1)
11548
11548
  });
11549
- const ShippingAddress = () => {
11549
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11550
+ const Shipping = () => {
11551
+ var _a;
11550
11552
  const { id } = reactRouterDom.useParams();
11551
11553
  const { order, isPending, isError, error } = useOrder(id, {
11552
- fields: "+shipping_address"
11554
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11553
11555
  });
11556
+ const {
11557
+ order: preview,
11558
+ isPending: isPreviewPending,
11559
+ isError: isPreviewError,
11560
+ error: previewError
11561
+ } = useOrderPreview(id);
11562
+ useInitiateOrderEdit({ preview });
11563
+ const { onCancel } = useCancelOrderEdit({ preview });
11554
11564
  if (isError) {
11555
11565
  throw error;
11556
11566
  }
11557
- const isReady = !isPending && !!order;
11558
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11559
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11560
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11562
- ] }),
11563
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11564
- ] });
11567
+ if (isPreviewError) {
11568
+ throw previewError;
11569
+ }
11570
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11571
+ const isReady = preview && !isPreviewPending && order && !isPending;
11572
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11573
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11574
+ /* @__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 py-16 px-6", children: [
11575
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11576
+ /* @__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." }) })
11577
+ ] }) }) }),
11578
+ /* @__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" }) }) })
11579
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11580
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11581
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11582
+ ] }) });
11565
11583
  };
11566
- const ShippingAddressForm = ({ order }) => {
11567
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11568
- const form = reactHookForm.useForm({
11569
- defaultValues: {
11570
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11571
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11572
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11573
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11574
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11575
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11576
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11577
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11578
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11579
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11584
+ const ShippingForm = ({ preview, order }) => {
11585
+ var _a;
11586
+ const { setIsOpen } = useStackedModal();
11587
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11588
+ const [data, setData] = React.useState(null);
11589
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11590
+ const { shipping_options } = useShippingOptions(
11591
+ {
11592
+ id: appliedShippingOptionIds,
11593
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11580
11594
  },
11581
- resolver: zod.zodResolver(schema$1)
11582
- });
11583
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11595
+ {
11596
+ enabled: appliedShippingOptionIds.length > 0
11597
+ }
11598
+ );
11599
+ const uniqueShippingProfiles = React.useMemo(() => {
11600
+ const profiles = /* @__PURE__ */ new Map();
11601
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11602
+ profiles.set(profile.id, profile);
11603
+ });
11604
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11605
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11606
+ });
11607
+ return Array.from(profiles.values());
11608
+ }, [order.items, shipping_options]);
11584
11609
  const { handleSuccess } = useRouteModal();
11585
- const onSubmit = form.handleSubmit(async (data) => {
11586
- await mutateAsync(
11587
- {
11588
- shipping_address: {
11589
- first_name: data.first_name,
11590
- last_name: data.last_name,
11591
- company: data.company,
11592
- address_1: data.address_1,
11593
- address_2: data.address_2,
11594
- city: data.city,
11595
- province: data.province,
11596
- country_code: data.country_code,
11597
- postal_code: data.postal_code,
11598
- phone: data.phone
11599
- }
11610
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11611
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11612
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11613
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11614
+ const onSubmit = async () => {
11615
+ setIsSubmitting(true);
11616
+ let requestSucceeded = false;
11617
+ await requestOrderEdit(void 0, {
11618
+ onError: (e) => {
11619
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11600
11620
  },
11601
- {
11602
- onSuccess: () => {
11603
- handleSuccess();
11604
- },
11605
- onError: (error) => {
11606
- ui.toast.error(error.message);
11607
- }
11608
- }
11609
- );
11610
- });
11611
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11612
- KeyboundForm,
11613
- {
11614
- className: "flex flex-1 flex-col overflow-hidden",
11615
- onSubmit,
11616
- children: [
11617
- /* @__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: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(
11619
- Form$2.Field,
11620
- {
11621
- control: form.control,
11622
- name: "country_code",
11623
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11624
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11625
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11626
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11627
- ] })
11628
- }
11629
- ),
11630
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(
11632
- Form$2.Field,
11633
- {
11634
- control: form.control,
11635
- name: "first_name",
11636
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11640
- ] })
11641
- }
11642
- ),
11643
- /* @__PURE__ */ jsxRuntime.jsx(
11644
- Form$2.Field,
11645
- {
11646
- control: form.control,
11647
- name: "last_name",
11648
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11652
- ] })
11653
- }
11654
- )
11655
- ] }),
11656
- /* @__PURE__ */ jsxRuntime.jsx(
11657
- Form$2.Field,
11658
- {
11659
- control: form.control,
11660
- name: "company",
11661
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11665
- ] })
11666
- }
11667
- ),
11668
- /* @__PURE__ */ jsxRuntime.jsx(
11669
- Form$2.Field,
11670
- {
11671
- control: form.control,
11672
- name: "address_1",
11673
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11677
- ] })
11678
- }
11679
- ),
11680
- /* @__PURE__ */ jsxRuntime.jsx(
11681
- Form$2.Field,
11682
- {
11683
- control: form.control,
11684
- name: "address_2",
11685
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11689
- ] })
11690
- }
11691
- ),
11692
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11693
- /* @__PURE__ */ jsxRuntime.jsx(
11694
- Form$2.Field,
11695
- {
11696
- control: form.control,
11697
- name: "postal_code",
11698
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11702
- ] })
11703
- }
11704
- ),
11705
- /* @__PURE__ */ jsxRuntime.jsx(
11706
- Form$2.Field,
11707
- {
11708
- control: form.control,
11709
- name: "city",
11710
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11714
- ] })
11715
- }
11716
- )
11717
- ] }),
11718
- /* @__PURE__ */ jsxRuntime.jsx(
11719
- Form$2.Field,
11720
- {
11721
- control: form.control,
11722
- name: "province",
11723
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11727
- ] })
11728
- }
11729
- ),
11730
- /* @__PURE__ */ jsxRuntime.jsx(
11731
- Form$2.Field,
11732
- {
11733
- control: form.control,
11734
- name: "phone",
11735
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11739
- ] })
11740
- }
11741
- )
11742
- ] }) }),
11743
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11744
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11745
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11746
- ] }) })
11747
- ]
11748
- }
11749
- ) });
11750
- };
11751
- const schema$1 = addressSchema;
11752
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11753
- const Shipping = () => {
11754
- var _a;
11755
- const { id } = reactRouterDom.useParams();
11756
- const { order, isPending, isError, error } = useOrder(id, {
11757
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11758
- });
11759
- const {
11760
- order: preview,
11761
- isPending: isPreviewPending,
11762
- isError: isPreviewError,
11763
- error: previewError
11764
- } = useOrderPreview(id);
11765
- useInitiateOrderEdit({ preview });
11766
- const { onCancel } = useCancelOrderEdit({ preview });
11767
- if (isError) {
11768
- throw error;
11769
- }
11770
- if (isPreviewError) {
11771
- throw previewError;
11772
- }
11773
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11774
- const isReady = preview && !isPreviewPending && order && !isPending;
11775
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11776
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11777
- /* @__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 py-16 px-6", children: [
11778
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11779
- /* @__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." }) })
11780
- ] }) }) }),
11781
- /* @__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" }) }) })
11782
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11783
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11784
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11785
- ] }) });
11786
- };
11787
- const ShippingForm = ({ preview, order }) => {
11788
- var _a;
11789
- const { setIsOpen } = useStackedModal();
11790
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11791
- const [data, setData] = React.useState(null);
11792
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11793
- const { shipping_options } = useShippingOptions(
11794
- {
11795
- id: appliedShippingOptionIds,
11796
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11797
- },
11798
- {
11799
- enabled: appliedShippingOptionIds.length > 0
11800
- }
11801
- );
11802
- const uniqueShippingProfiles = React.useMemo(() => {
11803
- const profiles = /* @__PURE__ */ new Map();
11804
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11805
- profiles.set(profile.id, profile);
11806
- });
11807
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11808
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11809
- });
11810
- return Array.from(profiles.values());
11811
- }, [order.items, shipping_options]);
11812
- const { handleSuccess } = useRouteModal();
11813
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11814
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11815
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11816
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11817
- const onSubmit = async () => {
11818
- setIsSubmitting(true);
11819
- let requestSucceeded = false;
11820
- await requestOrderEdit(void 0, {
11821
- onError: (e) => {
11822
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11823
- },
11824
- onSuccess: () => {
11825
- requestSucceeded = true;
11621
+ onSuccess: () => {
11622
+ requestSucceeded = true;
11826
11623
  }
11827
11624
  });
11828
11625
  if (!requestSucceeded) {
@@ -12556,6 +12353,209 @@ const CustomAmountField = ({
12556
12353
  }
12557
12354
  );
12558
12355
  };
12356
+ const ShippingAddress = () => {
12357
+ const { id } = reactRouterDom.useParams();
12358
+ const { order, isPending, isError, error } = useOrder(id, {
12359
+ fields: "+shipping_address"
12360
+ });
12361
+ if (isError) {
12362
+ throw error;
12363
+ }
12364
+ const isReady = !isPending && !!order;
12365
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12366
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12367
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12368
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12369
+ ] }),
12370
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12371
+ ] });
12372
+ };
12373
+ const ShippingAddressForm = ({ order }) => {
12374
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12375
+ const form = reactHookForm.useForm({
12376
+ defaultValues: {
12377
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12378
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12379
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12380
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12381
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12382
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12383
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12384
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12385
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12386
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12387
+ },
12388
+ resolver: zod.zodResolver(schema$1)
12389
+ });
12390
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12391
+ const { handleSuccess } = useRouteModal();
12392
+ const onSubmit = form.handleSubmit(async (data) => {
12393
+ await mutateAsync(
12394
+ {
12395
+ shipping_address: {
12396
+ first_name: data.first_name,
12397
+ last_name: data.last_name,
12398
+ company: data.company,
12399
+ address_1: data.address_1,
12400
+ address_2: data.address_2,
12401
+ city: data.city,
12402
+ province: data.province,
12403
+ country_code: data.country_code,
12404
+ postal_code: data.postal_code,
12405
+ phone: data.phone
12406
+ }
12407
+ },
12408
+ {
12409
+ onSuccess: () => {
12410
+ handleSuccess();
12411
+ },
12412
+ onError: (error) => {
12413
+ ui.toast.error(error.message);
12414
+ }
12415
+ }
12416
+ );
12417
+ });
12418
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12419
+ KeyboundForm,
12420
+ {
12421
+ className: "flex flex-1 flex-col overflow-hidden",
12422
+ onSubmit,
12423
+ children: [
12424
+ /* @__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: [
12425
+ /* @__PURE__ */ jsxRuntime.jsx(
12426
+ Form$2.Field,
12427
+ {
12428
+ control: form.control,
12429
+ name: "country_code",
12430
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12431
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12432
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12433
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12434
+ ] })
12435
+ }
12436
+ ),
12437
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(
12439
+ Form$2.Field,
12440
+ {
12441
+ control: form.control,
12442
+ name: "first_name",
12443
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
+ ] })
12448
+ }
12449
+ ),
12450
+ /* @__PURE__ */ jsxRuntime.jsx(
12451
+ Form$2.Field,
12452
+ {
12453
+ control: form.control,
12454
+ name: "last_name",
12455
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12456
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12459
+ ] })
12460
+ }
12461
+ )
12462
+ ] }),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(
12464
+ Form$2.Field,
12465
+ {
12466
+ control: form.control,
12467
+ name: "company",
12468
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12472
+ ] })
12473
+ }
12474
+ ),
12475
+ /* @__PURE__ */ jsxRuntime.jsx(
12476
+ Form$2.Field,
12477
+ {
12478
+ control: form.control,
12479
+ name: "address_1",
12480
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12481
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12484
+ ] })
12485
+ }
12486
+ ),
12487
+ /* @__PURE__ */ jsxRuntime.jsx(
12488
+ Form$2.Field,
12489
+ {
12490
+ control: form.control,
12491
+ name: "address_2",
12492
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12493
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12496
+ ] })
12497
+ }
12498
+ ),
12499
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12500
+ /* @__PURE__ */ jsxRuntime.jsx(
12501
+ Form$2.Field,
12502
+ {
12503
+ control: form.control,
12504
+ name: "postal_code",
12505
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12509
+ ] })
12510
+ }
12511
+ ),
12512
+ /* @__PURE__ */ jsxRuntime.jsx(
12513
+ Form$2.Field,
12514
+ {
12515
+ control: form.control,
12516
+ name: "city",
12517
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12518
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12521
+ ] })
12522
+ }
12523
+ )
12524
+ ] }),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(
12526
+ Form$2.Field,
12527
+ {
12528
+ control: form.control,
12529
+ name: "province",
12530
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
+ ] })
12535
+ }
12536
+ ),
12537
+ /* @__PURE__ */ jsxRuntime.jsx(
12538
+ Form$2.Field,
12539
+ {
12540
+ control: form.control,
12541
+ name: "phone",
12542
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12546
+ ] })
12547
+ }
12548
+ )
12549
+ ] }) }),
12550
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12551
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12552
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12553
+ ] }) })
12554
+ ]
12555
+ }
12556
+ ) });
12557
+ };
12558
+ const schema$1 = addressSchema;
12559
12559
  const TransferOwnership = () => {
12560
12560
  const { id } = reactRouterDom.useParams();
12561
12561
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13056,10 +13056,6 @@ const routeModule = {
13056
13056
  Component: BillingAddress,
13057
13057
  path: "/draft-orders/:id/billing-address"
13058
13058
  },
13059
- {
13060
- Component: Email,
13061
- path: "/draft-orders/:id/email"
13062
- },
13063
13059
  {
13064
13060
  Component: CustomItems,
13065
13061
  path: "/draft-orders/:id/custom-items"
@@ -13068,6 +13064,10 @@ const routeModule = {
13068
13064
  Component: Items,
13069
13065
  path: "/draft-orders/:id/items"
13070
13066
  },
13067
+ {
13068
+ Component: Email,
13069
+ path: "/draft-orders/:id/email"
13070
+ },
13071
13071
  {
13072
13072
  Component: Metadata,
13073
13073
  path: "/draft-orders/:id/metadata"
@@ -13080,14 +13080,14 @@ const routeModule = {
13080
13080
  Component: SalesChannel,
13081
13081
  path: "/draft-orders/:id/sales-channel"
13082
13082
  },
13083
- {
13084
- Component: ShippingAddress,
13085
- path: "/draft-orders/:id/shipping-address"
13086
- },
13087
13083
  {
13088
13084
  Component: Shipping,
13089
13085
  path: "/draft-orders/:id/shipping"
13090
13086
  },
13087
+ {
13088
+ Component: ShippingAddress,
13089
+ path: "/draft-orders/:id/shipping-address"
13090
+ },
13091
13091
  {
13092
13092
  Component: TransferOwnership,
13093
13093
  path: "/draft-orders/:id/transfer-ownership"