@medusajs/draft-order 2.11.4-preview-20251121180139 → 2.11.4-preview-20251122000259

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.
@@ -9762,74 +9762,6 @@ const BillingAddressForm = ({ order }) => {
9762
9762
  ) });
9763
9763
  };
9764
9764
  const schema$5 = addressSchema;
9765
- const Email = () => {
9766
- const { id } = reactRouterDom.useParams();
9767
- const { order, isPending, isError, error } = useOrder(id, {
9768
- fields: "+email"
9769
- });
9770
- if (isError) {
9771
- throw error;
9772
- }
9773
- const isReady = !isPending && !!order;
9774
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9775
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9778
- ] }),
9779
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9780
- ] });
9781
- };
9782
- const EmailForm = ({ order }) => {
9783
- const form = reactHookForm.useForm({
9784
- defaultValues: {
9785
- email: order.email ?? ""
9786
- },
9787
- resolver: zod.zodResolver(schema$4)
9788
- });
9789
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9790
- const { handleSuccess } = useRouteModal();
9791
- const onSubmit = form.handleSubmit(async (data) => {
9792
- await mutateAsync(
9793
- { email: data.email },
9794
- {
9795
- onSuccess: () => {
9796
- handleSuccess();
9797
- },
9798
- onError: (error) => {
9799
- ui.toast.error(error.message);
9800
- }
9801
- }
9802
- );
9803
- });
9804
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9805
- KeyboundForm,
9806
- {
9807
- className: "flex flex-1 flex-col overflow-hidden",
9808
- onSubmit,
9809
- children: [
9810
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9811
- Form$2.Field,
9812
- {
9813
- control: form.control,
9814
- name: "email",
9815
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9816
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9817
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9818
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9819
- ] })
9820
- }
9821
- ) }),
9822
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9823
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9824
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9825
- ] }) })
9826
- ]
9827
- }
9828
- ) });
9829
- };
9830
- const schema$4 = objectType({
9831
- email: stringType().email()
9832
- });
9833
9765
  const CustomItems = () => {
9834
9766
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9835
9767
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9838,7 +9770,7 @@ const CustomItems = () => {
9838
9770
  };
9839
9771
  const CustomItemsForm = () => {
9840
9772
  const form = reactHookForm.useForm({
9841
- resolver: zod.zodResolver(schema$3)
9773
+ resolver: zod.zodResolver(schema$4)
9842
9774
  });
9843
9775
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9844
9776
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9848,7 +9780,7 @@ const CustomItemsForm = () => {
9848
9780
  ] }) })
9849
9781
  ] }) });
9850
9782
  };
9851
- const schema$3 = objectType({
9783
+ const schema$4 = objectType({
9852
9784
  email: stringType().email()
9853
9785
  });
9854
9786
  const NumberInput = React.forwardRef(
@@ -11480,7 +11412,7 @@ const SalesChannelForm = ({ order }) => {
11480
11412
  defaultValues: {
11481
11413
  sales_channel_id: order.sales_channel_id || ""
11482
11414
  },
11483
- resolver: zod.zodResolver(schema$2)
11415
+ resolver: zod.zodResolver(schema$3)
11484
11416
  });
11485
11417
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
11418
  const { handleSuccess } = useRouteModal();
@@ -11555,334 +11487,131 @@ const SalesChannelField = ({ control, order }) => {
11555
11487
  }
11556
11488
  );
11557
11489
  };
