@medusajs/draft-order 2.11.4-preview-20251123032854 → 2.11.4-preview-20251123060129

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.
@@ -9572,10 +9572,10 @@ const ID = () => {
9572
9572
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9573
9573
  ] });
9574
9574
  };
9575
- const Email = () => {
9575
+ const BillingAddress = () => {
9576
9576
  const { id } = reactRouterDom.useParams();
9577
9577
  const { order, isPending, isError, error } = useOrder(id, {
9578
- fields: "+email"
9578
+ fields: "+billing_address"
9579
9579
  });
9580
9580
  if (isError) {
9581
9581
  throw error;
@@ -9583,16 +9583,26 @@ const Email = () => {
9583
9583
  const isReady = !isPending && !!order;
9584
9584
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9585
9585
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9588
9588
  ] }),
9589
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9589
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9590
9590
  ] });
9591
9591
  };
9592
- const EmailForm = ({ order }) => {
9592
+ const BillingAddressForm = ({ order }) => {
9593
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9593
9594
  const form = reactHookForm.useForm({
9594
9595
  defaultValues: {
9595
- email: order.email ?? ""
9596
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9597
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9598
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9599
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9600
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9601
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9602
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9603
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9604
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9605
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9596
9606
  },
9597
9607
  resolver: zod.zodResolver(schema$5)
9598
9608
  });
@@ -9600,7 +9610,7 @@ const EmailForm = ({ order }) => {
9600
9610
  const { handleSuccess } = useRouteModal();
9601
9611
  const onSubmit = form.handleSubmit(async (data) => {
9602
9612
  await mutateAsync(
9603
- { email: data.email },
9613
+ { billing_address: data },
9604
9614
  {
9605
9615
  onSuccess: () => {
9606
9616
  handleSuccess();
@@ -9617,18 +9627,132 @@ const EmailForm = ({ order }) => {
9617
9627
  className: "flex flex-1 flex-col overflow-hidden",
9618
9628
  onSubmit,
9619
9629
  children: [
9620
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9621
- Form$2.Field,
9622
- {
9623
- control: form.control,
9624
- name: "email",
9625
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9626
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9627
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9628
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9629
- ] })
9630
- }
9631
- ) }),
9630
+ /* @__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: [
9631
+ /* @__PURE__ */ jsxRuntime.jsx(
9632
+ Form$2.Field,
9633
+ {
9634
+ control: form.control,
9635
+ name: "country_code",
9636
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9640
+ ] })
9641
+ }
9642
+ ),
9643
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9644
+ /* @__PURE__ */ jsxRuntime.jsx(
9645
+ Form$2.Field,
9646
+ {
9647
+ control: form.control,
9648
+ name: "first_name",
9649
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9653
+ ] })
9654
+ }
9655
+ ),
9656
+ /* @__PURE__ */ jsxRuntime.jsx(
9657
+ Form$2.Field,
9658
+ {
9659
+ control: form.control,
9660
+ name: "last_name",
9661
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9664
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9665
+ ] })
9666
+ }
9667
+ )
9668
+ ] }),
9669
+ /* @__PURE__ */ jsxRuntime.jsx(
9670
+ Form$2.Field,
9671
+ {
9672
+ control: form.control,
9673
+ name: "company",
9674
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9678
+ ] })
9679
+ }
9680
+ ),
9681
+ /* @__PURE__ */ jsxRuntime.jsx(
9682
+ Form$2.Field,
9683
+ {
9684
+ control: form.control,
9685
+ name: "address_1",
9686
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9690
+ ] })
9691
+ }
9692
+ ),
9693
+ /* @__PURE__ */ jsxRuntime.jsx(
9694
+ Form$2.Field,
9695
+ {
9696
+ control: form.control,
9697
+ name: "address_2",
9698
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9702
+ ] })
9703
+ }
9704
+ ),
9705
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9706
+ /* @__PURE__ */ jsxRuntime.jsx(
9707
+ Form$2.Field,
9708
+ {
9709
+ control: form.control,
9710
+ name: "postal_code",
9711
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9715
+ ] })
9716
+ }
9717
+ ),
9718
+ /* @__PURE__ */ jsxRuntime.jsx(
9719
+ Form$2.Field,
9720
+ {
9721
+ control: form.control,
9722
+ name: "city",
9723
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9727
+ ] })
9728
+ }
9729
+ )
9730
+ ] }),
9731
+ /* @__PURE__ */ jsxRuntime.jsx(
9732
+ Form$2.Field,
9733
+ {
9734
+ control: form.control,
9735
+ name: "province",
9736
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9740
+ ] })
9741
+ }
9742
+ ),
9743
+ /* @__PURE__ */ jsxRuntime.jsx(
9744
+ Form$2.Field,
9745
+ {
9746
+ control: form.control,
9747
+ name: "phone",
9748
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9752
+ ] })
9753
+ }
9754
+ )
9755
+ ] }) }),
9632
9756
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9633
9757
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9634
9758
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -9637,9 +9761,7 @@ const EmailForm = ({ order }) => {
9637
9761
  }
