@medusajs/draft-order 2.11.1-preview-20251023210200 → 2.11.1-preview-20251024031436

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.
@@ -9571,196 +9571,6 @@ const ID = () => {
9571
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9572
9572
  ] });
9573
9573
  };
9574
- const BillingAddress = () => {
9575
- const { id } = reactRouterDom.useParams();
9576
- const { order, isPending, isError, error } = useOrder(id, {
9577
- fields: "+billing_address"
9578
- });
9579
- if (isError) {
9580
- throw error;
9581
- }
9582
- const isReady = !isPending && !!order;
9583
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9584
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9585
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9587
- ] }),
9588
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9589
- ] });
9590
- };
9591
- const BillingAddressForm = ({ order }) => {
9592
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9593
- const form = reactHookForm.useForm({
9594
- defaultValues: {
9595
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9596
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9597
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9598
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9599
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9600
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9601
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9602
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9603
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9604
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9605
- },
9606
- resolver: zod.zodResolver(schema$5)
9607
- });
9608
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9609
- const { handleSuccess } = useRouteModal();
9610
- const onSubmit = form.handleSubmit(async (data) => {
9611
- await mutateAsync(
9612
- { billing_address: data },
9613
- {
9614
- onSuccess: () => {
9615
- handleSuccess();
9616
- },
9617
- onError: (error) => {
9618
- ui.toast.error(error.message);
9619
- }
9620
- }
9621
- );
9622
- });
9623
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9624
- KeyboundForm,
9625
- {
9626
- className: "flex flex-1 flex-col overflow-hidden",
9627
- onSubmit,
9628
- children: [
9629
- /* @__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: [
9630
- /* @__PURE__ */ jsxRuntime.jsx(
9631
- Form$2.Field,
9632
- {
9633
- control: form.control,
9634
- name: "country_code",
9635
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9636
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9639
- ] })
9640
- }
9641
- ),
9642
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9643
- /* @__PURE__ */ jsxRuntime.jsx(
9644
- Form$2.Field,
9645
- {
9646
- control: form.control,
9647
- name: "first_name",
9648
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9652
- ] })
9653
- }
9654
- ),
9655
- /* @__PURE__ */ jsxRuntime.jsx(
9656
- Form$2.Field,
9657
- {
9658
- control: form.control,
9659
- name: "last_name",
9660
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9661
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9664
- ] })
9665
- }
9666
- )
9667
- ] }),
9668
- /* @__PURE__ */ jsxRuntime.jsx(
9669
- Form$2.Field,
9670
- {
9671
- control: form.control,
9672
- name: "company",
9673
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9674
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9677
- ] })
9678
- }
9679
- ),
9680
- /* @__PURE__ */ jsxRuntime.jsx(
9681
- Form$2.Field,
9682
- {
9683
- control: form.control,
9684
- name: "address_1",
9685
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9686
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9689
- ] })
9690
- }
9691
- ),
9692
- /* @__PURE__ */ jsxRuntime.jsx(
9693
- Form$2.Field,
9694
- {
9695
- control: form.control,
9696
- name: "address_2",
9697
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9698
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9701
- ] })
9702
- }
9703
- ),
9704
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9705
- /* @__PURE__ */ jsxRuntime.jsx(
9706
- Form$2.Field,
9707
- {
9708
- control: form.control,
9709
- name: "postal_code",
9710
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9711
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9714
- ] })
9715
- }
9716
- ),
9717
- /* @__PURE__ */ jsxRuntime.jsx(
9718
- Form$2.Field,
9719
- {
9720
- control: form.control,
9721
- name: "city",
9722
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9723
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9726
- ] })
9727
- }
9728
- )
9729
- ] }),
9730
- /* @__PURE__ */ jsxRuntime.jsx(
9731
- Form$2.Field,
9732
- {
9733
- control: form.control,
9734
- name: "province",
9735
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9736
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9739
- ] })
9740
- }
9741
- ),
9742
- /* @__PURE__ */ jsxRuntime.jsx(
9743
- Form$2.Field,
9744
- {
9745
- control: form.control,
9746
- name: "phone",
9747
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9748
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9751
- ] })
9752
- }
9753
- )
9754
- ] }) }),
9755
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9758
- ] }) })
9759
- ]
9760
- }
9761
- ) });
9762
- };
9763
- const schema$5 = addressSchema;
9764
9574
  const CustomItems = () => {
9765
9575
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9766
9576
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9769,7 +9579,7 @@ const CustomItems = () => {
9769
9579
  };
9770
9580
  const CustomItemsForm = () => {
9771
9581
  const form = reactHookForm.useForm({
9772
- resolver: zod.zodResolver(schema$4)
9582
+ resolver: zod.zodResolver(schema$5)
9773
9583
  });
9774
9584
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9775
9585
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9779,7 +9589,7 @@ const CustomItemsForm = () => {
9779
9589
  ] }) })
