@medusajs/draft-order 2.10.4-preview-20250919210158 → 2.10.4-preview-20250920000323

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.
@@ -9567,95 +9567,6 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const CustomItems = () => {
9571
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9573
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9574
- ] });
9575
- };
9576
- const CustomItemsForm = () => {
9577
- const form = useForm({
9578
- resolver: zodResolver(schema$5)
9579
- });
9580
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9583
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9584
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9585
- ] }) })
9586
- ] }) });
9587
- };
9588
- const schema$5 = objectType({
9589
- email: stringType().email()
9590
- });
9591
- const Email = () => {
9592
- const { id } = useParams();
9593
- const { order, isPending, isError, error } = useOrder(id, {
9594
- fields: "+email"
9595
- });
9596
- if (isError) {
9597
- throw error;
9598
- }
9599
- const isReady = !isPending && !!order;
9600
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9601
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9602
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9603
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9604
- ] }),
9605
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9606
- ] });
9607
- };
9608
- const EmailForm = ({ order }) => {
9609
- const form = useForm({
9610
- defaultValues: {
9611
- email: order.email ?? ""
9612
- },
9613
- resolver: zodResolver(schema$4)
9614
- });
9615
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9616
- const { handleSuccess } = useRouteModal();
9617
- const onSubmit = form.handleSubmit(async (data) => {
9618
- await mutateAsync(
9619
- { email: data.email },
9620
- {
9621
- onSuccess: () => {
9622
- handleSuccess();
9623
- },
9624
- onError: (error) => {
9625
- toast.error(error.message);
9626
- }
9627
- }
9628
- );
9629
- });
9630
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9631
- KeyboundForm,
9632
- {
9633
- className: "flex flex-1 flex-col overflow-hidden",
9634
- onSubmit,
9635
- children: [
9636
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9637
- Form$2.Field,
9638
- {
9639
- control: form.control,
9640
- name: "email",
9641
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9642
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9643
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9644
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9645
- ] })
9646
- }
9647
- ) }),
9648
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9649
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9650
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9651
- ] }) })
9652
- ]
9653
- }
9654
- ) });
9655
- };
9656
- const schema$4 = objectType({
9657
- email: stringType().email()
9658
- });
9659
9570
  const BillingAddress = () => {
9660
9571
  const { id } = useParams();
9661
9572
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9688,7 +9599,7 @@ const BillingAddressForm = ({ order }) => {
9688
9599
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9689
9600
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9690
9601
  },
9691
- resolver: zodResolver(schema$3)
9602
+ resolver: zodResolver(schema$5)
9692
9603
  });
9693
9604
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9694
9605
  const { handleSuccess } = useRouteModal();
@@ -9845,7 +9756,96 @@ const BillingAddressForm = ({ order }) => {
9845
9756
  }
9846
9757
  ) });
9847
9758
  };
9848
- const schema$3 = addressSchema;
9759
+ const schema$5 = addressSchema;
9760
+ const CustomItems = () => {
9761
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
+ ] });
9765
+ };
9766
+ const CustomItemsForm = () => {
9767
+ const form = useForm({
9768
+ resolver: zodResolver(schema$4)
9769
+ });
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
+ ] }) })
9776
+ ] }) });
9777
+ };
9778
+ const schema$4 = objectType({
9779
+ email: stringType().email()
9780
+ });
9781
+ const Email = () => {
9782
+ const { id } = useParams();
9783
+ const { order, isPending, isError, error } = useOrder(id, {
9784
+ fields: "+email"
9785
+ });
9786
+ if (isError) {
9787
+ throw error;
9788
+ }
9789
+ const isReady = !isPending && !!order;
9790
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9791
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9792
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9793
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9794
+ ] }),
9795
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9796
+ ] });
9797
+ };
9798
+ const EmailForm = ({ order }) => {
9799
+ const form = useForm({
9800
+ defaultValues: {
9801
+ email: order.email ?? ""
9802
+ },
9803
+ resolver: zodResolver(schema$3)
9804
+ });
9805
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
+ const { handleSuccess } = useRouteModal();
9807
+ const onSubmit = form.handleSubmit(async (data) => {
9808
+ await mutateAsync(
9809
+ { email: data.email },
9810
+ {
9811
+ onSuccess: () => {
9812
+ handleSuccess();
9813
+ },
9814
+ onError: (error) => {
9815
+ toast.error(error.message);
9816
+ }
9817
+ }
9818
+ );
9819
+ });
9820
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9821
+ KeyboundForm,
9822
+ {
9823
+ className: "flex flex-1 flex-col overflow-hidden",
9824
+ onSubmit,
9825
+ children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9827
+ Form$2.Field,
9828
+ {
9829
+ control: form.control,
9830
+ name: "email",
9831
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9832
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9833
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9834
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9835
+ ] })
9836
+ }
9837
+ ) }),
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", isLoading: isPending, children: "Save" })
9841
+ ] }) })
9842
+ ]
9843
+ }
9844
+ ) });
9845
+ };
9846
+ const schema$3 = objectType({
9847
+ email: stringType().email()
9848
+ });
9849
9849
  const NumberInput = forwardRef(
9850
9850
  ({
9851
9851
  value,
@@ -11447,33 +11447,37 @@ function getPromotionIds(items, shippingMethods) {
11447
11447
  }
11448
11448
  return Array.from(promotionIds);
11449
11449
  }
11450
- const SalesChannel = () => {
11450
+ const ShippingAddress = () => {
11451
11451
  const { id } = useParams();
11452
- const { draft_order, isPending, isError, error } = useDraftOrder(
11453
- id,
11454
- {
11455
- fields: "+sales_channel_id"
11456
- },
11457
- {
11458
- enabled: !!id
11459
- }
11460
- );
11452
+ const { order, isPending, isError, error } = useOrder(id, {
11453
+ fields: "+shipping_address"
11454
+ });
11461
11455
  if (isError) {
11462
11456
  throw error;
11463
11457
  }
11464
- const ISrEADY = !!draft_order && !isPending;
11458
+ const isReady = !isPending && !!order;
11465
11459
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
11460
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11461
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11462
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11469
11463
  ] }),
11470
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11464
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11471
11465
  ] });
