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