@medusajs/draft-order 2.11.4-preview-20251111090135 → 2.11.4-preview-20251111120137

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.
@@ -345,10 +345,14 @@ const DataTableAction = ({
345
345
  }
346
346
  return /* @__PURE__ */ jsx(Button, { ...buttonProps, onClick: props.onClick, children: label });
347
347
  };
348
+ const backendUrl = __BACKEND_URL__ ?? "/";
349
+ const authType = __AUTH_TYPE__ ?? "session";
350
+ const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || void 0;
348
351
  const sdk = new Medusa({
349
- baseUrl: __BACKEND_URL__ || "/",
352
+ baseUrl: backendUrl,
350
353
  auth: {
351
- type: "session"
354
+ type: authType,
355
+ jwtTokenStorageKey
352
356
  }
353
357
  });
354
358
  const CUSTOMER_QUERY_KEY = "customers";
@@ -9751,6 +9755,27 @@ const BillingAddressForm = ({ order }) => {
9751
9755
  ) });
9752
9756
  };
9753
9757
  const schema$5 = addressSchema;
9758
+ const CustomItems = () => {
9759
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9760
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9761
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9762
+ ] });
9763
+ };
9764
+ const CustomItemsForm = () => {
9765
+ const form = useForm({
9766
+ resolver: zodResolver(schema$4)
9767
+ });
9768
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9769
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9770
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9772
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9773
+ ] }) })
9774
+ ] }) });
9775
+ };
9776
+ const schema$4 = objectType({
9777
+ email: stringType().email()
9778
+ });
9754
9779
  const Email = () => {
9755
9780
  const { id } = useParams();
9756
9781
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9773,7 +9798,7 @@ const EmailForm = ({ order }) => {
9773
9798
  defaultValues: {
9774
9799
  email: order.email ?? ""
9775
9800
  },
9776
- resolver: zodResolver(schema$4)
9801
+ resolver: zodResolver(schema$3)
9777
9802
  });
9778
9803
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9779
9804
  const { handleSuccess } = useRouteModal();
@@ -9816,27 +9841,6 @@ const EmailForm = ({ order }) => {
9816
9841
  }
9817
9842
  ) });
9818
9843
  };
9819
- const schema$4 = objectType({
9820
- email: stringType().email()
9821
- });
9822
- const CustomItems = () => {
9823
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9824
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9825
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9826
- ] });
9827
- };
9828
- const CustomItemsForm = () => {
9829
- const form = useForm({
9830
- resolver: zodResolver(schema$3)
9831
- });
9832
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9833
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9834
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9835
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9836
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9837
- ] }) })
9838
- ] }) });
9839
- };
9840
9844
  const schema$3 = objectType({
9841
9845
  email: stringType().email()
9842
9846
  });
@@ -11441,386 +11445,77 @@ function getPromotionIds(items, shippingMethods) {
11441
11445
  }
11442
11446
  return Array.from(promotionIds);
11443
11447
  }
11444
- const SalesChannel = () => {
11448
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11449
+ const Shipping = () => {
11450
+ var _a;
11445
11451
  const { id } = useParams();
11446
- const { draft_order, isPending, isError, error } = useDraftOrder(
11447
- id,
11448
- {
11449
- fields: "+sales_channel_id"
11450
- },
11451
- {
11452
- enabled: !!id
11453
- }
11454
- );
11452
+ const { order, isPending, isError, error } = useOrder(id, {
11453
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11454
+ });
11455
+ const {
11456
+ order: preview,
11457
+ isPending: isPreviewPending,
11458
+ isError: isPreviewError,
11459
+ error: previewError
11460
+ } = useOrderPreview(id);
11461
+ useInitiateOrderEdit({ preview });
11462
+ const { onCancel } = useCancelOrderEdit({ preview });
11455
11463
  if (isError) {
11456
11464
  throw error;
11457
11465
  }
11458
- const ISrEADY = !!draft_order && !isPending;
11459
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11460
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11461
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11462
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11463
- ] }),
11464
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11465
- ] });
11466
+ if (isPreviewError) {
11467
+ throw previewError;
11468
+ }
11469
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11470
+ const isReady = preview && !isPreviewPending && order && !isPending;
11471
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11472
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11473
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11474
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11475
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11476
+ ] }) }) }),
11477
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11478
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11479
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11480
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11481
+ ] }) });
11466
11482
  };
