@medusajs/draft-order 2.11.2-preview-20251029000331 → 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.
@@ -9565,6 +9565,196 @@ const ID = () => {
9565
9565
  /* @__PURE__ */ jsx(Outlet, {})
9566
9566
  ] });
9567
9567
  };
9568
+ const BillingAddress = () => {
9569
+ const { id } = useParams();
9570
+ const { order, isPending, isError, error } = useOrder(id, {
9571
+ fields: "+billing_address"
9572
+ });
9573
+ if (isError) {
9574
+ throw error;
9575
+ }
9576
+ const isReady = !isPending && !!order;
9577
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9578
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9579
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9580
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9581
+ ] }),
9582
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9583
+ ] });
9584
+ };
9585
+ const BillingAddressForm = ({ order }) => {
9586
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9587
+ const form = useForm({
9588
+ defaultValues: {
9589
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9590
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9591
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9592
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9593
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9594
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9595
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9596
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9597
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9598
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9599
+ },
9600
+ resolver: zodResolver(schema$5)
9601
+ });
9602
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9603
+ const { handleSuccess } = useRouteModal();
9604
+ const onSubmit = form.handleSubmit(async (data) => {
9605
+ await mutateAsync(
9606
+ { billing_address: data },
9607
+ {
9608
+ onSuccess: () => {
9609
+ handleSuccess();
9610
+ },
9611
+ onError: (error) => {
9612
+ toast.error(error.message);
9613
+ }
9614
+ }
9615
+ );
9616
+ });
9617
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9618
+ KeyboundForm,
9619
+ {
9620
+ className: "flex flex-1 flex-col overflow-hidden",
9621
+ onSubmit,
9622
+ children: [
9623
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9624
+ /* @__PURE__ */ jsx(
9625
+ Form$2.Field,
9626
+ {
9627
+ control: form.control,
9628
+ name: "country_code",
9629
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9630
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9631
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9632
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9633
+ ] })
9634
+ }
9635
+ ),
9636
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9637
+ /* @__PURE__ */ jsx(
9638
+ Form$2.Field,
9639
+ {
9640
+ control: form.control,
9641
+ name: "first_name",
9642
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9643
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9644
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9645
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9646
+ ] })
9647
+ }
9648
+ ),
9649
+ /* @__PURE__ */ jsx(
9650
+ Form$2.Field,
9651
+ {
9652
+ control: form.control,
9653
+ name: "last_name",
9654
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9655
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9656
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9657
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9658
+ ] })
9659
+ }
9660
+ )
9661
+ ] }),
9662
+ /* @__PURE__ */ jsx(
9663
+ Form$2.Field,
9664
+ {
9665
+ control: form.control,
9666
+ name: "company",
9667
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9668
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9669
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9670
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9671
+ ] })
9672
+ }
9673
+ ),
9674
+ /* @__PURE__ */ jsx(
9675
+ Form$2.Field,
9676
+ {
9677
+ control: form.control,
9678
+ name: "address_1",
9679
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9680
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9681
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9682
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9683
+ ] })
9684
+ }
9685
+ ),
9686
+ /* @__PURE__ */ jsx(
9687
+ Form$2.Field,
9688
+ {
9689
+ control: form.control,
9690
+ name: "address_2",
9691
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9692
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9693
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9694
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9695
+ ] })
9696
+ }
9697
+ ),
9698
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9699
+ /* @__PURE__ */ jsx(
9700
+ Form$2.Field,
9701
+ {
9702
+ control: form.control,
9703
+ name: "postal_code",
9704
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9705
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9706
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9707
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9708
+ ] })
9709
+ }
9710
+ ),
9711
+ /* @__PURE__ */ jsx(
9712
+ Form$2.Field,
9713
+ {
9714
+ control: form.control,
9715
+ name: "city",
9716
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9717
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9718
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9719
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9720
+ ] })
9721
+ }
9722
+ )
9723
+ ] }),
9724
+ /* @__PURE__ */ jsx(
9725
+ Form$2.Field,
9726
+ {
9727
+ control: form.control,
9728
+ name: "province",
9729
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9730
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9731
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9732
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9733
+ ] })
9734
+ }
9735
+ ),
9736
+ /* @__PURE__ */ jsx(
9737
+ Form$2.Field,
9738
+ {
9739
+ control: form.control,
9740
+ name: "phone",
9741
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9742
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9743
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9744
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9745
+ ] })
9746
+ }
9747
+ )
9748
+ ] }) }),
9749
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9750
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9751
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9752
+ ] }) })
9753
+ ]
9754
+ }
9755
+ ) });
9756
+ };
9757
+ const schema$5 = addressSchema;
9568
9758
  const CustomItems = () => {
9569
9759
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9570
9760
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9573,7 +9763,7 @@ const CustomItems = () => {
9573
9763
  };
9574
9764
  const CustomItemsForm = () => {
9575
9765
  const form = useForm({
9576
- resolver: zodResolver(schema$5)
9766
+ resolver: zodResolver(schema$4)
9577
9767
  });
9578
9768
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9579
9769
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9583,7 +9773,7 @@ const CustomItemsForm = () => {
9583
9773
  ] }) })