11472
11466
  };
11473
- const SalesChannelForm = ({ order }) => {
11467
+ const ShippingAddressForm = ({ order }) => {
11468
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11474
11469
  const form = useForm({
11475
11470
  defaultValues: {
11476
- sales_channel_id: order.sales_channel_id || ""
11471
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11472
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11473
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11474
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11475
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11476
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11477
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11478
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11479
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11480
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11477
11481
  },
11478
11482
  resolver: zodResolver(schema$2)
11479
11483
  });
@@ -11482,11 +11486,21 @@ const SalesChannelForm = ({ order }) => {
11482
11486
  const onSubmit = form.handleSubmit(async (data) => {
11483
11487
  await mutateAsync(
11484
11488
  {
11485
- sales_channel_id: data.sales_channel_id
11489
+ shipping_address: {
11490
+ first_name: data.first_name,
11491
+ last_name: data.last_name,
11492
+ company: data.company,
11493
+ address_1: data.address_1,
11494
+ address_2: data.address_2,
11495
+ city: data.city,
11496
+ province: data.province,
11497
+ country_code: data.country_code,
11498
+ postal_code: data.postal_code,
11499
+ phone: data.phone
11500
+ }
11486
11501
  },
11487
11502
  {
11488
11503
  onSuccess: () => {
11489
- toast.success("Sales channel updated");
11490
11504
  handleSuccess();
11491
11505
  },
11492
11506
  onError: (error) => {
@@ -11501,58 +11515,141 @@ const SalesChannelForm = ({ order }) => {
11501
11515
  className: "flex flex-1 flex-col overflow-hidden",
11502
11516
  onSubmit,
11503
11517
  children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
- ] }) })
11509
- ]
11510
- }
11511
- ) });
11512
- };
11513
- const SalesChannelField = ({ control, order }) => {
11514
- const salesChannels = useComboboxData({
11515
- queryFn: async (params) => {
11516
- return await sdk.admin.salesChannel.list(params);
11517
- },
11518
- queryKey: ["sales-channels"],
11519
- getOptions: (data) => {
11520
- return data.sales_channels.map((salesChannel) => ({
11521
- label: salesChannel.name,
11522
- value: salesChannel.id
11523
- }));
11524
- },
11525
- defaultValue: order.sales_channel_id || void 0
11526
- });
11527
- return /* @__PURE__ */ jsx(
11528
- Form$2.Field,
11529
- {
11530
- control,
11531
- name: "sales_channel_id",
11532
- render: ({ field }) => {
11533
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
- Combobox,
11518
+ /* @__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: [
11519
+ /* @__PURE__ */ jsx(
11520
+ Form$2.Field,
11537
11521
  {
11538
- options: salesChannels.options,
11539
- fetchNextPage: salesChannels.fetchNextPage,
11540
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
- searchValue: salesChannels.searchValue,
11542
- onSearchValueChange: salesChannels.onSearchValueChange,
11543
- placeholder: "Select sales channel",
11544
- ...field
11522
+ control: form.control,
11523
+ name: "country_code",
11524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11528
+ ] })
11545
11529
  }
11546
- ) }),
11547
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
- ] });
11549
- }
11530
+ ),
11531
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11532
+ /* @__PURE__ */ jsx(
11533
+ Form$2.Field,
11534
+ {
11535
+ control: form.control,
11536
+ name: "first_name",
11537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11538
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11541
+ ] })
11542
+ }
11543
+ ),
11544
+ /* @__PURE__ */ jsx(
11545
+ Form$2.Field,
11546
+ {
11547
+ control: form.control,
11548
+ name: "last_name",
11549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11550
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11553
+ ] })
11554
+ }
11555
+ )
11556
+ ] }),
11557
+ /* @__PURE__ */ jsx(
11558
+ Form$2.Field,
11559
+ {
11560
+ control: form.control,
11561
+ name: "company",
11562
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11563
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11564
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11565
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11566
+ ] })
11567
+ }
11568
+ ),
11569
+ /* @__PURE__ */ jsx(
11570
+ Form$2.Field,
11571
+ {
11572
+ control: form.control,
11573
+ name: "address_1",
11574
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11575
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11576
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11577
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11578
+ ] })
11579
+ }
11580
+ ),
11581
+ /* @__PURE__ */ jsx(
11582
+ Form$2.Field,
11583
+ {
11584
+ control: form.control,
11585
+ name: "address_2",
11586
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11587
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11588
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11589
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11590
+ ] })
11591
+ }
11592
+ ),
11593
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11594
+ /* @__PURE__ */ jsx(
11595
+ Form$2.Field,
11596
+ {
11597
+ control: form.control,
11598
+ name: "postal_code",
11599
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11600
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11601
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11602
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11603
+ ] })
11604
+ }
11605
+ ),
11606
+ /* @__PURE__ */ jsx(
11607
+ Form$2.Field,
11608
+ {
11609
+ control: form.control,
11610
+ name: "city",
11611
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11612
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11613
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11614
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11615
+ ] })
11616
+ }
11617
+ )
11618
+ ] }),
11619
+ /* @__PURE__ */ jsx(
11620
+ Form$2.Field,
11621
+ {
11622
+ control: form.control,
11623
+ name: "province",
11624
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11625
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11626
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11627
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11628
+ ] })
11629
+ }
11630
+ ),
11631
+ /* @__PURE__ */ jsx(
11632
+ Form$2.Field,
11633
+ {
11634
+ control: form.control,
11635
+ name: "phone",
11636
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11637
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11638
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11639
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11640
+ ] })
11641
+ }
11642
+ )
11643
+ ] }) }),
11644
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11645
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11646
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11647
+ ] }) })
11648
+ ]
11550
11649
  }