11467
- const SalesChannelForm = ({ order }) => {
11468
- const form = useForm({
11469
- defaultValues: {
11470
- sales_channel_id: order.sales_channel_id || ""
11471
- },
11472
- resolver: zodResolver(schema$2)
11473
- });
11474
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11475
- const { handleSuccess } = useRouteModal();
11476
- const onSubmit = form.handleSubmit(async (data) => {
11477
- await mutateAsync(
11478
- {
11479
- sales_channel_id: data.sales_channel_id
11480
- },
11481
- {
11482
- onSuccess: () => {
11483
- toast.success("Sales channel updated");
11484
- handleSuccess();
11485
- },
11486
- onError: (error) => {
11487
- toast.error(error.message);
11488
- }
11489
- }
11490
- );
11491
- });
11492
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11493
- KeyboundForm,
11483
+ const ShippingForm = ({ preview, order }) => {
11484
+ var _a;
11485
+ const { setIsOpen } = useStackedModal();
11486
+ const [isSubmitting, setIsSubmitting] = useState(false);
11487
+ const [data, setData] = useState(null);
11488
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11489
+ const { shipping_options } = useShippingOptions(
11494
11490
  {
11495
- className: "flex flex-1 flex-col overflow-hidden",
11496
- onSubmit,
11497
- children: [
11498
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11499
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11500
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11501
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11502
- ] }) })
11503
- ]
11504
- }
11505
- ) });
11506
- };
11507
- const SalesChannelField = ({ control, order }) => {
11508
- const salesChannels = useComboboxData({
11509
- queryFn: async (params) => {
11510
- return await sdk.admin.salesChannel.list(params);
11511
- },
11512
- queryKey: ["sales-channels"],
11513
- getOptions: (data) => {
11514
- return data.sales_channels.map((salesChannel) => ({
11515
- label: salesChannel.name,
11516
- value: salesChannel.id
11517
- }));
11491
+ id: appliedShippingOptionIds,
11492
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11518
11493
  },
11519
- defaultValue: order.sales_channel_id || void 0
11520
- });
11521
- return /* @__PURE__ */ jsx(
11522
- Form$2.Field,
11523
11494
  {
11524
- control,
11525
- name: "sales_channel_id",
11526
- render: ({ field }) => {
11527
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11528
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11529
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11530
- Combobox,
11531
- {
11532
- options: salesChannels.options,
11533
- fetchNextPage: salesChannels.fetchNextPage,
11534
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11535
- searchValue: salesChannels.searchValue,
11536
- onSearchValueChange: salesChannels.onSearchValueChange,
11537
- placeholder: "Select sales channel",
11538
- ...field
11539
- }
11540
- ) }),
11541
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11542
- ] });
11543
- }
11495
+ enabled: appliedShippingOptionIds.length > 0
11544
11496
  }
11545
11497
  );
11546
- };
11547
- const schema$2 = objectType({
11548
- sales_channel_id: stringType().min(1)
11549
- });
11550
- const ShippingAddress = () => {
11551
- const { id } = useParams();
11552
- const { order, isPending, isError, error } = useOrder(id, {
11553
- fields: "+shipping_address"
11554
- });
11555
- if (isError) {
11556
- throw error;
11557
- }
11558
- const isReady = !isPending && !!order;
11559
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11560
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11561
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11562
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11563
- ] }),
11564
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11565
- ] });
11566
- };
11567
- const ShippingAddressForm = ({ order }) => {
11568
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11569
- const form = useForm({
11570
- defaultValues: {
11571
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11572
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11573
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11574
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11575
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11576
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11577
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11578
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11579
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11580
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11581
- },
11582
- resolver: zodResolver(schema$1)
11583
- });
11584
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11498
+ const uniqueShippingProfiles = useMemo(() => {
11499
+ const profiles = /* @__PURE__ */ new Map();
11500
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11501
+ profiles.set(profile.id, profile);
11502
+ });
11503
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11504
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11505
+ });
11506
+ return Array.from(profiles.values());
11507
+ }, [order.items, shipping_options]);
11585
11508
  const { handleSuccess } = useRouteModal();
