@medusajs/draft-order 2.11.2-preview-20251028210149 → 2.11.2-preview-20251029032258

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.
@@ -9761,6 +9761,27 @@ const BillingAddressForm = ({ order }) => {
9761
9761
  ) });
9762
9762
  };
9763
9763
  const schema$5 = addressSchema;
9764
+ const CustomItems = () => {
9765
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9766
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9767
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9768
+ ] });
9769
+ };
9770
+ const CustomItemsForm = () => {
9771
+ const form = reactHookForm.useForm({
9772
+ resolver: zod.zodResolver(schema$4)
9773
+ });
9774
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9775
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9776
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9778
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9779
+ ] }) })
9780
+ ] }) });
9781
+ };
9782
+ const schema$4 = objectType({
9783
+ email: stringType().email()
9784
+ });
9764
9785
  const Email = () => {
9765
9786
  const { id } = reactRouterDom.useParams();
9766
9787
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9783,7 +9804,7 @@ const EmailForm = ({ order }) => {
9783
9804
  defaultValues: {
9784
9805
  email: order.email ?? ""
9785
9806
  },
9786
- resolver: zod.zodResolver(schema$4)
9807
+ resolver: zod.zodResolver(schema$3)
9787
9808
  });
9788
9809
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9789
9810
  const { handleSuccess } = useRouteModal();
@@ -9826,7 +9847,7 @@ const EmailForm = ({ order }) => {
9826
9847
  }
9827
9848
  ) });
9828
9849
  };
