@medusajs/draft-order 2.12.2-preview-20251203180141 → 2.12.2-preview-20251204000309

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.
@@ -9572,196 +9572,6 @@ const ID = () => {
9572
9572
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9573
9573
  ] });
9574
9574
  };
9575
- const BillingAddress = () => {
9576
- const { id } = reactRouterDom.useParams();
9577
- const { order, isPending, isError, error } = useOrder(id, {
9578
- fields: "+billing_address"
9579
- });
9580
- if (isError) {
9581
- throw error;
9582
- }
9583
- const isReady = !isPending && !!order;
9584
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9585
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9588
- ] }),
9589
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9590
- ] });
9591
- };
9592
- const BillingAddressForm = ({ order }) => {
9593
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9594
- const form = reactHookForm.useForm({
9595
- defaultValues: {
9596
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9597
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9598
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9599
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9600
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9601
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9602
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9603
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9604
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9605
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9606
- },
9607
- resolver: zod.zodResolver(schema$5)
9608
- });
9609
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9610
- const { handleSuccess } = useRouteModal();
9611
- const onSubmit = form.handleSubmit(async (data) => {
9612
- await mutateAsync(
9613
- { billing_address: data },
9614
- {
9615
- onSuccess: () => {
9616
- handleSuccess();
9617
- },
9618
- onError: (error) => {
9619
- ui.toast.error(error.message);
9620
- }
9621
- }
9622
- );
9623
- });
9624
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9625
- KeyboundForm,
9626
- {
9627
- className: "flex flex-1 flex-col overflow-hidden",
9628
- onSubmit,
9629
- children: [
9630
- /* @__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: [
9631
- /* @__PURE__ */ jsxRuntime.jsx(
9632
- Form$2.Field,
9633
- {
9634
- control: form.control,
9635
- name: "country_code",
9636
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9640
- ] })
9641
- }
9642
- ),
9643
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9644
- /* @__PURE__ */ jsxRuntime.jsx(
9645
- Form$2.Field,
9646
- {
9647
- control: form.control,
9648
- name: "first_name",
9649
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9653
- ] })
9654
- }
9655
- ),
9656
- /* @__PURE__ */ jsxRuntime.jsx(
9657
- Form$2.Field,
9658
- {
9659
- control: form.control,
9660
- name: "last_name",
9661
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9665
- ] })
9666
- }
9667
- )
9668
- ] }),
9669
- /* @__PURE__ */ jsxRuntime.jsx(
9670
- Form$2.Field,
9671
- {
9672
- control: form.control,
9673
- name: "company",
9674
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9678
- ] })
9679
- }
9680
- ),
9681
- /* @__PURE__ */ jsxRuntime.jsx(
9682
- Form$2.Field,
9683
- {
9684
- control: form.control,
9685
- name: "address_1",
9686
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9690
- ] })
9691
- }
9692
- ),
9693
- /* @__PURE__ */ jsxRuntime.jsx(
9694
- Form$2.Field,
9695
- {
9696
- control: form.control,
9697
- name: "address_2",
9698
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9702
- ] })
9703
- }
9704
- ),
9705
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9706
- /* @__PURE__ */ jsxRuntime.jsx(
9707
- Form$2.Field,
9708
- {
9709
- control: form.control,
9710
- name: "postal_code",
9711
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9715
- ] })
9716
- }
9717
- ),
9718
- /* @__PURE__ */ jsxRuntime.jsx(
9719
- Form$2.Field,
9720
- {
9721
- control: form.control,
9722
- name: "city",
9723
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9727
- ] })
9728
- }
9729
- )
9730
- ] }),
9731
- /* @__PURE__ */ jsxRuntime.jsx(
9732
- Form$2.Field,
9733
- {
9734
- control: form.control,
9735
- name: "province",
9736
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9740
- ] })
9741
- }
9742
- ),
9743
- /* @__PURE__ */ jsxRuntime.jsx(
9744
- Form$2.Field,
9745
- {
9746
- control: form.control,
9747
- name: "phone",
9748
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9752
- ] })
9753
- }
9754
- )
9755
- ] }) }),
9756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9758
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9759
- ] }) })
9760
- ]
9761
- }
9762
- ) });
9763
- };
9764
- const schema$5 = addressSchema;
9765
9575
  const CustomItems = () => {
9766
9576
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
9577
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9770,7 +9580,7 @@ const CustomItems = () => {
9770
9580
  };
9771
9581
  const CustomItemsForm = () => {
9772
9582
  const form = reactHookForm.useForm({
9773
- resolver: zod.zodResolver(schema$4)
9583
+ resolver: zod.zodResolver(schema$5)
9774
9584
  });
9775
9585
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
9586
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9780,7 +9590,7 @@ const CustomItemsForm = () => {
9780
9590
  ] }) })
