@medusajs/draft-order 2.11.1-preview-20251022180207 → 2.11.1-preview-20251023000334

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.
@@ -10634,6 +10634,196 @@ const customItemSchema = objectType({
10634
10634
  quantity: numberType(),
10635
10635
  unit_price: unionType([numberType(), stringType()])
10636
10636
  });
10637
+ const BillingAddress = () => {
10638
+ const { id } = reactRouterDom.useParams();
10639
+ const { order, isPending, isError, error } = useOrder(id, {
10640
+ fields: "+billing_address"
10641
+ });
10642
+ if (isError) {
10643
+ throw error;
10644
+ }
10645
+ const isReady = !isPending && !!order;
10646
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10647
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10648
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
10649
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10650
+ ] }),
10651
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
10652
+ ] });
10653
+ };
10654
+ const BillingAddressForm = ({ order }) => {
10655
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10656
+ const form = reactHookForm.useForm({
10657
+ defaultValues: {
10658
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
10659
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10660
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10661
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10662
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10663
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10664
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10665
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10666
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
10667
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10668
+ },
10669
+ resolver: zod.zodResolver(schema$3)
10670
+ });
10671
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10672
+ const { handleSuccess } = useRouteModal();
10673
+ const onSubmit = form.handleSubmit(async (data) => {
10674
+ await mutateAsync(
10675
+ { billing_address: data },
10676
+ {
10677
+ onSuccess: () => {
10678
+ handleSuccess();
10679
+ },
10680
+ onError: (error) => {
10681
+ ui.toast.error(error.message);
10682
+ }
10683
+ }
10684
+ );
10685
+ });
10686
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10687
+ KeyboundForm,
10688
+ {
10689
+ className: "flex flex-1 flex-col overflow-hidden",
10690
+ onSubmit,
10691
+ children: [
10692
+ /* @__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: [
10693
+ /* @__PURE__ */ jsxRuntime.jsx(
10694
+ Form$2.Field,
10695
+ {
10696
+ control: form.control,
10697
+ name: "country_code",
10698
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
10700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
10701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10702
+ ] })
10703
+ }
10704
+ ),
10705
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10706
+ /* @__PURE__ */ jsxRuntime.jsx(
10707
+ Form$2.Field,
10708
+ {
10709
+ control: form.control,
10710
+ name: "first_name",
10711
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
10713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10715
+ ] })
10716
+ }
10717
+ ),
10718
+ /* @__PURE__ */ jsxRuntime.jsx(
10719
+ Form$2.Field,
10720
+ {
10721
+ control: form.control,
10722
+ name: "last_name",
10723
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
10725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10727
+ ] })
10728
+ }
10729
+ )
10730
+ ] }),
10731
+ /* @__PURE__ */ jsxRuntime.jsx(
10732
+ Form$2.Field,
10733
+ {
10734
+ control: form.control,
10735
+ name: "company",
10736
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
10738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10740
+ ] })
10741
+ }
10742
+ ),
10743
+ /* @__PURE__ */ jsxRuntime.jsx(
10744
+ Form$2.Field,
10745
+ {
10746
+ control: form.control,
10747
+ name: "address_1",
10748
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
10750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10752
+ ] })
10753
+ }
10754
+ ),
10755
+ /* @__PURE__ */ jsxRuntime.jsx(
10756
+ Form$2.Field,
10757
+ {
10758
+ control: form.control,
10759
+ name: "address_2",
10760
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10761
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10762
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10763
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10764
+ ] })
10765
+ }
10766
+ ),
10767
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10768
+ /* @__PURE__ */ jsxRuntime.jsx(
10769
+ Form$2.Field,
10770
+ {
10771
+ control: form.control,
10772
+ name: "postal_code",
10773
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10774
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
10775
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10776
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10777
+ ] })
10778
+ }
10779
+ ),
10780
+ /* @__PURE__ */ jsxRuntime.jsx(
10781
+ Form$2.Field,
10782
+ {
10783
+ control: form.control,
10784
+ name: "city",
10785
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10786
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
10787
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10788
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10789
+ ] })
10790
+ }
10791
+ )
10792
+ ] }),
10793
+ /* @__PURE__ */ jsxRuntime.jsx(
10794
+ Form$2.Field,
10795
+ {
10796
+ control: form.control,
10797
+ name: "province",
10798
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10799
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10800
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10801
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10802
+ ] })
10803
+ }
10804
+ ),
10805
+ /* @__PURE__ */ jsxRuntime.jsx(
10806
+ Form$2.Field,
10807
+ {
10808
+ control: form.control,
10809
+ name: "phone",
10810
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10811
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
10812
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10813
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10814
+ ] })
10815
+ }
10816
+ )
10817
+ ] }) }),
10818
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10819
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10820
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10821
+ ] }) })
10822
+ ]
10823
+ }
10824
+ ) });
10825
+ };
10826
+ const schema$3 = addressSchema;
10637
10827
  const InlineTip = React.forwardRef(
10638
10828
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10639
10829
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11289,7 +11479,7 @@ const SalesChannelForm = ({ order }) => {
11289
11479
  defaultValues: {
11290
11480
  sales_channel_id: order.sales_channel_id || ""
11291
11481
  },
11292
- resolver: zod.zodResolver(schema$3)
11482
+ resolver: zod.zodResolver(schema$2)
11293
11483
  });