9829
- const schema$4 = objectType({
9850
+ const schema$3 = objectType({
9830
9851
  email: stringType().email()
9831
9852
  });
9832
9853
  const NumberInput = React.forwardRef(
@@ -11430,46 +11451,60 @@ function getPromotionIds(items, shippingMethods) {
11430
11451
  }
11431
11452
  return Array.from(promotionIds);
11432
11453
  }
11433
- const SalesChannel = () => {
11454
+ const ShippingAddress = () => {
11434
11455
  const { id } = reactRouterDom.useParams();
11435
- const { draft_order, isPending, isError, error } = useDraftOrder(
11436
- id,
11437
- {
11438
- fields: "+sales_channel_id"
11439
- },
11440
- {
11441
- enabled: !!id
11442
- }
11443
- );
11456
+ const { order, isPending, isError, error } = useOrder(id, {
11457
+ fields: "+shipping_address"
11458
+ });
11444
11459
  if (isError) {
11445
11460
  throw error;
11446
11461
  }
11447
- const ISrEADY = !!draft_order && !isPending;
11462
+ const isReady = !isPending && !!order;
11448
11463
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11449
11464
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11450
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11451
- /* @__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" }) })
11465
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11466
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11452
11467
  ] }),
11453
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11468
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11454
11469
  ] });
11455
11470
  };
11456
- const SalesChannelForm = ({ order }) => {
11471
+ const ShippingAddressForm = ({ order }) => {
11472
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11457
11473
  const form = reactHookForm.useForm({
11458
11474
  defaultValues: {
11459
- sales_channel_id: order.sales_channel_id || ""
11475
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11476
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11477
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11478
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11479
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11480
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11481
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11482
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11483
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11484
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11460
11485
  },
11461
- resolver: zod.zodResolver(schema$3)
11486
+ resolver: zod.zodResolver(schema$2)
11462
11487
  });
11463
11488
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11464
11489
  const { handleSuccess } = useRouteModal();
11465
11490
  const onSubmit = form.handleSubmit(async (data) => {
11466
11491
  await mutateAsync(
11467
11492
  {
11468
- sales_channel_id: data.sales_channel_id
11493
+ shipping_address: {
11494
+ first_name: data.first_name,
11495
+ last_name: data.last_name,
11496
+ company: data.company,
11497
+ address_1: data.address_1,
11498
+ address_2: data.address_2,
11499
+ city: data.city,
11500
+ province: data.province,
11501
+ country_code: data.country_code,
11502
+ postal_code: data.postal_code,
11503
+ phone: data.phone
11504
+ }
11469
11505
  },
11470
11506
  {
11471
11507
  onSuccess: () => {
11472
- ui.toast.success("Sales channel updated");
11473
11508
  handleSuccess();
11474
11509
  },
11475
11510
  onError: (error) => {
@@ -11484,7 +11519,132 @@ const SalesChannelForm = ({ order }) => {
11484
11519
  className: "flex flex-1 flex-col overflow-hidden",
11485
11520
  onSubmit,
11486
11521
  children: [
11487
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11522
+ /* @__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: [
11523
+ /* @__PURE__ */ jsxRuntime.jsx(
11524
+ Form$2.Field,
11525
+ {
11526
+ control: form.control,
11527
+ name: "country_code",
11528
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11529
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11530
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11532
+ ] })
11533
+ }
11534
+ ),
11535
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11536
+ /* @__PURE__ */ jsxRuntime.jsx(
11537
+ Form$2.Field,
11538
+ {
11539
+ control: form.control,
11540
+ name: "first_name",
11541
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11542
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11545
+ ] })
11546
+ }
11547
+ ),
11548
+ /* @__PURE__ */ jsxRuntime.jsx(
11549
+ Form$2.Field,
11550
+ {
11551
+ control: form.control,
11552
+ name: "last_name",
11553
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11557
+ ] })
11558
+ }
11559
+ )
11560
+ ] }),
11561
+ /* @__PURE__ */ jsxRuntime.jsx(
11562
+ Form$2.Field,
11563
+ {
11564
+ control: form.control,
11565
+ name: "company",
11566
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11567
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11568
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11569
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11570
+ ] })
11571
+ }
11572
+ ),
11573
+ /* @__PURE__ */ jsxRuntime.jsx(
11574
+ Form$2.Field,
11575
+ {
11576
+ control: form.control,
11577
+ name: "address_1",
11578
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11579
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11580
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11581
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11582
+ ] })
11583
+ }
11584
+ ),
11585
+ /* @__PURE__ */ jsxRuntime.jsx(
11586
+ Form$2.Field,
11587
+ {
11588
+ control: form.control,
11589
+ name: "address_2",
11590
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11591
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11592
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11593
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11594
+ ] })
11595
+ }
11596
+ ),
11597
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11598
+ /* @__PURE__ */ jsxRuntime.jsx(
11599
+ Form$2.Field,
11600
+ {
11601
+ control: form.control,
11602
+ name: "postal_code",
11603
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11604
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11605
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11606
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11607
+ ] })
11608
+ }
11609
+ ),
11610
+ /* @__PURE__ */ jsxRuntime.jsx(
11611
+ Form$2.Field,
11612
+ {
11613
+ control: form.control,
11614
+ name: "city",
11615
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11616
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11617
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11618
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11619
+ ] })
11620
+ }
11621
+ )
11622
+ ] }),
11623
+ /* @__PURE__ */ jsxRuntime.jsx(
11624
+ Form$2.Field,
11625
+ {
11626
+ control: form.control,
11627
+ name: "province",
11628
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11629
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11630
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11631
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11632
+ ] })
11633
+ }
11634
+ ),
11635
+ /* @__PURE__ */ jsxRuntime.jsx(
11636
+ Form$2.Field,
11637
+ {
11638
+ control: form.control,
11639
+ name: "phone",
11640
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11641
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11642
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11643
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11644
+ ] })
11645
+ }
11646
+ )
11647
+ ] }) }),
11488
11648
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11489
11649
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11490
11650
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11493,49 +11653,7 @@ const SalesChannelForm = ({ order }) => {
11493
11653
  }
11494
11654
  ) });
11495
11655
  };
