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

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,6 +9762,74 @@ 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
+ });
9765
9833
  const CustomItems = () => {
9766
9834
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
9835
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9770,7 +9838,7 @@ const CustomItems = () => {
9770
9838
  };
9771
9839
  const CustomItemsForm = () => {
9772
9840
  const form = reactHookForm.useForm({
9773
- resolver: zod.zodResolver(schema$4)
9841
+ resolver: zod.zodResolver(schema$3)
9774
9842
  });
9775
9843
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
9844
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9780,7 +9848,7 @@ const CustomItemsForm = () => {
9780
9848
  ] }) })
9781
9849
  ] }) });
9782
9850
  };
9783
- const schema$4 = objectType({
9851
+ const schema$3 = objectType({
9784
9852
  email: stringType().email()
9785
9853
  });
9786
9854
  const NumberInput = React.forwardRef(
@@ -11412,7 +11480,7 @@ const SalesChannelForm = ({ order }) => {
11412
11480
  defaultValues: {
11413
11481
  sales_channel_id: order.sales_channel_id || ""
11414
11482
  },
11415
- resolver: zod.zodResolver(schema$3)
11483
+ resolver: zod.zodResolver(schema$2)
11416
11484
  });
11417
11485
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11418
11486
  const { handleSuccess } = useRouteModal();
@@ -11487,131 +11555,334 @@ const SalesChannelField = ({ control, order }) => {
11487
11555
  }
11488
11556
  );
11489
11557
  };
