@medusajs/draft-order 2.11.0-preview-20251018180153 → 2.11.0-preview-20251019000333

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