11496
- const SalesChannelField = ({ control, order }) => {
11497
- const salesChannels = useComboboxData({
11498
- queryFn: async (params) => {
11499
- return await sdk.admin.salesChannel.list(params);
11500
- },
11501
- queryKey: ["sales-channels"],
11502
- getOptions: (data) => {
11503
- return data.sales_channels.map((salesChannel) => ({
11504
- label: salesChannel.name,
11505
- value: salesChannel.id
11506
- }));
11507
- },
11508
- defaultValue: order.sales_channel_id || void 0
11509
- });
11510
- return /* @__PURE__ */ jsxRuntime.jsx(
11511
- Form$2.Field,
11512
- {
11513
- control,
11514
- name: "sales_channel_id",
11515
- render: ({ field }) => {
11516
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11517
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11518
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11519
- Combobox,
11520
- {
11521
- options: salesChannels.options,
11522
- fetchNextPage: salesChannels.fetchNextPage,
11523
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11524
- searchValue: salesChannels.searchValue,
11525
- onSearchValueChange: salesChannels.onSearchValueChange,
11526
- placeholder: "Select sales channel",
11527
- ...field
11528
- }
11529
- ) }),
11530
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11531
- ] });
11532
- }
11533
- }
11534
- );
11535
- };
11536
- const schema$3 = objectType({
11537
- sales_channel_id: stringType().min(1)
11538
- });
11656
+ const schema$2 = addressSchema;
11539
11657
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11540
11658
  const Shipping = () => {
11541
11659
  var _a;
@@ -12343,218 +12461,15 @@ const CustomAmountField = ({
12343
12461
  }
12344
12462
  );
12345
12463
  };