9780
9590
  ] }) });
9781
9591
  };
9782
- const schema$4 = objectType({
9592
+ const schema$5 = objectType({
9783
9593
  email: stringType().email()
9784
9594
  });
9785
9595
  const Email = () => {
@@ -9804,7 +9614,7 @@ const EmailForm = ({ order }) => {
9804
9614
  defaultValues: {
9805
9615
  email: order.email ?? ""
9806
9616
  },
9807
- resolver: zod.zodResolver(schema$3)
9617
+ resolver: zod.zodResolver(schema$4)
9808
9618
  });
9809
9619
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9810
9620
  const { handleSuccess } = useRouteModal();
@@ -9847,7 +9657,7 @@ const EmailForm = ({ order }) => {
9847
9657
  }
9848
9658
  ) });
9849
9659
  };
9850
- const schema$3 = objectType({
9660
+ const schema$4 = objectType({
9851
9661
  email: stringType().email()
9852
9662
  });
9853
9663
  const NumberInput = React.forwardRef(
@@ -11479,7 +11289,7 @@ const SalesChannelForm = ({ order }) => {
11479
11289
  defaultValues: {
11480
11290
  sales_channel_id: order.sales_channel_id || ""
11481
11291
  },
11482
- resolver: zod.zodResolver(schema$2)
11292
+ resolver: zod.zodResolver(schema$3)
11483
11293
  });
11484
11294
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
11295
  const { handleSuccess } = useRouteModal();
@@ -11554,63 +11364,266 @@ const SalesChannelField = ({ control, order }) => {
11554
11364
  }
11555
11365
  );
11556
11366
  };
11557
- const schema$2 = objectType({
11367
+ const schema$3 = objectType({
11558
11368
  sales_channel_id: stringType().min(1)
11559
11369
  });
11560
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11561
- const Shipping = () => {
11562
- var _a;
11370
+ const ShippingAddress = () => {
11563
11371
  const { id } = reactRouterDom.useParams();
11564
11372
  const { order, isPending, isError, error } = useOrder(id, {
11565
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11373
+ fields: "+shipping_address"
11566
11374
  });
11567
- const {
11568
- order: preview,
11569
- isPending: isPreviewPending,
11570
- isError: isPreviewError,
11571
- error: previewError
11572
- } = useOrderPreview(id);
11573
- useInitiateOrderEdit({ preview });
11574
- const { onCancel } = useCancelOrderEdit({ preview });
11575
11375
  if (isError) {
11576
11376
  throw error;
11577
11377
  }
11578
- if (isPreviewError) {
11579
- throw previewError;
11580
- }
11581
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11582
- const isReady = preview && !isPreviewPending && order && !isPending;
11583
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11584
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11585
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11586
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11587
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11588
- ] }) }) }),
11589
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11590
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11591
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11592
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11593
- ] }) });
11378
+ const isReady = !isPending && !!order;
11379
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11380
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11382
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11383
+ ] }),
11384
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11385
+ ] });
11594
11386
  };
