@medusajs/draft-order 2.11.2-preview-20251029180202 → 2.11.2-preview-20251029210154

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