9638
9762
  ) });
9639
9763
  };
9640
- const schema$5 = objectType({
9641
- email: stringType().email()
9642
- });
9764
+ const schema$5 = addressSchema;
9643
9765
  const CustomItems = () => {
9644
9766
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9645
9767
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9661,6 +9783,74 @@ const CustomItemsForm = () => {
9661
9783
  const schema$4 = objectType({
9662
9784
  email: stringType().email()
9663
9785
  });
9786
+ const Email = () => {
9787
+ const { id } = reactRouterDom.useParams();
9788
+ const { order, isPending, isError, error } = useOrder(id, {
9789
+ fields: "+email"
9790
+ });
9791
+ if (isError) {
9792
+ throw error;
9793
+ }
9794
+ const isReady = !isPending && !!order;
9795
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9796
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9797
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9798
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9799
+ ] }),
9800
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9801
+ ] });
9802
+ };
9803
+ const EmailForm = ({ order }) => {
9804
+ const form = reactHookForm.useForm({
9805
+ defaultValues: {
9806
+ email: order.email ?? ""
9807
+ },
9808
+ resolver: zod.zodResolver(schema$3)
9809
+ });
9810
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9811
+ const { handleSuccess } = useRouteModal();
9812
+ const onSubmit = form.handleSubmit(async (data) => {
9813
+ await mutateAsync(
9814
+ { email: data.email },
9815
+ {
9816
+ onSuccess: () => {
9817
+ handleSuccess();
9818
+ },
9819
+ onError: (error) => {
9820
+ ui.toast.error(error.message);
9821
+ }
9822
+ }
9823
+ );
9824
+ });
9825
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9826
+ KeyboundForm,
9827
+ {
9828
+ className: "flex flex-1 flex-col overflow-hidden",
9829
+ onSubmit,
9830
+ children: [
9831
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9832
+ Form$2.Field,
9833
+ {
9834
+ control: form.control,
9835
+ name: "email",
9836
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
+ ] })
9841
+ }
9842
+ ) }),
9843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9845
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9846
+ ] }) })
9847
+ ]
9848
+ }
9849
+ ) });
9850
+ };
9851
+ const schema$3 = objectType({
9852
+ email: stringType().email()
9853
+ });
9664
9854
  const NumberInput = React.forwardRef(
9665
9855
  ({
9666
9856
  value,
@@ -11290,7 +11480,7 @@ const SalesChannelForm = ({ order }) => {
11290
11480
  defaultValues: {
11291
11481
  sales_channel_id: order.sales_channel_id || ""
11292
11482
  },
11293
- resolver: zod.zodResolver(schema$3)
11483
+ resolver: zod.zodResolver(schema$2)
11294
11484
  });
11295
11485
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11296
11486
  const { handleSuccess } = useRouteModal();
@@ -11365,32 +11555,235 @@ const SalesChannelField = ({ control, order }) => {
11365
11555
  }
11366
11556
  );
11367
11557
  };