11551
- );
11650
+ ) });
11552
11651
  };
11553
- const schema$2 = objectType({
11554
- sales_channel_id: stringType().min(1)
11555
- });
11652
+ const schema$2 = addressSchema;
11556
11653
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
11654
  const Shipping = () => {
11558
11655
  var _a;
@@ -12836,37 +12933,33 @@ const Illustration = () => {
12836
12933
  const schema$1 = objectType({
12837
12934
  customer_id: stringType().min(1)
12838
12935
  });
12839
- const ShippingAddress = () => {
12936
+ const SalesChannel = () => {
12840
12937
  const { id } = useParams();
12841
- const { order, isPending, isError, error } = useOrder(id, {
12842
- fields: "+shipping_address"
12843
- });
12938
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12939
+ id,
12940
+ {
12941
+ fields: "+sales_channel_id"
12942
+ },
12943
+ {
12944
+ enabled: !!id
12945
+ }
12946
+ );
12844
12947
  if (isError) {
12845
12948
  throw error;
12846
12949
  }
12847
- const isReady = !isPending && !!order;
12950
+ const ISrEADY = !!draft_order && !isPending;
12848
12951
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12849
12952
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12850
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12851
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12953
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12954
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12852
12955
  ] }),
12853
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12956
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12854
12957
  ] });
12855
12958
  };