9584
9774
  ] }) });
9585
9775
  };
9586
- const schema$5 = objectType({
9776
+ const schema$4 = objectType({
9587
9777
  email: stringType().email()
9588
9778
  });
9589
9779
  const Email = () => {
@@ -9608,7 +9798,7 @@ const EmailForm = ({ order }) => {
9608
9798
  defaultValues: {
9609
9799
  email: order.email ?? ""
9610
9800
  },
9611
- resolver: zodResolver(schema$4)
9801
+ resolver: zodResolver(schema$3)
9612
9802
  });
9613
9803
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9614
9804
  const { handleSuccess } = useRouteModal();
@@ -9651,7 +9841,7 @@ const EmailForm = ({ order }) => {
9651
9841
  }
9652
9842
  ) });
9653
9843
  };
9654
- const schema$4 = objectType({
9844
+ const schema$3 = objectType({
9655
9845
  email: stringType().email()
9656
9846
  });
9657
9847
  const NumberInput = forwardRef(
@@ -11255,46 +11445,60 @@ function getPromotionIds(items, shippingMethods) {
11255
11445
  }
11256
11446
  return Array.from(promotionIds);
11257
11447
  }
11258
- const SalesChannel = () => {
11448
+ const ShippingAddress = () => {
11259
11449
  const { id } = useParams();
11260
- const { draft_order, isPending, isError, error } = useDraftOrder(
11261
- id,
11262
- {
11263
- fields: "+sales_channel_id"
11264
- },
11265
- {
11266
- enabled: !!id
11267
- }
11268
- );
11450
+ const { order, isPending, isError, error } = useOrder(id, {
11451
+ fields: "+shipping_address"
11452
+ });
11269
11453
  if (isError) {
11270
11454
  throw error;
11271
11455
  }
11272
- const ISrEADY = !!draft_order && !isPending;
11456
+ const isReady = !isPending && !!order;
11273
11457
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11274
11458
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11275
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11276
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11459
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11460
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11277
11461
  ] }),
11278
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11462
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11279
11463
  ] });
11280
11464
  };