11368
- const schema$3 = objectType({
11558
+ const schema$2 = objectType({
11369
11559
  sales_channel_id: stringType().min(1)
11370
11560
  });
11371
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11372
- const Shipping = () => {
11373
- var _a;
11561
+ const ShippingAddress = () => {
11374
11562
  const { id } = reactRouterDom.useParams();
11375
11563
  const { order, isPending, isError, error } = useOrder(id, {
11376
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11564
+ fields: "+shipping_address"
11377
11565
  });
11378
- const {
11379
- order: preview,
11380
- isPending: isPreviewPending,
11381
- isError: isPreviewError,
11382
- error: previewError
11383
- } = useOrderPreview(id);
11384
- useInitiateOrderEdit({ preview });
11385
- const { onCancel } = useCancelOrderEdit({ preview });
11386
11566
  if (isError) {
11387
11567
  throw error;
11388
11568
  }
11389
- if (isPreviewError) {
11390
- throw previewError;
11391
- }
11392
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11393
- const isReady = preview && !isPreviewPending && order && !isPending;
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
+ ] });
11577
+ };
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) ?? ""
11592
+ },
11593
+ resolver: zod.zodResolver(schema$1)
11594
+ });
11595
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11596
+ const { handleSuccess } = useRouteModal();
11597
+ const onSubmit = form.handleSubmit(async (data) => {
11598
+ await mutateAsync(
11599
+ {
11600
+ shipping_address: {
11601
+ first_name: data.first_name,
11602
+ last_name: data.last_name,
11603
+ company: data.company,
11604
+ address_1: data.address_1,
11605
+ address_2: data.address_2,
11606
+ city: data.city,
11607
+ province: data.province,
11608
+ country_code: data.country_code,
11609
+ postal_code: data.postal_code,
11610
+ phone: data.phone
11611
+ }
11612
+ },
11613
+ {
11614
+ onSuccess: () => {
11615
+ handleSuccess();
11616
+ },
11617
+ onError: (error) => {
11618
+ ui.toast.error(error.message);
11619
+ }
11620
+ }
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: [
11643
+ /* @__PURE__ */ jsxRuntime.jsx(
11644
+ Form$2.Field,
11645
+ {
11646
+ control: form.control,
11647
+ name: "first_name",
11648
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11652
+ ] })
11653
+ }
11654
+ ),
11655
+ /* @__PURE__ */ jsxRuntime.jsx(
11656
+ Form$2.Field,
11657
+ {
11658
+ control: form.control,
11659
+ name: "last_name",
11660
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11664
+ ] })
11665
+ }
11666
+ )
11667
+ ] }),
11668
+ /* @__PURE__ */ jsxRuntime.jsx(
11669
+ Form$2.Field,
11670
+ {
11671
+ control: form.control,
11672
+ name: "company",
11673
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11677
+ ] })
11678
+ }
11679
+ ),
11680
+ /* @__PURE__ */ jsxRuntime.jsx(
11681
+ Form$2.Field,
11682
+ {
11683
+ control: form.control,
11684
+ name: "address_1",
11685
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11689
+ ] })
11690
+ }
11691
+ ),
11692
+ /* @__PURE__ */ jsxRuntime.jsx(
11693
+ Form$2.Field,
11694
+ {
11695
+ control: form.control,
11696
+ name: "address_2",
11697
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11701
+ ] })
11702
+ }
11703
+ ),
11704
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11705
+ /* @__PURE__ */ jsxRuntime.jsx(
11706
+ Form$2.Field,
11707
+ {
11708
+ control: form.control,
11709
+ name: "postal_code",
11710
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11714
+ ] })
11715
+ }
11716
+ ),
11717
+ /* @__PURE__ */ jsxRuntime.jsx(
11718
+ Form$2.Field,
11719
+ {
11720
+ control: form.control,
11721
+ name: "city",
11722
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11726
+ ] })
11727
+ }
11728
+ )
11729
+ ] }),
11730
+ /* @__PURE__ */ jsxRuntime.jsx(
11731
+ Form$2.Field,
11732
+ {
11733
+ control: form.control,
11734
+ name: "province",
11735
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11739
+ ] })
11740
+ }
11741
+ ),
11742
+ /* @__PURE__ */ jsxRuntime.jsx(
11743
+ Form$2.Field,
11744
+ {
11745
+ control: form.control,
11746
+ name: "phone",
11747
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11751
+ ] })
11752
+ }
11753
+ )
11754
+ ] }) }),
11755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11757
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11758
+ ] }) })
11759
+ ]
11760
+ }
11761
+ ) });
11762
+ };
11763
+ const schema$1 = addressSchema;
11764
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11765
+ const Shipping = () => {
11766
+ var _a;
11767
+ const { id } = reactRouterDom.useParams();
11768
+ const { order, isPending, isError, error } = useOrder(id, {
11769
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11770
+ });
11771
+ const {
11772
+ order: preview,
11773
+ isPending: isPreviewPending,
11774
+ isError: isPreviewError,
11775
+ error: previewError
11776
+ } = useOrderPreview(id);
11777
+ useInitiateOrderEdit({ preview });
11778
+ const { onCancel } = useCancelOrderEdit({ preview });
11779
+ if (isError) {
11780
+ throw error;
11781
+ }
11782
+ if (isPreviewError) {
11783
+ throw previewError;
11784
+ }
11785
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11786
+ const isReady = preview && !isPreviewPending && order && !isPending;
11394
11787
  return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11395
11788
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11396
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: [
@@ -12175,244 +12568,41 @@ const CustomAmountField = ({
12175
12568
  }
12176
12569
  );
12177
12570
  };
12178
- const ShippingAddress = () => {
12571
+ const TransferOwnership = () => {
12179
12572
  const { id } = reactRouterDom.useParams();
12180
- const { order, isPending, isError, error } = useOrder(id, {
12181
- fields: "+shipping_address"
12573
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12574
+ fields: "id,customer_id,customer.*"
12182
12575
  });
12183
12576
  if (isError) {
12184
12577
  throw error;
12185
12578
  }
12186
- const isReady = !isPending && !!order;
12579
+ const isReady = !isPending && !!draft_order;
12187
12580
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12188
12581
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12189
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12190
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12582
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12583
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12191
12584
  ] }),
