@medusajs/draft-order 2.11.4-preview-20251108000302 → 2.11.4-preview-20251108060129

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.
@@ -9779,74 +9779,6 @@ const CustomItemsForm = () => {
9779
9779
  const schema$4 = objectType({
9780
9780
  email: stringType().email()
9781
9781
  });
9782
- const Email = () => {
9783
- const { id } = reactRouterDom.useParams();
9784
- const { order, isPending, isError, error } = useOrder(id, {
9785
- fields: "+email"
9786
- });
9787
- if (isError) {
9788
- throw error;
9789
- }
9790
- const isReady = !isPending && !!order;
9791
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9792
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9793
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9794
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9795
- ] }),
9796
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9797
- ] });
9798
- };
9799
- const EmailForm = ({ order }) => {
9800
- const form = reactHookForm.useForm({
9801
- defaultValues: {
9802
- email: order.email ?? ""
9803
- },
9804
- resolver: zod.zodResolver(schema$3)
9805
- });
9806
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9807
- const { handleSuccess } = useRouteModal();
9808
- const onSubmit = form.handleSubmit(async (data) => {
9809
- await mutateAsync(
9810
- { email: data.email },
9811
- {
9812
- onSuccess: () => {
9813
- handleSuccess();
9814
- },
9815
- onError: (error) => {
9816
- ui.toast.error(error.message);
9817
- }
9818
- }
9819
- );
9820
- });
9821
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9822
- KeyboundForm,
9823
- {
9824
- className: "flex flex-1 flex-col overflow-hidden",
9825
- onSubmit,
9826
- children: [
9827
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9828
- Form$2.Field,
9829
- {
9830
- control: form.control,
9831
- name: "email",
9832
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9833
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9834
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9835
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9836
- ] })
9837
- }
9838
- ) }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9840
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9841
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9842
- ] }) })
9843
- ]
9844
- }
9845
- ) });
9846
- };
9847
- const schema$3 = objectType({
9848
- email: stringType().email()
9849
- });
9850
9782
  const NumberInput = React.forwardRef(
9851
9783
  ({
9852
9784
  value,
@@ -10821,6 +10753,74 @@ const customItemSchema = objectType({
10821
10753
  quantity: numberType(),
10822
10754
  unit_price: unionType([numberType(), stringType()])
10823
10755
  });
10756
+ const Email = () => {
10757
+ const { id } = reactRouterDom.useParams();
10758
+ const { order, isPending, isError, error } = useOrder(id, {
10759
+ fields: "+email"
10760
+ });
10761
+ if (isError) {
10762
+ throw error;
10763
+ }
10764
+ const isReady = !isPending && !!order;
10765
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10766
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10767
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10768
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10769
+ ] }),
10770
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10771
+ ] });
10772
+ };
10773
+ const EmailForm = ({ order }) => {
10774
+ const form = reactHookForm.useForm({
10775
+ defaultValues: {
10776
+ email: order.email ?? ""
10777
+ },
10778
+ resolver: zod.zodResolver(schema$3)
10779
+ });
10780
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10781
+ const { handleSuccess } = useRouteModal();
10782
+ const onSubmit = form.handleSubmit(async (data) => {
10783
+ await mutateAsync(
10784
+ { email: data.email },
10785
+ {
10786
+ onSuccess: () => {
10787
+ handleSuccess();
10788
+ },
10789
+ onError: (error) => {
10790
+ ui.toast.error(error.message);
10791
+ }
10792
+ }
10793
+ );
10794
+ });
10795
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10796
+ KeyboundForm,
10797
+ {
10798
+ className: "flex flex-1 flex-col overflow-hidden",
10799
+ onSubmit,
10800
+ children: [
10801
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10802
+ Form$2.Field,
10803
+ {
10804
+ control: form.control,
10805
+ name: "email",
10806
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10807
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10808
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10809
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10810
+ ] })
10811
+ }
10812
+ ) }),
10813
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10814
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10815
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10816
+ ] }) })
10817
+ ]
10818
+ }
10819
+ ) });
10820
+ };
10821
+ const schema$3 = objectType({
10822
+ email: stringType().email()
10823
+ });
10824
10824
  const InlineTip = React.forwardRef(
10825
10825
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10826
10826
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11554,283 +11554,80 @@ const SalesChannelField = ({ control, order }) => {
11554
11554
  const schema$2 = objectType({
11555
11555
  sales_channel_id: stringType().min(1)
11556
11556
  });
11557
- const ShippingAddress = () => {
11557
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11558
+ const Shipping = () => {
11559
+ var _a;
11558
11560
  const { id } = reactRouterDom.useParams();
11559
11561
  const { order, isPending, isError, error } = useOrder(id, {
11560
- fields: "+shipping_address"
11562
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11561
11563
  });
11564
+ const {
11565
+ order: preview,
11566
+ isPending: isPreviewPending,
11567
+ isError: isPreviewError,
11568
+ error: previewError
11569
+ } = useOrderPreview(id);
11570
+ useInitiateOrderEdit({ preview });
11571
+ const { onCancel } = useCancelOrderEdit({ preview });
11562
11572
  if (isError) {
11563
11573
  throw error;
11564
11574
  }
11565
- const isReady = !isPending && !!order;
11566
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11567
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11568
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11569
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11570
- ] }),
11571
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11572
- ] });
11575
+ if (isPreviewError) {
11576
+ throw previewError;
11577
+ }
11578
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11579
+ const isReady = preview && !isPreviewPending && order && !isPending;
11580
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11581
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11582
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11583
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11584
+ /* @__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." }) })
11585
+ ] }) }) }),
11586
+ /* @__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" }) }) })
11587
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11590
+ ] }) });
11573
11591
  };
11574
- const ShippingAddressForm = ({ order }) => {
11575
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11576
- const form = reactHookForm.useForm({
11577
- defaultValues: {
11578
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11579
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11580
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11581
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11582
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11583
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11584
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11585
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11586
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11587
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11592
+ const ShippingForm = ({ preview, order }) => {
11593
+ var _a;
11594
+ const { setIsOpen } = useStackedModal();
11595
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11596
+ const [data, setData] = React.useState(null);
11597
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11598
+ const { shipping_options } = useShippingOptions(
11599
+ {
11600
+ id: appliedShippingOptionIds,
11601
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11588
11602
  },
11589
- resolver: zod.zodResolver(schema$1)
11590
- });
11591
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11603
+ {
11604
+ enabled: appliedShippingOptionIds.length > 0
11605
+ }
11606
+ );
11607
+ const uniqueShippingProfiles = React.useMemo(() => {
11608
+ const profiles = /* @__PURE__ */ new Map();
11609
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11610
+ profiles.set(profile.id, profile);
11611
+ });
11612
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11613
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11614
+ });
11615
+ return Array.from(profiles.values());
11616
+ }, [order.items, shipping_options]);
11592
11617
  const { handleSuccess } = useRouteModal();
