@medusajs/draft-order 3.0.0-snapshot-20251211181725 → 3.0.0-snapshot-20251212142124

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.
@@ -9755,6 +9755,27 @@ const BillingAddressForm = ({ order }) => {
9755
9755
  ) });
9756
9756
  };
9757
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
+ });
9758
9779
  const Email = () => {
9759
9780
  const { id } = useParams();
9760
9781
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9777,7 +9798,7 @@ const EmailForm = ({ order }) => {
9777
9798
  defaultValues: {
9778
9799
  email: order.email ?? ""
9779
9800
  },
9780
- resolver: zodResolver(schema$4)
9801
+ resolver: zodResolver(schema$3)
9781
9802
  });
9782
9803
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9783
9804
  const { handleSuccess } = useRouteModal();
@@ -9820,27 +9841,6 @@ const EmailForm = ({ order }) => {
9820
9841
  }
9821
9842
  ) });
9822
9843
  };
9823
- const schema$4 = objectType({
9824
- email: stringType().email()
9825
- });
9826
- const CustomItems = () => {
9827
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9828
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9829
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9830
- ] });
9831
- };
9832
- const CustomItemsForm = () => {
9833
- const form = useForm({
9834
- resolver: zodResolver(schema$3)
9835
- });
9836
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9837
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9838
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9841
- ] }) })
9842
- ] }) });
9843
- };
9844
9844
  const schema$3 = objectType({
9845
9845
  email: stringType().email()
9846
9846
  });
@@ -11445,386 +11445,77 @@ function getPromotionIds(items, shippingMethods) {
11445
11445
  }
11446
11446
  return Array.from(promotionIds);
11447
11447
  }
11448
- const SalesChannel = () => {
11448
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11449
+ const Shipping = () => {
11450
+ var _a;
11449
11451
  const { id } = useParams();
11450
- const { draft_order, isPending, isError, error } = useDraftOrder(
11451
- id,
11452
- {
11453
- fields: "+sales_channel_id"
11454
- },
11455
- {
11456
- enabled: !!id
11457
- }
11458
- );
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 });
11459
11463
  if (isError) {
11460
11464
  throw error;
11461
11465
  }
11462
- const ISrEADY = !!draft_order && !isPending;
11463
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
- ] }),
11468
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
- ] });
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
+ ] }) });
11470
11482
  };
11471
- const SalesChannelForm = ({ order }) => {
11472
- const form = useForm({
11473
- defaultValues: {
11474
- sales_channel_id: order.sales_channel_id || ""
11475
- },
11476
- resolver: zodResolver(schema$2)
11477
- });
11478
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
- const { handleSuccess } = useRouteModal();
11480
- const onSubmit = form.handleSubmit(async (data) => {
11481
- await mutateAsync(
11482
- {
11483
- sales_channel_id: data.sales_channel_id
11484
- },
11485
- {
11486
- onSuccess: () => {
11487
- toast.success("Sales channel updated");
11488
- handleSuccess();
11489
- },
11490
- onError: (error) => {
11491
- toast.error(error.message);
11492
- }
11493
- }
11494
- );
11495
- });
11496
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11497
- 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(
11498
11490
  {
11499
- className: "flex flex-1 flex-col overflow-hidden",
11500
- onSubmit,
11501
- children: [
11502
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11503
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11505
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11506
- ] }) })
11507
- ]
11508
- }
11509
- ) });
11510
- };
11511
- const SalesChannelField = ({ control, order }) => {
11512
- const salesChannels = useComboboxData({
11513
- queryFn: async (params) => {
11514
- return await sdk.admin.salesChannel.list(params);
11515
- },
11516
- queryKey: ["sales-channels"],
11517
- getOptions: (data) => {
11518
- return data.sales_channels.map((salesChannel) => ({
11519
- label: salesChannel.name,
11520
- value: salesChannel.id
11521
- }));
11491
+ id: appliedShippingOptionIds,
11492
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11522
11493
  },
11523
- defaultValue: order.sales_channel_id || void 0
11524
- });
11525
- return /* @__PURE__ */ jsx(
11526
- Form$2.Field,
11527
11494
  {
11528
- control,
11529
- name: "sales_channel_id",
11530
- render: ({ field }) => {
11531
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11533
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11534
- Combobox,
11535
- {
11536
- options: salesChannels.options,
11537
- fetchNextPage: salesChannels.fetchNextPage,
11538
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11539
- searchValue: salesChannels.searchValue,
11540
- onSearchValueChange: salesChannels.onSearchValueChange,
11541
- placeholder: "Select sales channel",
11542
- ...field
11543
- }
11544
- ) }),
11545
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11546
- ] });
11547
- }
11495
+ enabled: appliedShippingOptionIds.length > 0
11548
11496
  }