11558
- const schema$2 = objectType({
11490
+ const schema$3 = objectType({
11559
11491
  sales_channel_id: stringType().min(1)
11560
11492
  });
11561
- const ShippingAddress = () => {
11493
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11494
+ const Shipping = () => {
11495
+ var _a;
11562
11496
  const { id } = reactRouterDom.useParams();
11563
11497
  const { order, isPending, isError, error } = useOrder(id, {
11564
- fields: "+shipping_address"
11498
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11565
11499
  });
11500
+ const {
11501
+ order: preview,
11502
+ isPending: isPreviewPending,
11503
+ isError: isPreviewError,
11504
+ error: previewError
11505
+ } = useOrderPreview(id);
11506
+ useInitiateOrderEdit({ preview });
11507
+ const { onCancel } = useCancelOrderEdit({ preview });
11566
11508
  if (isError) {
11567
11509
  throw error;
11568
11510
  }
11569
- const isReady = !isPending && !!order;
11570
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11571
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11572
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11573
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11574
- ] }),
11575
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11576
- ] });
11511
+ if (isPreviewError) {
11512
+ throw previewError;
11513
+ }
11514
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11515
+ const isReady = preview && !isPreviewPending && order && !isPending;
11516
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11517
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11518
+ /* @__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: [
11519
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11520
+ /* @__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." }) })
11521
+ ] }) }) }),
11522
+ /* @__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" }) }) })
11523
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11524
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11525
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11526
+ ] }) });
11577
11527
  };
11578
- const ShippingAddressForm = ({ order }) => {
11579
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11580
- const form = reactHookForm.useForm({
11581
- defaultValues: {
11582
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11583
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11584
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11585
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11586
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11587
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11588
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11589
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11590
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11591
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11528
+ const ShippingForm = ({ preview, order }) => {
11529
+ var _a;
11530
+ const { setIsOpen } = useStackedModal();
11531
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11532
+ const [data, setData] = React.useState(null);
11533
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11534
+ const { shipping_options } = useShippingOptions(
11535
+ {
11536
+ id: appliedShippingOptionIds,
11537
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11592
11538
  },
11593
- resolver: zod.zodResolver(schema$1)
11594
- });
11595
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11539
+ {
11540
+ enabled: appliedShippingOptionIds.length > 0
11541
+ }
11542
+ );
11543
+ const uniqueShippingProfiles = React.useMemo(() => {
11544
+ const profiles = /* @__PURE__ */ new Map();
11545
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11546
+ profiles.set(profile.id, profile);
11547
+ });
11548
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11549
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11550
+ });
11551
+ return Array.from(profiles.values());
11552
+ }, [order.items, shipping_options]);
11596
11553
  const { handleSuccess } = useRouteModal();