11281
- const SalesChannelForm = ({ order }) => {
11465
+ const ShippingAddressForm = ({ order }) => {
11466
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11282
11467
  const form = useForm({
11283
11468
  defaultValues: {
11284
- sales_channel_id: order.sales_channel_id || ""
11469
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11470
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11471
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11472
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11473
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11474
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11475
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11476
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11477
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11478
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11285
11479
  },
11286
- resolver: zodResolver(schema$3)
11480
+ resolver: zodResolver(schema$2)
11287
11481
  });
11288
11482
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11289
11483
  const { handleSuccess } = useRouteModal();
11290
11484
  const onSubmit = form.handleSubmit(async (data) => {
11291
11485
  await mutateAsync(
11292
11486
  {
11293
- sales_channel_id: data.sales_channel_id
11487
+ shipping_address: {
11488
+ first_name: data.first_name,
11489
+ last_name: data.last_name,
11490
+ company: data.company,
11491
+ address_1: data.address_1,
11492
+ address_2: data.address_2,
11493
+ city: data.city,
11494
+ province: data.province,
11495
+ country_code: data.country_code,
11496
+ postal_code: data.postal_code,
11497
+ phone: data.phone
11498
+ }
11294
11499
  },
11295
11500
  {
11296
11501
  onSuccess: () => {
11297
- toast.success("Sales channel updated");
11298
11502
  handleSuccess();
11299
11503
  },
11300
11504
  onError: (error) => {
@@ -11309,58 +11513,141 @@ const SalesChannelForm = ({ order }) => {
11309
11513
  className: "flex flex-1 flex-col overflow-hidden",
11310
11514
  onSubmit,
11311
11515
  children: [
11312
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11313
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11314
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11315
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11316
- ] }) })
11317
- ]
11318
- }
11319
- ) });
11320
- };
11321
- const SalesChannelField = ({ control, order }) => {
11322
- const salesChannels = useComboboxData({
11323
- queryFn: async (params) => {
11324
- return await sdk.admin.salesChannel.list(params);
11325
- },
11326
- queryKey: ["sales-channels"],
11327
- getOptions: (data) => {
11328
- return data.sales_channels.map((salesChannel) => ({
11329
- label: salesChannel.name,
11330
- value: salesChannel.id
11331
- }));
11332
- },
11333
- defaultValue: order.sales_channel_id || void 0
11334
- });
11335
- return /* @__PURE__ */ jsx(
11336
- Form$2.Field,
11337
- {
11338
- control,
11339
- name: "sales_channel_id",
11340
- render: ({ field }) => {
11341
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11342
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11343
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11344
- Combobox,
11516
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11517
+ /* @__PURE__ */ jsx(
11518
+ Form$2.Field,
11345
11519
  {
11346
- options: salesChannels.options,
11347
- fetchNextPage: salesChannels.fetchNextPage,
11348
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11349
- searchValue: salesChannels.searchValue,
11350
- onSearchValueChange: salesChannels.onSearchValueChange,
11351
- placeholder: "Select sales channel",
11352
- ...field
11520
+ control: form.control,
11521
+ name: "country_code",
11522
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11523
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11524
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11525
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11526
+ ] })
11353
11527
  }
11354
- ) }),
11355
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11356
- ] });
11357
- }
11528
+ ),
11529
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11530
+ /* @__PURE__ */ jsx(
11531
+ Form$2.Field,
11532
+ {
11533
+ control: form.control,
11534
+ name: "first_name",
11535
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11536
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11537
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11538
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11539
+ ] })
11540
+ }
11541
+ ),
11542
+ /* @__PURE__ */ jsx(
11543
+ Form$2.Field,
11544
+ {
11545
+ control: form.control,
11546
+ name: "last_name",
11547
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11548
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11549
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11550
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11551
+ ] })
11552
+ }
11553
+ )
11554
+ ] }),
11555
+ /* @__PURE__ */ jsx(
11556
+ Form$2.Field,
11557
+ {
11558
+ control: form.control,
11559
+ name: "company",
11560
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11561
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11562
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11563
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11564
+ ] })
11565
+ }
11566
+ ),
11567
+ /* @__PURE__ */ jsx(
11568
+ Form$2.Field,
11569
+ {
11570
+ control: form.control,
11571
+ name: "address_1",
11572
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11573
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11574
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11575
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11576
+ ] })
11577
+ }
11578
+ ),
11579
+ /* @__PURE__ */ jsx(
11580
+ Form$2.Field,
11581
+ {
11582
+ control: form.control,
11583
+ name: "address_2",
11584
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11585
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11586
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11587
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11588
+ ] })
11589
+ }
11590
+ ),
11591
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11592
+ /* @__PURE__ */ jsx(
11593
+ Form$2.Field,
11594
+ {
11595
+ control: form.control,
11596
+ name: "postal_code",
11597
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11598
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11599
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11600
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11601
+ ] })
11602
+ }
11603
+ ),
11604
+ /* @__PURE__ */ jsx(
11605
+ Form$2.Field,
11606
+ {
11607
+ control: form.control,
11608
+ name: "city",
11609
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11610
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11611
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11612
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11613
+ ] })
11614
+ }
11615
+ )
11616
+ ] }),
11617
+ /* @__PURE__ */ jsx(
11618
+ Form$2.Field,
11619
+ {
11620
+ control: form.control,
11621
+ name: "province",
11622
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11623
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11624
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11625
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11626
+ ] })
11627
+ }
11628
+ ),
11629
+ /* @__PURE__ */ jsx(
11630
+ Form$2.Field,
11631
+ {
11632
+ control: form.control,
11633
+ name: "phone",
11634
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11635
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11636
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11637
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11638
+ ] })
11639
+ }
11640
+ )
11641
+ ] }) }),
11642
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11643
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11644
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11645
+ ] }) })
11646
+ ]
11358
11647
  }