12192
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12585
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12193
12586
  ] });
12194
12587
  };
12195
- const ShippingAddressForm = ({ order }) => {
12196
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12588
+ const TransferOwnershipForm = ({ order }) => {
12589
+ var _a, _b;
12197
12590
  const form = reactHookForm.useForm({
12198
12591
  defaultValues: {
12199
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12200
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12201
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12202
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12203
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12204
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12205
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12206
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12207
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12208
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12592
+ customer_id: order.customer_id || ""
12209
12593
  },
12210
- resolver: zod.zodResolver(schema$2)
12594
+ resolver: zod.zodResolver(schema)
12211
12595
  });
12212
12596
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12213
12597
  const { handleSuccess } = useRouteModal();
12598
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12599
+ const currentCustomer = order.customer ? {
12600
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12601
+ value: order.customer.id
12602
+ } : null;
12214
12603
  const onSubmit = form.handleSubmit(async (data) => {
12215
12604
  await mutateAsync(
12216
- {
12217
- shipping_address: {
12218
- first_name: data.first_name,
12219
- last_name: data.last_name,
12220
- company: data.company,
12221
- address_1: data.address_1,
12222
- address_2: data.address_2,
12223
- city: data.city,
12224
- province: data.province,
12225
- country_code: data.country_code,
12226
- postal_code: data.postal_code,
12227
- phone: data.phone
12228
- }
12229
- },
12230
- {
12231
- onSuccess: () => {
12232
- handleSuccess();
12233
- },
12234
- onError: (error) => {
12235
- ui.toast.error(error.message);
12236
- }
12237
- }
12238
- );
12239
- });
12240
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12241
- KeyboundForm,
12242
- {
12243
- className: "flex flex-1 flex-col overflow-hidden",
12244
- onSubmit,
12245
- children: [
12246
- /* @__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: [
12247
- /* @__PURE__ */ jsxRuntime.jsx(
12248
- Form$2.Field,
12249
- {
12250
- control: form.control,
12251
- name: "country_code",
12252
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12253
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12254
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12255
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12256
- ] })
12257
- }
12258
- ),
12259
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12260
- /* @__PURE__ */ jsxRuntime.jsx(
12261
- Form$2.Field,
12262
- {
12263
- control: form.control,
12264
- name: "first_name",
12265
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12266
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12268
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12269
- ] })
12270
- }
12271
- ),
12272
- /* @__PURE__ */ jsxRuntime.jsx(
12273
- Form$2.Field,
12274
- {
12275
- control: form.control,
12276
- name: "last_name",
12277
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12278
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12280
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12281
- ] })
12282
- }
12283
- )
12284
- ] }),
12285
- /* @__PURE__ */ jsxRuntime.jsx(
12286
- Form$2.Field,
12287
- {
12288
- control: form.control,
12289
- name: "company",
12290
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12291
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12292
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12293
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12294
- ] })
12295
- }
12296
- ),
12297
- /* @__PURE__ */ jsxRuntime.jsx(
12298
- Form$2.Field,
12299
- {
12300
- control: form.control,
12301
- name: "address_1",
12302
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12303
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12305
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12306
- ] })
12307
- }
12308
- ),
12309
- /* @__PURE__ */ jsxRuntime.jsx(
12310
- Form$2.Field,
12311
- {
12312
- control: form.control,
12313
- name: "address_2",
12314
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12315
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12316
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12317
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12318
- ] })
12319
- }
12320
- ),
12321
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12322
- /* @__PURE__ */ jsxRuntime.jsx(
12323
- Form$2.Field,
12324
- {
12325
- control: form.control,
12326
- name: "postal_code",
12327
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12330
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12331
- ] })
12332
- }
12333
- ),
12334
- /* @__PURE__ */ jsxRuntime.jsx(
12335
- Form$2.Field,
12336
- {
12337
- control: form.control,
12338
- name: "city",
12339
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12342
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12343
- ] })
12344
- }
12345
- )
12346
- ] }),
12347
- /* @__PURE__ */ jsxRuntime.jsx(
12348
- Form$2.Field,
12349
- {
12350
- control: form.control,
12351
- name: "province",
12352
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12355
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12356
- ] })
12357
- }
12358
- ),
12359
- /* @__PURE__ */ jsxRuntime.jsx(
12360
- Form$2.Field,
12361
- {
12362
- control: form.control,
12363
- name: "phone",
12364
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12367
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12368
- ] })
12369
- }
12370
- )
12371
- ] }) }),
12372
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12373
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12374
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12375
- ] }) })
12376
- ]
12377
- }
12378
- ) });
12379
- };
12380
- const schema$2 = addressSchema;
12381
- const TransferOwnership = () => {
12382
- const { id } = reactRouterDom.useParams();
12383
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12384
- fields: "id,customer_id,customer.*"
12385
- });
12386
- if (isError) {
12387
- throw error;
12388
- }
12389
- const isReady = !isPending && !!draft_order;
12390
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12391
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12392
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12393
- /* @__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" }) })
12394
- ] }),
12395
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12396
- ] });
12397
- };
12398
- const TransferOwnershipForm = ({ order }) => {
12399
- var _a, _b;
12400
- const form = reactHookForm.useForm({
12401
- defaultValues: {
12402
- customer_id: order.customer_id || ""
12403
- },
12404
- resolver: zod.zodResolver(schema$1)
12405
- });
12406
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12407
- const { handleSuccess } = useRouteModal();
12408
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12409
- const currentCustomer = order.customer ? {
12410
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12411
- value: order.customer.id
12412
- } : null;
12413
- const onSubmit = form.handleSubmit(async (data) => {
12414
- await mutateAsync(
12415
- { customer_id: data.customer_id },
12605
+ { customer_id: data.customer_id },
12416
12606
  {
12417
12607
  onSuccess: () => {
12418
12608
  ui.toast.success("Customer updated");
@@ -12851,199 +13041,9 @@ const Illustration = () => {
12851
13041
  }
12852
13042
  );
12853
13043
  };
12854
- const schema$1 = objectType({
13044
+ const schema = objectType({
12855
13045
  customer_id: stringType().min(1)
12856
13046
  });
12857
- const BillingAddress = () => {
12858
- const { id } = reactRouterDom.useParams();
12859
- const { order, isPending, isError, error } = useOrder(id, {
12860
- fields: "+billing_address"
12861
- });
12862
- if (isError) {
12863
- throw error;
12864
- }
12865
- const isReady = !isPending && !!order;
12866
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12867
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12868
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12869
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12870
- ] }),
12871
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12872
- ] });
12873
- };
12874
- const BillingAddressForm = ({ order }) => {
12875
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12876
- const form = reactHookForm.useForm({
12877
- defaultValues: {
12878
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12879
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12880
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12881
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12882
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12883
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12884
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12885
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12886
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12887
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12888
- },
12889
- resolver: zod.zodResolver(schema)
12890
- });
12891
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12892
- const { handleSuccess } = useRouteModal();
12893
- const onSubmit = form.handleSubmit(async (data) => {
12894
- await mutateAsync(
12895
- { billing_address: data },
12896
- {
12897
- onSuccess: () => {
12898
- handleSuccess();
12899
- },
12900
- onError: (error) => {
12901
- ui.toast.error(error.message);
12902
- }
12903
- }
12904
- );
12905
- });
12906
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12907
- KeyboundForm,
12908
- {
12909
- className: "flex flex-1 flex-col overflow-hidden",
12910
- onSubmit,
12911
- children: [
12912
- /* @__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: [
12913
- /* @__PURE__ */ jsxRuntime.jsx(
12914
- Form$2.Field,
12915
- {
12916
- control: form.control,
12917
- name: "country_code",
12918
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12919
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12921
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12922
- ] })
12923
- }
12924
- ),
12925
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12926
- /* @__PURE__ */ jsxRuntime.jsx(
12927
- Form$2.Field,
12928
- {
12929
- control: form.control,
12930
- name: "first_name",
12931
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
- ] })
12936
- }
12937
- ),
12938
- /* @__PURE__ */ jsxRuntime.jsx(
12939
- Form$2.Field,
12940
- {
12941
- control: form.control,
12942
- name: "last_name",
12943
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12944
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12946
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12947
- ] })
12948
- }
12949
- )
12950
- ] }),
12951
- /* @__PURE__ */ jsxRuntime.jsx(
12952
- Form$2.Field,
12953
- {
12954
- control: form.control,
12955
- name: "company",
12956
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
- ] })
12961
- }
12962
- ),
12963
- /* @__PURE__ */ jsxRuntime.jsx(
12964
- Form$2.Field,
12965
- {
12966
- control: form.control,
12967
- name: "address_1",
12968
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
- ] })
12973
- }
12974
- ),
12975
- /* @__PURE__ */ jsxRuntime.jsx(
12976
- Form$2.Field,
12977
- {
12978
- control: form.control,
12979
- name: "address_2",
12980
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12981
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12983
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12984
- ] })
12985
- }
12986
- ),
12987
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12988
- /* @__PURE__ */ jsxRuntime.jsx(
12989
- Form$2.Field,
12990
- {
12991
- control: form.control,
12992
- name: "postal_code",
12993
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
- ] })
12998
- }
12999
- ),
13000
- /* @__PURE__ */ jsxRuntime.jsx(
13001
- Form$2.Field,
13002
- {
13003
- control: form.control,
13004
- name: "city",
13005
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13006
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13008
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13009
- ] })
13010
- }
13011
- )
13012
- ] }),
13013
- /* @__PURE__ */ jsxRuntime.jsx(
13014
- Form$2.Field,
13015
- {
13016
- control: form.control,
13017
- name: "province",
13018
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
- ] })
13023
- }
13024
- ),
13025
- /* @__PURE__ */ jsxRuntime.jsx(
13026
- Form$2.Field,
13027
- {
13028
- control: form.control,
13029
- name: "phone",
13030
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
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
- ] }) }),
13038
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13039
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13040
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13041
- ] }) })
13042
- ]
13043
- }
13044
- ) });
13045
- };
13046
- const schema = addressSchema;
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13065,13 +13065,17 @@ const routeModule = {
13065
13065
  loader,
13066
13066
  children: [
13067
13067
  {
13068
- Component: Email,
13069
- path: "/draft-orders/:id/email"
13068
+ Component: BillingAddress,
13069
+ path: "/draft-orders/:id/billing-address"
13070
13070
  },
13071
13071
  {
13072
13072
  Component: CustomItems,
13073
13073
  path: "/draft-orders/:id/custom-items"
13074
13074
  },
13075
+ {
13076
+ Component: Email,
13077
+ path: "/draft-orders/:id/email"
13078
+ },
13075
13079
  {
13076
13080
  Component: Items,
13077
13081
  path: "/draft-orders/:id/items"
@@ -13088,21 +13092,17 @@ const routeModule = {
13088
13092
  Component: SalesChannel,
13089
13093
  path: "/draft-orders/:id/sales-channel"
13090
13094
  },
13091
- {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13094
- },
13095
13095
  {
13096
13096
  Component: ShippingAddress,
13097
13097
  path: "/draft-orders/:id/shipping-address"
13098
13098
  },
13099
13099
  {
13100
- Component: TransferOwnership,
13101
- path: "/draft-orders/:id/transfer-ownership"
13100
+ Component: Shipping,
13101
+ path: "/draft-orders/:id/shipping"
13102
13102
  },
13103
13103
  {
13104
- Component: BillingAddress,
13105
- path: "/draft-orders/:id/billing-address"
13104
+ Component: TransferOwnership,
13105
+ path: "/draft-orders/:id/transfer-ownership"
13106
13106
  }
13107
13107
  ]
13108
13108
  }