9781
9591
  ] }) });
9782
9592
  };
9783
- const schema$4 = objectType({
9593
+ const schema$5 = objectType({
9784
9594
  email: stringType().email()
9785
9595
  });
9786
9596
  const Email = () => {
@@ -9805,7 +9615,7 @@ const EmailForm = ({ order }) => {
9805
9615
  defaultValues: {
9806
9616
  email: order.email ?? ""
9807
9617
  },
9808
- resolver: zod.zodResolver(schema$3)
9618
+ resolver: zod.zodResolver(schema$4)
9809
9619
  });
9810
9620
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9811
9621
  const { handleSuccess } = useRouteModal();
@@ -9848,7 +9658,7 @@ const EmailForm = ({ order }) => {
9848
9658
  }
9849
9659
  ) });
9850
9660
  };
9851
- const schema$3 = objectType({
9661
+ const schema$4 = objectType({
9852
9662
  email: stringType().email()
9853
9663
  });
9854
9664
  const NumberInput = React.forwardRef(
@@ -11452,46 +11262,47 @@ function getPromotionIds(items, shippingMethods) {
11452
11262
  }
11453
11263
  return Array.from(promotionIds);
11454
11264
  }
11455
- const SalesChannel = () => {
11265
+ const BillingAddress = () => {
11456
11266
  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
- );
11267
+ const { order, isPending, isError, error } = useOrder(id, {
11268
+ fields: "+billing_address"
11269
+ });
11466
11270
  if (isError) {
11467
11271
  throw error;
11468
11272
  }
11469
- const ISrEADY = !!draft_order && !isPending;
11273
+ const isReady = !isPending && !!order;
11470
11274
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11471
11275
  /* @__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" }) })
11276
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
11277
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11474
11278
  ] }),
11475
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11279
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
11476
11280
  ] });
11477
11281
  };
11478
- const SalesChannelForm = ({ order }) => {
11282
+ const BillingAddressForm = ({ order }) => {
11283
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11479
11284
  const form = reactHookForm.useForm({
11480
11285
  defaultValues: {
11481
- sales_channel_id: order.sales_channel_id || ""
11286
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11287
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11288
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11289
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11290
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11291
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11292
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11293
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11294
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11295
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11482
11296
  },
11483
- resolver: zod.zodResolver(schema$2)
11297
+ resolver: zod.zodResolver(schema$3)
11484
11298
  });
11485
11299
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
11300
  const { handleSuccess } = useRouteModal();
11487
11301
  const onSubmit = form.handleSubmit(async (data) => {
11488
11302
  await mutateAsync(
11489
- {
11490
- sales_channel_id: data.sales_channel_id
11491
- },
11303
+ { billing_address: data },
11492
11304
  {
11493
11305
  onSuccess: () => {
11494
- ui.toast.success("Sales channel updated");
11495
11306
  handleSuccess();
11496
11307
  },
11497
11308
  onError: (error) => {
@@ -11506,58 +11317,141 @@ const SalesChannelForm = ({ order }) => {
11506
11317
  className: "flex flex-1 flex-col overflow-hidden",
11507
11318
  onSubmit,
11508
11319
  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
- }));
11529
- },
11530
- defaultValue: order.sales_channel_id || void 0
11531
- });
11532
- return /* @__PURE__ */ jsxRuntime.jsx(
11533
- Form$2.Field,
11534
- {
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,
11320
+ /* @__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: [
11321
+ /* @__PURE__ */ jsxRuntime.jsx(
11322
+ Form$2.Field,
11542
11323
  {
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
11324
+ control: form.control,
11325
+ name: "country_code",
11326
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11327
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11328
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11329
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11330
+ ] })
11550
11331
  }
11551
- ) }),
11552
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
- ] });
11554
- }
11332
+ ),
11333
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11334
+ /* @__PURE__ */ jsxRuntime.jsx(
11335
+ Form$2.Field,
11336
+ {
11337
+ control: form.control,
11338
+ name: "first_name",
11339
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11341
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11342
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11343
+ ] })
11344
+ }
11345
+ ),
11346
+ /* @__PURE__ */ jsxRuntime.jsx(
11347
+ Form$2.Field,
11348
+ {
11349
+ control: form.control,
11350
+ name: "last_name",
11351
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11355
+ ] })
11356
+ }
11357
+ )
11358
+ ] }),
11359
+ /* @__PURE__ */ jsxRuntime.jsx(
11360
+ Form$2.Field,
11361
+ {
11362
+ control: form.control,
11363
+ name: "company",
11364
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11365
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11367
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11368
+ ] })
11369
+ }
11370
+ ),
11371
+ /* @__PURE__ */ jsxRuntime.jsx(
11372
+ Form$2.Field,
11373
+ {
11374
+ control: form.control,
11375
+ name: "address_1",
11376
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11377
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11378
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11379
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11380
+ ] })
11381
+ }
11382
+ ),
11383
+ /* @__PURE__ */ jsxRuntime.jsx(
11384
+ Form$2.Field,
11385
+ {
11386
+ control: form.control,
11387
+ name: "address_2",
11388
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11389
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11390
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11391
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11392
+ ] })
11393
+ }
11394
+ ),
11395
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11396
+ /* @__PURE__ */ jsxRuntime.jsx(
11397
+ Form$2.Field,
11398
+ {
11399
+ control: form.control,
11400
+ name: "postal_code",
11401
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11402
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11403
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11404
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11405
+ ] })
11406
+ }
11407
+ ),
11408
+ /* @__PURE__ */ jsxRuntime.jsx(
11409
+ Form$2.Field,
11410
+ {
11411
+ control: form.control,
11412
+ name: "city",
11413
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11414
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11415
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11416
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11417
+ ] })
11418
+ }
11419
+ )
11420
+ ] }),
11421
+ /* @__PURE__ */ jsxRuntime.jsx(
11422
+ Form$2.Field,
11423
+ {
11424
+ control: form.control,
11425
+ name: "province",
11426
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11427
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11428
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11429
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11430
+ ] })
11431
+ }
11432
+ ),
11433
+ /* @__PURE__ */ jsxRuntime.jsx(
11434
+ Form$2.Field,
11435
+ {
11436
+ control: form.control,
11437
+ name: "phone",
11438
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11440
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11441
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11442
+ ] })
11443
+ }
11444
+ )
11445
+ ] }) }),
11446
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11447
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11448
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11449
+ ] }) })
11450
+ ]
11555
11451
  }
