@medusajs/draft-order 2.10.2-preview-20250912000322 → 2.10.2-preview-20250912060156

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.
@@ -9784,74 +9784,6 @@ const CustomItemsForm = () => {
9784
9784
  const schema$4 = objectType({
9785
9785
  email: stringType().email()
9786
9786
  });
9787
- const Email = () => {
9788
- const { id } = reactRouterDom.useParams();
9789
- const { order, isPending, isError, error } = useOrder(id, {
9790
- fields: "+email"
9791
- });
9792
- if (isError) {
9793
- throw error;
9794
- }
9795
- const isReady = !isPending && !!order;
9796
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9797
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9800
- ] }),
9801
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9802
- ] });
9803
- };
9804
- const EmailForm = ({ order }) => {
9805
- const form = reactHookForm.useForm({
9806
- defaultValues: {
9807
- email: order.email ?? ""
9808
- },
9809
- resolver: zod.zodResolver(schema$3)
9810
- });
9811
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
- const { handleSuccess } = useRouteModal();
9813
- const onSubmit = form.handleSubmit(async (data) => {
9814
- await mutateAsync(
9815
- { email: data.email },
9816
- {
9817
- onSuccess: () => {
9818
- handleSuccess();
9819
- },
9820
- onError: (error) => {
9821
- ui.toast.error(error.message);
9822
- }
9823
- }
9824
- );
9825
- });
9826
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9827
- KeyboundForm,
9828
- {
9829
- className: "flex flex-1 flex-col overflow-hidden",
9830
- onSubmit,
9831
- children: [
9832
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9833
- Form$2.Field,
9834
- {
9835
- control: form.control,
9836
- name: "email",
9837
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9840
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9841
- ] })
9842
- }
9843
- ) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
- ] }) })
9848
- ]
9849
- }
9850
- ) });
9851
- };
9852
- const schema$3 = objectType({
9853
- email: stringType().email()
9854
- });
9855
9787
  const NumberInput = React.forwardRef(
9856
9788
  ({
9857
9789
  value,
@@ -11453,60 +11385,46 @@ function getPromotionIds(items, shippingMethods) {
11453
11385
  }
11454
11386
  return Array.from(promotionIds);
11455
11387
  }
11456
- const ShippingAddress = () => {
11388
+ const SalesChannel = () => {
11457
11389
  const { id } = reactRouterDom.useParams();
11458
- const { order, isPending, isError, error } = useOrder(id, {
11459
- fields: "+shipping_address"
11460
- });
11390
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11391
+ id,
11392
+ {
11393
+ fields: "+sales_channel_id"
11394
+ },
11395
+ {
11396
+ enabled: !!id
11397
+ }
11398
+ );
11461
11399
  if (isError) {
11462
11400
  throw error;
11463
11401
  }
11464
- const isReady = !isPending && !!order;
11402
+ const ISrEADY = !!draft_order && !isPending;
11465
11403
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11466
11404
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11467
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11468
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11405
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11406
+ /* @__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" }) })
11469
11407
  ] }),
11470
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11408
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11471
11409
  ] });
11472
11410
  };
11473
- const ShippingAddressForm = ({ order }) => {
11474
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11411
+ const SalesChannelForm = ({ order }) => {
11475
11412
  const form = reactHookForm.useForm({
11476
11413
  defaultValues: {
11477
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11478
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11479
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11480
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11481
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11482
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11483
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11484
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11485
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11486
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11414
+ sales_channel_id: order.sales_channel_id || ""
11487
11415
  },
11488
- resolver: zod.zodResolver(schema$2)
11416
+ resolver: zod.zodResolver(schema$3)
11489
11417
  });
11490
11418
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11491
11419
  const { handleSuccess } = useRouteModal();
11492
11420
  const onSubmit = form.handleSubmit(async (data) => {
11493
11421
  await mutateAsync(
11494
11422
  {
11495
- shipping_address: {
11496
- first_name: data.first_name,
11497
- last_name: data.last_name,
11498
- company: data.company,
11499
- address_1: data.address_1,
11500
- address_2: data.address_2,
11501
- city: data.city,
11502
- province: data.province,
11503
- country_code: data.country_code,
11504
- postal_code: data.postal_code,
11505
- phone: data.phone
11506
- }
11423
+ sales_channel_id: data.sales_channel_id
11507
11424
  },
11508
11425
  {
11509
11426
  onSuccess: () => {
11427
+ ui.toast.success("Sales channel updated");
11510
11428
  handleSuccess();
11511
11429
  },
11512
11430
  onError: (error) => {
@@ -11521,132 +11439,7 @@ const ShippingAddressForm = ({ order }) => {
11521
11439
  className: "flex flex-1 flex-col overflow-hidden",
11522
11440
  onSubmit,
11523
11441
  children: [
11524
- /* @__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: [
11525
- /* @__PURE__ */ jsxRuntime.jsx(
11526
- Form$2.Field,
11527
- {
11528
- control: form.control,
11529
- name: "country_code",
11530
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11534
- ] })
11535
- }
11536
- ),
11537
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11538
- /* @__PURE__ */ jsxRuntime.jsx(
11539
- Form$2.Field,
11540
- {
11541
- control: form.control,
11542
- name: "first_name",
11543
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11546
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11547
- ] })
11548
- }
11549
- ),
11550
- /* @__PURE__ */ jsxRuntime.jsx(
11551
- Form$2.Field,
11552
- {
11553
- control: form.control,
11554
- name: "last_name",
11555
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11558
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11559
- ] })
11560
- }
11561
- )
11562
- ] }),
11563
- /* @__PURE__ */ jsxRuntime.jsx(
11564
- Form$2.Field,
11565
- {
11566
- control: form.control,
11567
- name: "company",
11568
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11569
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11570
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11571
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11572
- ] })
11573
- }
11574
- ),
11575
- /* @__PURE__ */ jsxRuntime.jsx(
11576
- Form$2.Field,
11577
- {
11578
- control: form.control,
11579
- name: "address_1",
11580
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11581
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11582
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11583
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11584
- ] })
11585
- }
11586
- ),
11587
- /* @__PURE__ */ jsxRuntime.jsx(
11588
- Form$2.Field,
11589
- {
11590
- control: form.control,
11591
- name: "address_2",
11592
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11593
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11594
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11595
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11596
- ] })
11597
- }
11598
- ),
11599
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11600
- /* @__PURE__ */ jsxRuntime.jsx(
11601
- Form$2.Field,
11602
- {
11603
- control: form.control,
11604
- name: "postal_code",
11605
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11606
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11607
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11608
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11609
- ] })
11610
- }
11611
- ),
11612
- /* @__PURE__ */ jsxRuntime.jsx(
11613
- Form$2.Field,
11614
- {
11615
- control: form.control,
11616
- name: "city",
11617
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11619
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11620
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11621
- ] })
11622
- }
11623
- )
11624
- ] }),
11625
- /* @__PURE__ */ jsxRuntime.jsx(
11626
- Form$2.Field,
11627
- {
11628
- control: form.control,
11629
- name: "province",
11630
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11632
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11633
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11634
- ] })
11635
- }
11636
- ),
11637
- /* @__PURE__ */ jsxRuntime.jsx(
11638
- Form$2.Field,
11639
- {
11640
- control: form.control,
11641
- name: "phone",
11642
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11643
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11644
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11645
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11646
- ] })
11647
- }
11648
- )
11649
- ] }) }),
11442
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11650
11443
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11651
11444
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11652
11445
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11655,15 +11448,57 @@ const ShippingAddressForm = ({ order }) => {
11655
11448
  }