11359
- );
11648
+ ) });
11360
11649
  };
11361
- const schema$3 = objectType({
11362
- sales_channel_id: stringType().min(1)
11363
- });
11650
+ const schema$2 = addressSchema;
11364
11651
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11365
11652
  const Shipping = () => {
11366
11653
  var _a;
@@ -12168,60 +12455,44 @@ const CustomAmountField = ({
12168
12455
  }
12169
12456
  );
12170
12457
  };
12171
- const ShippingAddress = () => {
12458
+ const TransferOwnership = () => {
12172
12459
  const { id } = useParams();
12173
- const { order, isPending, isError, error } = useOrder(id, {
12174
- fields: "+shipping_address"
12460
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12461
+ fields: "id,customer_id,customer.*"
12175
12462
  });
12176
12463
  if (isError) {
12177
12464
  throw error;
12178
12465
  }
12179
- const isReady = !isPending && !!order;
12466
+ const isReady = !isPending && !!draft_order;
12180
12467
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12181
12468
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12182
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12183
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12469
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12470
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12184
12471
  ] }),
12185
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12472
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12186
12473
  ] });
12187
12474
  };
12188
- const ShippingAddressForm = ({ order }) => {
12189
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12475
+ const TransferOwnershipForm = ({ order }) => {
12476
+ var _a, _b;
12190
12477
  const form = useForm({
12191
12478
  defaultValues: {
12192
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12193
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12194
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12195
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12196
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12197
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12198
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12199
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12200
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12201
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12479
+ customer_id: order.customer_id || ""
12202
12480
  },
12203
- resolver: zodResolver(schema$2)
12481
+ resolver: zodResolver(schema$1)
12204
12482
  });
12205
12483
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12206
12484
  const { handleSuccess } = useRouteModal();
12485
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12486
+ const currentCustomer = order.customer ? {
12487
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12488
+ value: order.customer.id
12489
+ } : null;
12207
12490
  const onSubmit = form.handleSubmit(async (data) => {
12208
12491
  await mutateAsync(
12209
- {
12210
- shipping_address: {
12211
- first_name: data.first_name,
12212
- last_name: data.last_name,
12213
- company: data.company,
12214
- address_1: data.address_1,
12215
- address_2: data.address_2,
12216
- city: data.city,
12217
- province: data.province,
12218
- country_code: data.country_code,
12219
- postal_code: data.postal_code,
12220
- phone: data.phone
12221
- }
12222
- },
12492
+ { customer_id: data.customer_id },
12223
12493
  {
12224
12494
  onSuccess: () => {
12495
+ toast.success("Customer updated");
12225
12496
  handleSuccess();
12226
12497
  },
12227
12498
  onError: (error) => {
@@ -12236,210 +12507,23 @@ const ShippingAddressForm = ({ order }) => {
12236
12507
  className: "flex flex-1 flex-col overflow-hidden",
12237
12508
  onSubmit,
12238
12509
  children: [
12239
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12510
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12511
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12512
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12513
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12514
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12515
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12516
+ ] }),
12517
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12518
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12519
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12520
+ ] })
12521
+ ] }),
12240
12522
  /* @__PURE__ */ jsx(
12241
- Form$2.Field,
12523
+ CustomerField,
12242
12524
  {
12243
12525
  control: form.control,
12244
- name: "country_code",
12245
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12246
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12247
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12248
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12249
- ] })
12250
- }
12251
- ),
12252
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12253
- /* @__PURE__ */ jsx(
12254
- Form$2.Field,
12255
- {
12256
- control: form.control,
12257
- name: "first_name",
12258
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12259
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12260
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12261
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12262
- ] })
12263
- }
12264
- ),
12265
- /* @__PURE__ */ jsx(
12266
- Form$2.Field,
12267
- {
12268
- control: form.control,
12269
- name: "last_name",
12270
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12271
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12272
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12273
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12274
- ] })
12275
- }
12276
- )
12277
- ] }),
12278
- /* @__PURE__ */ jsx(
12279
- Form$2.Field,
12280
- {
12281
- control: form.control,
12282
- name: "company",
12283
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12284
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12285
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12286
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12287
- ] })
12288
- }
12289
- ),
12290
- /* @__PURE__ */ jsx(
12291
- Form$2.Field,
12292
- {
12293
- control: form.control,
12294
- name: "address_1",
12295
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12296
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12297
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12298
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12299
- ] })
12300
- }
12301
- ),
12302
- /* @__PURE__ */ jsx(
12303
- Form$2.Field,
12304
- {
12305
- control: form.control,
12306
- name: "address_2",
12307
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12308
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12309
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12310
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12311
- ] })
12312
- }
12313
- ),
12314
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12315
- /* @__PURE__ */ jsx(
12316
- Form$2.Field,
12317
- {
12318
- control: form.control,
12319
- name: "postal_code",
12320
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12321
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12322
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12323
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12324
- ] })
12325
- }
12326
- ),
12327
- /* @__PURE__ */ jsx(
12328
- Form$2.Field,
12329
- {
12330
- control: form.control,
12331
- name: "city",
12332
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12333
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12334
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12335
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12336
- ] })
12337
- }
12338
- )
12339
- ] }),
12340
- /* @__PURE__ */ jsx(
12341
- Form$2.Field,
12342
- {
12343
- control: form.control,
12344
- name: "province",
12345
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12346
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12347
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12348
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12349
- ] })
12350
- }
12351
- ),
12352
- /* @__PURE__ */ jsx(
12353
- Form$2.Field,
12354
- {
12355
- control: form.control,
12356
- name: "phone",
12357
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12358
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12359
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12360
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12361
- ] })
12362
- }
12363
- )
12364
- ] }) }),
12365
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12366
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12367
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12368
- ] }) })
12369
- ]
12370
- }
12371
- ) });
12372
- };
12373
- const schema$2 = addressSchema;
12374
- const TransferOwnership = () => {
12375
- const { id } = useParams();
12376
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12377
- fields: "id,customer_id,customer.*"
12378
- });
12379
- if (isError) {
12380
- throw error;
12381
- }
12382
- const isReady = !isPending && !!draft_order;
12383
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12384
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12385
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12386
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12387
- ] }),
12388
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12389
- ] });
12390
- };
12391
- const TransferOwnershipForm = ({ order }) => {
12392
- var _a, _b;
12393
- const form = useForm({
12394
- defaultValues: {
12395
- customer_id: order.customer_id || ""
12396
- },
12397
- resolver: zodResolver(schema$1)
12398
- });
12399
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12400
- const { handleSuccess } = useRouteModal();
12401
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12402
- const currentCustomer = order.customer ? {
12403
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12404
- value: order.customer.id
12405
- } : null;
12406
- const onSubmit = form.handleSubmit(async (data) => {
12407
- await mutateAsync(
12408
- { customer_id: data.customer_id },
12409
- {
12410
- onSuccess: () => {
12411
- toast.success("Customer updated");
12412
- handleSuccess();
12413
- },
12414
- onError: (error) => {
12415
- toast.error(error.message);
12416
- }
12417
- }
12418
- );
12419
- });
12420
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12421
- KeyboundForm,
12422
- {
12423
- className: "flex flex-1 flex-col overflow-hidden",
12424
- onSubmit,
12425
- children: [
12426
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12427
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12428
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12429
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12430
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12431
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12432
- ] }),
12433
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12434
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12435
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12436
- ] })
12437
- ] }),
12438
- /* @__PURE__ */ jsx(
12439
- CustomerField,
12440
- {
12441
- control: form.control,
12442
- currentCustomerId: order.customer_id
12526
+ currentCustomerId: order.customer_id
12443
12527
  }
12444
12528
  )
