@medusajs/draft-order 2.11.4-preview-20251110150136 → 2.11.4-preview-20251110180138

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.
@@ -9582,74 +9582,6 @@ const CustomItemsForm = () => {
9582
9582
  const schema$5 = objectType({
9583
9583
  email: stringType().email()
9584
9584
  });
9585
- const Email = () => {
9586
- const { id } = useParams();
9587
- const { order, isPending, isError, error } = useOrder(id, {
9588
- fields: "+email"
9589
- });
9590
- if (isError) {
9591
- throw error;
9592
- }
9593
- const isReady = !isPending && !!order;
9594
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9595
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9596
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9597
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9598
- ] }),
9599
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9600
- ] });
9601
- };
9602
- const EmailForm = ({ order }) => {
9603
- const form = useForm({
9604
- defaultValues: {
9605
- email: order.email ?? ""
9606
- },
9607
- resolver: zodResolver(schema$4)
9608
- });
9609
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9610
- const { handleSuccess } = useRouteModal();
9611
- const onSubmit = form.handleSubmit(async (data) => {
9612
- await mutateAsync(
9613
- { email: data.email },
9614
- {
9615
- onSuccess: () => {
9616
- handleSuccess();
9617
- },
9618
- onError: (error) => {
9619
- toast.error(error.message);
9620
- }
9621
- }
9622
- );
9623
- });
9624
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9625
- KeyboundForm,
9626
- {
9627
- className: "flex flex-1 flex-col overflow-hidden",
9628
- onSubmit,
9629
- children: [
9630
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9631
- Form$2.Field,
9632
- {
9633
- control: form.control,
9634
- name: "email",
9635
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9636
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9637
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9638
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9639
- ] })
9640
- }
9641
- ) }),
9642
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9643
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9644
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9645
- ] }) })
9646
- ]
9647
- }
9648
- ) });
9649
- };
9650
- const schema$4 = objectType({
9651
- email: stringType().email()
9652
- });
9653
9585
  const BillingAddress = () => {
9654
9586
  const { id } = useParams();
9655
9587
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9682,7 +9614,7 @@ const BillingAddressForm = ({ order }) => {
9682
9614
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9683
9615
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9684
9616
  },
9685
- resolver: zodResolver(schema$3)
9617
+ resolver: zodResolver(schema$4)
9686
9618
  });
9687
9619
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9688
9620
  const { handleSuccess } = useRouteModal();
@@ -9839,7 +9771,75 @@ const BillingAddressForm = ({ order }) => {
9839
9771
  }
9840
9772
  ) });
9841
9773
  };