11490
- const schema$3 = objectType({
11558
+ const schema$2 = objectType({
11491
11559
  sales_channel_id: stringType().min(1)
11492
11560
  });
11493
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11494
- const Shipping = () => {
11495
- var _a;
11561
+ const ShippingAddress = () => {
11496
11562
  const { id } = reactRouterDom.useParams();
11497
11563
  const { order, isPending, isError, error } = useOrder(id, {
11498
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11564
+ fields: "+shipping_address"
11499
11565
  });
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 });
11508
11566
  if (isError) {
11509
11567
  throw error;
11510
11568
  }
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
- ] }) });
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
+ ] });
11527
11577
  };
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.*"
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) ?? ""
11538
11592
  },
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]);
11593
+ resolver: zod.zodResolver(schema$1)
11594
+ });
11595
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11553
11596
  const { handleSuccess } = useRouteModal();
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}`);
11564
- },
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();
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
+ }
11579
11612
  },
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;
11613
+ {
11614
+ onSuccess: () => {
11615
+ handleSuccess();
11616
+ },
11617
+ onError: (error) => {
11618
+ ui.toast.error(error.message);
11590
11619
  }
11591
- onSubmit();
11592
11620
  }
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: [
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: [
11613
11643
  /* @__PURE__ */ jsxRuntime.jsx(
11614
- ui.Text,
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,
11615
11886
  {
11616
11887
  size: "xsmall",
11617
11888
  weight: "plus",
@@ -12320,7 +12591,7 @@ const TransferOwnershipForm = ({ order }) => {
12320
12591
  defaultValues: {
12321
12592
  customer_id: order.customer_id || ""
12322
12593
  },
12323
- resolver: zod.zodResolver(schema$2)
12594
+ resolver: zod.zodResolver(schema)
12324
12595
  });
12325
12596
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12326
12597
  const { handleSuccess } = useRouteModal();
@@ -12770,280 +13041,9 @@ const Illustration = () => {
12770
13041
  }
12771
13042
  );
12772
13043
  };
12773
- const schema$2 = objectType({
13044
+ const schema = objectType({
12774
13045
  customer_id: stringType().min(1)
12775
13046
  });
12776
- const ShippingAddress = () => {
12777
- const { id } = reactRouterDom.useParams();
12778
- const { order, isPending, isError, error } = useOrder(id, {
12779
- fields: "+shipping_address"
12780
- });
12781
- if (isError) {
12782
- throw error;
12783
- }
12784
- const isReady = !isPending && !!order;
12785
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12786
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12787
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12788
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12789
- ] }),
12790
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12791
- ] });
12792
- };
12793
- const ShippingAddressForm = ({ order }) => {
12794
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12795
- const form = reactHookForm.useForm({
12796
- defaultValues: {
12797
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12798
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12799
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12800
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12801
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12802
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12803
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12804
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12805
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12806
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12807
- },
12808
- resolver: zod.zodResolver(schema$1)
12809
- });
12810
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12811
- const { handleSuccess } = useRouteModal();
12812
- const onSubmit = form.handleSubmit(async (data) => {
12813
- await mutateAsync(
12814
- {
12815
- shipping_address: {
12816
- first_name: data.first_name,
12817
- last_name: data.last_name,
12818
- company: data.company,
12819
- address_1: data.address_1,
12820
- address_2: data.address_2,
12821
- city: data.city,
12822
- province: data.province,
12823
- country_code: data.country_code,
12824
- postal_code: data.postal_code,
12825
- phone: data.phone
12826
- }
12827
- },
12828
- {
12829
- onSuccess: () => {
12830
- handleSuccess();
12831
- },
12832
- onError: (error) => {
12833
- ui.toast.error(error.message);
12834
- }
12835
- }
12836
- );
12837
- });
12838
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12839
- KeyboundForm,
12840
- {
12841
- className: "flex flex-1 flex-col overflow-hidden",
12842
- onSubmit,
12843
- children: [
12844
- /* @__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: [
12845
- /* @__PURE__ */ jsxRuntime.jsx(
12846
- Form$2.Field,
12847
- {
12848
- control: form.control,
12849
- name: "country_code",
12850
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12851
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12852
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12853
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12854
- ] })
12855
- }
12856
- ),
12857
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12858
- /* @__PURE__ */ jsxRuntime.jsx(
12859
- Form$2.Field,
12860
- {
12861
- control: form.control,
12862
- name: "first_name",
12863
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12864
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12865
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12866
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12867
- ] })
12868
- }
12869
- ),
12870
- /* @__PURE__ */ jsxRuntime.jsx(
12871
- Form$2.Field,
12872
- {
12873
- control: form.control,
12874
- name: "last_name",
12875
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12876
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12877
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12878
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12879
- ] })
12880
- }
12881
- )
12882
- ] }),
12883
- /* @__PURE__ */ jsxRuntime.jsx(
12884
- Form$2.Field,
12885
- {
12886
- control: form.control,
12887
- name: "company",
12888
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12889
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12890
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12891
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12892
- ] })
12893
- }
12894
- ),
12895
- /* @__PURE__ */ jsxRuntime.jsx(
12896
- Form$2.Field,
12897
- {
12898
- control: form.control,
12899
- name: "address_1",
12900
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12901
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12902
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12903
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12904
- ] })
12905
- }
12906
- ),
12907
- /* @__PURE__ */ jsxRuntime.jsx(
12908
- Form$2.Field,
12909
- {
12910
- control: form.control,
12911
- name: "address_2",
12912
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12913
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12914
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12915
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12916
- ] })
12917
- }
12918
- ),
12919
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12920
- /* @__PURE__ */ jsxRuntime.jsx(
12921
- Form$2.Field,
12922
- {
12923
- control: form.control,
12924
- name: "postal_code",
12925
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12926
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12927
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12928
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12929
- ] })
12930
- }
12931
- ),
12932
- /* @__PURE__ */ jsxRuntime.jsx(
12933
- Form$2.Field,
12934
- {
12935
- control: form.control,
12936
- name: "city",
12937
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12938
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12939
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12940
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12941
- ] })
12942
- }
12943
- )
12944
- ] }),
12945
- /* @__PURE__ */ jsxRuntime.jsx(
12946
- Form$2.Field,
12947
- {
12948
- control: form.control,
12949
- name: "province",
12950
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12951
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12952
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12953
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12954
- ] })
12955
- }
12956
- ),
12957
- /* @__PURE__ */ jsxRuntime.jsx(
12958
- Form$2.Field,
12959
- {
12960
- control: form.control,
12961
- name: "phone",
12962
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12963
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12964
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12965
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12966
- ] })
12967
- }
12968
- )
12969
- ] }) }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12971
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12972
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12973
- ] }) })
12974
- ]
12975
- }
12976
- ) });
12977
- };
12978
- const schema$1 = addressSchema;
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,6 +13068,10 @@ 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
+ },
13071
13075
  {
13072
13076
  Component: CustomItems,
13073
13077
  path: "/draft-orders/:id/custom-items"
@@ -13088,6 +13092,10 @@ const routeModule = {
13088
13092
  Component: SalesChannel,
13089
13093
  path: "/draft-orders/:id/sales-channel"
13090
13094
  },
13095
+ {
13096
+ Component: ShippingAddress,
13097
+ path: "/draft-orders/:id/shipping-address"
13098
+ },
13091
13099
  {
13092
13100
  Component: Shipping,
13093
13101
  path: "/draft-orders/:id/shipping"
@@ -13095,14 +13103,6 @@ const routeModule = {
13095
13103
  {
13096
13104
  Component: TransferOwnership,
13097
13105
  path: "/draft-orders/:id/transfer-ownership"
13098
- },
13099
- {
13100
- Component: ShippingAddress,
13101
- path: "/draft-orders/:id/shipping-address"
13102
- },
13103
- {
13104
- Component: Email,
13105
- path: "/draft-orders/:id/email"
13106
13106
  }
13107
13107
  ]
13108
13108
  }