11593
- const onSubmit = form.handleSubmit(async (data) => {
11594
- await mutateAsync(
11595
- {
11596
- shipping_address: {
11597
- first_name: data.first_name,
11598
- last_name: data.last_name,
11599
- company: data.company,
11600
- address_1: data.address_1,
11601
- address_2: data.address_2,
11602
- city: data.city,
11603
- province: data.province,
11604
- country_code: data.country_code,
11605
- postal_code: data.postal_code,
11606
- phone: data.phone
11607
- }
11618
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11619
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11620
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11621
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11622
+ const onSubmit = async () => {
11623
+ setIsSubmitting(true);
11624
+ let requestSucceeded = false;
11625
+ await requestOrderEdit(void 0, {
11626
+ onError: (e) => {
11627
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11608
11628
  },
11609
- {
11610
- onSuccess: () => {
11611
- handleSuccess();
11612
- },
11613
- onError: (error) => {
11614
- ui.toast.error(error.message);
11615
- }
11616
- }
11617
- );
11618
- });
11619
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11620
- KeyboundForm,
11621
- {
11622
- className: "flex flex-1 flex-col overflow-hidden",
11623
- onSubmit,
11624
- children: [
11625
- /* @__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: [
11626
- /* @__PURE__ */ jsxRuntime.jsx(
11627
- Form$2.Field,
11628
- {
11629
- control: form.control,
11630
- name: "country_code",
11631
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11632
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11633
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11634
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11635
- ] })
11636
- }
11637
- ),
11638
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11639
- /* @__PURE__ */ jsxRuntime.jsx(
11640
- Form$2.Field,
11641
- {
11642
- control: form.control,
11643
- name: "first_name",
11644
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11645
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11646
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11647
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11648
- ] })
11649
- }
11650
- ),
11651
- /* @__PURE__ */ jsxRuntime.jsx(
11652
- Form$2.Field,
11653
- {
11654
- control: form.control,
11655
- name: "last_name",
11656
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11657
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11658
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11659
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11660
- ] })
11661
- }
11662
- )
11663
- ] }),
11664
- /* @__PURE__ */ jsxRuntime.jsx(
11665
- Form$2.Field,
11666
- {
11667
- control: form.control,
11668
- name: "company",
11669
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11670
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11671
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11672
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11673
- ] })
11674
- }
11675
- ),
11676
- /* @__PURE__ */ jsxRuntime.jsx(
11677
- Form$2.Field,
11678
- {
11679
- control: form.control,
11680
- name: "address_1",
11681
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11682
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11683
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11684
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11685
- ] })
11686
- }
11687
- ),
11688
- /* @__PURE__ */ jsxRuntime.jsx(
11689
- Form$2.Field,
11690
- {
11691
- control: form.control,
11692
- name: "address_2",
11693
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11694
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11695
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11696
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11697
- ] })
11698
- }
11699
- ),
11700
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11701
- /* @__PURE__ */ jsxRuntime.jsx(
11702
- Form$2.Field,
11703
- {
11704
- control: form.control,
11705
- name: "postal_code",
11706
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11707
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11708
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11709
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11710
- ] })
11711
- }
11712
- ),
11713
- /* @__PURE__ */ jsxRuntime.jsx(
11714
- Form$2.Field,
11715
- {
11716
- control: form.control,
11717
- name: "city",
11718
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11719
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11720
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11721
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11722
- ] })
11723
- }
11724
- )
11725
- ] }),
11726
- /* @__PURE__ */ jsxRuntime.jsx(
11727
- Form$2.Field,
11728
- {
11729
- control: form.control,
11730
- name: "province",
11731
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11732
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11733
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11734
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11735
- ] })
11736
- }
11737
- ),
11738
- /* @__PURE__ */ jsxRuntime.jsx(
11739
- Form$2.Field,
11740
- {
11741
- control: form.control,
11742
- name: "phone",
11743
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11744
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11745
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11746
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11747
- ] })
11748
- }
11749
- )
11750
- ] }) }),
11751
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11752
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11753
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11754
- ] }) })
11755
- ]
11756
- }
11757
- ) });
11758
- };
11759
- const schema$1 = addressSchema;
11760
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11761
- const Shipping = () => {
11762
- var _a;
11763
- const { id } = reactRouterDom.useParams();
11764
- const { order, isPending, isError, error } = useOrder(id, {
11765
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11766
- });
11767
- const {
11768
- order: preview,
11769
- isPending: isPreviewPending,
11770
- isError: isPreviewError,
11771
- error: previewError
11772
- } = useOrderPreview(id);
11773
- useInitiateOrderEdit({ preview });
11774
- const { onCancel } = useCancelOrderEdit({ preview });
11775
- if (isError) {
11776
- throw error;
11777
- }
11778
- if (isPreviewError) {
11779
- throw previewError;
11780
- }
11781
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11782
- const isReady = preview && !isPreviewPending && order && !isPending;
11783
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11784
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11785
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11786
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11787
- /* @__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." }) })
11788
- ] }) }) }),
11789
- /* @__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" }) }) })
11790
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11791
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11792
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11793
- ] }) });
11794
- };
11795
- const ShippingForm = ({ preview, order }) => {
11796
- var _a;
11797
- const { setIsOpen } = useStackedModal();
11798
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11799
- const [data, setData] = React.useState(null);
11800
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11801
- const { shipping_options } = useShippingOptions(
11802
- {
11803
- id: appliedShippingOptionIds,
11804
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11805
- },
11806
- {
11807
- enabled: appliedShippingOptionIds.length > 0
11808
- }
11809
- );
11810
- const uniqueShippingProfiles = React.useMemo(() => {
11811
- const profiles = /* @__PURE__ */ new Map();
11812
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11813
- profiles.set(profile.id, profile);
11814
- });
11815
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11816
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11817
- });
11818
- return Array.from(profiles.values());
11819
- }, [order.items, shipping_options]);
11820
- const { handleSuccess } = useRouteModal();
11821
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11822
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11823
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11824
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11825
- const onSubmit = async () => {
11826
- setIsSubmitting(true);
11827
- let requestSucceeded = false;
11828
- await requestOrderEdit(void 0, {
11829
- onError: (e) => {
11830
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11831
- },
11832
- onSuccess: () => {
11833
- requestSucceeded = true;
11629
+ onSuccess: () => {
11630
+ requestSucceeded = true;
11834
11631
  }
11835
11632
  });
11836
11633
  if (!requestSucceeded) {
@@ -12587,7 +12384,7 @@ const TransferOwnershipForm = ({ order }) => {
12587
12384
  defaultValues: {
12588
12385
  customer_id: order.customer_id || ""
12589
12386
  },
12590
- resolver: zod.zodResolver(schema)
12387
+ resolver: zod.zodResolver(schema$1)
12591
12388
  });
12592
12389
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12593
12390
  const { handleSuccess } = useRouteModal();
@@ -13037,9 +12834,212 @@ const Illustration = () => {
13037
12834
  }
13038
12835
  );
13039
12836
  };