11595
- const ShippingForm = ({ preview, order }) => {
11596
- var _a;
11597
- const { setIsOpen } = useStackedModal();
11598
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11599
- const [data, setData] = React.useState(null);
11600
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11601
- const { shipping_options } = useShippingOptions(
11602
- {
11603
- id: appliedShippingOptionIds,
11604
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11605
- },
11606
- {
11607
- enabled: appliedShippingOptionIds.length > 0
11608
- }
11609
- );
11610
- const uniqueShippingProfiles = React.useMemo(() => {
11611
- const profiles = /* @__PURE__ */ new Map();
11612
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11613
- profiles.set(profile.id, profile);
11387
+ const ShippingAddressForm = ({ order }) => {
11388
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11389
+ const form = reactHookForm.useForm({
11390
+ defaultValues: {
11391
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11392
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11393
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11394
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11395
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11396
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11397
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11398
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11399
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11400
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11401
+ },
11402
+ resolver: zod.zodResolver(schema$2)
11403
+ });
11404
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11405
+ const { handleSuccess } = useRouteModal();
11406
+ const onSubmit = form.handleSubmit(async (data) => {
11407
+ await mutateAsync(
11408
+ {
11409
+ shipping_address: {
11410
+ first_name: data.first_name,
11411
+ last_name: data.last_name,
11412
+ company: data.company,
11413
+ address_1: data.address_1,
11414
+ address_2: data.address_2,
11415
+ city: data.city,
11416
+ province: data.province,
11417
+ country_code: data.country_code,
11418
+ postal_code: data.postal_code,
11419
+ phone: data.phone
11420
+ }
11421
+ },
11422
+ {
11423
+ onSuccess: () => {
11424
+ handleSuccess();
11425
+ },
11426
+ onError: (error) => {
11427
+ ui.toast.error(error.message);
11428
+ }
11429
+ }
11430
+ );
11431
+ });
11432
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11433
+ KeyboundForm,
11434
+ {
11435
+ className: "flex flex-1 flex-col overflow-hidden",
11436
+ onSubmit,
11437
+ children: [
11438
+ /* @__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: [
11439
+ /* @__PURE__ */ jsxRuntime.jsx(
11440
+ Form$2.Field,
11441
+ {
11442
+ control: form.control,
11443
+ name: "country_code",
11444
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11448
+ ] })
11449
+ }
11450
+ ),
11451
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11452
+ /* @__PURE__ */ jsxRuntime.jsx(
11453
+ Form$2.Field,
11454
+ {
11455
+ control: form.control,
11456
+ name: "first_name",
11457
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11459
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11460
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11461
+ ] })
11462
+ }
11463
+ ),
11464
+ /* @__PURE__ */ jsxRuntime.jsx(
11465
+ Form$2.Field,
11466
+ {
11467
+ control: form.control,
11468
+ name: "last_name",
11469
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11472
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11473
+ ] })
11474
+ }
11475
+ )
11476
+ ] }),
11477
+ /* @__PURE__ */ jsxRuntime.jsx(
11478
+ Form$2.Field,
11479
+ {
11480
+ control: form.control,
11481
+ name: "company",
11482
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11484
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11485
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11486
+ ] })
11487
+ }
11488
+ ),
11489
+ /* @__PURE__ */ jsxRuntime.jsx(
11490
+ Form$2.Field,
11491
+ {
11492
+ control: form.control,
11493
+ name: "address_1",
11494
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11497
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11498
+ ] })
11499
+ }
11500
+ ),
11501
+ /* @__PURE__ */ jsxRuntime.jsx(
11502
+ Form$2.Field,
11503
+ {
11504
+ control: form.control,
11505
+ name: "address_2",
11506
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11509
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11510
+ ] })
11511
+ }
11512
+ ),
11513
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11514
+ /* @__PURE__ */ jsxRuntime.jsx(
11515
+ Form$2.Field,
11516
+ {
11517
+ control: form.control,
11518
+ name: "postal_code",
11519
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11521
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11522
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11523
+ ] })
11524
+ }
11525
+ ),
11526
+ /* @__PURE__ */ jsxRuntime.jsx(
11527
+ Form$2.Field,
11528
+ {
11529
+ control: form.control,
11530
+ name: "city",
11531
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11534
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11535
+ ] })
11536
+ }
11537
+ )
11538
+ ] }),
11539
+ /* @__PURE__ */ jsxRuntime.jsx(
11540
+ Form$2.Field,
11541
+ {
11542
+ control: form.control,
11543
+ name: "province",
11544
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11546
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11547
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11548
+ ] })
11549
+ }
11550
+ ),
11551
+ /* @__PURE__ */ jsxRuntime.jsx(
11552
+ Form$2.Field,
11553
+ {
11554
+ control: form.control,
11555
+ name: "phone",
11556
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11559
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11560
+ ] })
11561
+ }
11562
+ )
11563
+ ] }) }),
11564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11565
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11566
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11567
+ ] }) })
11568
+ ]
11569
+ }
11570
+ ) });
11571
+ };
11572
+ const schema$2 = addressSchema;
11573
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11574
+ const Shipping = () => {
11575
+ var _a;
11576
+ const { id } = reactRouterDom.useParams();
11577
+ const { order, isPending, isError, error } = useOrder(id, {
11578
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11579
+ });
11580
+ const {
11581
+ order: preview,
11582
+ isPending: isPreviewPending,
11583
+ isError: isPreviewError,
11584
+ error: previewError
11585
+ } = useOrderPreview(id);
11586
+ useInitiateOrderEdit({ preview });
11587
+ const { onCancel } = useCancelOrderEdit({ preview });
11588
+ if (isError) {
11589
+ throw error;
11590
+ }
11591
+ if (isPreviewError) {
11592
+ throw previewError;
11593
+ }
11594
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11595
+ const isReady = preview && !isPreviewPending && order && !isPending;
11596
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11597
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11598
+ /* @__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: [
11599
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11600
+ /* @__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." }) })
11601
+ ] }) }) }),
11602
+ /* @__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" }) }) })
11603
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11604
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11605
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11606
+ ] }) });
11607
+ };
11608
+ const ShippingForm = ({ preview, order }) => {
11609
+ var _a;
11610
+ const { setIsOpen } = useStackedModal();
11611
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11612
+ const [data, setData] = React.useState(null);
11613
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11614
+ const { shipping_options } = useShippingOptions(
11615
+ {
11616
+ id: appliedShippingOptionIds,
11617
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11618
+ },
11619
+ {
11620
+ enabled: appliedShippingOptionIds.length > 0
11621
+ }
11622
+ );
11623
+ const uniqueShippingProfiles = React.useMemo(() => {
11624
+ const profiles = /* @__PURE__ */ new Map();
11625
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11626
+ profiles.set(profile.id, profile);
11614
11627
  });
