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