9842
- const schema$3 = addressSchema;
9774
+ const schema$4 = addressSchema;
9775
+ const Email = () => {
9776
+ const { id } = useParams();
9777
+ const { order, isPending, isError, error } = useOrder(id, {
9778
+ fields: "+email"
9779
+ });
9780
+ if (isError) {
9781
+ throw error;
9782
+ }
9783
+ const isReady = !isPending && !!order;
9784
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9785
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9786
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9787
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9788
+ ] }),
9789
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9790
+ ] });
9791
+ };
9792
+ const EmailForm = ({ order }) => {
9793
+ const form = useForm({
9794
+ defaultValues: {
9795
+ email: order.email ?? ""
9796
+ },
9797
+ resolver: zodResolver(schema$3)
9798
+ });
9799
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9800
+ const { handleSuccess } = useRouteModal();
9801
+ const onSubmit = form.handleSubmit(async (data) => {
9802
+ await mutateAsync(
9803
+ { email: data.email },
9804
+ {
9805
+ onSuccess: () => {
9806
+ handleSuccess();
9807
+ },
9808
+ onError: (error) => {
9809
+ toast.error(error.message);
9810
+ }
9811
+ }
9812
+ );
9813
+ });
9814
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9815
+ KeyboundForm,
9816
+ {
9817
+ className: "flex flex-1 flex-col overflow-hidden",
9818
+ onSubmit,
9819
+ children: [
9820
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9821
+ Form$2.Field,
9822
+ {
9823
+ control: form.control,
9824
+ name: "email",
9825
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9826
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9827
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9828
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9829
+ ] })
9830
+ }
9831
+ ) }),
9832
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9833
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9834
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9835
+ ] }) })
9836
+ ]
9837
+ }
9838
+ ) });
9839
+ };
9840
+ const schema$3 = objectType({
9841
+ email: stringType().email()
9842
+ });
9843
9843
  const NumberInput = forwardRef(
9844
9844
  ({
9845
9845
  value,
@@ -11547,88 +11547,291 @@ const SalesChannelField = ({ control, order }) => {
11547
11547
  const schema$2 = objectType({
11548
11548
  sales_channel_id: stringType().min(1)
11549
11549
  });
11550
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11551
- const Shipping = () => {
11552
- var _a;
11550
+ const ShippingAddress = () => {
11553
11551
  const { id } = useParams();
11554
11552
  const { order, isPending, isError, error } = useOrder(id, {
11555
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11553
+ fields: "+shipping_address"
11556
11554
  });
11557
- const {
11558
- order: preview,
11559
- isPending: isPreviewPending,
11560
- isError: isPreviewError,
11561
- error: previewError
11562
- } = useOrderPreview(id);
11563
- useInitiateOrderEdit({ preview });
11564
- const { onCancel } = useCancelOrderEdit({ preview });
11565
11555
  if (isError) {
11566
11556
  throw error;
11567
11557
  }
11568
- if (isPreviewError) {
11569
- throw previewError;
11570
- }
11571
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11572
- const isReady = preview && !isPreviewPending && order && !isPending;
11573
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11574
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11575
- /* @__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 px-6 py-16", children: [
11576
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11577
- /* @__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." }) })
11578
- ] }) }) }),
11579
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11580
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11581
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11582
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11583
- ] }) });
11558
+ const isReady = !isPending && !!order;
11559
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11560
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11561
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11562
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11563
+ ] }),
11564
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11565
+ ] });
11584
11566
  };
11585
- const ShippingForm = ({ preview, order }) => {
11586
- var _a;
11587
- const { setIsOpen } = useStackedModal();
11588
- const [isSubmitting, setIsSubmitting] = useState(false);
11589
- const [data, setData] = useState(null);
11590
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11591
- const { shipping_options } = useShippingOptions(
11592
- {
11593
- id: appliedShippingOptionIds,
11594
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11567
+ const ShippingAddressForm = ({ order }) => {
11568
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11569
+ const form = useForm({
11570
+ defaultValues: {
11571
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11572
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11573
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11574
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11575
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11576
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11577
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11578
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11579
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11580
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11595
11581
  },
11596
- {
11597
- enabled: appliedShippingOptionIds.length > 0
11598
- }
11599
- );
11600
- const uniqueShippingProfiles = useMemo(() => {
11601
- const profiles = /* @__PURE__ */ new Map();
11602
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11603
- profiles.set(profile.id, profile);
11604
- });
11605
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11606
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11607
- });
11608
- return Array.from(profiles.values());
11609
- }, [order.items, shipping_options]);
11582
+ resolver: zodResolver(schema$1)
11583
+ });
11584
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11610
11585
  const { handleSuccess } = useRouteModal();