11556
- );
11452
+ ) });
11557
11453
  };
11558
- const schema$2 = objectType({
11559
- sales_channel_id: stringType().min(1)
11560
- });
11454
+ const schema$3 = addressSchema;
11561
11455
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11562
11456
  const Shipping = () => {
11563
11457
  var _a;
@@ -12397,7 +12291,7 @@ const ShippingAddressForm = ({ order }) => {
12397
12291
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12398
12292
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12399
12293
  },
12400
- resolver: zod.zodResolver(schema$1)
12294
+ resolver: zod.zodResolver(schema$2)
12401
12295
  });
12402
12296
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12403
12297
  const { handleSuccess } = useRouteModal();
@@ -12567,7 +12461,7 @@ const ShippingAddressForm = ({ order }) => {
12567
12461
  }
12568
12462
  ) });
12569
12463
  };
12570
- const schema$1 = addressSchema;
12464
+ const schema$2 = addressSchema;
12571
12465
  const TransferOwnership = () => {
12572
12466
  const { id } = reactRouterDom.useParams();
12573
12467
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12591,7 +12485,7 @@ const TransferOwnershipForm = ({ order }) => {
12591
12485
  defaultValues: {
12592
12486
  customer_id: order.customer_id || ""
12593
12487
  },
12594
- resolver: zod.zodResolver(schema)
12488
+ resolver: zod.zodResolver(schema$1)
12595
12489
  });
12596
12490
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12597
12491
  const { handleSuccess } = useRouteModal();
@@ -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: [
@@ -13064,10 +13064,6 @@ const routeModule = {
13064
13064
  handle,
13065
13065
  loader,
13066
13066
  children: [
13067
- {
13068
- Component: BillingAddress,
13069
- path: "/draft-orders/:id/billing-address"
13070
- },
13071
13067
  {
13072
13068
  Component: CustomItems,
13073
13069
  path: "/draft-orders/:id/custom-items"
@@ -13089,8 +13085,8 @@ const routeModule = {
13089
13085
  path: "/draft-orders/:id/promotions"
13090
13086
  },
13091
13087
  {
13092
- Component: SalesChannel,
13093
- path: "/draft-orders/:id/sales-channel"
13088
+ Component: BillingAddress,
13089
+ path: "/draft-orders/:id/billing-address"
13094
13090
  },
13095
13091
  {
13096
13092
  Component: Shipping,
@@ -13103,6 +13099,10 @@ const routeModule = {
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
  }