@medusajs/draft-order 2.11.0-preview-20251018031037 → 2.11.0-preview-20251018060206

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.
@@ -9763,6 +9763,27 @@ const BillingAddressForm = ({ order }) => {
9763
9763
  ) });
9764
9764
  };
9765
9765
  const schema$5 = addressSchema;
9766
+ const CustomItems = () => {
9767
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
+ ] });
9771
+ };
9772
+ const CustomItemsForm = () => {
9773
+ const form = reactHookForm.useForm({
9774
+ resolver: zod.zodResolver(schema$4)
9775
+ });
9776
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
+ ] }) })
9782
+ ] }) });
9783
+ };
9784
+ const schema$4 = objectType({
9785
+ email: stringType().email()
9786
+ });
9766
9787
  const Email = () => {
9767
9788
  const { id } = reactRouterDom.useParams();
9768
9789
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9785,7 +9806,7 @@ const EmailForm = ({ order }) => {
9785
9806
  defaultValues: {
9786
9807
  email: order.email ?? ""
9787
9808
  },
9788
- resolver: zod.zodResolver(schema$4)
9809
+ resolver: zod.zodResolver(schema$3)
9789
9810
  });
9790
9811
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9791
9812
  const { handleSuccess } = useRouteModal();
@@ -9828,7 +9849,7 @@ const EmailForm = ({ order }) => {
9828
9849
  }
9829
9850
  ) });
9830
9851
  };
9831
- const schema$4 = objectType({
9852
+ const schema$3 = objectType({
9832
9853
  email: stringType().email()
9833
9854
  });
9834
9855
  const NumberInput = React.forwardRef(
@@ -11432,46 +11453,60 @@ function getPromotionIds(items, shippingMethods) {
11432
11453
  }
11433
11454
  return Array.from(promotionIds);
11434
11455
  }
11435
- const SalesChannel = () => {
11456
+ const ShippingAddress = () => {
11436
11457
  const { id } = reactRouterDom.useParams();
11437
- const { draft_order, isPending, isError, error } = useDraftOrder(
11438
- id,
11439
- {
11440
- fields: "+sales_channel_id"
11441
- },
11442
- {
11443
- enabled: !!id
11444
- }
11445
- );
11458
+ const { order, isPending, isError, error } = useOrder(id, {
11459
+ fields: "+shipping_address"
11460
+ });
11446
11461
  if (isError) {
11447
11462
  throw error;
11448
11463
  }
11449
- const ISrEADY = !!draft_order && !isPending;
11464
+ const isReady = !isPending && !!order;
11450
11465
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11451
11466
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11452
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11453
- /* @__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" }) })
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" }) })
11454
11469
  ] }),
11455
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11470
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11456
11471
  ] });
11457
11472
  };
11458
- const SalesChannelForm = ({ order }) => {
11473
+ const ShippingAddressForm = ({ order }) => {
11474
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11459
11475
  const form = reactHookForm.useForm({
11460
11476
  defaultValues: {
11461
- sales_channel_id: order.sales_channel_id || ""
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) ?? ""
11462
11487
  },
11463
- resolver: zod.zodResolver(schema$3)
11488
+ resolver: zod.zodResolver(schema$2)
11464
11489
  });
11465
11490
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11466
11491
  const { handleSuccess } = useRouteModal();
11467
11492
  const onSubmit = form.handleSubmit(async (data) => {
11468
11493
  await mutateAsync(
11469
11494
  {
11470
- sales_channel_id: data.sales_channel_id
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
+ }
11471
11507
  },
11472
11508
  {
11473
11509
  onSuccess: () => {
11474
- ui.toast.success("Sales channel updated");
11475
11510
  handleSuccess();
11476
11511
  },
11477
11512
  onError: (error) => {
@@ -11486,7 +11521,132 @@ const SalesChannelForm = ({ order }) => {
11486
11521
  className: "flex flex-1 flex-col overflow-hidden",
11487
11522
  onSubmit,
11488
11523
  children: [
11489
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
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
+ ] }) }),
11490
11650
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11491
11651
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11492
11652
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11495,49 +11655,7 @@ const SalesChannelForm = ({ order }) => {
11495
11655
  }
11496
11656
  ) });
11497
11657
  };
11498
- const SalesChannelField = ({ control, order }) => {
11499
- const salesChannels = useComboboxData({
11500
- queryFn: async (params) => {
11501
- return await sdk.admin.salesChannel.list(params);
11502
- },
11503
- queryKey: ["sales-channels"],
11504
- getOptions: (data) => {
11505
- return data.sales_channels.map((salesChannel) => ({
11506
- label: salesChannel.name,
11507
- value: salesChannel.id
11508
- }));
11509
- },
11510
- defaultValue: order.sales_channel_id || void 0
11511
- });
11512
- return /* @__PURE__ */ jsxRuntime.jsx(
11513
- Form$2.Field,
11514
- {
11515
- control,
11516
- name: "sales_channel_id",
11517
- render: ({ field }) => {
11518
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11521
- Combobox,
11522
- {
11523
- options: salesChannels.options,
11524
- fetchNextPage: salesChannels.fetchNextPage,
11525
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11526
- searchValue: salesChannels.searchValue,
11527
- onSearchValueChange: salesChannels.onSearchValueChange,
11528
- placeholder: "Select sales channel",
11529
- ...field
11530
- }
11531
- ) }),
11532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11533
- ] });
11534
- }
11535
- }
11536
- );
11537
- };
11538
- const schema$3 = objectType({
11539
- sales_channel_id: stringType().min(1)
11540
- });
11658
+ const schema$2 = addressSchema;
11541
11659
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11542
11660
  const Shipping = () => {
11543
11661
  var _a;
@@ -12345,218 +12463,15 @@ const CustomAmountField = ({
12345
12463
  }
12346
12464
  );
12347
12465
  };