13040
- const schema = objectType({
12837
+ const schema$1 = objectType({
13041
12838
  customer_id: stringType().min(1)
13042
12839
  });
12840
+ const ShippingAddress = () => {
12841
+ const { id } = reactRouterDom.useParams();
12842
+ const { order, isPending, isError, error } = useOrder(id, {
12843
+ fields: "+shipping_address"
12844
+ });
12845
+ if (isError) {
12846
+ throw error;
12847
+ }
12848
+ const isReady = !isPending && !!order;
12849
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12850
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12851
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12852
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12853
+ ] }),
12854
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12855
+ ] });
12856
+ };
12857
+ const ShippingAddressForm = ({ order }) => {
12858
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12859
+ const form = reactHookForm.useForm({
12860
+ defaultValues: {
12861
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12862
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12863
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12864
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12865
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12866
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12867
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12868
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12869
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12870
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12871
+ },
12872
+ resolver: zod.zodResolver(schema)
12873
+ });
12874
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12875
+ const { handleSuccess } = useRouteModal();
12876
+ const onSubmit = form.handleSubmit(async (data) => {
12877
+ await mutateAsync(
12878
+ {
12879
+ shipping_address: {
12880
+ first_name: data.first_name,
12881
+ last_name: data.last_name,
12882
+ company: data.company,
12883
+ address_1: data.address_1,
12884
+ address_2: data.address_2,
12885
+ city: data.city,
12886
+ province: data.province,
12887
+ country_code: data.country_code,
12888
+ postal_code: data.postal_code,
12889
+ phone: data.phone
12890
+ }
12891
+ },
12892
+ {
12893
+ onSuccess: () => {
12894
+ handleSuccess();
12895
+ },
12896
+ onError: (error) => {
12897
+ ui.toast.error(error.message);
12898
+ }
12899
+ }
12900
+ );
12901
+ });
12902
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12903
+ KeyboundForm,
12904
+ {
12905
+ className: "flex flex-1 flex-col overflow-hidden",
12906
+ onSubmit,
12907
+ children: [
12908
+ /* @__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: [
12909
+ /* @__PURE__ */ jsxRuntime.jsx(
12910
+ Form$2.Field,
12911
+ {
12912
+ control: form.control,
12913
+ name: "country_code",
12914
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12915
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12916
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12917
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12918
+ ] })
12919
+ }
12920
+ ),
12921
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12922
+ /* @__PURE__ */ jsxRuntime.jsx(
12923
+ Form$2.Field,
12924
+ {
12925
+ control: form.control,
12926
+ name: "first_name",
12927
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12928
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12929
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12930
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12931
+ ] })
12932
+ }
12933
+ ),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(
12935
+ Form$2.Field,
12936
+ {
12937
+ control: form.control,
12938
+ name: "last_name",
12939
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12940
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12941
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12942
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12943
+ ] })
12944
+ }
12945
+ )
12946
+ ] }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(
12948
+ Form$2.Field,
12949
+ {
12950
+ control: form.control,
12951
+ name: "company",
12952
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12953
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12954
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12955
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12956
+ ] })
12957
+ }
12958
+ ),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(
12960
+ Form$2.Field,
12961
+ {
12962
+ control: form.control,
12963
+ name: "address_1",
12964
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12965
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12966
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12967
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12968
+ ] })
12969
+ }
12970
+ ),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(
12972
+ Form$2.Field,
12973
+ {
12974
+ control: form.control,
12975
+ name: "address_2",
12976
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12977
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12978
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12979
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12980
+ ] })
12981
+ }
12982
+ ),
12983
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12984
+ /* @__PURE__ */ jsxRuntime.jsx(
12985
+ Form$2.Field,
12986
+ {
12987
+ control: form.control,
12988
+ name: "postal_code",
12989
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12990
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12991
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12993
+ ] })
12994
+ }
12995
+ ),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(
12997
+ Form$2.Field,
12998
+ {
12999
+ control: form.control,
13000
+ name: "city",
13001
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13002
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13003
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13004
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13005
+ ] })
13006
+ }
13007
+ )
13008
+ ] }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(
13010
+ Form$2.Field,
13011
+ {
13012
+ control: form.control,
13013
+ name: "province",
13014
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13015
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13016
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13017
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13018
+ ] })
13019
+ }
13020
+ ),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(
13022
+ Form$2.Field,
13023
+ {
13024
+ control: form.control,
13025
+ name: "phone",
13026
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13027
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13028
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13029
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13030
+ ] })
13031
+ }
13032
+ )
13033
+ ] }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13035
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13036
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13037
+ ] }) })
13038
+ ]
13039
+ }
13040
+ ) });
13041
+ };
13042
+ const schema = addressSchema;
13043
13043
  const widgetModule = { widgets: [] };