12856
- const ShippingAddressForm = ({ order }) => {
12857
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12959
+ const SalesChannelForm = ({ order }) => {
12858
12960
  const form = useForm({
12859
12961
  defaultValues: {
12860
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12861
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12862
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12863
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12864
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12865
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12866
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12867
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12868
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12869
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12962
+ sales_channel_id: order.sales_channel_id || ""
12870
12963
  },
12871
12964
  resolver: zodResolver(schema)
12872
12965
  });
@@ -12875,21 +12968,11 @@ const ShippingAddressForm = ({ order }) => {
12875
12968
  const onSubmit = form.handleSubmit(async (data) => {
12876
12969
  await mutateAsync(
12877
12970
  {
12878
- shipping_address: {
12879
- first_name: data.first_name,
12880
- last_name: data.last_name,
12881
- company: data.company,
12882
- address_1: data.address_1,
12883
- address_2: data.address_2,
12884
- city: data.city,
12885
- province: data.province,
12886
- country_code: data.country_code,
12887
- postal_code: data.postal_code,
12888
- phone: data.phone
12889
- }
12971
+ sales_channel_id: data.sales_channel_id
12890
12972
  },
12891
12973
  {
12892
12974
  onSuccess: () => {
12975
+ toast.success("Sales channel updated");
12893
12976
  handleSuccess();
12894
12977
  },
12895
12978
  onError: (error) => {
@@ -12904,132 +12987,7 @@ const ShippingAddressForm = ({ order }) => {
12904
12987
  className: "flex flex-1 flex-col overflow-hidden",
12905
12988
  onSubmit,
12906
12989
  children: [
12907
- /* @__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: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- control: form.control,
12912
- name: "country_code",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
- /* @__PURE__ */ jsx(
12922
- Form$2.Field,
12923
- {
12924
- control: form.control,
12925
- name: "first_name",
12926
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
- ] })
12931
- }
12932
- ),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "last_name",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- )
12945
- ] }),
12946
- /* @__PURE__ */ jsx(
12947
- Form$2.Field,
12948
- {
12949
- control: form.control,
12950
- name: "company",
12951
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
- ] })
12956
- }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12960
- {
12961
- control: form.control,
12962
- name: "address_1",
12963
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
- ] })
12968
- }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
12972
- {
12973
- control: form.control,
12974
- name: "address_2",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
12980
- }
12981
- ),
12982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
- /* @__PURE__ */ jsx(
12984
- Form$2.Field,
12985
- {
12986
- control: form.control,
12987
- name: "postal_code",
12988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
- ] })
12993
- }
12994
- ),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "city",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- )
13007
- ] }),
13008
- /* @__PURE__ */ jsx(
13009
- Form$2.Field,
13010
- {
13011
- control: form.control,
13012
- name: "province",
13013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
- ] })
13018
- }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13022
- {
13023
- control: form.control,
13024
- name: "phone",
13025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
- ] })
13030
- }
13031
- )
13032
- ] }) }),
12990
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
13033
12991
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
12992
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
12993
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13038,7 +12996,49 @@ const ShippingAddressForm = ({ order }) => {
13038
12996
  }
13039
12997
  ) });
13040
12998
  };
13041
- const schema = addressSchema;
12999
+ const SalesChannelField = ({ control, order }) => {
13000
+ const salesChannels = useComboboxData({
13001
+ queryFn: async (params) => {
13002
+ return await sdk.admin.salesChannel.list(params);
13003
+ },
13004
+ queryKey: ["sales-channels"],
13005
+ getOptions: (data) => {
13006
+ return data.sales_channels.map((salesChannel) => ({
13007
+ label: salesChannel.name,
13008
+ value: salesChannel.id
13009
+ }));
13010
+ },
13011
+ defaultValue: order.sales_channel_id || void 0
13012
+ });
13013
+ return /* @__PURE__ */ jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control,
13017
+ name: "sales_channel_id",
13018
+ render: ({ field }) => {
13019
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13021
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13022
+ Combobox,
13023
+ {
13024
+ options: salesChannels.options,
13025
+ fetchNextPage: salesChannels.fetchNextPage,
13026
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13027
+ searchValue: salesChannels.searchValue,
13028
+ onSearchValueChange: salesChannels.onSearchValueChange,
13029
+ placeholder: "Select sales channel",
13030
+ ...field
13031
+ }
13032
+ ) }),
13033
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13034
+ ] });
13035
+ }
13036
+ }
13037
+ );
13038
+ };
13039
+ const schema = objectType({
13040
+ sales_channel_id: stringType().min(1)
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,6 +13059,10 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
+ {
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
+ },
13062
13066
  {
13063
13067
  Component: CustomItems,
13064
13068
  path: "/draft-orders/:id/custom-items"
@@ -13067,10 +13071,6 @@ const routeModule = {
13067
13071
  Component: Email,
13068
13072
  path: "/draft-orders/:id/email"
13069
13073
  },
13070
- {
13071
- Component: BillingAddress,
13072
- path: "/draft-orders/:id/billing-address"
13073
- },
13074
13074
  {
13075
13075
  Component: Items,
13076
13076
  path: "/draft-orders/:id/items"
@@ -13084,8 +13084,8 @@ const routeModule = {
13084
13084
  path: "/draft-orders/:id/promotions"
13085
13085
  },
13086
13086
  {
13087
- Component: SalesChannel,
13088
- path: "/draft-orders/:id/sales-channel"
13087
+ Component: ShippingAddress,
13088
+ path: "/draft-orders/:id/shipping-address"
13089
13089
  },
13090
13090
  {
13091
13091
  Component: Shipping,
@@ -13096,8 +13096,8 @@ const routeModule = {
13096
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
13097
  },
13098
13098
  {
13099
- Component: ShippingAddress,
13100
- path: "/draft-orders/:id/shipping-address"
13099
+ Component: SalesChannel,
13100
+ path: "/draft-orders/:id/sales-channel"
13101
13101
  }
13102
13102
  ]
13103
13103
  }