12445
12529
  ] }),
@@ -12847,37 +12931,33 @@ const Illustration = () => {
12847
12931
  const schema$1 = objectType({
12848
12932
  customer_id: stringType().min(1)
12849
12933
  });
12850
- const BillingAddress = () => {
12934
+ const SalesChannel = () => {
12851
12935
  const { id } = useParams();
12852
- const { order, isPending, isError, error } = useOrder(id, {
12853
- fields: "+billing_address"
12854
- });
12936
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12937
+ id,
12938
+ {
12939
+ fields: "+sales_channel_id"
12940
+ },
12941
+ {
12942
+ enabled: !!id
12943
+ }
12944
+ );
12855
12945
  if (isError) {
12856
12946
  throw error;
12857
12947
  }
12858
- const isReady = !isPending && !!order;
12948
+ const ISrEADY = !!draft_order && !isPending;
12859
12949
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12860
12950
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12861
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12862
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12951
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12952
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12863
12953
  ] }),
12864
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12954
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12865
12955
  ] });
12866
12956
  };
12867
- const BillingAddressForm = ({ order }) => {
12868
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12957
+ const SalesChannelForm = ({ order }) => {
12869
12958
  const form = useForm({
12870
12959
  defaultValues: {
12871
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12872
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12873
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12874
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12875
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12876
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12877
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12878
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12879
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12880
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12960
+ sales_channel_id: order.sales_channel_id || ""
12881
12961
  },
12882
12962
  resolver: zodResolver(schema)
12883
12963
  });
@@ -12885,9 +12965,12 @@ const BillingAddressForm = ({ order }) => {
12885
12965
  const { handleSuccess } = useRouteModal();
12886
12966
  const onSubmit = form.handleSubmit(async (data) => {
12887
12967
  await mutateAsync(
12888
- { billing_address: data },
12968
+ {
12969
+ sales_channel_id: data.sales_channel_id
12970
+ },
12889
12971
  {
12890
12972
  onSuccess: () => {
12973
+ toast.success("Sales channel updated");
12891
12974
  handleSuccess();
12892
12975
  },
12893
12976
  onError: (error) => {
@@ -12902,132 +12985,7 @@ const BillingAddressForm = ({ order }) => {
12902
12985
  className: "flex flex-1 flex-col overflow-hidden",
12903
12986
  onSubmit,
12904
12987
  children: [
12905
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12906
- /* @__PURE__ */ jsx(
12907
- Form$2.Field,
12908
- {
12909
- control: form.control,
12910
- name: "country_code",
12911
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
- ] })
12916
- }
12917
- ),
12918
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
- /* @__PURE__ */ jsx(
12920
- Form$2.Field,
12921
- {
12922
- control: form.control,
12923
- name: "first_name",
12924
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
- ] })
12929
- }
12930
- ),
12931
- /* @__PURE__ */ jsx(
12932
- Form$2.Field,
12933
- {
12934
- control: form.control,
12935
- name: "last_name",
12936
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
- ] })
12941
- }
12942
- )
12943
- ] }),
12944
- /* @__PURE__ */ jsx(
12945
- Form$2.Field,
12946
- {
12947
- control: form.control,
12948
- name: "company",
12949
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
- ] })
12954
- }
12955
- ),
12956
- /* @__PURE__ */ jsx(
12957
- Form$2.Field,
12958
- {
12959
- control: form.control,
12960
- name: "address_1",
12961
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
- ] })
12966
- }
12967
- ),
12968
- /* @__PURE__ */ jsx(
12969
- Form$2.Field,
12970
- {
12971
- control: form.control,
12972
- name: "address_2",
12973
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
- ] })
12978
- }
12979
- ),
12980
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
- /* @__PURE__ */ jsx(
12982
- Form$2.Field,
12983
- {
12984
- control: form.control,
12985
- name: "postal_code",
12986
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
- ] })
12991
- }
12992
- ),
12993
- /* @__PURE__ */ jsx(
12994
- Form$2.Field,
12995
- {
12996
- control: form.control,
12997
- name: "city",
12998
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
- ] })
13003
- }
13004
- )
13005
- ] }),
13006
- /* @__PURE__ */ jsx(
13007
- Form$2.Field,
13008
- {
13009
- control: form.control,
13010
- name: "province",
13011
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
- ] })
13016
- }
13017
- ),
13018
- /* @__PURE__ */ jsx(
13019
- Form$2.Field,
13020
- {
13021
- control: form.control,
13022
- name: "phone",
13023
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
- ] })
13028
- }
13029
- )
13030
- ] }) }),
12988
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
13031
12989
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
12990
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
12991
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13036,7 +12994,49 @@ const BillingAddressForm = ({ order }) => {
13036
12994
  }