11611
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11612
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11613
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11614
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11615
- const onSubmit = async () => {
11616
- setIsSubmitting(true);
11617
- let requestSucceeded = false;
11618
- await requestOrderEdit(void 0, {
11619
- onError: (e) => {
11620
- toast.error(`Failed to request order edit: ${e.message}`);
11586
+ const onSubmit = form.handleSubmit(async (data) => {
11587
+ await mutateAsync(
11588
+ {
11589
+ shipping_address: {
11590
+ first_name: data.first_name,
11591
+ last_name: data.last_name,
11592
+ company: data.company,
11593
+ address_1: data.address_1,
11594
+ address_2: data.address_2,
11595
+ city: data.city,
11596
+ province: data.province,
11597
+ country_code: data.country_code,
11598
+ postal_code: data.postal_code,
11599
+ phone: data.phone
11600
+ }
11621
11601
  },
11622
- onSuccess: () => {
11623
- requestSucceeded = true;
11602
+ {
11603
+ onSuccess: () => {
11604
+ handleSuccess();
11605
+ },
11606
+ onError: (error) => {
11607
+ toast.error(error.message);
11608
+ }
11624
11609
  }
11625
- });
11626
- if (!requestSucceeded) {
11627
- setIsSubmitting(false);
11628
- return;
11629
- }
11630
- await confirmOrderEdit(void 0, {
11631
- onError: (e) => {
11610
+ );
11611
+ });
11612
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11613
+ KeyboundForm,
11614
+ {
11615
+ className: "flex flex-1 flex-col overflow-hidden",
11616
+ onSubmit,
11617
+ children: [
11618
+ /* @__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: [
11619
+ /* @__PURE__ */ jsx(
11620
+ Form$2.Field,
11621
+ {
11622
+ control: form.control,
11623
+ name: "country_code",
11624
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11625
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11626
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11627
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11628
+ ] })
11629
+ }
11630
+ ),
11631
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11632
+ /* @__PURE__ */ jsx(
11633
+ Form$2.Field,
11634
+ {
11635
+ control: form.control,
11636
+ name: "first_name",
11637
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11638
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11639
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11640
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11641
+ ] })
11642
+ }
11643
+ ),
11644
+ /* @__PURE__ */ jsx(
11645
+ Form$2.Field,
11646
+ {
11647
+ control: form.control,
11648
+ name: "last_name",
11649
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11650
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11651
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11652
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11653
+ ] })
11654
+ }
11655
+ )
11656
+ ] }),
11657
+ /* @__PURE__ */ jsx(
11658
+ Form$2.Field,
11659
+ {
11660
+ control: form.control,
11661
+ name: "company",
11662
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11663
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11664
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11665
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11666
+ ] })
11667
+ }
11668
+ ),
11669
+ /* @__PURE__ */ jsx(
11670
+ Form$2.Field,
11671
+ {
11672
+ control: form.control,
11673
+ name: "address_1",
11674
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11675
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11676
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11677
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11678
+ ] })
11679
+ }
11680
+ ),
11681
+ /* @__PURE__ */ jsx(
11682
+ Form$2.Field,
11683
+ {
11684
+ control: form.control,
11685
+ name: "address_2",
11686
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11687
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11688
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11689
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11690
+ ] })
11691
+ }
11692
+ ),
11693
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11694
+ /* @__PURE__ */ jsx(
11695
+ Form$2.Field,
11696
+ {
11697
+ control: form.control,
11698
+ name: "postal_code",
11699
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11700
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11701
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11702
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11703
+ ] })
11704
+ }
11705
+ ),
11706
+ /* @__PURE__ */ jsx(
11707
+ Form$2.Field,
11708
+ {
11709
+ control: form.control,
11710
+ name: "city",
11711
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11712
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11713
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11714
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11715
+ ] })
11716
+ }
11717
+ )
11718
+ ] }),
11719
+ /* @__PURE__ */ jsx(
11720
+ Form$2.Field,
11721
+ {
11722
+ control: form.control,
11723
+ name: "province",
11724
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11725
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11726
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11727
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11728
+ ] })
11729
+ }
11730
+ ),
11731
+ /* @__PURE__ */ jsx(
11732
+ Form$2.Field,
11733
+ {
11734
+ control: form.control,
11735
+ name: "phone",
11736
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11737
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11738
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11739
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11740
+ ] })
11741
+ }
11742
+ )
11743
+ ] }) }),
11744
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11745
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11746
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11747
+ ] }) })
11748
+ ]
11749
+ }
11750
+ ) });
11751
+ };
11752
+ const schema$1 = addressSchema;
11753
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11754
+ const Shipping = () => {
11755
+ var _a;
11756
+ const { id } = useParams();
11757
+ const { order, isPending, isError, error } = useOrder(id, {
11758
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11759
+ });
11760
+ const {
11761
+ order: preview,
11762
+ isPending: isPreviewPending,
11763
+ isError: isPreviewError,
11764
+ error: previewError
11765
+ } = useOrderPreview(id);
11766
+ useInitiateOrderEdit({ preview });
11767
+ const { onCancel } = useCancelOrderEdit({ preview });
11768
+ if (isError) {
11769
+ throw error;
11770
+ }
11771
+ if (isPreviewError) {
11772
+ throw previewError;
11773
+ }
11774
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11775
+ const isReady = preview && !isPreviewPending && order && !isPending;
11776
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11777
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11778
+ /* @__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 px-6 py-16", children: [
11779
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11780
+ /* @__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." }) })
11781
+ ] }) }) }),
11782
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11783
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11784
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11785
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11786
+ ] }) });
11787
+ };
11788
+ const ShippingForm = ({ preview, order }) => {
11789
+ var _a;
11790
+ const { setIsOpen } = useStackedModal();
11791
+ const [isSubmitting, setIsSubmitting] = useState(false);
11792
+ const [data, setData] = useState(null);
11793
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11794
+ const { shipping_options } = useShippingOptions(
11795
+ {
11796
+ id: appliedShippingOptionIds,
11797
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11798
+ },
11799
+ {
11800
+ enabled: appliedShippingOptionIds.length > 0
11801
+ }
11802
+ );
11803
+ const uniqueShippingProfiles = useMemo(() => {
11804
+ const profiles = /* @__PURE__ */ new Map();
11805
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11806
+ profiles.set(profile.id, profile);
11807
+ });
11808
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11809
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11810
+ });
11811
+ return Array.from(profiles.values());
11812
+ }, [order.items, shipping_options]);
11813
+ const { handleSuccess } = useRouteModal();
11814
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11815
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11816
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11817
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11818
+ const onSubmit = async () => {
11819
+ setIsSubmitting(true);
11820
+ let requestSucceeded = false;
11821
+ await requestOrderEdit(void 0, {
11822
+ onError: (e) => {
11823
+ toast.error(`Failed to request order edit: ${e.message}`);
11824
+ },
11825
+ onSuccess: () => {
11826
+ requestSucceeded = true;
11827
+ }
11828
+ });
11829
+ if (!requestSucceeded) {
11830
+ setIsSubmitting(false);
11831
+ return;
11832
+ }
11833
+ await confirmOrderEdit(void 0, {
11834
+ onError: (e) => {
11632
11835
  toast.error(`Failed to confirm order edit: ${e.message}`);
11633
11836
  },
11634
11837
  onSuccess: () => {
@@ -12354,209 +12557,6 @@ const CustomAmountField = ({
12354
12557
  }
12355
12558
  );
12356
12559
  };
12357
- const ShippingAddress = () => {
12358
- const { id } = useParams();
12359
- const { order, isPending, isError, error } = useOrder(id, {
12360
- fields: "+shipping_address"
12361
- });
12362
- if (isError) {
12363
- throw error;
12364
- }
12365
- const isReady = !isPending && !!order;
12366
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12367
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12368
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12369
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12370
- ] }),
12371
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12372
- ] });
12373
- };
12374
- const ShippingAddressForm = ({ order }) => {
12375
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12376
- const form = useForm({
12377
- defaultValues: {
12378
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12379
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12380
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12381
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12382
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12383
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12384
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12385
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12386
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12387
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12388
- },
12389
- resolver: zodResolver(schema$1)
12390
- });
12391
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12392
- const { handleSuccess } = useRouteModal();
12393
- const onSubmit = form.handleSubmit(async (data) => {
12394
- await mutateAsync(
12395
- {
12396
- shipping_address: {
12397
- first_name: data.first_name,
12398
- last_name: data.last_name,
12399
- company: data.company,
12400
- address_1: data.address_1,
12401
- address_2: data.address_2,
12402
- city: data.city,
12403
- province: data.province,
12404
- country_code: data.country_code,
12405
- postal_code: data.postal_code,
12406
- phone: data.phone
12407
- }
12408
- },
12409
- {
12410
- onSuccess: () => {
12411
- handleSuccess();
12412
- },
12413
- onError: (error) => {
12414
- toast.error(error.message);
12415
- }
12416
- }
12417
- );
12418
- });
12419
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12420
- KeyboundForm,
12421
- {
12422
- className: "flex flex-1 flex-col overflow-hidden",
12423
- onSubmit,
12424
- children: [
12425
- /* @__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: [
12426
- /* @__PURE__ */ jsx(
12427
- Form$2.Field,
12428
- {
12429
- control: form.control,
12430
- name: "country_code",
12431
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12432
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12433
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12434
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12435
- ] })
12436
- }
12437
- ),
12438
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12439
- /* @__PURE__ */ jsx(
12440
- Form$2.Field,
12441
- {
12442
- control: form.control,
12443
- name: "first_name",
12444
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12445
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12446
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12447
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12448
- ] })
12449
- }
12450
- ),
12451
- /* @__PURE__ */ jsx(
12452
- Form$2.Field,
12453
- {
12454
- control: form.control,
12455
- name: "last_name",
12456
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12457
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12458
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12459
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12460
- ] })
12461
- }
12462
- )
12463
- ] }),
12464
- /* @__PURE__ */ jsx(
12465
- Form$2.Field,
12466
- {
12467
- control: form.control,
12468
- name: "company",
12469
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12470
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12471
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12472
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12473
- ] })
12474
- }
12475
- ),
12476
- /* @__PURE__ */ jsx(
12477
- Form$2.Field,
12478
- {
12479
- control: form.control,
12480
- name: "address_1",
12481
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12482
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12483
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12484
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12485
- ] })
12486
- }
12487
- ),
12488
- /* @__PURE__ */ jsx(
12489
- Form$2.Field,
12490
- {
12491
- control: form.control,
12492
- name: "address_2",
12493
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12494
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12495
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12496
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12497
- ] })
12498
- }
12499
- ),
12500
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12501
- /* @__PURE__ */ jsx(
12502
- Form$2.Field,
12503
- {
12504
- control: form.control,
12505
- name: "postal_code",
12506
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12507
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12508
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12509
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12510
- ] })
12511
- }
12512
- ),
12513
- /* @__PURE__ */ jsx(
12514
- Form$2.Field,
12515
- {
12516
- control: form.control,
12517
- name: "city",
12518
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12519
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12520
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12521
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12522
- ] })
12523
- }
12524
- )
12525
- ] }),
12526
- /* @__PURE__ */ jsx(
12527
- Form$2.Field,
12528
- {
12529
- control: form.control,
12530
- name: "province",
12531
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12532
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12533
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12534
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12535
- ] })
12536
- }
12537
- ),
12538
- /* @__PURE__ */ jsx(
12539
- Form$2.Field,
12540
- {
12541
- control: form.control,
12542
- name: "phone",
12543
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12544
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12545
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12546
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12547
- ] })
12548
- }
12549
- )
12550
- ] }) }),
12551
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12552
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12553
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12554
- ] }) })
12555
- ]
12556
- }
12557
- ) });
12558
- };
12559
- const schema$1 = addressSchema;
12560
12560
  const TransferOwnership = () => {
12561
12561
  const { id } = useParams();
12562
12562
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13057,14 +13057,14 @@ const routeModule = {
13057
13057
  Component: CustomItems,
13058
13058
  path: "/draft-orders/:id/custom-items"
13059
13059
  },
13060
- {
13061
- Component: Email,
13062
- path: "/draft-orders/:id/email"
13063
- },
13064
13060
  {
13065
13061
  Component: BillingAddress,
13066
13062
  path: "/draft-orders/:id/billing-address"
13067
13063
  },
13064
+ {
13065
+ Component: Email,
13066
+ path: "/draft-orders/:id/email"
13067
+ },
13068
13068
  {
13069
13069
  Component: Items,
13070
13070
  path: "/draft-orders/:id/items"
@@ -13081,14 +13081,14 @@ const routeModule = {
13081
13081
  Component: SalesChannel,
13082
13082
  path: "/draft-orders/:id/sales-channel"
13083
13083
  },
13084
- {
13085
- Component: Shipping,
13086
- path: "/draft-orders/:id/shipping"
13087
- },
13088
13084
  {
13089
13085
  Component: ShippingAddress,
13090
13086
  path: "/draft-orders/:id/shipping-address"
13091
13087
  },
13088
+ {
13089
+ Component: Shipping,
13090
+ path: "/draft-orders/:id/shipping"
13091
+ },
13092
13092
  {
13093
13093
  Component: TransferOwnership,
13094
13094
  path: "/draft-orders/:id/transfer-ownership"