11656
11449
  ) });
11657
11450
  };
11658
- const schema$2 = addressSchema;
11659
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11660
- const Shipping = () => {
11661
- var _a;
11662
- const { id } = reactRouterDom.useParams();
11663
- const { order, isPending, isError, error } = useOrder(id, {
11664
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11665
- });
11666
- const {
11451
+ const SalesChannelField = ({ control, order }) => {
11452
+ const salesChannels = useComboboxData({
11453
+ queryFn: async (params) => {
11454
+ return await sdk.admin.salesChannel.list(params);
11455
+ },
11456
+ queryKey: ["sales-channels"],
11457
+ getOptions: (data) => {
11458
+ return data.sales_channels.map((salesChannel) => ({
11459
+ label: salesChannel.name,
11460
+ value: salesChannel.id
11461
+ }));
11462
+ },
11463
+ defaultValue: order.sales_channel_id || void 0
11464
+ });
11465
+ return /* @__PURE__ */ jsxRuntime.jsx(
11466
+ Form$2.Field,
11467
+ {
11468
+ control,
11469
+ name: "sales_channel_id",
11470
+ render: ({ field }) => {
11471
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11473
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11474
+ Combobox,
11475
+ {
11476
+ options: salesChannels.options,
11477
+ fetchNextPage: salesChannels.fetchNextPage,
11478
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11479
+ searchValue: salesChannels.searchValue,
11480
+ onSearchValueChange: salesChannels.onSearchValueChange,
11481
+ placeholder: "Select sales channel",
11482
+ ...field
11483
+ }
11484
+ ) }),
11485
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11486
+ ] });
11487
+ }
11488
+ }
11489
+ );
11490
+ };
11491
+ const schema$3 = objectType({
11492
+ sales_channel_id: stringType().min(1)
11493
+ });
11494
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11495
+ const Shipping = () => {
11496
+ var _a;
11497
+ const { id } = reactRouterDom.useParams();
11498
+ const { order, isPending, isError, error } = useOrder(id, {
11499
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11500
+ });
11501
+ const {
11667
11502
  order: preview,
11668
11503
  isPending: isPreviewPending,
11669
11504
  isError: isPreviewError,
@@ -12463,6 +12298,209 @@ const CustomAmountField = ({
12463
12298
  }
12464
12299
  );
12465
12300
  };
12301
+ const ShippingAddress = () => {
12302
+ const { id } = reactRouterDom.useParams();
12303
+ const { order, isPending, isError, error } = useOrder(id, {
12304
+ fields: "+shipping_address"
12305
+ });
12306
+ if (isError) {
12307
+ throw error;
12308
+ }
12309
+ const isReady = !isPending && !!order;
12310
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12311
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12312
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12313
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12314
+ ] }),
12315
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12316
+ ] });
12317
+ };
12318
+ const ShippingAddressForm = ({ order }) => {
12319
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12320
+ const form = reactHookForm.useForm({
12321
+ defaultValues: {
12322
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12323
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12324
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12325
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12326
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12327
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12328
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12329
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12330
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12331
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12332
+ },
12333
+ resolver: zod.zodResolver(schema$2)
12334
+ });
12335
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12336
+ const { handleSuccess } = useRouteModal();
12337
+ const onSubmit = form.handleSubmit(async (data) => {
12338
+ await mutateAsync(
12339
+ {
12340
+ shipping_address: {
12341
+ first_name: data.first_name,
12342
+ last_name: data.last_name,
12343
+ company: data.company,
12344
+ address_1: data.address_1,
12345
+ address_2: data.address_2,
12346
+ city: data.city,
12347
+ province: data.province,
12348
+ country_code: data.country_code,
12349
+ postal_code: data.postal_code,
12350
+ phone: data.phone
12351
+ }
12352
+ },
12353
+ {
12354
+ onSuccess: () => {
12355
+ handleSuccess();
12356
+ },
12357
+ onError: (error) => {
12358
+ ui.toast.error(error.message);
12359
+ }
12360
+ }
12361
+ );
12362
+ });
12363
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12364
+ KeyboundForm,
12365
+ {
12366
+ className: "flex flex-1 flex-col overflow-hidden",
12367
+ onSubmit,
12368
+ children: [
12369
+ /* @__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: [
12370
+ /* @__PURE__ */ jsxRuntime.jsx(
12371
+ Form$2.Field,
12372
+ {
12373
+ control: form.control,
12374
+ name: "country_code",
12375
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12376
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12377
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12378
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12379
+ ] })
12380
+ }
12381
+ ),
12382
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12383
+ /* @__PURE__ */ jsxRuntime.jsx(
12384
+ Form$2.Field,
12385
+ {
12386
+ control: form.control,
12387
+ name: "first_name",
12388
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12389
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12390
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12391
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12392
+ ] })
12393
+ }
12394
+ ),
12395
+ /* @__PURE__ */ jsxRuntime.jsx(
12396
+ Form$2.Field,
12397
+ {
12398
+ control: form.control,
12399
+ name: "last_name",
12400
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12401
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12402
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12403
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12404
+ ] })
12405
+ }
12406
+ )
12407
+ ] }),
12408
+ /* @__PURE__ */ jsxRuntime.jsx(
12409
+ Form$2.Field,
12410
+ {
12411
+ control: form.control,
12412
+ name: "company",
12413
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12414
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12415
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12416
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12417
+ ] })
12418
+ }
12419
+ ),
12420
+ /* @__PURE__ */ jsxRuntime.jsx(
12421
+ Form$2.Field,
12422
+ {
12423
+ control: form.control,
12424
+ name: "address_1",
12425
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12426
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12427
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12428
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12429
+ ] })
12430
+ }
12431
+ ),
12432
+ /* @__PURE__ */ jsxRuntime.jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "address_2",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12440
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
+ /* @__PURE__ */ jsxRuntime.jsx(
12446
+ Form$2.Field,
12447
+ {
12448
+ control: form.control,
12449
+ name: "postal_code",
12450
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12451
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12452
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12453
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12454
+ ] })
12455
+ }
12456
+ ),
12457
+ /* @__PURE__ */ jsxRuntime.jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "city",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12464
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12467
+ }
12468
+ )
12469
+ ] }),
12470
+ /* @__PURE__ */ jsxRuntime.jsx(
12471
+ Form$2.Field,
12472
+ {
12473
+ control: form.control,
12474
+ name: "province",
12475
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12476
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12477
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12478
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12479
+ ] })
12480
+ }
12481
+ ),
12482
+ /* @__PURE__ */ jsxRuntime.jsx(
12483
+ Form$2.Field,
12484
+ {
12485
+ control: form.control,
12486
+ name: "phone",
12487
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12488
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12489
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12490
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12492
+ }
12493
+ )
12494
+ ] }) }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12496
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12497
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12498
+ ] }) })
12499
+ ]
12500
+ }
12501
+ ) });
12502
+ };
12503
+ const schema$2 = addressSchema;
12466
12504
  const TransferOwnership = () => {
12467
12505
  const { id } = reactRouterDom.useParams();
12468
12506
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12939,33 +12977,27 @@ const Illustration = () => {
12939
12977
  const schema$1 = objectType({
12940
12978
  customer_id: stringType().min(1)
12941
12979
  });
12942
- const SalesChannel = () => {
12980
+ const Email = () => {
12943
12981
  const { id } = reactRouterDom.useParams();
12944
- const { draft_order, isPending, isError, error } = useDraftOrder(
12945
- id,
12946
- {
12947
- fields: "+sales_channel_id"
12948
- },
12949
- {
12950
- enabled: !!id
12951
- }
12952
- );
12982
+ const { order, isPending, isError, error } = useOrder(id, {
12983
+ fields: "+email"
12984
+ });
12953
12985
  if (isError) {
12954
12986
  throw error;
12955
12987
  }
12956
- const ISrEADY = !!draft_order && !isPending;
12988
+ const isReady = !isPending && !!order;
12957
12989
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12958
12990
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12959
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12960
- /* @__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" }) })
12991
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12961
12993
  ] }),
12962
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12994
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12963
12995
  ] });
12964
12996
  };
12965
- const SalesChannelForm = ({ order }) => {
12997
+ const EmailForm = ({ order }) => {
12966
12998
  const form = reactHookForm.useForm({
12967
12999
  defaultValues: {
12968
- sales_channel_id: order.sales_channel_id || ""
13000
+ email: order.email ?? ""
12969
13001
  },
12970
13002
  resolver: zod.zodResolver(schema)
12971
13003
  });
@@ -12973,12 +13005,9 @@ const SalesChannelForm = ({ order }) => {
12973
13005
  const { handleSuccess } = useRouteModal();
12974
13006
  const onSubmit = form.handleSubmit(async (data) => {
12975
13007
  await mutateAsync(
12976
- {
12977
- sales_channel_id: data.sales_channel_id
12978
- },
13008
+ { email: data.email },
12979
13009
  {
12980
13010
  onSuccess: () => {
12981
- ui.toast.success("Sales channel updated");
12982
13011
  handleSuccess();
12983
13012
  },
12984
13013
  onError: (error) => {
@@ -12993,7 +13022,18 @@ const SalesChannelForm = ({ order }) => {
12993
13022
  className: "flex flex-1 flex-col overflow-hidden",
12994
13023
  onSubmit,
12995
13024
  children: [
12996
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
13025
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
13027
+ {
13028
+ control: form.control,
13029
+ name: "email",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
13035
+ }
13036
+ ) }),
12997
13037
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12998
13038
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12999
13039
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13002,48 +13042,8 @@ const SalesChannelForm = ({ order }) => {
13002
13042
  }
13003
13043
  ) });
13004
13044
  };
13005
- const SalesChannelField = ({ control, order }) => {
13006
- const salesChannels = useComboboxData({
13007
- queryFn: async (params) => {
13008
- return await sdk.admin.salesChannel.list(params);
13009
- },
13010
- queryKey: ["sales-channels"],
13011
- getOptions: (data) => {
13012
- return data.sales_channels.map((salesChannel) => ({
13013
- label: salesChannel.name,
13014
- value: salesChannel.id
13015
- }));
13016
- },
13017
- defaultValue: order.sales_channel_id || void 0
13018
- });
13019
- return /* @__PURE__ */ jsxRuntime.jsx(
13020
- Form$2.Field,
13021
- {
13022
- control,
13023
- name: "sales_channel_id",
13024
- render: ({ field }) => {
13025
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13028
- Combobox,
13029
- {
13030
- options: salesChannels.options,
13031
- fetchNextPage: salesChannels.fetchNextPage,
13032
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13033
- searchValue: salesChannels.searchValue,
13034
- onSearchValueChange: salesChannels.onSearchValueChange,
13035
- placeholder: "Select sales channel",
13036
- ...field
13037
- }
13038
- ) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13040
- ] });
13041
- }
13042
- }
13043
- );
13044
- };
13045
13045
  const schema = objectType({
13046
- sales_channel_id: stringType().min(1)
13046
+ email: stringType().email()
13047
13047
  });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