11549
11497
  );
11550
- };
11551
- const schema$2 = objectType({
11552
- sales_channel_id: stringType().min(1)
11553
- });
11554
- const ShippingAddress = () => {
11555
- const { id } = useParams();
11556
- const { order, isPending, isError, error } = useOrder(id, {
11557
- fields: "+shipping_address"
11558
- });
11559
- if (isError) {
11560
- throw error;
11561
- }
11562
- const isReady = !isPending && !!order;
11563
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11564
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11565
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11566
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11567
- ] }),
11568
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11569
- ] });
11570
- };
11571
- const ShippingAddressForm = ({ order }) => {
11572
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11573
- const form = useForm({
11574
- defaultValues: {
11575
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11576
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11577
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11578
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11579
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11580
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11581
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11582
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11583
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11584
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11585
- },
11586
- resolver: zodResolver(schema$1)
11587
- });
11588
- 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]);
11589
11508
  const { handleSuccess } = useRouteModal();
11590
- const onSubmit = form.handleSubmit(async (data) => {
11591
- await mutateAsync(
11592
- {
11593
- shipping_address: {
11594
- first_name: data.first_name,
11595
- last_name: data.last_name,
11596
- company: data.company,
11597
- address_1: data.address_1,
11598
- address_2: data.address_2,
11599
- city: data.city,
11600
- province: data.province,
11601
- country_code: data.country_code,
11602
- postal_code: data.postal_code,
11603
- phone: data.phone
11604
- }
11605
- },
11606
- {
11607
- onSuccess: () => {
11608
- handleSuccess();
11609
- },
11610
- onError: (error) => {
11611
- toast.error(error.message);
11612
- }
11613
- }
11614
- );
11615
- });
11616
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11617
- KeyboundForm,
11618
- {
11619
- className: "flex flex-1 flex-col overflow-hidden",
11620
- onSubmit,
11621
- children: [
11622
- /* @__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: [
11623
- /* @__PURE__ */ jsx(
11624
- Form$2.Field,
11625
- {
11626
- control: form.control,
11627
- name: "country_code",
11628
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11629
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11630
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11631
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11632
- ] })
11633
- }
11634
- ),
11635
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11636
- /* @__PURE__ */ jsx(
11637
- Form$2.Field,
11638
- {
11639
- control: form.control,
11640
- name: "first_name",
11641
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11642
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11643
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11644
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11645
- ] })
11646
- }
11647
- ),
11648
- /* @__PURE__ */ jsx(
11649
- Form$2.Field,
11650
- {
11651
- control: form.control,
11652
- name: "last_name",
11653
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11654
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11655
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11656
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11657
- ] })
11658
- }
11659
- )
11660
- ] }),
11661
- /* @__PURE__ */ jsx(
11662
- Form$2.Field,
11663
- {
11664
- control: form.control,
11665
- name: "company",
11666
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11667
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11668
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11669
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11670
- ] })
11671
- }
11672
- ),
11673
- /* @__PURE__ */ jsx(
11674
- Form$2.Field,
11675
- {
11676
- control: form.control,
11677
- name: "address_1",
11678
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11679
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11680
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11681
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11682
- ] })
11683
- }
11684
- ),
11685
- /* @__PURE__ */ jsx(
11686
- Form$2.Field,
11687
- {
11688
- control: form.control,
11689
- name: "address_2",
11690
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11691
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11692
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11693
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11694
- ] })
11695
- }
11696
- ),
11697
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11698
- /* @__PURE__ */ jsx(
11699
- Form$2.Field,
11700
- {
11701
- control: form.control,
11702
- name: "postal_code",
11703
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11704
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11705
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11706
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11707
- ] })
11708
- }
11709
- ),
11710
- /* @__PURE__ */ jsx(
11711
- Form$2.Field,
11712
- {
11713
- control: form.control,
11714
- name: "city",
11715
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11716
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11717
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11718
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11719
- ] })
11720
- }
11721
- )
11722
- ] }),
11723
- /* @__PURE__ */ jsx(
11724
- Form$2.Field,
11725
- {
11726
- control: form.control,
11727
- name: "province",
11728
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11729
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11730
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11731
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11732
- ] })
11733
- }
11734
- ),
11735
- /* @__PURE__ */ jsx(
11736
- Form$2.Field,
11737
- {
11738
- control: form.control,
11739
- name: "phone",
11740
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11741
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11742
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11743
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11744
- ] })
11745
- }
11746
- )
11747
- ] }) }),
11748
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11749
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11750
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11751
- ] }) })
11752
- ]
11753
- }
11754
- ) });
11755
- };
11756
- const schema$1 = addressSchema;
11757
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11758
- const Shipping = () => {
11759
- var _a;
11760
- const { id } = useParams();
11761
- const { order, isPending, isError, error } = useOrder(id, {
11762
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11763
- });
11764
- const {
11765
- order: preview,
11766
- isPending: isPreviewPending,
11767
- isError: isPreviewError,
11768
- error: previewError
11769
- } = useOrderPreview(id);
11770
- useInitiateOrderEdit({ preview });
11771
- const { onCancel } = useCancelOrderEdit({ preview });
11772
- if (isError) {
11773
- throw error;
11774
- }
11775
- if (isPreviewError) {
11776
- throw previewError;
11777
- }
11778
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11779
- const isReady = preview && !isPreviewPending && order && !isPending;
11780
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11781
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11782
- /* @__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: [
11783
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11784
- /* @__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." }) })
11785
- ] }) }) }),
11786
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11787
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11788
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11789
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11790
- ] }) });
11791
- };
11792
- const ShippingForm = ({ preview, order }) => {
11793
- var _a;
11794
- const { setIsOpen } = useStackedModal();
11795
- const [isSubmitting, setIsSubmitting] = useState(false);
11796
- const [data, setData] = useState(null);
11797
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11798
- const { shipping_options } = useShippingOptions(
11799
- {
11800
- id: appliedShippingOptionIds,
11801
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11802
- },
11803
- {
11804
- enabled: appliedShippingOptionIds.length > 0
11805
- }
11806
- );
11807
- const uniqueShippingProfiles = useMemo(() => {
11808
- const profiles = /* @__PURE__ */ new Map();
11809
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11810
- profiles.set(profile.id, profile);
11811
- });
11812
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11813
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11814
- });
11815
- return Array.from(profiles.values());
11816
- }, [order.items, shipping_options]);
11817
- const { handleSuccess } = useRouteModal();
11818
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11819
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11820
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11821
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11822
- const onSubmit = async () => {
11823
- setIsSubmitting(true);
11824
- let requestSucceeded = false;
11825
- await requestOrderEdit(void 0, {
11826
- onError: (e) => {
11827
- 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}`);
11828
11519
  },
11829
11520
  onSuccess: () => {
11830
11521
  requestSucceeded = true;
@@ -12561,46 +12252,249 @@ const CustomAmountField = ({
12561
12252
  }
12562
12253
  );
12563
12254
  };
12564
- const TransferOwnership = () => {
12255
+ const ShippingAddress = () => {
12565
12256
  const { id } = useParams();
12566
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12567
- fields: "id,customer_id,customer.*"
12257
+ const { order, isPending, isError, error } = useOrder(id, {
12258
+ fields: "+shipping_address"
12568
12259
  });
12569
12260
  if (isError) {
12570
12261
  throw error;
12571
12262
  }
12572
- const isReady = !isPending && !!draft_order;
12263
+ const isReady = !isPending && !!order;
12573
12264
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12574
12265
  /* @__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" }) })
12266
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12267
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12577
12268
  ] }),
12578
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12269
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12579
12270
  ] });
12580
12271
  };
12581
- const TransferOwnershipForm = ({ order }) => {
12582
- var _a, _b;
12272
+ const ShippingAddressForm = ({ order }) => {
12273
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12583
12274
  const form = useForm({
12584
12275
  defaultValues: {
12585
- customer_id: order.customer_id || ""
12276
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12277
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12278
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12279
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12280
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12281
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12282
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12283
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12284
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12285
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12586
12286
  },
12587
- resolver: zodResolver(schema)
12287
+ resolver: zodResolver(schema$2)
12588
12288
  });
12589
12289
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
12290
  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
12291
  const onSubmit = form.handleSubmit(async (data) => {
12597
12292
  await mutateAsync(
12598
- { customer_id: data.customer_id },
12599
12293
  {
12600
- onSuccess: () => {
12601
- toast.success("Customer updated");
12602
- handleSuccess();
12603
- },
12294
+ shipping_address: {
12295
+ first_name: data.first_name,
12296
+ last_name: data.last_name,
12297
+ company: data.company,
12298
+ address_1: data.address_1,
12299
+ address_2: data.address_2,
12300
+ city: data.city,
12301
+ province: data.province,
12302
+ country_code: data.country_code,
12303
+ postal_code: data.postal_code,
12304
+ phone: data.phone
12305
+ }
12306
+ },
12307
+ {
12308
+ onSuccess: () => {
12309
+ handleSuccess();
12310
+ },
12311
+ onError: (error) => {
12312
+ toast.error(error.message);
12313
+ }
12314
+ }
12315
+ );
12316
+ });
12317
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12318
+ KeyboundForm,
12319
+ {
12320
+ className: "flex flex-1 flex-col overflow-hidden",
12321
+ onSubmit,
12322
+ children: [
12323
+ /* @__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: [
12324
+ /* @__PURE__ */ jsx(
12325
+ Form$2.Field,
12326
+ {
12327
+ control: form.control,
12328
+ name: "country_code",
12329
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12330
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12331
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12332
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12333
+ ] })
12334
+ }
12335
+ ),
12336
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12337
+ /* @__PURE__ */ jsx(
12338
+ Form$2.Field,
12339
+ {
12340
+ control: form.control,
12341
+ name: "first_name",
12342
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12343
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12344
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12345
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12346
+ ] })
12347
+ }
12348
+ ),
12349
+ /* @__PURE__ */ jsx(
12350
+ Form$2.Field,
12351
+ {
12352
+ control: form.control,
12353
+ name: "last_name",
12354
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12355
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12356
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12357
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12358
+ ] })
12359
+ }
12360
+ )
12361
+ ] }),
12362
+ /* @__PURE__ */ jsx(
12363
+ Form$2.Field,
12364
+ {
12365
+ control: form.control,
12366
+ name: "company",
12367
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12368
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12369
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12370
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12371
+ ] })
12372
+ }
12373
+ ),
12374
+ /* @__PURE__ */ jsx(
12375
+ Form$2.Field,
12376
+ {
12377
+ control: form.control,
12378
+ name: "address_1",
12379
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12380
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12381
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12382
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12383
+ ] })
12384
+ }
12385
+ ),
12386
+ /* @__PURE__ */ jsx(
12387
+ Form$2.Field,
12388
+ {
12389
+ control: form.control,
12390
+ name: "address_2",
12391
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12392
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12393
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12394
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12395
+ ] })
12396
+ }
12397
+ ),
12398
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12399
+ /* @__PURE__ */ jsx(
12400
+ Form$2.Field,
12401
+ {
12402
+ control: form.control,
12403
+ name: "postal_code",
12404
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12405
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12406
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12407
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12408
+ ] })
12409
+ }
12410
+ ),
12411
+ /* @__PURE__ */ jsx(
12412
+ Form$2.Field,
12413
+ {
12414
+ control: form.control,
12415
+ name: "city",
12416
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12417
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12418
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12419
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12420
+ ] })
12421
+ }
12422
+ )
12423
+ ] }),
12424
+ /* @__PURE__ */ jsx(
12425
+ Form$2.Field,
12426
+ {
12427
+ control: form.control,
12428
+ name: "province",
12429
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12430
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12431
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12432
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12433
+ ] })
12434
+ }
12435
+ ),
12436
+ /* @__PURE__ */ jsx(
12437
+ Form$2.Field,
12438
+ {
12439
+ control: form.control,
12440
+ name: "phone",
12441
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12442
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12443
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12444
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12445
+ ] })
12446
+ }
12447
+ )
12448
+ ] }) }),
12449
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12450
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12451
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12452
+ ] }) })
12453
+ ]
12454
+ }
12455
+ ) });
12456
+ };
12457
+ const schema$2 = addressSchema;
12458
+ const TransferOwnership = () => {
12459
+ const { id } = useParams();
12460
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12461
+ fields: "id,customer_id,customer.*"
12462
+ });
12463
+ if (isError) {
12464
+ throw error;
12465
+ }
12466
+ const isReady = !isPending && !!draft_order;
12467
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12468
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12469
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12470
+ /* @__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" }) })
12471
+ ] }),
12472
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12473
+ ] });
12474
+ };
12475
+ const TransferOwnershipForm = ({ order }) => {
12476
+ var _a, _b;
12477
+ const form = useForm({
12478
+ defaultValues: {
12479
+ customer_id: order.customer_id || ""
12480
+ },
12481
+ resolver: zodResolver(schema$1)
12482
+ });
12483
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12484
+ const { handleSuccess } = useRouteModal();
12485
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12486
+ const currentCustomer = order.customer ? {
12487
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12488
+ value: order.customer.id
12489
+ } : null;
12490
+ const onSubmit = form.handleSubmit(async (data) => {
12491
+ await mutateAsync(
12492
+ { customer_id: data.customer_id },
12493
+ {
12494
+ onSuccess: () => {
12495
+ toast.success("Customer updated");
12496
+ handleSuccess();
12497
+ },
12604
12498
  onError: (error) => {
12605
12499
  toast.error(error.message);
12606
12500
  }
@@ -13034,9 +12928,115 @@ const Illustration = () => {
13034
12928
  }
13035
12929
  );
13036
12930
  };
13037
- const schema = objectType({
12931
+ const schema$1 = objectType({
13038
12932
  customer_id: stringType().min(1)
13039
12933
  });
12934
+ const SalesChannel = () => {
12935
+ const { id } = useParams();
12936
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12937
+ id,
12938
+ {
12939
+ fields: "+sales_channel_id"
12940
+ },
12941
+ {
12942
+ enabled: !!id
12943
+ }
12944
+ );
12945
+ if (isError) {
12946
+ throw error;
12947
+ }
12948
+ const ISrEADY = !!draft_order && !isPending;
12949
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12950
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12951
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12952
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12953
+ ] }),
12954
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12955
+ ] });
12956
+ };
12957
+ const SalesChannelForm = ({ order }) => {
12958
+ const form = useForm({
12959
+ defaultValues: {
12960
+ sales_channel_id: order.sales_channel_id || ""
12961
+ },
12962
+ resolver: zodResolver(schema)
12963
+ });
12964
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12965
+ const { handleSuccess } = useRouteModal();
12966
+ const onSubmit = form.handleSubmit(async (data) => {
12967
+ await mutateAsync(
12968
+ {
12969
+ sales_channel_id: data.sales_channel_id
12970
+ },
12971
+ {
12972
+ onSuccess: () => {
12973
+ toast.success("Sales channel updated");
12974
+ handleSuccess();
12975
+ },
12976
+ onError: (error) => {
12977
+ toast.error(error.message);
12978
+ }
12979
+ }
12980
+ );
12981
+ });
12982
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12983
+ KeyboundForm,
12984
+ {
12985
+ className: "flex flex-1 flex-col overflow-hidden",
12986
+ onSubmit,
12987
+ children: [
12988
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12989
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12990
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12991
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12992
+ ] }) })
12993
+ ]
12994
+ }
12995
+ ) });
12996
+ };
12997
+ const SalesChannelField = ({ control, order }) => {
12998
+ const salesChannels = useComboboxData({
12999
+ queryFn: async (params) => {
13000
+ return await sdk.admin.salesChannel.list(params);
13001
+ },
13002
+ queryKey: ["sales-channels"],
13003
+ getOptions: (data) => {
13004
+ return data.sales_channels.map((salesChannel) => ({
13005
+ label: salesChannel.name,
13006
+ value: salesChannel.id
13007
+ }));
13008
+ },
13009
+ defaultValue: order.sales_channel_id || void 0
13010
+ });
13011
+ return /* @__PURE__ */ jsx(
13012
+ Form$2.Field,
13013
+ {
13014
+ control,
13015
+ name: "sales_channel_id",
13016
+ render: ({ field }) => {
13017
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13018
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13019
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13020
+ Combobox,
13021
+ {
13022
+ options: salesChannels.options,
13023
+ fetchNextPage: salesChannels.fetchNextPage,
13024
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13025
+ searchValue: salesChannels.searchValue,
13026
+ onSearchValueChange: salesChannels.onSearchValueChange,
13027
+ placeholder: "Select sales channel",
13028
+ ...field
13029
+ }
13030
+ ) }),
13031
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13032
+ ] });
13033
+ }
13034
+ }
13035
+ );
13036
+ };
13037
+ const schema = objectType({
13038
+ sales_channel_id: stringType().min(1)
13039
+ });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13061,14 +13061,14 @@ const routeModule = {
13061
13061
  Component: BillingAddress,
13062
13062
  path: "/draft-orders/:id/billing-address"
13063
13063
  },
13064
- {
13065
- Component: Email,
13066
- path: "/draft-orders/:id/email"
13067
- },
13068
13064
  {
13069
13065
  Component: CustomItems,
13070
13066
  path: "/draft-orders/:id/custom-items"
13071
13067
  },
13068
+ {
13069
+ Component: Email,
13070
+ path: "/draft-orders/:id/email"
13071
+ },
13072
13072
  {
13073
13073
  Component: Items,
13074
13074
  path: "/draft-orders/:id/items"
@@ -13082,20 +13082,20 @@ const routeModule = {
13082
13082
  path: "/draft-orders/:id/promotions"
13083
13083
  },
13084
13084
  {
13085
- Component: SalesChannel,
13086
- path: "/draft-orders/:id/sales-channel"
13085
+ Component: Shipping,
13086
+ path: "/draft-orders/:id/shipping"
13087
13087
  },
13088
13088
  {
13089
13089
  Component: ShippingAddress,
13090
13090
  path: "/draft-orders/:id/shipping-address"
13091
13091
  },
13092
- {
13093
- Component: Shipping,
13094
- path: "/draft-orders/:id/shipping"
13095
- },
13096
13092
  {
13097
13093
  Component: TransferOwnership,
13098
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
+ },
13096
+ {
13097
+ Component: SalesChannel,
13098
+ path: "/draft-orders/:id/sales-channel"
13099
13099
  }
13100
13100
  ]
13101
13101
  }