12348
- const ShippingAddress = () => {
12466
+ const TransferOwnership = () => {
12349
12467
  const { id } = reactRouterDom.useParams();
12350
- const { order, isPending, isError, error } = useOrder(id, {
12351
- fields: "+shipping_address"
12468
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12469
+ fields: "id,customer_id,customer.*"
12352
12470
  });
12353
12471
  if (isError) {
12354
12472
  throw error;
12355
12473
  }
12356
- const isReady = !isPending && !!order;
12357
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12358
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12359
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12360
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12361
- ] }),
12362
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12363
- ] });
12364
- };
12365
- const ShippingAddressForm = ({ order }) => {
12366
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12367
- const form = reactHookForm.useForm({
12368
- defaultValues: {
12369
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12370
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12371
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12372
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12373
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12374
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12375
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12376
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12377
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12378
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12379
- },
12380
- resolver: zod.zodResolver(schema$2)
12381
- });
12382
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12383
- const { handleSuccess } = useRouteModal();
12384
- const onSubmit = form.handleSubmit(async (data) => {
12385
- await mutateAsync(
12386
- {
12387
- shipping_address: {
12388
- first_name: data.first_name,
12389
- last_name: data.last_name,
12390
- company: data.company,
12391
- address_1: data.address_1,
12392
- address_2: data.address_2,
12393
- city: data.city,
12394
- province: data.province,
12395
- country_code: data.country_code,
12396
- postal_code: data.postal_code,
12397
- phone: data.phone
12398
- }
12399
- },
12400
- {
12401
- onSuccess: () => {
12402
- handleSuccess();
12403
- },
12404
- onError: (error) => {
12405
- ui.toast.error(error.message);
12406
- }
12407
- }
12408
- );
12409
- });
12410
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12411
- KeyboundForm,
12412
- {
12413
- className: "flex flex-1 flex-col overflow-hidden",
12414
- onSubmit,
12415
- children: [
12416
- /* @__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: [
12417
- /* @__PURE__ */ jsxRuntime.jsx(
12418
- Form$2.Field,
12419
- {
12420
- control: form.control,
12421
- name: "country_code",
12422
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12423
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12424
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12426
- ] })
12427
- }
12428
- ),
12429
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12430
- /* @__PURE__ */ jsxRuntime.jsx(
12431
- Form$2.Field,
12432
- {
12433
- control: form.control,
12434
- name: "first_name",
12435
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12437
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12438
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12439
- ] })
12440
- }
12441
- ),
12442
- /* @__PURE__ */ jsxRuntime.jsx(
12443
- Form$2.Field,
12444
- {
12445
- control: form.control,
12446
- name: "last_name",
12447
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12451
- ] })
12452
- }
12453
- )
12454
- ] }),
12455
- /* @__PURE__ */ jsxRuntime.jsx(
12456
- Form$2.Field,
12457
- {
12458
- control: form.control,
12459
- name: "company",
12460
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12461
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12462
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12463
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12464
- ] })
12465
- }
12466
- ),
12467
- /* @__PURE__ */ jsxRuntime.jsx(
12468
- Form$2.Field,
12469
- {
12470
- control: form.control,
12471
- name: "address_1",
12472
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12473
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12474
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12475
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12476
- ] })
12477
- }
12478
- ),
12479
- /* @__PURE__ */ jsxRuntime.jsx(
12480
- Form$2.Field,
12481
- {
12482
- control: form.control,
12483
- name: "address_2",
12484
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12485
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12486
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12487
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12488
- ] })
12489
- }
12490
- ),
12491
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12492
- /* @__PURE__ */ jsxRuntime.jsx(
12493
- Form$2.Field,
12494
- {
12495
- control: form.control,
12496
- name: "postal_code",
12497
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12498
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12499
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12500
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12501
- ] })
12502
- }
12503
- ),
12504
- /* @__PURE__ */ jsxRuntime.jsx(
12505
- Form$2.Field,
12506
- {
12507
- control: form.control,
12508
- name: "city",
12509
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12510
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12511
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12512
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12513
- ] })
12514
- }
12515
- )
12516
- ] }),
12517
- /* @__PURE__ */ jsxRuntime.jsx(
12518
- Form$2.Field,
12519
- {
12520
- control: form.control,
12521
- name: "province",
12522
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12523
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12524
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12525
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12526
- ] })
12527
- }
12528
- ),
12529
- /* @__PURE__ */ jsxRuntime.jsx(
12530
- Form$2.Field,
12531
- {
12532
- control: form.control,
12533
- name: "phone",
12534
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12536
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12537
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12538
- ] })
12539
- }
12540
- )
12541
- ] }) }),
12542
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12543
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12544
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12545
- ] }) })
12546
- ]
12547
- }
12548
- ) });
12549
- };
12550
- const schema$2 = addressSchema;
12551
- const TransferOwnership = () => {
12552
- const { id } = reactRouterDom.useParams();
12553
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12554
- fields: "id,customer_id,customer.*"
12555
- });
12556
- if (isError) {
12557
- throw error;
12558
- }
12559
- const isReady = !isPending && !!draft_order;
12474
+ const isReady = !isPending && !!draft_order;
12560
12475
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12561
12476
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12562
12477
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
@@ -13024,26 +12939,111 @@ const Illustration = () => {
13024
12939
  const schema$1 = objectType({
13025
12940
  customer_id: stringType().min(1)
13026
12941
  });
13027
- const CustomItems = () => {
12942
+ const SalesChannel = () => {
12943
+ 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
+ );
12953
+ if (isError) {
12954
+ throw error;
12955
+ }
12956
+ const ISrEADY = !!draft_order && !isPending;
13028
12957
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13029
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
13030
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
12958
+ /* @__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" }) })
12961
+ ] }),
12962
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
13031
12963
  ] });
13032
12964
  };
13033
- const CustomItemsForm = () => {
12965
+ const SalesChannelForm = ({ order }) => {
13034
12966
  const form = reactHookForm.useForm({
12967
+ defaultValues: {
12968
+ sales_channel_id: order.sales_channel_id || ""
12969
+ },
13035
12970
  resolver: zod.zodResolver(schema)
13036
12971
  });
13037
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13038
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
13039
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
13042
- ] }) })
13043
- ] }) });
12972
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12973
+ const { handleSuccess } = useRouteModal();
12974
+ const onSubmit = form.handleSubmit(async (data) => {
12975
+ await mutateAsync(
12976
+ {
12977
+ sales_channel_id: data.sales_channel_id
12978
+ },
12979
+ {
12980
+ onSuccess: () => {
12981
+ ui.toast.success("Sales channel updated");
12982
+ handleSuccess();
12983
+ },
12984
+ onError: (error) => {
12985
+ ui.toast.error(error.message);
12986
+ }
12987
+ }
12988
+ );
12989
+ });
12990
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12991
+ KeyboundForm,
12992
+ {
12993
+ className: "flex flex-1 flex-col overflow-hidden",
12994
+ onSubmit,
12995
+ 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 }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12998
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12999
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13000
+ ] }) })
13001
+ ]
13002
+ }
13003
+ ) });
13004
+ };
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
13044
  };
13045
13045
  const schema = objectType({
13046
- email: stringType().email()
13046
+ sales_channel_id: stringType().min(1)
13047
13047
  });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
@@ -13069,6 +13069,10 @@ const routeModule = {
13069
13069
  Component: BillingAddress,
13070
13070
  path: "/draft-orders/:id/billing-address"
13071
13071
  },
13072
+ {
13073
+ Component: CustomItems,
13074
+ path: "/draft-orders/:id/custom-items"
13075
+ },
13072
13076
  {
13073
13077
  Component: Email,
13074
13078
  path: "/draft-orders/:id/email"
@@ -13086,24 +13090,20 @@ const routeModule = {
13086
13090
  path: "/draft-orders/:id/promotions"
13087
13091
  },
13088
13092
  {
13089
- Component: SalesChannel,
13090
- path: "/draft-orders/:id/sales-channel"
13093
+ Component: ShippingAddress,
13094
+ path: "/draft-orders/:id/shipping-address"
13091
13095
  },
13092
13096
  {
13093
13097
  Component: Shipping,
13094
13098
  path: "/draft-orders/:id/shipping"
13095
13099
  },
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: CustomItems,
13106
- path: "/draft-orders/:id/custom-items"
13105
+ Component: SalesChannel,
13106
+ path: "/draft-orders/:id/sales-channel"
13107
13107
  }
13108
13108
  ]
13109
13109
  }