11615
11628
  shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11616
11629
  profiles.set(option.shipping_profile_id, option.shipping_profile);
@@ -12364,224 +12377,21 @@ const CustomAmountField = ({
12364
12377
  }
12365
12378
  );
12366
12379
  };
12367
- const ShippingAddress = () => {
12380
+ const TransferOwnership = () => {
12368
12381
  const { id } = reactRouterDom.useParams();
12369
- const { order, isPending, isError, error } = useOrder(id, {
12370
- fields: "+shipping_address"
12382
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12383
+ fields: "id,customer_id,customer.*"
12371
12384
  });
12372
12385
  if (isError) {
12373
12386
  throw error;
12374
12387
  }
12375
- const isReady = !isPending && !!order;
12388
+ const isReady = !isPending && !!draft_order;
12376
12389
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12377
12390
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12378
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12379
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12391
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12392
+ /* @__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
12393
  ] }),
12381
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12382
- ] });
12383
- };
12384
- const ShippingAddressForm = ({ order }) => {
12385
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12386
- const form = reactHookForm.useForm({
12387
- defaultValues: {
12388
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12389
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12390
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12391
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12392
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12393
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12394
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12395
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12396
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12397
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12398
- },
12399
- resolver: zod.zodResolver(schema$1)
12400
- });
12401
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
- const { handleSuccess } = useRouteModal();
12403
- const onSubmit = form.handleSubmit(async (data) => {
12404
- await mutateAsync(
12405
- {
12406
- shipping_address: {
12407
- first_name: data.first_name,
12408
- last_name: data.last_name,
12409
- company: data.company,
12410
- address_1: data.address_1,
12411
- address_2: data.address_2,
12412
- city: data.city,
12413
- province: data.province,
12414
- country_code: data.country_code,
12415
- postal_code: data.postal_code,
12416
- phone: data.phone
12417
- }
12418
- },
12419
- {
12420
- onSuccess: () => {
12421
- handleSuccess();
12422
- },
12423
- onError: (error) => {
12424
- ui.toast.error(error.message);
12425
- }
12426
- }
12427
- );
12428
- });
12429
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12430
- KeyboundForm,
12431
- {
12432
- className: "flex flex-1 flex-col overflow-hidden",
12433
- onSubmit,
12434
- children: [
12435
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(
12437
- Form$2.Field,
12438
- {
12439
- control: form.control,
12440
- name: "country_code",
12441
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12442
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12443
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12444
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12445
- ] })
12446
- }
12447
- ),
12448
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12449
- /* @__PURE__ */ jsxRuntime.jsx(
12450
- Form$2.Field,
12451
- {
12452
- control: form.control,
12453
- name: "first_name",
12454
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12455
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12456
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12457
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12458
- ] })
12459
- }
12460
- ),
12461
- /* @__PURE__ */ jsxRuntime.jsx(
12462
- Form$2.Field,
12463
- {
12464
- control: form.control,
12465
- name: "last_name",
12466
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12467
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12468
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12469
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12470
- ] })
12471
- }
12472
- )
12473
- ] }),
12474
- /* @__PURE__ */ jsxRuntime.jsx(
12475
- Form$2.Field,
12476
- {
12477
- control: form.control,
12478
- name: "company",
12479
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12480
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12481
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12482
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12483
- ] })
12484
- }
12485
- ),
12486
- /* @__PURE__ */ jsxRuntime.jsx(
12487
- Form$2.Field,
12488
- {
12489
- control: form.control,
12490
- name: "address_1",
12491
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12492
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12493
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12494
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12495
- ] })
12496
- }
12497
- ),
12498
- /* @__PURE__ */ jsxRuntime.jsx(
12499
- Form$2.Field,
12500
- {
12501
- control: form.control,
12502
- name: "address_2",
12503
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12504
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12505
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12507
- ] })
12508
- }
12509
- ),
12510
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12511
- /* @__PURE__ */ jsxRuntime.jsx(
12512
- Form$2.Field,
12513
- {
12514
- control: form.control,
12515
- name: "postal_code",
12516
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12517
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12518
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12520
- ] })
12521
- }
12522
- ),
12523
- /* @__PURE__ */ jsxRuntime.jsx(
12524
- Form$2.Field,
12525
- {
12526
- control: form.control,
12527
- name: "city",
12528
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12529
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12530
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12532
- ] })
12533
- }
12534
- )
12535
- ] }),
12536
- /* @__PURE__ */ jsxRuntime.jsx(
12537
- Form$2.Field,
12538
- {
12539
- control: form.control,
12540
- name: "province",
12541
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12542
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12543
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12545
- ] })
12546
- }
12547
- ),
12548
- /* @__PURE__ */ jsxRuntime.jsx(
12549
- Form$2.Field,
12550
- {
12551
- control: form.control,
12552
- name: "phone",
12553
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12554
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12555
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12557
- ] })
12558
- }
12559
- )
12560
- ] }) }),
12561
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12562
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12563
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12564
- ] }) })
12565
- ]
12566
- }
12567
- ) });
12568
- };
12569
- const schema$1 = addressSchema;
12570
- const TransferOwnership = () => {
12571
- const { id } = reactRouterDom.useParams();
12572
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12573
- fields: "id,customer_id,customer.*"
12574
- });
12575
- if (isError) {
12576
- throw error;
12577
- }
12578
- const isReady = !isPending && !!draft_order;
12579
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12580
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12581
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12582
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12583
- ] }),
12584
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12394
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12585
12395
  ] });