11586
- const onSubmit = form.handleSubmit(async (data) => {
11587
- await mutateAsync(
11588
- {
11589
- shipping_address: {
11590
- first_name: data.first_name,
11591
- last_name: data.last_name,
11592
- company: data.company,
11593
- address_1: data.address_1,
11594
- address_2: data.address_2,
11595
- city: data.city,
11596
- province: data.province,
11597
- country_code: data.country_code,
11598
- postal_code: data.postal_code,
11599
- phone: data.phone
11600
- }
11601
- },
11602
- {
11603
- onSuccess: () => {
11604
- handleSuccess();
11605
- },
11606
- onError: (error) => {
11607
- toast.error(error.message);
11608
- }
11609
- }
11610
- );
11611
- });
11612
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11613
- KeyboundForm,
11614
- {
11615
- className: "flex flex-1 flex-col overflow-hidden",
11616
- onSubmit,
11617
- children: [
11618
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11619
- /* @__PURE__ */ jsx(
11620
- Form$2.Field,
11621
- {
11622
- control: form.control,
11623
- name: "country_code",
11624
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11625
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11626
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11627
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11628
- ] })
11629
- }
11630
- ),
11631
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11632
- /* @__PURE__ */ jsx(
11633
- Form$2.Field,
11634
- {
11635
- control: form.control,
11636
- name: "first_name",
11637
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11638
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11639
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11640
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11641
- ] })
11642
- }
11643
- ),
11644
- /* @__PURE__ */ jsx(
11645
- Form$2.Field,
11646
- {
11647
- control: form.control,
11648
- name: "last_name",
11649
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11650
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11651
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11652
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11653
- ] })
11654
- }
11655
- )
11656
- ] }),
11657
- /* @__PURE__ */ jsx(
11658
- Form$2.Field,
11659
- {
11660
- control: form.control,
11661
- name: "company",
11662
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11663
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11664
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11665
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11666
- ] })
11667
- }
11668
- ),
11669
- /* @__PURE__ */ jsx(
11670
- Form$2.Field,
11671
- {
11672
- control: form.control,
11673
- name: "address_1",
11674
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11675
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11676
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11677
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11678
- ] })
11679
- }
11680
- ),
11681
- /* @__PURE__ */ jsx(
11682
- Form$2.Field,
11683
- {
11684
- control: form.control,
11685
- name: "address_2",
11686
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11687
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11688
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11689
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11690
- ] })
11691
- }
11692
- ),
11693
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11694
- /* @__PURE__ */ jsx(
11695
- Form$2.Field,
11696
- {
11697
- control: form.control,
11698
- name: "postal_code",
11699
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11700
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11701
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11702
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11703
- ] })
11704
- }
11705
- ),
11706
- /* @__PURE__ */ jsx(
11707
- Form$2.Field,
11708
- {
11709
- control: form.control,
11710
- name: "city",
11711
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11712
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11713
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11714
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11715
- ] })
11716
- }
11717
- )
11718
- ] }),
11719
- /* @__PURE__ */ jsx(
11720
- Form$2.Field,
11721
- {
11722
- control: form.control,
11723
- name: "province",
11724
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11725
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11726
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11727
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11728
- ] })
11729
- }
11730
- ),
11731
- /* @__PURE__ */ jsx(
11732
- Form$2.Field,
11733
- {
11734
- control: form.control,
11735
- name: "phone",
11736
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11737
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11738
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11739
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11740
- ] })
11741
- }
11742
- )
11743
- ] }) }),
11744
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11745
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11746
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11747
- ] }) })
11748
- ]
11749
- }
11750
- ) });
11751
- };
11752
- const schema$1 = addressSchema;
11753
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11754
- const Shipping = () => {
11755
- var _a;
11756
- const { id } = useParams();
11757
- const { order, isPending, isError, error } = useOrder(id, {
11758
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11759
- });
11760
- const {
11761
- order: preview,
11762
- isPending: isPreviewPending,
11763
- isError: isPreviewError,
11764
- error: previewError
11765
- } = useOrderPreview(id);
11766
- useInitiateOrderEdit({ preview });
11767
- const { onCancel } = useCancelOrderEdit({ preview });
11768
- if (isError) {
11769
- throw error;
11770
- }
11771
- if (isPreviewError) {
11772
- throw previewError;
11773
- }
11774
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11775
- const isReady = preview && !isPreviewPending && order && !isPending;
11776
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11777
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11778
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11779
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11780
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11781
- ] }) }) }),
11782
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11783
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11784
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11785
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11786
- ] }) });
11787
- };
11788
- const ShippingForm = ({ preview, order }) => {
11789
- var _a;
11790
- const { setIsOpen } = useStackedModal();
11791
- const [isSubmitting, setIsSubmitting] = useState(false);
11792
- const [data, setData] = useState(null);
11793
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11794
- const { shipping_options } = useShippingOptions(
11795
- {
11796
- id: appliedShippingOptionIds,
11797
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11798
- },
11799
- {
11800
- enabled: appliedShippingOptionIds.length > 0
11801
- }
11802
- );
11803
- const uniqueShippingProfiles = useMemo(() => {
11804
- const profiles = /* @__PURE__ */ new Map();
11805
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11806
- profiles.set(profile.id, profile);
11807
- });
11808
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11809
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11810
- });
11811
- return Array.from(profiles.values());
11812
- }, [order.items, shipping_options]);
11813
- const { handleSuccess } = useRouteModal();
11814
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11815
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11816
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11817
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11818
- const onSubmit = async () => {
11819
- setIsSubmitting(true);
11820
- let requestSucceeded = false;
11821
- await requestOrderEdit(void 0, {
11822
- onError: (e) => {
11823
- toast.error(`Failed to request order edit: ${e.message}`);
11509
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11510
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11511
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11512
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11513
+ const onSubmit = async () => {
11514
+ setIsSubmitting(true);
11515
+ let requestSucceeded = false;
11516
+ await requestOrderEdit(void 0, {
11517
+ onError: (e) => {
11518
+ toast.error(`Failed to request order edit: ${e.message}`);
11824
11519
  },
11825
11520
  onSuccess: () => {
11826
11521
  requestSucceeded = true;
@@ -12557,44 +12252,353 @@ const CustomAmountField = ({
12557
12252
  }
12558
12253
  );
12559
12254
  };
12560
- const TransferOwnership = () => {
12255
+ const SalesChannel = () => {
12561
12256
  const { id } = useParams();
12562
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12563
- fields: "id,customer_id,customer.*"
12564
- });
12257
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12258
+ id,
12259
+ {
12260
+ fields: "+sales_channel_id"
12261
+ },
12262
+ {
12263
+ enabled: !!id
12264
+ }
12265
+ );
12565
12266
  if (isError) {
12566
12267
  throw error;
12567
12268
  }
12568
- const isReady = !isPending && !!draft_order;
12269
+ const ISrEADY = !!draft_order && !isPending;
12569
12270
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12570
12271
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12571
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12572
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12272
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12273
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12573
12274
  ] }),
12574
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12275
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12575
12276
  ] });