11294
11484
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11295
11485
  const { handleSuccess } = useRouteModal();
@@ -11364,58 +11554,261 @@ const SalesChannelField = ({ control, order }) => {
11364
11554
  }
11365
11555
  );
11366
11556
  };
11367
- const schema$3 = objectType({
11557
+ const schema$2 = objectType({
11368
11558
  sales_channel_id: stringType().min(1)
11369
11559
  });
11370
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11371
- const Shipping = () => {
11372
- var _a;
11560
+ const ShippingAddress = () => {
11373
11561
  const { id } = reactRouterDom.useParams();
11374
11562
  const { order, isPending, isError, error } = useOrder(id, {
11375
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11563
+ fields: "+shipping_address"
11376
11564
  });
11377
- const {
11378
- order: preview,
11379
- isPending: isPreviewPending,
11380
- isError: isPreviewError,
11381
- error: previewError
11382
- } = useOrderPreview(id);
11383
- useInitiateOrderEdit({ preview });
11384
- const { onCancel } = useCancelOrderEdit({ preview });
11385
11565
  if (isError) {
11386
11566
  throw error;
11387
11567
  }
11388
- if (isPreviewError) {
11389
- throw previewError;
11390
- }
11391
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11392
- const isReady = preview && !isPreviewPending && order && !isPending;
11393
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11394
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11395
- /* @__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: [
11396
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11397
- /* @__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." }) })
11398
- ] }) }) }),
11399
- /* @__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" }) }) })
11400
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11401
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11402
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11403
- ] }) });
11568
+ const isReady = !isPending && !!order;
11569
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11570
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11571
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11573
+ ] }),
11574
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11575
+ ] });
11404
11576
  };
11405
- const ShippingForm = ({ preview, order }) => {
11406
- var _a;
11407
- const { setIsOpen } = useStackedModal();
11408
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11409
- const [data, setData] = React.useState(null);
11410
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11411
- const { shipping_options } = useShippingOptions(
11412
- {
11413
- id: appliedShippingOptionIds,
11414
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11577
+ const ShippingAddressForm = ({ order }) => {
11578
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11579
+ const form = reactHookForm.useForm({
11580
+ defaultValues: {
11581
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11582
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11583
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11584
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11585
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11586
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11587
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11588
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11589
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11590
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11415
11591
  },
11416
- {
11417
- enabled: appliedShippingOptionIds.length > 0
11418
- }
11592
+ resolver: zod.zodResolver(schema$1)
11593
+ });
11594
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11595
+ const { handleSuccess } = useRouteModal();
11596
+ const onSubmit = form.handleSubmit(async (data) => {
11597
+ await mutateAsync(
11598
+ {
11599
+ shipping_address: {
11600
+ first_name: data.first_name,
11601
+ last_name: data.last_name,
11602
+ company: data.company,
11603
+ address_1: data.address_1,
11604
+ address_2: data.address_2,
11605
+ city: data.city,
11606
+ province: data.province,
11607
+ country_code: data.country_code,
11608
+ postal_code: data.postal_code,
11609
+ phone: data.phone
11610
+ }
11611
+ },
11612
+ {
11613
+ onSuccess: () => {
11614
+ handleSuccess();
11615
+ },
11616
+ onError: (error) => {
11617
+ ui.toast.error(error.message);
11618
+ }
11619
+ }
11620
+ );
11621
+ });
11622
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11623
+ KeyboundForm,
11624
+ {
11625
+ className: "flex flex-1 flex-col overflow-hidden",
11626
+ onSubmit,
11627
+ children: [
11628
+ /* @__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: [
11629
+ /* @__PURE__ */ jsxRuntime.jsx(
11630
+ Form$2.Field,
11631
+ {
11632
+ control: form.control,
11633
+ name: "country_code",
11634
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11635
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11638
+ ] })
11639
+ }
11640
+ ),
11641
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11642
+ /* @__PURE__ */ jsxRuntime.jsx(
11643
+ Form$2.Field,
11644
+ {
11645
+ control: form.control,
11646
+ name: "first_name",
11647
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11651
+ ] })
11652
+ }
11653
+ ),
11654
+ /* @__PURE__ */ jsxRuntime.jsx(
11655
+ Form$2.Field,
11656
+ {
11657
+ control: form.control,
11658
+ name: "last_name",
11659
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11660
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11663
+ ] })
11664
+ }
11665
+ )
11666
+ ] }),
11667
+ /* @__PURE__ */ jsxRuntime.jsx(
11668
+ Form$2.Field,
11669
+ {
11670
+ control: form.control,
11671
+ name: "company",
11672
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11673
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11676
+ ] })
11677
+ }
11678
+ ),
11679
+ /* @__PURE__ */ jsxRuntime.jsx(
11680
+ Form$2.Field,
11681
+ {
11682
+ control: form.control,
11683
+ name: "address_1",
11684
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11685
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11688
+ ] })
11689
+ }
11690
+ ),
11691
+ /* @__PURE__ */ jsxRuntime.jsx(
11692
+ Form$2.Field,
11693
+ {
11694
+ control: form.control,
11695
+ name: "address_2",
11696
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11697
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11700
+ ] })
11701
+ }
11702
+ ),
11703
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11704
+ /* @__PURE__ */ jsxRuntime.jsx(
11705
+ Form$2.Field,
11706
+ {
11707
+ control: form.control,
11708
+ name: "postal_code",
11709
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11710
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11713
+ ] })
11714
+ }
11715
+ ),
11716
+ /* @__PURE__ */ jsxRuntime.jsx(
11717
+ Form$2.Field,
11718
+ {
11719
+ control: form.control,
11720
+ name: "city",
11721
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11722
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11725
+ ] })
11726
+ }
11727
+ )
11728
+ ] }),
11729
+ /* @__PURE__ */ jsxRuntime.jsx(
11730
+ Form$2.Field,
11731
+ {
11732
+ control: form.control,
11733
+ name: "province",
11734
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11735
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11738
+ ] })
11739
+ }
11740
+ ),
11741
+ /* @__PURE__ */ jsxRuntime.jsx(
11742
+ Form$2.Field,
11743
+ {
11744
+ control: form.control,
11745
+ name: "phone",
11746
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11747
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11750
+ ] })
11751
+ }
11752
+ )
11753
+ ] }) }),
11754
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11756
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11757
+ ] }) })
11758
+ ]
11759
+ }
11760
+ ) });
11761
+ };
11762
+ const schema$1 = addressSchema;
11763
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11764
+ const Shipping = () => {
11765
+ var _a;
11766
+ const { id } = reactRouterDom.useParams();
11767
+ const { order, isPending, isError, error } = useOrder(id, {
11768
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11769
+ });
11770
+ const {
11771
+ order: preview,
11772
+ isPending: isPreviewPending,
11773
+ isError: isPreviewError,
11774
+ error: previewError
11775
+ } = useOrderPreview(id);
11776
+ useInitiateOrderEdit({ preview });
11777
+ const { onCancel } = useCancelOrderEdit({ preview });
11778
+ if (isError) {
11779
+ throw error;
11780
+ }
11781
+ if (isPreviewError) {
11782
+ throw previewError;
11783
+ }
11784
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11785
+ const isReady = preview && !isPreviewPending && order && !isPending;
11786
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11787
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11788
+ /* @__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: [
11789
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11790
+ /* @__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." }) })
11791
+ ] }) }) }),
11792
+ /* @__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" }) }) })
11793
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11794
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11795
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11796
+ ] }) });
11797
+ };
11798
+ const ShippingForm = ({ preview, order }) => {
11799
+ var _a;
11800
+ const { setIsOpen } = useStackedModal();
11801
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11802
+ const [data, setData] = React.useState(null);
11803
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11804
+ const { shipping_options } = useShippingOptions(
11805
+ {
11806
+ id: appliedShippingOptionIds,
11807
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11808
+ },
11809
+ {
11810
+ enabled: appliedShippingOptionIds.length > 0
11811
+ }
11419
11812
  );
11420
11813
  const uniqueShippingProfiles = React.useMemo(() => {
11421
11814
  const profiles = /* @__PURE__ */ new Map();
@@ -12174,244 +12567,41 @@ const CustomAmountField = ({
12174
12567
  }
12175
12568
  );
12176
12569
  };