13037
12995
  ) });
13038
12996
  };
13039
- const schema = addressSchema;
12997
+ const SalesChannelField = ({ control, order }) => {
12998
+ const salesChannels = useComboboxData({
12999
+ queryFn: async (params) => {
13000
+ return await sdk.admin.salesChannel.list(params);
13001
+ },
13002
+ queryKey: ["sales-channels"],
13003
+ getOptions: (data) => {
13004
+ return data.sales_channels.map((salesChannel) => ({
13005
+ label: salesChannel.name,
13006
+ value: salesChannel.id
13007
+ }));
13008
+ },
13009
+ defaultValue: order.sales_channel_id || void 0
13010
+ });
13011
+ return /* @__PURE__ */ jsx(
13012
+ Form$2.Field,
13013
+ {
13014
+ control,
13015
+ name: "sales_channel_id",
13016
+ render: ({ field }) => {
13017
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13018
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13019
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13020
+ Combobox,
13021
+ {
13022
+ options: salesChannels.options,
13023
+ fetchNextPage: salesChannels.fetchNextPage,
13024
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13025
+ searchValue: salesChannels.searchValue,
13026
+ onSearchValueChange: salesChannels.onSearchValueChange,
13027
+ placeholder: "Select sales channel",
13028
+ ...field
13029
+ }
13030
+ ) }),
13031
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13032
+ ] });
13033
+ }
13034
+ }
13035
+ );
13036
+ };
13037
+ const schema = objectType({
13038
+ sales_channel_id: stringType().min(1)
13039
+ });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13057,6 +13057,10 @@ const routeModule = {
13057
13057
  handle,
13058
13058
  loader,
13059
13059
  children: [
13060
+ {
13061
+ Component: BillingAddress,
13062
+ path: "/draft-orders/:id/billing-address"
13063
+ },
13060
13064
  {
13061
13065
  Component: CustomItems,
13062
13066
  path: "/draft-orders/:id/custom-items"
@@ -13078,24 +13082,20 @@ const routeModule = {
13078
13082
  path: "/draft-orders/:id/promotions"
13079
13083
  },
13080
13084
  {
13081
- Component: SalesChannel,
13082
- path: "/draft-orders/:id/sales-channel"
13085
+ Component: ShippingAddress,
13086
+ path: "/draft-orders/:id/shipping-address"
13083
13087
  },
13084
13088
  {
13085
13089
  Component: Shipping,
13086
13090
  path: "/draft-orders/:id/shipping"
13087
13091
  },
13088
- {
13089
- Component: ShippingAddress,
13090
- path: "/draft-orders/:id/shipping-address"
13091
- },
13092
13092
  {
13093
13093
  Component: TransferOwnership,
13094
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
13095
  },
13096
13096
  {
13097
- Component: BillingAddress,
13098
- path: "/draft-orders/:id/billing-address"
13097
+ Component: SalesChannel,
13098
+ path: "/draft-orders/:id/sales-channel"
13099
13099
  }
13100
13100
  ]
13101
13101
  }