11597
- const onSubmit = form.handleSubmit(async (data) => {
11598
- await mutateAsync(
11599
- {
11600
- shipping_address: {
11601
- first_name: data.first_name,
11602
- last_name: data.last_name,
11603
- company: data.company,
11604
- address_1: data.address_1,
11605
- address_2: data.address_2,
11606
- city: data.city,
11607
- province: data.province,
11608
- country_code: data.country_code,
11609
- postal_code: data.postal_code,
11610
- phone: data.phone
11611
- }
11554
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11555
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11556
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11557
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11558
+ const onSubmit = async () => {
11559
+ setIsSubmitting(true);
11560
+ let requestSucceeded = false;
11561
+ await requestOrderEdit(void 0, {
11562
+ onError: (e) => {
11563
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11612
11564
  },
11613
- {
11614
- onSuccess: () => {
11615
- handleSuccess();
11616
- },
11617
- onError: (error) => {
11618
- ui.toast.error(error.message);
11565
+ onSuccess: () => {
11566
+ requestSucceeded = true;
11567
+ }
11568
+ });
11569
+ if (!requestSucceeded) {
11570
+ setIsSubmitting(false);
11571
+ return;
11572
+ }
11573
+ await confirmOrderEdit(void 0, {
11574
+ onError: (e) => {
11575
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11576
+ },
11577
+ onSuccess: () => {
11578
+ handleSuccess();
11579
+ },
11580
+ onSettled: () => {
11581
+ setIsSubmitting(false);
11582
+ }
11583
+ });
11584
+ };
11585
+ const onKeydown = React.useCallback(
11586
+ (e) => {
11587
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11588
+ if (data || isSubmitting) {
11589
+ return;
11619
11590
  }
11591
+ onSubmit();
11620
11592
  }
11621
- );
11622
- });
11623
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11624
- KeyboundForm,
11625
- {
11626
- className: "flex flex-1 flex-col overflow-hidden",
11627
- onSubmit,
11628
- children: [
11629
- /* @__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: [
11630
- /* @__PURE__ */ jsxRuntime.jsx(
11631
- Form$2.Field,
11632
- {
11633
- control: form.control,
11634
- name: "country_code",
11635
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11636
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11639
- ] })
11640
- }
11641
- ),
11642
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11593
+ },
11594
+ [data, isSubmitting, onSubmit]
11595
+ );
11596
+ React.useEffect(() => {
11597
+ document.addEventListener("keydown", onKeydown);
11598
+ return () => {
11599
+ document.removeEventListener("keydown", onKeydown);
11600
+ };
11601
+ }, [onKeydown]);
11602
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11603
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11604
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11605
+ /* @__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: [
11606
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11607
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11608
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11609
+ ] }),
11610
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11611
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11612
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11643
11613
  /* @__PURE__ */ jsxRuntime.jsx(
11644
- Form$2.Field,
11645
- {
11646
- control: form.control,
11647
- name: "first_name",
11648
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11652
- ] })
11653
- }
11654
- ),
11655
- /* @__PURE__ */ jsxRuntime.jsx(
11656
- Form$2.Field,
11657
- {
11658
- control: form.control,
11659
- name: "last_name",
11660
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11661
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11664
- ] })
11665
- }
11666
- )
11667
- ] }),
11668
- /* @__PURE__ */ jsxRuntime.jsx(
11669
- Form$2.Field,
11670
- {
11671
- control: form.control,
11672
- name: "company",
11673
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11677
- ] })
11678
- }
11679
- ),
11680
- /* @__PURE__ */ jsxRuntime.jsx(
11681
- Form$2.Field,
11682
- {
11683
- control: form.control,
11684
- name: "address_1",
11685
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11689
- ] })
11690
- }
11691
- ),
11692
- /* @__PURE__ */ jsxRuntime.jsx(
11693
- Form$2.Field,
11694
- {
11695
- control: form.control,
11696
- name: "address_2",
11697
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11698
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11701
- ] })
11702
- }
11703
- ),
11704
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11705
- /* @__PURE__ */ jsxRuntime.jsx(
11706
- Form$2.Field,
11707
- {
11708
- control: form.control,
11709
- name: "postal_code",
11710
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11714
- ] })
11715
- }
11716
- ),
11717
- /* @__PURE__ */ jsxRuntime.jsx(
11718
- Form$2.Field,
11719
- {
11720
- control: form.control,
11721
- name: "city",
11722
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11723
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11726
- ] })
11727
- }
11728
- )
11729
- ] }),
11730
- /* @__PURE__ */ jsxRuntime.jsx(
11731
- Form$2.Field,
11732
- {
11733
- control: form.control,
11734
- name: "province",
11735
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11739
- ] })
11740
- }
11741
- ),
11742
- /* @__PURE__ */ jsxRuntime.jsx(
11743
- Form$2.Field,
11744
- {
11745
- control: form.control,
11746
- name: "phone",
11747
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11748
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11751
- ] })
11752
- }
11753
- )
11754
- ] }) }),
11755
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11757
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11758
- ] }) })
11759
- ]
11760
- }
11761
- ) });
11762
- };
11763
- const schema$1 = addressSchema;
11764
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11765
- const Shipping = () => {
11766
- var _a;
11767
- const { id } = reactRouterDom.useParams();
11768
- const { order, isPending, isError, error } = useOrder(id, {
11769
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11770
- });
11771
- const {
11772
- order: preview,
11773
- isPending: isPreviewPending,
11774
- isError: isPreviewError,
11775
- error: previewError
11776
- } = useOrderPreview(id);
11777
- useInitiateOrderEdit({ preview });
11778
- const { onCancel } = useCancelOrderEdit({ preview });
11779
- if (isError) {
11780
- throw error;
11781
- }
11782
- if (isPreviewError) {
11783
- throw previewError;
11784
- }
11785
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11786
- const isReady = preview && !isPreviewPending && order && !isPending;
11787
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11788
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11789
- /* @__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: [
11790
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11791
- /* @__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." }) })
11792
- ] }) }) }),
11793
- /* @__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" }) }) })
11794
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11795
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11796
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11797
- ] }) });
11798
- };
11799
- const ShippingForm = ({ preview, order }) => {
11800
- var _a;
11801
- const { setIsOpen } = useStackedModal();
11802
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11803
- const [data, setData] = React.useState(null);
11804
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11805
- const { shipping_options } = useShippingOptions(
11806
- {
11807
- id: appliedShippingOptionIds,
11808
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11809
- },
11810
- {
11811
- enabled: appliedShippingOptionIds.length > 0
11812
- }
11813
- );
11814
- const uniqueShippingProfiles = React.useMemo(() => {
11815
- const profiles = /* @__PURE__ */ new Map();
11816
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11817
- profiles.set(profile.id, profile);
11818
- });
11819
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11820
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11821
- });
11822
- return Array.from(profiles.values());
11823
- }, [order.items, shipping_options]);
11824
- const { handleSuccess } = useRouteModal();
11825
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11826
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11827
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11828
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11829
- const onSubmit = async () => {
11830
- setIsSubmitting(true);
11831
- let requestSucceeded = false;
11832
- await requestOrderEdit(void 0, {
11833
- onError: (e) => {
11834
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11835
- },
11836
- onSuccess: () => {
11837
- requestSucceeded = true;
11838
- }
11839
- });
11840
- if (!requestSucceeded) {
11841
- setIsSubmitting(false);
11842
- return;
11843
- }
11844
- await confirmOrderEdit(void 0, {
11845
- onError: (e) => {
11846
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11847
- },
11848
- onSuccess: () => {
11849
- handleSuccess();
11850
- },
11851
- onSettled: () => {
11852
- setIsSubmitting(false);
11853
- }
11854
- });
11855
- };
11856
- const onKeydown = React.useCallback(
11857
- (e) => {
11858
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11859
- if (data || isSubmitting) {
11860
- return;
11861
- }
11862
- onSubmit();
11863
- }
11864
- },
11865
- [data, isSubmitting, onSubmit]
11866
- );
11867
- React.useEffect(() => {
11868
- document.addEventListener("keydown", onKeydown);
11869
- return () => {
11870
- document.removeEventListener("keydown", onKeydown);
11871
- };
11872
- }, [onKeydown]);
11873
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11874
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11875
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11876
- /* @__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: [
11877
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11878
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11879
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11880
- ] }),
11881
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11882
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11883
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11884
- /* @__PURE__ */ jsxRuntime.jsx(
11885
- ui.Text,
11614
+ ui.Text,
11886
11615
  {
11887
11616
  size: "xsmall",
11888
11617
  weight: "plus",
@@ -12568,30 +12297,233 @@ const CustomAmountField = ({
12568
12297
  }
12569
12298
  );
12570
12299
  };
12571
- const TransferOwnership = () => {
12300
+ const ShippingAddress = () => {
12572
12301
  const { id } = reactRouterDom.useParams();
12573
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12574
- fields: "id,customer_id,customer.*"
12302
+ const { order, isPending, isError, error } = useOrder(id, {
12303
+ fields: "+shipping_address"
12575
12304
  });
12576
12305
  if (isError) {
12577
12306
  throw error;
12578
12307
  }
12579
- const isReady = !isPending && !!draft_order;
12308
+ const isReady = !isPending && !!order;
12580
12309
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12581
12310
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12582
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12583
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12311
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12312
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12584
12313
  ] }),