12177
- const ShippingAddress = () => {
12570
+ const TransferOwnership = () => {
12178
12571
  const { id } = reactRouterDom.useParams();
12179
- const { order, isPending, isError, error } = useOrder(id, {
12180
- fields: "+shipping_address"
12572
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12573
+ fields: "id,customer_id,customer.*"
12181
12574
  });
12182
12575
  if (isError) {
12183
12576
  throw error;
12184
12577
  }
12185
- const isReady = !isPending && !!order;
12578
+ const isReady = !isPending && !!draft_order;
12186
12579
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12187
12580
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12188
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12189
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
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" }) })
12190
12583
  ] }),
12191
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12584
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12192
12585
  ] });
12193
12586
  };
12194
- const ShippingAddressForm = ({ order }) => {
12195
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12587
+ const TransferOwnershipForm = ({ order }) => {
12588
+ var _a, _b;
12196
12589
  const form = reactHookForm.useForm({
12197
12590
  defaultValues: {
12198
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12199
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12200
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12201
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12202
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12203
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12204
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12205
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12206
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12207
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12591
+ customer_id: order.customer_id || ""
12208
12592
  },
12209
- resolver: zod.zodResolver(schema$2)
12593
+ resolver: zod.zodResolver(schema)
12210
12594
  });
12211
12595
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12212
12596
  const { handleSuccess } = useRouteModal();
12597
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12598
+ const currentCustomer = order.customer ? {
12599
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12600
+ value: order.customer.id
12601
+ } : null;
12213
12602
  const onSubmit = form.handleSubmit(async (data) => {
12214
12603
  await mutateAsync(
12215
- {
12216
- shipping_address: {
12217
- first_name: data.first_name,
12218
- last_name: data.last_name,
12219
- company: data.company,
12220
- address_1: data.address_1,
12221
- address_2: data.address_2,
12222
- city: data.city,
12223
- province: data.province,
12224
- country_code: data.country_code,
12225
- postal_code: data.postal_code,
12226
- phone: data.phone
12227
- }
12228
- },
12229
- {
12230
- onSuccess: () => {
12231
- handleSuccess();
12232
- },
12233
- onError: (error) => {
12234
- ui.toast.error(error.message);
12235
- }
12236
- }
12237
- );
12238
- });
12239
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12240
- KeyboundForm,
12241
- {
12242
- className: "flex flex-1 flex-col overflow-hidden",
12243
- onSubmit,
12244
- children: [
12245
- /* @__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: [
12246
- /* @__PURE__ */ jsxRuntime.jsx(
12247
- Form$2.Field,
12248
- {
12249
- control: form.control,
12250
- name: "country_code",
12251
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12252
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12253
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12254
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12255
- ] })
12256
- }
12257
- ),
12258
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12259
- /* @__PURE__ */ jsxRuntime.jsx(
12260
- Form$2.Field,
12261
- {
12262
- control: form.control,
12263
- name: "first_name",
12264
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12266
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12268
- ] })
12269
- }
12270
- ),
12271
- /* @__PURE__ */ jsxRuntime.jsx(
12272
- Form$2.Field,
12273
- {
12274
- control: form.control,
12275
- name: "last_name",
12276
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12277
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12278
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12280
- ] })
12281
- }
12282
- )
12283
- ] }),
12284
- /* @__PURE__ */ jsxRuntime.jsx(
12285
- Form$2.Field,
12286
- {
12287
- control: form.control,
12288
- name: "company",
12289
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12290
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12291
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12292
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12293
- ] })
12294
- }
12295
- ),
12296
- /* @__PURE__ */ jsxRuntime.jsx(
12297
- Form$2.Field,
12298
- {
12299
- control: form.control,
12300
- name: "address_1",
12301
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12302
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12303
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12305
- ] })
12306
- }
12307
- ),
12308
- /* @__PURE__ */ jsxRuntime.jsx(
12309
- Form$2.Field,
12310
- {
12311
- control: form.control,
12312
- name: "address_2",
12313
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12314
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12315
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12316
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12317
- ] })
12318
- }
12319
- ),
12320
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12321
- /* @__PURE__ */ jsxRuntime.jsx(
12322
- Form$2.Field,
12323
- {
12324
- control: form.control,
12325
- name: "postal_code",
12326
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12330
- ] })
12331
- }
12332
- ),
12333
- /* @__PURE__ */ jsxRuntime.jsx(
12334
- Form$2.Field,
12335
- {
12336
- control: form.control,
12337
- name: "city",
12338
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12342
- ] })
12343
- }
12344
- )
12345
- ] }),
12346
- /* @__PURE__ */ jsxRuntime.jsx(
12347
- Form$2.Field,
12348
- {
12349
- control: form.control,
12350
- name: "province",
12351
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12355
- ] })
12356
- }
12357
- ),
12358
- /* @__PURE__ */ jsxRuntime.jsx(
12359
- Form$2.Field,
12360
- {
12361
- control: form.control,
12362
- name: "phone",
12363
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12367
- ] })
12368
- }
12369
- )
12370
- ] }) }),
12371
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12372
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12373
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12374
- ] }) })
12375
- ]
12376
- }
12377
- ) });
12378
- };
12379
- const schema$2 = addressSchema;
12380
- const TransferOwnership = () => {
12381
- const { id } = reactRouterDom.useParams();
12382
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12383
- fields: "id,customer_id,customer.*"
12384
- });
12385
- if (isError) {
12386
- throw error;
12387
- }
12388
- const isReady = !isPending && !!draft_order;
12389
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12390
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
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" }) })
12393
- ] }),
12394
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12395
- ] });
12396
- };
12397
- const TransferOwnershipForm = ({ order }) => {
12398
- var _a, _b;
12399
- const form = reactHookForm.useForm({
12400
- defaultValues: {
12401
- customer_id: order.customer_id || ""
12402
- },
12403
- resolver: zod.zodResolver(schema$1)
12404
- });
12405
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12406
- const { handleSuccess } = useRouteModal();
12407
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12408
- const currentCustomer = order.customer ? {
12409
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12410
- value: order.customer.id
12411
- } : null;
12412
- const onSubmit = form.handleSubmit(async (data) => {
12413
- await mutateAsync(
12414
- { customer_id: data.customer_id },
12604
+ { customer_id: data.customer_id },
12415
12605
  {
12416
12606
  onSuccess: () => {
12417
12607
  ui.toast.success("Customer updated");
@@ -12850,199 +13040,9 @@ const Illustration = () => {
12850
13040
  }
12851
13041
  );
12852
13042
  };
12853
- const schema$1 = objectType({
13043
+ const schema = objectType({
12854
13044
  customer_id: stringType().min(1)
12855
13045
  });
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: [
@@ -13075,6 +13075,10 @@ const routeModule = {
13075
13075
  Component: Items,
13076
13076
  path: "/draft-orders/:id/items"
13077
13077
  },
13078
+ {
13079
+ Component: BillingAddress,
13080
+ path: "/draft-orders/:id/billing-address"
13081
+ },
13078
13082
  {
13079
13083
  Component: Metadata,
13080
13084
  path: "/draft-orders/:id/metadata"
@@ -13087,21 +13091,17 @@ const routeModule = {
13087
13091
  Component: SalesChannel,
13088
13092
  path: "/draft-orders/:id/sales-channel"
13089
13093
  },
13090
- {
13091
- Component: Shipping,
13092
- path: "/draft-orders/:id/shipping"
13093
- },
13094
13094
  {
13095
13095
  Component: ShippingAddress,
13096
13096
  path: "/draft-orders/:id/shipping-address"
13097
13097
  },
13098
13098
  {
13099
- Component: TransferOwnership,
13100
- path: "/draft-orders/:id/transfer-ownership"
13099
+ Component: Shipping,
13100
+ path: "/draft-orders/:id/shipping"
13101
13101
  },
13102
13102
  {
13103
- Component: BillingAddress,
13104
- path: "/draft-orders/:id/billing-address"
13103
+ Component: TransferOwnership,
13104
+ path: "/draft-orders/:id/transfer-ownership"
13105
13105
  }
13106
13106
  ]
13107
13107
  }