12346
- const ShippingAddress = () => {
12464
+ const TransferOwnership = () => {
12347
12465
  const { id } = reactRouterDom.useParams();
12348
- const { order, isPending, isError, error } = useOrder(id, {
12349
- fields: "+shipping_address"
12466
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12467
+ fields: "id,customer_id,customer.*"
12350
12468
  });
12351
12469
  if (isError) {
12352
12470
  throw error;
12353
12471
  }
12354
- const isReady = !isPending && !!order;
12355
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12356
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12357
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12358
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12359
- ] }),
12360
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12361
- ] });
12362
- };
12363
- const ShippingAddressForm = ({ order }) => {
12364
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12365
- const form = reactHookForm.useForm({
12366
- defaultValues: {
12367
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12368
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12369
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12370
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12371
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12372
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12373
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12374
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12375
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12376
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12377
- },
12378
- resolver: zod.zodResolver(schema$2)
12379
- });
12380
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12381
- const { handleSuccess } = useRouteModal();
12382
- const onSubmit = form.handleSubmit(async (data) => {
12383
- await mutateAsync(
12384
- {
12385
- shipping_address: {
12386
- first_name: data.first_name,
12387
- last_name: data.last_name,
12388
- company: data.company,
12389
- address_1: data.address_1,
12390
- address_2: data.address_2,
12391
- city: data.city,
12392
- province: data.province,
12393
- country_code: data.country_code,
12394
- postal_code: data.postal_code,
12395
- phone: data.phone
12396
- }
12397
- },
12398
- {
12399
- onSuccess: () => {
12400
- handleSuccess();
12401
- },
12402
- onError: (error) => {
12403
- ui.toast.error(error.message);
12404
- }
12405
- }
12406
- );
12407
- });
12408
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12409
- KeyboundForm,
12410
- {
12411
- className: "flex flex-1 flex-col overflow-hidden",
12412
- onSubmit,
12413
- children: [
12414
- /* @__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: [
12415
- /* @__PURE__ */ jsxRuntime.jsx(
12416
- Form$2.Field,
12417
- {
12418
- control: form.control,
12419
- name: "country_code",
12420
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12421
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12422
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12423
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12424
- ] })
12425
- }
12426
- ),
12427
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12428
- /* @__PURE__ */ jsxRuntime.jsx(
12429
- Form$2.Field,
12430
- {
12431
- control: form.control,
12432
- name: "first_name",
12433
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12434
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12435
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12436
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12437
- ] })
12438
- }
12439
- ),
12440
- /* @__PURE__ */ jsxRuntime.jsx(
12441
- Form$2.Field,
12442
- {
12443
- control: form.control,
12444
- name: "last_name",
12445
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12446
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12449
- ] })
12450
- }
12451
- )
12452
- ] }),
12453
- /* @__PURE__ */ jsxRuntime.jsx(
12454
- Form$2.Field,
12455
- {
12456
- control: form.control,
12457
- name: "company",
12458
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12459
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12461
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12462
- ] })
12463
- }
12464
- ),
12465
- /* @__PURE__ */ jsxRuntime.jsx(
12466
- Form$2.Field,
12467
- {
12468
- control: form.control,
12469
- name: "address_1",
12470
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12471
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12473
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12474
- ] })
12475
- }
12476
- ),
12477
- /* @__PURE__ */ jsxRuntime.jsx(
12478
- Form$2.Field,
12479
- {
12480
- control: form.control,
12481
- name: "address_2",
12482
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12484
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12485
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12486
- ] })
12487
- }
12488
- ),
12489
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12490
- /* @__PURE__ */ jsxRuntime.jsx(
12491
- Form$2.Field,
12492
- {
12493
- control: form.control,
12494
- name: "postal_code",
12495
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12496
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12497
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12498
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12499
- ] })
12500
- }
12501
- ),
12502
- /* @__PURE__ */ jsxRuntime.jsx(
12503
- Form$2.Field,
12504
- {
12505
- control: form.control,
12506
- name: "city",
12507
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12508
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12509
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12510
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12511
- ] })
12512
- }
12513
- )
12514
- ] }),
12515
- /* @__PURE__ */ jsxRuntime.jsx(
12516
- Form$2.Field,
12517
- {
12518
- control: form.control,
12519
- name: "province",
12520
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12521
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12522
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12523
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12524
- ] })
12525
- }
12526
- ),
12527
- /* @__PURE__ */ jsxRuntime.jsx(
12528
- Form$2.Field,
12529
- {
12530
- control: form.control,
12531
- name: "phone",
12532
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12534
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12536
- ] })
12537
- }
12538
- )
12539
- ] }) }),
12540
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12541
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12542
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12543
- ] }) })
12544
- ]
12545
- }
12546
- ) });
12547
- };
12548
- const schema$2 = addressSchema;
12549
- const TransferOwnership = () => {
12550
- const { id } = reactRouterDom.useParams();
12551
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12552
- fields: "id,customer_id,customer.*"
12553
- });
12554
- if (isError) {
12555
- throw error;
12556
- }
12557
- const isReady = !isPending && !!draft_order;
12472
+ const isReady = !isPending && !!draft_order;
12558
12473
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12559
12474
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12560
12475
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
@@ -13022,26 +12937,111 @@ const Illustration = () => {
13022
12937
  const schema$1 = objectType({
13023
12938
  customer_id: stringType().min(1)
13024
12939
  });
13025
- const CustomItems = () => {
12940
+ const SalesChannel = () => {
12941
+ const { id } = reactRouterDom.useParams();
12942
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12943
+ id,
12944
+ {
12945
+ fields: "+sales_channel_id"
12946
+ },
12947
+ {
12948
+ enabled: !!id
12949
+ }
12950
+ );
12951
+ if (isError) {
12952
+ throw error;
12953
+ }
12954
+ const ISrEADY = !!draft_order && !isPending;
13026
12955
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13027
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
13028
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
12956
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12958
+ /* @__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" }) })
12959
+ ] }),
12960
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
13029
12961
  ] });
13030
12962
  };
13031
- const CustomItemsForm = () => {
12963
+ const SalesChannelForm = ({ order }) => {
13032
12964
  const form = reactHookForm.useForm({
12965
+ defaultValues: {
12966
+ sales_channel_id: order.sales_channel_id || ""
12967
+ },
13033
12968
  resolver: zod.zodResolver(schema)
13034
12969
  });
13035
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13036
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
13037
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
13040
- ] }) })
13041
- ] }) });
12970
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12971
+ const { handleSuccess } = useRouteModal();
12972
+ const onSubmit = form.handleSubmit(async (data) => {
12973
+ await mutateAsync(
12974
+ {
12975
+ sales_channel_id: data.sales_channel_id
12976
+ },
12977
+ {
12978
+ onSuccess: () => {
12979
+ ui.toast.success("Sales channel updated");
12980
+ handleSuccess();
12981
+ },
12982
+ onError: (error) => {
12983
+ ui.toast.error(error.message);
12984
+ }
12985
+ }
12986
+ );
12987
+ });
12988
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12989
+ KeyboundForm,
12990
+ {
12991
+ className: "flex flex-1 flex-col overflow-hidden",
12992
+ onSubmit,
12993
+ children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12996
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12998
+ ] }) })
12999
+ ]
13000
+ }
13001
+ ) });
13002
+ };
13003
+ const SalesChannelField = ({ control, order }) => {
13004
+ const salesChannels = useComboboxData({
13005
+ queryFn: async (params) => {
13006
+ return await sdk.admin.salesChannel.list(params);
13007
+ },
13008
+ queryKey: ["sales-channels"],
13009
+ getOptions: (data) => {
13010
+ return data.sales_channels.map((salesChannel) => ({
13011
+ label: salesChannel.name,
13012
+ value: salesChannel.id
13013
+ }));
13014
+ },
13015
+ defaultValue: order.sales_channel_id || void 0
13016
+ });
13017
+ return /* @__PURE__ */ jsxRuntime.jsx(
13018
+ Form$2.Field,
13019
+ {
13020
+ control,
13021
+ name: "sales_channel_id",
13022
+ render: ({ field }) => {
13023
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13024
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13025
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Combobox,
13027
+ {
13028
+ options: salesChannels.options,
13029
+ fetchNextPage: salesChannels.fetchNextPage,
13030
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13031
+ searchValue: salesChannels.searchValue,
13032
+ onSearchValueChange: salesChannels.onSearchValueChange,
13033
+ placeholder: "Select sales channel",
13034
+ ...field
13035
+ }
13036
+ ) }),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13038
+ ] });
13039
+ }
13040
+ }
13041
+ );
13042
13042
  };