12585
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12314
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12586
12315
  ] });
12587
12316
  };
12588
- const TransferOwnershipForm = ({ order }) => {
12589
- var _a, _b;
12590
- const form = reactHookForm.useForm({
12317
+ const ShippingAddressForm = ({ order }) => {
12318
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12319
+ const form = reactHookForm.useForm({
12320
+ defaultValues: {
12321
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12322
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12323
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12324
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12325
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12326
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12327
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12328
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12329
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12330
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12331
+ },
12332
+ resolver: zod.zodResolver(schema$2)
12333
+ });
12334
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12335
+ const { handleSuccess } = useRouteModal();
12336
+ const onSubmit = form.handleSubmit(async (data) => {
12337
+ await mutateAsync(
12338
+ {
12339
+ shipping_address: {
12340
+ first_name: data.first_name,
12341
+ last_name: data.last_name,
12342
+ company: data.company,
12343
+ address_1: data.address_1,
12344
+ address_2: data.address_2,
12345
+ city: data.city,
12346
+ province: data.province,
12347
+ country_code: data.country_code,
12348
+ postal_code: data.postal_code,
12349
+ phone: data.phone
12350
+ }
12351
+ },
12352
+ {
12353
+ onSuccess: () => {
12354
+ handleSuccess();
12355
+ },
12356
+ onError: (error) => {
12357
+ ui.toast.error(error.message);
12358
+ }
12359
+ }
12360
+ );
12361
+ });
12362
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12363
+ KeyboundForm,
12364
+ {
12365
+ className: "flex flex-1 flex-col overflow-hidden",
12366
+ onSubmit,
12367
+ children: [
12368
+ /* @__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: [
12369
+ /* @__PURE__ */ jsxRuntime.jsx(
12370
+ Form$2.Field,
12371
+ {
12372
+ control: form.control,
12373
+ name: "country_code",
12374
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12375
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12376
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12377
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12378
+ ] })
12379
+ }
12380
+ ),
12381
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12382
+ /* @__PURE__ */ jsxRuntime.jsx(
12383
+ Form$2.Field,
12384
+ {
12385
+ control: form.control,
12386
+ name: "first_name",
12387
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12388
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12389
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12390
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12391
+ ] })
12392
+ }
12393
+ ),
12394
+ /* @__PURE__ */ jsxRuntime.jsx(
12395
+ Form$2.Field,
12396
+ {
12397
+ control: form.control,
12398
+ name: "last_name",
12399
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12400
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12401
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12402
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12403
+ ] })
12404
+ }
12405
+ )
12406
+ ] }),
12407
+ /* @__PURE__ */ jsxRuntime.jsx(
12408
+ Form$2.Field,
12409
+ {
12410
+ control: form.control,
12411
+ name: "company",
12412
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12413
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12414
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12415
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12416
+ ] })
12417
+ }
12418
+ ),
12419
+ /* @__PURE__ */ jsxRuntime.jsx(
12420
+ Form$2.Field,
12421
+ {
12422
+ control: form.control,
12423
+ name: "address_1",
12424
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12425
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12426
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12427
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12428
+ ] })
12429
+ }
12430
+ ),
12431
+ /* @__PURE__ */ jsxRuntime.jsx(
12432
+ Form$2.Field,
12433
+ {
12434
+ control: form.control,
12435
+ name: "address_2",
12436
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12437
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12438
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12440
+ ] })
12441
+ }
12442
+ ),
12443
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(
12445
+ Form$2.Field,
12446
+ {
12447
+ control: form.control,
12448
+ name: "postal_code",
12449
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12450
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12451
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12452
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12453
+ ] })
12454
+ }
12455
+ ),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(
12457
+ Form$2.Field,
12458
+ {
12459
+ control: form.control,
12460
+ name: "city",
12461
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12462
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12464
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12465
+ ] })
12466
+ }
12467
+ )
12468
+ ] }),
12469
+ /* @__PURE__ */ jsxRuntime.jsx(
12470
+ Form$2.Field,
12471
+ {
12472
+ control: form.control,
12473
+ name: "province",
12474
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12475
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12476
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12477
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12478
+ ] })
12479
+ }
12480
+ ),
12481
+ /* @__PURE__ */ jsxRuntime.jsx(
12482
+ Form$2.Field,
12483
+ {
12484
+ control: form.control,
12485
+ name: "phone",
12486
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12487
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12488
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12489
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12490
+ ] })
12491
+ }
12492
+ )
12493
+ ] }) }),
12494
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12495
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12496
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12497
+ ] }) })
12498
+ ]
12499
+ }
12500
+ ) });
12501
+ };
12502
+ const schema$2 = addressSchema;
12503
+ const TransferOwnership = () => {
12504
+ const { id } = reactRouterDom.useParams();
12505
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12506
+ fields: "id,customer_id,customer.*"
12507
+ });
12508
+ if (isError) {
12509
+ throw error;
12510
+ }
12511
+ const isReady = !isPending && !!draft_order;
12512
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12514
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12515
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12516
+ ] }),
12517
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12518
+ ] });
12519
+ };
12520
+ const TransferOwnershipForm = ({ order }) => {
12521
+ var _a, _b;
12522
+ const form = reactHookForm.useForm({
12591
12523
  defaultValues: {
12592
12524
  customer_id: order.customer_id || ""
12593
12525
  },
12594
- resolver: zod.zodResolver(schema)
12526
+ resolver: zod.zodResolver(schema$1)
12595
12527
  });
12596
12528
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12597
12529
  const { handleSuccess } = useRouteModal();
@@ -13041,9 +12973,77 @@ const Illustration = () => {
13041
12973
  }
13042
12974
  );
