@medusajs/draft-order 2.10.4-snapshot-20250922165717 → 2.10.4-snapshot-20250922195925

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.
@@ -9573,95 +9573,6 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const CustomItems = () => {
9577
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9580
- ] });
9581
- };
9582
- const CustomItemsForm = () => {
9583
- const form = reactHookForm.useForm({
9584
- resolver: zod.zodResolver(schema$5)
9585
- });
9586
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
- ] }) })
9592
- ] }) });
9593
- };
9594
- const schema$5 = objectType({
9595
- email: stringType().email()
9596
- });
9597
- const Email = () => {
9598
- const { id } = reactRouterDom.useParams();
9599
- const { order, isPending, isError, error } = useOrder(id, {
9600
- fields: "+email"
9601
- });
9602
- if (isError) {
9603
- throw error;
9604
- }
9605
- const isReady = !isPending && !!order;
9606
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9607
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9608
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9609
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9610
- ] }),
9611
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9612
- ] });
9613
- };
9614
- const EmailForm = ({ order }) => {
9615
- const form = reactHookForm.useForm({
9616
- defaultValues: {
9617
- email: order.email ?? ""
9618
- },
9619
- resolver: zod.zodResolver(schema$4)
9620
- });
9621
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9622
- const { handleSuccess } = useRouteModal();
9623
- const onSubmit = form.handleSubmit(async (data) => {
9624
- await mutateAsync(
9625
- { email: data.email },
9626
- {
9627
- onSuccess: () => {
9628
- handleSuccess();
9629
- },
9630
- onError: (error) => {
9631
- ui.toast.error(error.message);
9632
- }
9633
- }
9634
- );
9635
- });
9636
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9637
- KeyboundForm,
9638
- {
9639
- className: "flex flex-1 flex-col overflow-hidden",
9640
- onSubmit,
9641
- children: [
9642
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9643
- Form$2.Field,
9644
- {
9645
- control: form.control,
9646
- name: "email",
9647
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9648
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9651
- ] })
9652
- }
9653
- ) }),
9654
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9655
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9656
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9657
- ] }) })
9658
- ]
9659
- }
9660
- ) });
9661
- };
9662
- const schema$4 = objectType({
9663
- email: stringType().email()
9664
- });
9665
9576
  const BillingAddress = () => {
9666
9577
  const { id } = reactRouterDom.useParams();
9667
9578
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9694,7 +9605,7 @@ const BillingAddressForm = ({ order }) => {
9694
9605
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9695
9606
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9696
9607
  },
9697
- resolver: zod.zodResolver(schema$3)
9608
+ resolver: zod.zodResolver(schema$5)
9698
9609
  });
9699
9610
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9700
9611
  const { handleSuccess } = useRouteModal();
@@ -9851,7 +9762,96 @@ const BillingAddressForm = ({ order }) => {
9851
9762
  }
9852
9763
  ) });
9853
9764
  };