13043
13043
  const schema = objectType({
13044
- email: stringType().email()
13044
+ sales_channel_id: stringType().min(1)
13045
13045
  });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
@@ -13067,6 +13067,10 @@ const routeModule = {
13067
13067
  Component: BillingAddress,
13068
13068
  path: "/draft-orders/:id/billing-address"
13069
13069
  },
13070
+ {
13071
+ Component: CustomItems,
13072
+ path: "/draft-orders/:id/custom-items"
13073
+ },
13070
13074
  {
13071
13075
  Component: Email,
13072
13076
  path: "/draft-orders/:id/email"
@@ -13084,24 +13088,20 @@ const routeModule = {
13084
13088
  path: "/draft-orders/:id/promotions"
13085
13089
  },
13086
13090
  {
13087
- Component: SalesChannel,
13088
- path: "/draft-orders/:id/sales-channel"
13091
+ Component: ShippingAddress,
13092
+ path: "/draft-orders/:id/shipping-address"
13089
13093
  },
13090
13094
  {
13091
13095
  Component: Shipping,
13092
13096
  path: "/draft-orders/:id/shipping"
13093
13097
  },
13094
- {
13095
- Component: ShippingAddress,
13096
- path: "/draft-orders/:id/shipping-address"
13097
- },
13098
13098
  {
13099
13099
  Component: TransferOwnership,
13100
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
13101
  },
13102
13102
  {
13103
- Component: CustomItems,
13104
- path: "/draft-orders/:id/custom-items"
13103
+ Component: SalesChannel,
13104
+ path: "/draft-orders/:id/sales-channel"
13105
13105
  }
13106
13106
  ]
13107
13107
  }