@@ -13073,10 +13073,6 @@ const routeModule = {
13073
13073
  Component: CustomItems,
13074
13074
  path: "/draft-orders/:id/custom-items"
13075
13075
  },
13076
- {
13077
- Component: Email,
13078
- path: "/draft-orders/:id/email"
13079
- },
13080
13076
  {
13081
13077
  Component: Items,
13082
13078
  path: "/draft-orders/:id/items"
@@ -13090,20 +13086,24 @@ const routeModule = {
13090
13086
  path: "/draft-orders/:id/promotions"
13091
13087
  },
13092
13088
  {
13093
- Component: ShippingAddress,
13094
- path: "/draft-orders/:id/shipping-address"
13089
+ Component: SalesChannel,
13090
+ path: "/draft-orders/:id/sales-channel"
13095
13091
  },
13096
13092
  {
13097
13093
  Component: Shipping,
13098
13094
  path: "/draft-orders/:id/shipping"
13099
13095
  },
13096
+ {
13097
+ Component: ShippingAddress,
13098
+ path: "/draft-orders/:id/shipping-address"
13099
+ },
13100
13100
  {
13101
13101
  Component: TransferOwnership,
13102
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
13103
  },
13104
13104
  {
13105
- Component: SalesChannel,
13106
- path: "/draft-orders/:id/sales-channel"
13105
+ Component: Email,
13106
+ path: "/draft-orders/:id/email"
13107
13107
  }
13108
13108
  ]
13109
13109
  }