13043
12975
  };
13044
- const schema = objectType({
12976
+ const schema$1 = objectType({
13045
12977
  customer_id: stringType().min(1)
13046
12978
  });
12979
+ const Email = () => {
12980
+ const { id } = reactRouterDom.useParams();
12981
+ const { order, isPending, isError, error } = useOrder(id, {
12982
+ fields: "+email"
12983
+ });
12984
+ if (isError) {
12985
+ throw error;
12986
+ }
12987
+ const isReady = !isPending && !!order;
12988
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12990
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12991
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12992
+ ] }),
12993
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12994
+ ] });
12995
+ };
12996
+ const EmailForm = ({ order }) => {
12997
+ const form = reactHookForm.useForm({
12998
+ defaultValues: {
12999
+ email: order.email ?? ""
13000
+ },
13001
+ resolver: zod.zodResolver(schema)
13002
+ });
13003
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
13004
+ const { handleSuccess } = useRouteModal();
13005
+ const onSubmit = form.handleSubmit(async (data) => {
13006
+ await mutateAsync(
13007
+ { email: data.email },
13008
+ {
13009
+ onSuccess: () => {
13010
+ handleSuccess();
13011
+ },
13012
+ onError: (error) => {
13013
+ ui.toast.error(error.message);
13014
+ }
13015
+ }
13016
+ );
13017
+ });
13018
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13019
+ KeyboundForm,
13020
+ {
13021
+ className: "flex flex-1 flex-col overflow-hidden",
13022
+ onSubmit,
13023
+ children: [
13024
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13025
+ Form$2.Field,
13026
+ {
13027
+ control: form.control,
13028
+ name: "email",
13029
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
+ ] })
13034
+ }
13035
+ ) }),
13036
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13037
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13038
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13039
+ ] }) })
13040
+ ]
13041
+ }
13042
+ ) });
13043
+ };
13044
+ const schema = objectType({
13045
+ email: stringType().email()
13046
+ });
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13068,10 +13068,6 @@ const routeModule = {
13068
13068
  Component: BillingAddress,
13069
13069
  path: "/draft-orders/:id/billing-address"
13070
13070
  },
13071
- {
13072
- Component: Email,
13073
- path: "/draft-orders/:id/email"
13074
- },
13075
13071
  {
13076
13072
  Component: CustomItems,
13077
13073
  path: "/draft-orders/:id/custom-items"
@@ -13092,17 +13088,21 @@ const routeModule = {
13092
13088
  Component: SalesChannel,
13093
13089
  path: "/draft-orders/:id/sales-channel"
13094
13090
  },
13095
- {
13096
- Component: ShippingAddress,
13097
- path: "/draft-orders/:id/shipping-address"
13098
- },
13099
13091
  {
13100
13092
  Component: Shipping,
13101
13093
  path: "/draft-orders/:id/shipping"
13102
13094
  },
13095
+ {
13096
+ Component: ShippingAddress,
13097
+ path: "/draft-orders/:id/shipping-address"
13098
+ },
13103
13099
  {
13104
13100
  Component: TransferOwnership,
13105
13101
  path: "/draft-orders/:id/transfer-ownership"
13102
+ },
13103
+ {
13104
+ Component: Email,
13105
+ path: "/draft-orders/:id/email"
13106
13106
  }
13107
13107
  ]
13108
13108
  }