12586
12396
  };
12587
12397
  const TransferOwnershipForm = ({ order }) => {
@@ -12590,7 +12400,7 @@ const TransferOwnershipForm = ({ order }) => {
12590
12400
  defaultValues: {
12591
12401
  customer_id: order.customer_id || ""
12592
12402
  },
12593
- resolver: zod.zodResolver(schema)
12403
+ resolver: zod.zodResolver(schema$1)
12594
12404
  });
12595
12405
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12596
12406
  const { handleSuccess } = useRouteModal();
@@ -13040,9 +12850,199 @@ const Illustration = () => {
13040
12850
  }
13041
12851
  );
13042
12852
  };
13043
- const schema = objectType({
12853
+ const schema$1 = objectType({
13044
12854
  customer_id: stringType().min(1)
13045
12855
  });
12856
+ const BillingAddress = () => {
12857
+ const { id } = reactRouterDom.useParams();
12858
+ const { order, isPending, isError, error } = useOrder(id, {
12859
+ fields: "+billing_address"
12860
+ });
12861
+ if (isError) {
12862
+ throw error;
12863
+ }
12864
+ const isReady = !isPending && !!order;
12865
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12866
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12867
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12868
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12869
+ ] }),
12870
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12871
+ ] });
12872
+ };
12873
+ const BillingAddressForm = ({ order }) => {
12874
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12875
+ const form = reactHookForm.useForm({
12876
+ defaultValues: {
12877
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12878
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12879
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12880
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12881
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12882
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12883
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12884
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12885
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12886
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12887
+ },
12888
+ resolver: zod.zodResolver(schema)
12889
+ });
12890
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12891
+ const { handleSuccess } = useRouteModal();
12892
+ const onSubmit = form.handleSubmit(async (data) => {
12893
+ await mutateAsync(
12894
+ { billing_address: data },
12895
+ {
12896
+ onSuccess: () => {
12897
+ handleSuccess();
12898
+ },
12899
+ onError: (error) => {
12900
+ ui.toast.error(error.message);
12901
+ }
12902
+ }
12903
+ );
12904
+ });
12905
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12906
+ KeyboundForm,
12907
+ {
12908
+ className: "flex flex-1 flex-col overflow-hidden",
12909
+ onSubmit,
12910
+ children: [
12911
+ /* @__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: [
12912
+ /* @__PURE__ */ jsxRuntime.jsx(
12913
+ Form$2.Field,
12914
+ {
12915
+ control: form.control,
12916
+ name: "country_code",
12917
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12918
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12921
+ ] })
12922
+ }
12923
+ ),
12924
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12925
+ /* @__PURE__ */ jsxRuntime.jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "first_name",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ ),
12937
+ /* @__PURE__ */ jsxRuntime.jsx(
12938
+ Form$2.Field,
12939
+ {
12940
+ control: form.control,
12941
+ name: "last_name",
12942
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12943
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12944
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
+ ] })
12947
+ }
12948
+ )
12949
+ ] }),
12950
+ /* @__PURE__ */ jsxRuntime.jsx(
12951
+ Form$2.Field,
12952
+ {
12953
+ control: form.control,
12954
+ name: "company",
12955
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12956
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
+ ] })
12960
+ }
12961
+ ),
12962
+ /* @__PURE__ */ jsxRuntime.jsx(
12963
+ Form$2.Field,
12964
+ {
12965
+ control: form.control,
12966
+ name: "address_1",
12967
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12968
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12971
+ ] })
12972
+ }
12973
+ ),
12974
+ /* @__PURE__ */ jsxRuntime.jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "address_2",
12979
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12980
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12981
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12983
+ ] })
12984
+ }
12985
+ ),
12986
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12987
+ /* @__PURE__ */ jsxRuntime.jsx(
12988
+ Form$2.Field,
12989
+ {
12990
+ control: form.control,
12991
+ name: "postal_code",
12992
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12993
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12996
+ ] })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsxRuntime.jsx(
13000
+ Form$2.Field,
13001
+ {
13002
+ control: form.control,
13003
+ name: "city",
13004
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13005
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
+ ] })
13009
+ }
13010
+ )
13011
+ ] }),
13012
+ /* @__PURE__ */ jsxRuntime.jsx(
13013
+ Form$2.Field,
13014
+ {
13015
+ control: form.control,
13016
+ name: "province",
13017
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
+ ] })
13022
+ }
13023
+ ),
13024
+ /* @__PURE__ */ jsxRuntime.jsx(
13025
+ Form$2.Field,
13026
+ {
13027
+ control: form.control,
13028
+ name: "phone",
13029
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
+ ] })
13034
+ }
13035
+ )
13036
+ ] }) }),
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
+ const schema = addressSchema;
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13063,10 +13063,6 @@ const routeModule = {
13063
13063
  handle,
13064
13064
  loader,
13065
13065
  children: [
13066
- {
13067
- Component: BillingAddress,
13068
- path: "/draft-orders/:id/billing-address"
13069
- },
13070
13066
  {
13071
13067
  Component: CustomItems,
13072
13068
  path: "/draft-orders/:id/custom-items"
@@ -13091,17 +13087,21 @@ const routeModule = {
13091
13087
  Component: SalesChannel,
13092
13088
  path: "/draft-orders/:id/sales-channel"
13093
13089
  },
13094
- {
13095
- Component: Shipping,
13096
- path: "/draft-orders/:id/shipping"
13097
- },
13098
13090
  {
13099
13091
  Component: ShippingAddress,
13100
13092
  path: "/draft-orders/:id/shipping-address"
13101
13093
  },
13094
+ {
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
+ },
13102
13098
  {
13103
13099
  Component: TransferOwnership,
13104
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
+ },
13102
+ {
13103
+ Component: BillingAddress,
13104
+ path: "/draft-orders/:id/billing-address"
13105
13105
  }
13106
13106
  ]
13107
13107
  }