@medusajs/draft-order 2.10.2-preview-20250911000329 → 2.10.2-preview-20250911060156

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