12576
12277
  };
12577
- const TransferOwnershipForm = ({ order }) => {
12578
- var _a, _b;
12278
+ const SalesChannelForm = ({ order }) => {
12579
12279
  const form = useForm({
12580
12280
  defaultValues: {
12581
- customer_id: order.customer_id || ""
12281
+ sales_channel_id: order.sales_channel_id || ""
12582
12282
  },
12583
- resolver: zodResolver(schema)
12283
+ resolver: zodResolver(schema$2)
12584
12284
  });
12585
12285
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12586
12286
  const { handleSuccess } = useRouteModal();
12587
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12588
- const currentCustomer = order.customer ? {
12589
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12590
- value: order.customer.id
12591
- } : null;
12592
12287
  const onSubmit = form.handleSubmit(async (data) => {
12593
12288
  await mutateAsync(
12594
- { customer_id: data.customer_id },
12289
+ {
12290
+ sales_channel_id: data.sales_channel_id
12291
+ },
12595
12292
  {
12596
12293
  onSuccess: () => {
12597
- toast.success("Customer updated");
12294
+ toast.success("Sales channel updated");
12295
+ handleSuccess();
12296
+ },
12297
+ onError: (error) => {
12298
+ toast.error(error.message);
12299
+ }
12300
+ }
12301
+ );
12302
+ });
12303
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12304
+ KeyboundForm,
12305
+ {
12306
+ className: "flex flex-1 flex-col overflow-hidden",
12307
+ onSubmit,
12308
+ children: [
12309
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12310
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12311
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12312
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12313
+ ] }) })
12314
+ ]
12315
+ }
12316
+ ) });
12317
+ };
12318
+ const SalesChannelField = ({ control, order }) => {
12319
+ const salesChannels = useComboboxData({
12320
+ queryFn: async (params) => {
12321
+ return await sdk.admin.salesChannel.list(params);
12322
+ },
12323
+ queryKey: ["sales-channels"],
12324
+ getOptions: (data) => {
12325
+ return data.sales_channels.map((salesChannel) => ({
12326
+ label: salesChannel.name,
12327
+ value: salesChannel.id
12328
+ }));
12329
+ },
12330
+ defaultValue: order.sales_channel_id || void 0
12331
+ });
12332
+ return /* @__PURE__ */ jsx(
12333
+ Form$2.Field,
12334
+ {
12335
+ control,
12336
+ name: "sales_channel_id",
12337
+ render: ({ field }) => {
12338
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12339
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12340
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12341
+ Combobox,
12342
+ {
12343
+ options: salesChannels.options,
12344
+ fetchNextPage: salesChannels.fetchNextPage,
12345
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12346
+ searchValue: salesChannels.searchValue,
12347
+ onSearchValueChange: salesChannels.onSearchValueChange,
12348
+ placeholder: "Select sales channel",
12349
+ ...field
12350
+ }
12351
+ ) }),
12352
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12353
+ ] });
12354
+ }
12355
+ }
12356
+ );
12357
+ };
12358
+ const schema$2 = objectType({
12359
+ sales_channel_id: stringType().min(1)
12360
+ });
12361
+ const ShippingAddress = () => {
12362
+ const { id } = useParams();
12363
+ const { order, isPending, isError, error } = useOrder(id, {
12364
+ fields: "+shipping_address"
12365
+ });
12366
+ if (isError) {
12367
+ throw error;
12368
+ }
12369
+ const isReady = !isPending && !!order;
12370
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12371
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12372
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12374
+ ] }),
12375
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12376
+ ] });
12377
+ };
12378
+ const ShippingAddressForm = ({ order }) => {
12379
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12380
+ const form = useForm({
12381
+ defaultValues: {
12382
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12392
+ },
12393
+ resolver: zodResolver(schema$1)
12394
+ });
12395
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12396
+ const { handleSuccess } = useRouteModal();
12397
+ const onSubmit = form.handleSubmit(async (data) => {
12398
+ await mutateAsync(
12399
+ {
12400
+ shipping_address: {
12401
+ first_name: data.first_name,
12402
+ last_name: data.last_name,
12403
+ company: data.company,
12404
+ address_1: data.address_1,
12405
+ address_2: data.address_2,
12406
+ city: data.city,
12407
+ province: data.province,
12408
+ country_code: data.country_code,
12409
+ postal_code: data.postal_code,
12410
+ phone: data.phone
12411
+ }
12412
+ },
12413
+ {
12414
+ onSuccess: () => {
12415
+ handleSuccess();
12416
+ },
12417
+ onError: (error) => {
12418
+ toast.error(error.message);
12419
+ }
12420
+ }
12421
+ );
12422
+ });
12423
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12424
+ KeyboundForm,
12425
+ {
12426
+ className: "flex flex-1 flex-col overflow-hidden",
12427
+ onSubmit,
12428
+ children: [
12429
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12430
+ /* @__PURE__ */ jsx(
12431
+ Form$2.Field,
12432
+ {
12433
+ control: form.control,
12434
+ name: "country_code",
12435
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
+ ] })
12440
+ }
12441
+ ),
12442
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
+ /* @__PURE__ */ jsx(
12444
+ Form$2.Field,
12445
+ {
12446
+ control: form.control,
12447
+ name: "first_name",
12448
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
+ ] })
12453
+ }
12454
+ ),
12455
+ /* @__PURE__ */ jsx(
12456
+ Form$2.Field,
12457
+ {
12458
+ control: form.control,
12459
+ name: "last_name",
12460
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
+ ] })
12465
+ }
12466
+ )
12467
+ ] }),
12468
+ /* @__PURE__ */ jsx(
12469
+ Form$2.Field,
12470
+ {
12471
+ control: form.control,
12472
+ name: "company",
12473
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
+ ] })
12478
+ }
12479
+ ),
12480
+ /* @__PURE__ */ jsx(
12481
+ Form$2.Field,
12482
+ {
12483
+ control: form.control,
12484
+ name: "address_1",
12485
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
+ ] })
12490
+ }
12491
+ ),
12492
+ /* @__PURE__ */ jsx(
12493
+ Form$2.Field,
12494
+ {
12495
+ control: form.control,
12496
+ name: "address_2",
12497
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
+ ] })
12502
+ }
12503
+ ),
12504
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
+ /* @__PURE__ */ jsx(
12506
+ Form$2.Field,
12507
+ {
12508
+ control: form.control,
12509
+ name: "postal_code",
12510
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
+ ] })
12515
+ }
12516
+ ),
12517
+ /* @__PURE__ */ jsx(
12518
+ Form$2.Field,
12519
+ {
12520
+ control: form.control,
12521
+ name: "city",
12522
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
+ ] })
12527
+ }
12528
+ )
12529
+ ] }),
12530
+ /* @__PURE__ */ jsx(
12531
+ Form$2.Field,
12532
+ {
12533
+ control: form.control,
12534
+ name: "province",
12535
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
+ ] })
12540
+ }
12541
+ ),
12542
+ /* @__PURE__ */ jsx(
12543
+ Form$2.Field,
12544
+ {
12545
+ control: form.control,
12546
+ name: "phone",
12547
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
+ ] })
12552
+ }
12553
+ )
12554
+ ] }) }),
12555
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
+ ] }) })
12559
+ ]
12560
+ }
12561
+ ) });
12562
+ };
12563
+ const schema$1 = addressSchema;
12564
+ const TransferOwnership = () => {
12565
+ const { id } = useParams();
12566
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12567
+ fields: "id,customer_id,customer.*"
12568
+ });
12569
+ if (isError) {
12570
+ throw error;
12571
+ }
12572
+ const isReady = !isPending && !!draft_order;
12573
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12574
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12575
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12576
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12577
+ ] }),
12578
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12579
+ ] });
12580
+ };
12581
+ const TransferOwnershipForm = ({ order }) => {
12582
+ var _a, _b;
12583
+ const form = useForm({
12584
+ defaultValues: {
12585
+ customer_id: order.customer_id || ""
12586
+ },
12587
+ resolver: zodResolver(schema)
12588
+ });
12589
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
+ const { handleSuccess } = useRouteModal();
12591
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12592
+ const currentCustomer = order.customer ? {
12593
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12594
+ value: order.customer.id
12595
+ } : null;
12596
+ const onSubmit = form.handleSubmit(async (data) => {
12597
+ await mutateAsync(
12598
+ { customer_id: data.customer_id },
12599
+ {
12600
+ onSuccess: () => {
12601
+ toast.success("Customer updated");
12598
12602
  handleSuccess();
12599
12603
  },
12600
12604
  onError: (error) => {
@@ -13057,14 +13061,14 @@ const routeModule = {
13057
13061
  Component: BillingAddress,
13058
13062
  path: "/draft-orders/:id/billing-address"
13059
13063
  },
13060
- {
13061
- Component: Email,
13062
- path: "/draft-orders/:id/email"
13063
- },
13064
13064
  {
13065
13065
  Component: CustomItems,
13066
13066
  path: "/draft-orders/:id/custom-items"
13067
13067
  },
13068
+ {
13069
+ Component: Email,
13070
+ path: "/draft-orders/:id/email"
13071
+ },
13068
13072
  {
13069
13073
  Component: Items,
13070
13074
  path: "/draft-orders/:id/items"
@@ -13077,6 +13081,10 @@ const routeModule = {
13077
13081
  Component: Promotions,
13078
13082
  path: "/draft-orders/:id/promotions"
13079
13083
  },
13084
+ {
13085
+ Component: Shipping,
13086
+ path: "/draft-orders/:id/shipping"
13087
+ },
13080
13088
  {
13081
13089
  Component: SalesChannel,
13082
13090
  path: "/draft-orders/:id/sales-channel"
@@ -13085,10 +13093,6 @@ const routeModule = {
13085
13093
  Component: ShippingAddress,
13086
13094
  path: "/draft-orders/:id/shipping-address"
13087
13095
  },
13088
- {
13089
- Component: Shipping,
13090
- path: "/draft-orders/:id/shipping"
13091
- },
13092
13096
  {
13093
13097
  Component: TransferOwnership,
13094
13098
  path: "/draft-orders/:id/transfer-ownership"