9854
- const schema$3 = addressSchema;
9765
+ const schema$5 = addressSchema;
9766
+ const CustomItems = () => {
9767
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
+ ] });
9771
+ };
9772
+ const CustomItemsForm = () => {
9773
+ const form = reactHookForm.useForm({
9774
+ resolver: zod.zodResolver(schema$4)
9775
+ });
9776
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
+ ] }) })
9782
+ ] }) });
9783
+ };
9784
+ const schema$4 = objectType({
9785
+ email: stringType().email()
9786
+ });
9787
+ const Email = () => {
9788
+ const { id } = reactRouterDom.useParams();
9789
+ const { order, isPending, isError, error } = useOrder(id, {
9790
+ fields: "+email"
9791
+ });
9792
+ if (isError) {
9793
+ throw error;
9794
+ }
9795
+ const isReady = !isPending && !!order;
9796
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9797
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9798
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9799
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9800
+ ] }),
9801
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9802
+ ] });
9803
+ };
9804
+ const EmailForm = ({ order }) => {
9805
+ const form = reactHookForm.useForm({
9806
+ defaultValues: {
9807
+ email: order.email ?? ""
9808
+ },
9809
+ resolver: zod.zodResolver(schema$3)
9810
+ });
9811
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
+ const { handleSuccess } = useRouteModal();
9813
+ const onSubmit = form.handleSubmit(async (data) => {
9814
+ await mutateAsync(
9815
+ { email: data.email },
9816
+ {
9817
+ onSuccess: () => {
9818
+ handleSuccess();
9819
+ },
9820
+ onError: (error) => {
9821
+ ui.toast.error(error.message);
9822
+ }
9823
+ }
9824
+ );
9825
+ });
9826
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9827
+ KeyboundForm,
9828
+ {
9829
+ className: "flex flex-1 flex-col overflow-hidden",
9830
+ onSubmit,
9831
+ children: [
9832
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9833
+ Form$2.Field,
9834
+ {
9835
+ control: form.control,
9836
+ name: "email",
9837
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9840
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9841
+ ] })
9842
+ }
9843
+ ) }),
9844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
+ ] }) })
9848
+ ]
9849
+ }
9850
+ ) });
9851
+ };
9852
+ const schema$3 = objectType({
9853
+ email: stringType().email()
9854
+ });
9855
9855
  const NumberInput = React.forwardRef(
9856
9856
  ({
9857
9857
  value,
@@ -11559,254 +11559,51 @@ const SalesChannelField = ({ control, order }) => {
11559
11559
  const schema$2 = objectType({
11560
11560
  sales_channel_id: stringType().min(1)
11561
11561
  });
11562
- const ShippingAddress = () => {
11562
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
+ const Shipping = () => {
11564
+ var _a;
11563
11565
  const { id } = reactRouterDom.useParams();
11564
11566
  const { order, isPending, isError, error } = useOrder(id, {
11565
- fields: "+shipping_address"
11567
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11566
11568
  });
11569
+ const {
11570
+ order: preview,
11571
+ isPending: isPreviewPending,
11572
+ isError: isPreviewError,
11573
+ error: previewError
11574
+ } = useOrderPreview(id);
11575
+ useInitiateOrderEdit({ preview });
11576
+ const { onCancel } = useCancelOrderEdit({ preview });
11567
11577
  if (isError) {
11568
11578
  throw error;
11569
11579
  }
11570
- const isReady = !isPending && !!order;
11571
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11572
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11573
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11574
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11575
- ] }),
11576
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11577
- ] });
11580
+ if (isPreviewError) {
11581
+ throw previewError;
11582
+ }
11583
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11584
+ const isReady = preview && !isPreviewPending && order && !isPending;
11585
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11587
+ /* @__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: [
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11589
+ /* @__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." }) })
11590
+ ] }) }) }),
11591
+ /* @__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" }) }) })
11592
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11595
+ ] }) });
11578
11596
  };
11579
- const ShippingAddressForm = ({ order }) => {
11580
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11581
- const form = reactHookForm.useForm({
11582
- defaultValues: {
11583
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11584
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11585
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11586
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11587
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11588
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11589
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11590
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11591
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11592
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11593
- },
11594
- resolver: zod.zodResolver(schema$1)
11595
- });
11596
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11597
- const { handleSuccess } = useRouteModal();
11598
- const onSubmit = form.handleSubmit(async (data) => {
11599
- await mutateAsync(
11600
- {
11601
- shipping_address: {
11602
- first_name: data.first_name,
11603
- last_name: data.last_name,
11604
- company: data.company,
11605
- address_1: data.address_1,
11606
- address_2: data.address_2,
11607
- city: data.city,
11608
- province: data.province,
11609
- country_code: data.country_code,
11610
- postal_code: data.postal_code,
11611
- phone: data.phone
11612
- }
11613
- },
11614
- {
11615
- onSuccess: () => {
11616
- handleSuccess();
11617
- },
11618
- onError: (error) => {
11619
- ui.toast.error(error.message);
11620
- }
11621
- }
11622
- );
11623
- });
11624
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11625
- KeyboundForm,
11626
- {
11627
- className: "flex flex-1 flex-col overflow-hidden",
11628
- onSubmit,
11629
- children: [
11630
- /* @__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: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(
11632
- Form$2.Field,
11633
- {
11634
- control: form.control,
11635
- name: "country_code",
11636
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11640
- ] })
11641
- }
11642
- ),
11643
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11644
- /* @__PURE__ */ jsxRuntime.jsx(
11645
- Form$2.Field,
11646
- {
11647
- control: form.control,
11648
- name: "first_name",
11649
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11653
- ] })
11654
- }
11655
- ),
11656
- /* @__PURE__ */ jsxRuntime.jsx(
11657
- Form$2.Field,
11658
- {
11659
- control: form.control,
11660
- name: "last_name",
11661
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
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
- ] }),
11669
- /* @__PURE__ */ jsxRuntime.jsx(
11670
- Form$2.Field,
11671
- {
11672
- control: form.control,
11673
- name: "company",
11674
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11678
- ] })
11679
- }
11680
- ),
11681
- /* @__PURE__ */ jsxRuntime.jsx(
11682
- Form$2.Field,
11683
- {
11684
- control: form.control,
11685
- name: "address_1",
11686
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11690
- ] })
11691
- }
11692
- ),
11693
- /* @__PURE__ */ jsxRuntime.jsx(
11694
- Form$2.Field,
11695
- {
11696
- control: form.control,
11697
- name: "address_2",
11698
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
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.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11706
- /* @__PURE__ */ jsxRuntime.jsx(
11707
- Form$2.Field,
11708
- {
11709
- control: form.control,
11710
- name: "postal_code",
11711
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11715
- ] })
11716
- }
11717
- ),
11718
- /* @__PURE__ */ jsxRuntime.jsx(
11719
- Form$2.Field,
11720
- {
11721
- control: form.control,
11722
- name: "city",
11723
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
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
- ] }),
11731
- /* @__PURE__ */ jsxRuntime.jsx(
11732
- Form$2.Field,
11733
- {
11734
- control: form.control,
11735
- name: "province",
11736
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11740
- ] })
11741
- }
11742
- ),
11743
- /* @__PURE__ */ jsxRuntime.jsx(
11744
- Form$2.Field,
11745
- {
11746
- control: form.control,
11747
- name: "phone",
11748
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11752
- ] })
11753
- }
11754
- )
11755
- ] }) }),
11756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11758
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11759
- ] }) })
11760
- ]
11761
- }
11762
- ) });
11763
- };
11764
- const schema$1 = addressSchema;
11765
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11766
- const Shipping = () => {
11767
- var _a;
11768
- const { id } = reactRouterDom.useParams();
11769
- const { order, isPending, isError, error } = useOrder(id, {
11770
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11771
- });
11772
- const {
11773
- order: preview,
11774
- isPending: isPreviewPending,
11775
- isError: isPreviewError,
11776
- error: previewError
11777
- } = useOrderPreview(id);
11778
- useInitiateOrderEdit({ preview });
11779
- const { onCancel } = useCancelOrderEdit({ preview });
11780
- if (isError) {
11781
- throw error;
11782
- }
11783
- if (isPreviewError) {
11784
- throw previewError;
11785
- }
11786
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11787
- const isReady = preview && !isPreviewPending && order && !isPending;
11788
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11789
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11790
- /* @__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: [
11791
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11792
- /* @__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." }) })
11793
- ] }) }) }),
11794
- /* @__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" }) }) })
11795
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11796
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11797
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11798
- ] }) });
11799
- };
11800
- const ShippingForm = ({ preview, order }) => {
11801
- var _a;
11802
- const { setIsOpen } = useStackedModal();
11803
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11804
- const [data, setData] = React.useState(null);
11805
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11806
- const { shipping_options } = useShippingOptions(
11807
- {
11808
- id: appliedShippingOptionIds,
11809
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11597
+ const ShippingForm = ({ preview, order }) => {
11598
+ var _a;
11599
+ const { setIsOpen } = useStackedModal();
11600
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11601
+ const [data, setData] = React.useState(null);
11602
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11603
+ const { shipping_options } = useShippingOptions(
11604
+ {
11605
+ id: appliedShippingOptionIds,
11606
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11810
11607
  },
11811
11608
  {
11812
11609
  enabled: appliedShippingOptionIds.length > 0
@@ -12569,6 +12366,209 @@ const CustomAmountField = ({
12569
12366
  }
12570
12367
  );
12571
12368
  };
12369
+ const ShippingAddress = () => {
12370
+ const { id } = reactRouterDom.useParams();
12371
+ const { order, isPending, isError, error } = useOrder(id, {
12372
+ fields: "+shipping_address"
12373
+ });
12374
+ if (isError) {
12375
+ throw error;
12376
+ }
12377
+ const isReady = !isPending && !!order;
12378
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12380
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12382
+ ] }),
12383
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12384
+ ] });
12385
+ };
12386
+ const ShippingAddressForm = ({ order }) => {
12387
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12388
+ const form = reactHookForm.useForm({
12389
+ defaultValues: {
12390
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12391
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12392
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12393
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12394
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12395
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12396
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12397
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12398
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12399
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12400
+ },
12401
+ resolver: zod.zodResolver(schema$1)
12402
+ });
12403
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12404
+ const { handleSuccess } = useRouteModal();
12405
+ const onSubmit = form.handleSubmit(async (data) => {
12406
+ await mutateAsync(
12407
+ {
12408
+ shipping_address: {
12409
+ first_name: data.first_name,
12410
+ last_name: data.last_name,
12411
+ company: data.company,
12412
+ address_1: data.address_1,
12413
+ address_2: data.address_2,
12414
+ city: data.city,
12415
+ province: data.province,
12416
+ country_code: data.country_code,
12417
+ postal_code: data.postal_code,
12418
+ phone: data.phone
12419
+ }
12420
+ },
12421
+ {
12422
+ onSuccess: () => {
12423
+ handleSuccess();
12424
+ },
12425
+ onError: (error) => {
12426
+ ui.toast.error(error.message);
12427
+ }
12428
+ }
12429
+ );
12430
+ });
12431
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12432
+ KeyboundForm,
12433
+ {
12434
+ className: "flex flex-1 flex-col overflow-hidden",
12435
+ onSubmit,
12436
+ children: [
12437
+ /* @__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: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(
12439
+ Form$2.Field,
12440
+ {
12441
+ control: form.control,
12442
+ name: "country_code",
12443
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
+ ] })
12448
+ }
12449
+ ),
12450
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12451
+ /* @__PURE__ */ jsxRuntime.jsx(
12452
+ Form$2.Field,
12453
+ {
12454
+ control: form.control,
12455
+ name: "first_name",
12456
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12459
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12460
+ ] })
12461
+ }
12462
+ ),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(
12464
+ Form$2.Field,
12465
+ {
12466
+ control: form.control,
12467
+ name: "last_name",
12468
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
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
+ ] }),
12476
+ /* @__PURE__ */ jsxRuntime.jsx(
12477
+ Form$2.Field,
12478
+ {
12479
+ control: form.control,
12480
+ name: "company",
12481
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12484
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12485
+ ] })
12486
+ }
12487
+ ),
12488
+ /* @__PURE__ */ jsxRuntime.jsx(
12489
+ Form$2.Field,
12490
+ {
12491
+ control: form.control,
12492
+ name: "address_1",
12493
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12497
+ ] })
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsxRuntime.jsx(
12501
+ Form$2.Field,
12502
+ {
12503
+ control: form.control,
12504
+ name: "address_2",
12505
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
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.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "postal_code",
12518
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12521
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12522
+ ] })
12523
+ }
12524
+ ),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(
12526
+ Form$2.Field,
12527
+ {
12528
+ control: form.control,
12529
+ name: "city",
12530
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
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
+ ] }),
12538
+ /* @__PURE__ */ jsxRuntime.jsx(
12539
+ Form$2.Field,
12540
+ {
12541
+ control: form.control,
12542
+ name: "province",
12543
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12546
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12547
+ ] })
12548
+ }
12549
+ ),
12550
+ /* @__PURE__ */ jsxRuntime.jsx(
12551
+ Form$2.Field,
12552
+ {
12553
+ control: form.control,
12554
+ name: "phone",
12555
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12559
+ ] })
12560
+ }
12561
+ )
12562
+ ] }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12565
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12566
+ ] }) })
12567
+ ]
12568
+ }
12569
+ ) });
12570
+ };
12571
+ const schema$1 = addressSchema;
12572
12572
  const TransferOwnership = () => {
12573
12573
  const { id } = reactRouterDom.useParams();
12574
12574
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13065,6 +13065,10 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
+ {
13069
+ Component: BillingAddress,
13070
+ path: "/draft-orders/:id/billing-address"
13071
+ },
13068
13072
  {
13069
13073
  Component: CustomItems,
13070
13074
  path: "/draft-orders/:id/custom-items"
@@ -13073,10 +13077,6 @@ const routeModule = {
13073
13077
  Component: Email,
13074
13078
  path: "/draft-orders/:id/email"
13075
13079
  },
13076
- {
13077
- Component: BillingAddress,
13078
- path: "/draft-orders/:id/billing-address"
13079
- },
13080
13080
  {
13081
13081
  Component: Items,
13082
13082
  path: "/draft-orders/:id/items"
@@ -13093,14 +13093,14 @@ const routeModule = {
13093
13093
  Component: SalesChannel,
13094
13094
  path: "/draft-orders/:id/sales-channel"
13095
13095
  },
13096
- {
13097
- Component: ShippingAddress,
13098
- path: "/draft-orders/:id/shipping-address"
13099
- },
13100
13096
  {
13101
13097
  Component: Shipping,
13102
13098
  path: "/draft-orders/:id/shipping"
13103
13099
  },
13100
+ {
13101
+ Component: ShippingAddress,
13102
+ path: "/draft-orders/:id/shipping-address"
13103
+ },
13104
13104
  {
13105
13105
  Component: TransferOwnership,
13106
13106
  path: "/draft-orders/:id/transfer-ownership"