13044
13044
  const routeModule = {
13045
13045
  routes: [
@@ -13068,14 +13068,14 @@ const routeModule = {
13068
13068
  Component: CustomItems,
13069
13069
  path: "/draft-orders/:id/custom-items"
13070
13070
  },
13071
- {
13072
- Component: Email,
13073
- path: "/draft-orders/:id/email"
13074
- },
13075
13071
  {
13076
13072
  Component: Items,
13077
13073
  path: "/draft-orders/:id/items"
13078
13074
  },
13075
+ {
13076
+ Component: Email,
13077
+ path: "/draft-orders/:id/email"
13078
+ },
13079
13079
  {
13080
13080
  Component: Metadata,
13081
13081
  path: "/draft-orders/:id/metadata"
@@ -13088,10 +13088,6 @@ const routeModule = {
13088
13088
  Component: SalesChannel,
13089
13089
  path: "/draft-orders/:id/sales-channel"
13090
13090
  },
13091
- {
13092
- Component: ShippingAddress,
13093
- path: "/draft-orders/:id/shipping-address"
13094
- },
13095
13091
  {
13096
13092
  Component: Shipping,
13097
13093
  path: "/draft-orders/:id/shipping"
@@ -13099,6 +13095,10 @@ const routeModule = {
13099
13095
  {
13100
13096
  Component: TransferOwnership,
13101
13097
  path: "/draft-orders/:id/transfer-ownership"
13098
+ },
13099
+ {
13100
+ Component: ShippingAddress,
13101
+ path: "/draft-orders/:id/shipping-address"
13102
13102
  }
13103
13103
  ]
13104
13104
  }