@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.
@@ -9571,6 +9571,196 @@ const ID = () => {
9571
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9572
9572
  ] });
9573
9573
  };
9574
+ const BillingAddress = () => {
9575
+ const { id } = reactRouterDom.useParams();
9576
+ const { order, isPending, isError, error } = useOrder(id, {
9577
+ fields: "+billing_address"
9578
+ });
9579
+ if (isError) {
9580
+ throw error;
9581
+ }
9582
+ const isReady = !isPending && !!order;
9583
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9584
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9585
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9587
+ ] }),
9588
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9589
+ ] });
9590
+ };
9591
+ const BillingAddressForm = ({ order }) => {
9592
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9593
+ const form = reactHookForm.useForm({
9594
+ defaultValues: {
9595
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9596
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9597
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9598
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9599
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9600
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9601
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9602
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9603
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9604
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9605
+ },
9606
+ resolver: zod.zodResolver(schema$5)
9607
+ });
9608
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9609
+ const { handleSuccess } = useRouteModal();
9610
+ const onSubmit = form.handleSubmit(async (data) => {
9611
+ await mutateAsync(
9612
+ { billing_address: data },
9613
+ {
9614
+ onSuccess: () => {
9615
+ handleSuccess();
9616
+ },
9617
+ onError: (error) => {
9618
+ ui.toast.error(error.message);
9619
+ }
9620
+ }
9621
+ );
9622
+ });
9623
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9624
+ KeyboundForm,
9625
+ {
9626
+ className: "flex flex-1 flex-col overflow-hidden",
9627
+ onSubmit,
9628
+ children: [
9629
+ /* @__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: [
9630
+ /* @__PURE__ */ jsxRuntime.jsx(
9631
+ Form$2.Field,
9632
+ {
9633
+ control: form.control,
9634
+ name: "country_code",
9635
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9639
+ ] })
9640
+ }
9641
+ ),
9642
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9643
+ /* @__PURE__ */ jsxRuntime.jsx(
9644
+ Form$2.Field,
9645
+ {
9646
+ control: form.control,
9647
+ name: "first_name",
9648
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9652
+ ] })
9653
+ }
9654
+ ),
9655
+ /* @__PURE__ */ jsxRuntime.jsx(
9656
+ Form$2.Field,
9657
+ {
9658
+ control: form.control,
9659
+ name: "last_name",
9660
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9664
+ ] })
9665
+ }
9666
+ )
9667
+ ] }),
9668
+ /* @__PURE__ */ jsxRuntime.jsx(
9669
+ Form$2.Field,
9670
+ {
9671
+ control: form.control,
9672
+ name: "company",
9673
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9677
+ ] })
9678
+ }
9679
+ ),
9680
+ /* @__PURE__ */ jsxRuntime.jsx(
9681
+ Form$2.Field,
9682
+ {
9683
+ control: form.control,
9684
+ name: "address_1",
9685
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9689
+ ] })
9690
+ }
9691
+ ),
9692
+ /* @__PURE__ */ jsxRuntime.jsx(
9693
+ Form$2.Field,
9694
+ {
9695
+ control: form.control,
9696
+ name: "address_2",
9697
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9701
+ ] })
9702
+ }
9703
+ ),
9704
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9705
+ /* @__PURE__ */ jsxRuntime.jsx(
9706
+ Form$2.Field,
9707
+ {
9708
+ control: form.control,
9709
+ name: "postal_code",
9710
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9714
+ ] })
9715
+ }
9716
+ ),
9717
+ /* @__PURE__ */ jsxRuntime.jsx(
9718
+ Form$2.Field,
9719
+ {
9720
+ control: form.control,
9721
+ name: "city",
9722
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9726
+ ] })
9727
+ }
9728
+ )
9729
+ ] }),
9730
+ /* @__PURE__ */ jsxRuntime.jsx(
9731
+ Form$2.Field,
9732
+ {
9733
+ control: form.control,
9734
+ name: "province",
9735
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9739
+ ] })
9740
+ }
9741
+ ),
9742
+ /* @__PURE__ */ jsxRuntime.jsx(
9743
+ Form$2.Field,
9744
+ {
9745
+ control: form.control,
9746
+ name: "phone",
9747
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9751
+ ] })
9752
+ }
9753
+ )
9754
+ ] }) }),
9755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9757
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9758
+ ] }) })
9759
+ ]
9760
+ }
9761
+ ) });
9762
+ };
9763
+ const schema$5 = addressSchema;
9574
9764
  const CustomItems = () => {
9575
9765
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9576
9766
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9579,7 +9769,7 @@ const CustomItems = () => {
9579
9769
  };
9580
9770
  const CustomItemsForm = () => {
9581
9771
  const form = reactHookForm.useForm({
9582
- resolver: zod.zodResolver(schema$5)
9772
+ resolver: zod.zodResolver(schema$4)
9583
9773
  });
9584
9774
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9585
9775
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9589,7 +9779,7 @@ const CustomItemsForm = () => {
9589
9779
  ] }) })
9590
9780
  ] }) });
9591
9781
  };
9592
- const schema$5 = objectType({
9782
+ const schema$4 = objectType({
9593
9783
  email: stringType().email()
9594
9784
  });
9595
9785
  const Email = () => {
@@ -9614,7 +9804,7 @@ const EmailForm = ({ order }) => {
9614
9804
  defaultValues: {
9615
9805
  email: order.email ?? ""
9616
9806
  },
9617
- resolver: zod.zodResolver(schema$4)
9807
+ resolver: zod.zodResolver(schema$3)
9618
9808
  });
9619
9809
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9620
9810
  const { handleSuccess } = useRouteModal();
@@ -9657,7 +9847,7 @@ const EmailForm = ({ order }) => {
9657
9847
  }
9658
9848
  ) });
9659
9849
  };
9660
- const schema$4 = objectType({
9850
+ const schema$3 = objectType({
9661
9851
  email: stringType().email()
9662
9852
  });
9663
9853
  const NumberInput = React.forwardRef(
@@ -11261,46 +11451,60 @@ function getPromotionIds(items, shippingMethods) {
11261
11451
  }
11262
11452
  return Array.from(promotionIds);
11263
11453
  }
11264
- const SalesChannel = () => {
11454
+ const ShippingAddress = () => {
11265
11455
  const { id } = reactRouterDom.useParams();
11266
- const { draft_order, isPending, isError, error } = useDraftOrder(
11267
- id,
11268
- {
11269
- fields: "+sales_channel_id"
11270
- },
11271
- {
11272
- enabled: !!id
11273
- }
11274
- );
11456
+ const { order, isPending, isError, error } = useOrder(id, {
11457
+ fields: "+shipping_address"
11458
+ });
11275
11459
  if (isError) {
11276
11460
  throw error;
11277
11461
  }
11278
- const ISrEADY = !!draft_order && !isPending;
11462
+ const isReady = !isPending && !!order;
11279
11463
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11280
11464
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11281
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11282
- /* @__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" }) })
11283
11467
  ] }),
11284
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11468
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11285
11469
  ] });
11286
11470
  };
11287
- const SalesChannelForm = ({ order }) => {
11471
+ const ShippingAddressForm = ({ order }) => {
11472
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11288
11473
  const form = reactHookForm.useForm({
11289
11474
  defaultValues: {
11290
- 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) ?? ""
11291
11485
  },
11292
- resolver: zod.zodResolver(schema$3)
11486
+ resolver: zod.zodResolver(schema$2)
11293
11487
  });
11294
11488
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11295
11489
  const { handleSuccess } = useRouteModal();
11296
11490
  const onSubmit = form.handleSubmit(async (data) => {
11297
11491
  await mutateAsync(
11298
11492
  {
11299
- 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
+ }
11300
11505
  },
11301
11506
  {
11302
11507
  onSuccess: () => {
11303
- ui.toast.success("Sales channel updated");
11304
11508
  handleSuccess();
11305
11509
  },
11306
11510
  onError: (error) => {
@@ -11315,58 +11519,141 @@ const SalesChannelForm = ({ order }) => {
11315
11519
  className: "flex flex-1 flex-col overflow-hidden",
11316
11520
  onSubmit,
11317
11521
  children: [
11318
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11319
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11320
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11321
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11322
- ] }) })
11323
- ]
11324
- }
11325
- ) });
11326
- };
11327
- const SalesChannelField = ({ control, order }) => {
11328
- const salesChannels = useComboboxData({
11329
- queryFn: async (params) => {
11330
- return await sdk.admin.salesChannel.list(params);
11331
- },
11332
- queryKey: ["sales-channels"],
11333
- getOptions: (data) => {
11334
- return data.sales_channels.map((salesChannel) => ({
11335
- label: salesChannel.name,
11336
- value: salesChannel.id
11337
- }));
11338
- },
11339
- defaultValue: order.sales_channel_id || void 0
11340
- });
11341
- return /* @__PURE__ */ jsxRuntime.jsx(
11342
- Form$2.Field,
11343
- {
11344
- control,
11345
- name: "sales_channel_id",
11346
- render: ({ field }) => {
11347
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11348
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11349
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11350
- Combobox,
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,
11351
11525
  {
11352
- options: salesChannels.options,
11353
- fetchNextPage: salesChannels.fetchNextPage,
11354
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11355
- searchValue: salesChannels.searchValue,
11356
- onSearchValueChange: salesChannels.onSearchValueChange,
11357
- placeholder: "Select sales channel",
11358
- ...field
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
+ ] })
11359
11533
  }
11360
- ) }),
11361
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11362
- ] });
11363
- }
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
+ ] }) }),
11648
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11649
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11650
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11651
+ ] }) })
11652
+ ]
11364
11653
  }
11365
- );
11654
+ ) });
11366
11655
  };
11367
- const schema$3 = objectType({
11368
- sales_channel_id: stringType().min(1)
11369
- });
11656
+ const schema$2 = addressSchema;
11370
11657
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11371
11658
  const Shipping = () => {
11372
11659
  var _a;
@@ -12174,60 +12461,44 @@ const CustomAmountField = ({
12174
12461
  }
12175
12462
  );
12176
12463
  };
12177
- const ShippingAddress = () => {
12464
+ const TransferOwnership = () => {
12178
12465
  const { id } = reactRouterDom.useParams();
12179
- const { order, isPending, isError, error } = useOrder(id, {
12180
- fields: "+shipping_address"
12466
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12467
+ fields: "id,customer_id,customer.*"
12181
12468
  });
12182
12469
  if (isError) {
12183
12470
  throw error;
12184
12471
  }
12185
- const isReady = !isPending && !!order;
12472
+ const isReady = !isPending && !!draft_order;
12186
12473
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12187
12474
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12188
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12189
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12475
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12476
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12190
12477
  ] }),
12191
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12478
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12192
12479
  ] });
12193
12480
  };
12194
- const ShippingAddressForm = ({ order }) => {
12195
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12481
+ const TransferOwnershipForm = ({ order }) => {
12482
+ var _a, _b;
12196
12483
  const form = reactHookForm.useForm({
12197
12484
  defaultValues: {
12198
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12199
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12200
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12201
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12202
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12203
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12204
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12205
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12206
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12207
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12485
+ customer_id: order.customer_id || ""
12208
12486
  },
12209
- resolver: zod.zodResolver(schema$2)
12487
+ resolver: zod.zodResolver(schema$1)
12210
12488
  });
12211
12489
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12212
12490
  const { handleSuccess } = useRouteModal();
12491
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12492
+ const currentCustomer = order.customer ? {
12493
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12494
+ value: order.customer.id
12495
+ } : null;
12213
12496
  const onSubmit = form.handleSubmit(async (data) => {
12214
12497
  await mutateAsync(
12215
- {
12216
- shipping_address: {
12217
- first_name: data.first_name,
12218
- last_name: data.last_name,
12219
- company: data.company,
12220
- address_1: data.address_1,
12221
- address_2: data.address_2,
12222
- city: data.city,
12223
- province: data.province,
12224
- country_code: data.country_code,
12225
- postal_code: data.postal_code,
12226
- phone: data.phone
12227
- }
12228
- },
12498
+ { customer_id: data.customer_id },
12229
12499
  {
12230
12500
  onSuccess: () => {
12501
+ ui.toast.success("Customer updated");
12231
12502
  handleSuccess();
12232
12503
  },
12233
12504
  onError: (error) => {
@@ -12242,210 +12513,23 @@ const ShippingAddressForm = ({ order }) => {
12242
12513
  className: "flex flex-1 flex-col overflow-hidden",
12243
12514
  onSubmit,
12244
12515
  children: [
12245
- /* @__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: [
12516
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12517
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12518
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12519
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12520
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12521
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12522
+ ] }),
12523
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12524
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12526
+ ] })
12527
+ ] }),
12246
12528
  /* @__PURE__ */ jsxRuntime.jsx(
12247
- Form$2.Field,
12529
+ CustomerField,
12248
12530
  {
12249
12531
  control: form.control,
12250
- name: "country_code",
12251
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12252
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12253
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12254
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12255
- ] })
12256
- }
12257
- ),
12258
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12259
- /* @__PURE__ */ jsxRuntime.jsx(
12260
- Form$2.Field,
12261
- {
12262
- control: form.control,
12263
- name: "first_name",
12264
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12266
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12268
- ] })
12269
- }
12270
- ),
12271
- /* @__PURE__ */ jsxRuntime.jsx(
12272
- Form$2.Field,
12273
- {
12274
- control: form.control,
12275
- name: "last_name",
12276
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12277
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12278
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12280
- ] })
12281
- }
12282
- )
12283
- ] }),
12284
- /* @__PURE__ */ jsxRuntime.jsx(
12285
- Form$2.Field,
12286
- {
12287
- control: form.control,
12288
- name: "company",
12289
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12290
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12291
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12292
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12293
- ] })
12294
- }
12295
- ),
12296
- /* @__PURE__ */ jsxRuntime.jsx(
12297
- Form$2.Field,
12298
- {
12299
- control: form.control,
12300
- name: "address_1",
12301
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12302
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12303
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12305
- ] })
12306
- }
12307
- ),
12308
- /* @__PURE__ */ jsxRuntime.jsx(
12309
- Form$2.Field,
12310
- {
12311
- control: form.control,
12312
- name: "address_2",
12313
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12314
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12315
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12316
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12317
- ] })
12318
- }
12319
- ),
12320
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12321
- /* @__PURE__ */ jsxRuntime.jsx(
12322
- Form$2.Field,
12323
- {
12324
- control: form.control,
12325
- name: "postal_code",
12326
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12330
- ] })
12331
- }
12332
- ),
12333
- /* @__PURE__ */ jsxRuntime.jsx(
12334
- Form$2.Field,
12335
- {
12336
- control: form.control,
12337
- name: "city",
12338
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12342
- ] })
12343
- }
12344
- )
12345
- ] }),
12346
- /* @__PURE__ */ jsxRuntime.jsx(
12347
- Form$2.Field,
12348
- {
12349
- control: form.control,
12350
- name: "province",
12351
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12355
- ] })
12356
- }
12357
- ),
12358
- /* @__PURE__ */ jsxRuntime.jsx(
12359
- Form$2.Field,
12360
- {
12361
- control: form.control,
12362
- name: "phone",
12363
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12367
- ] })
12368
- }
12369
- )
12370
- ] }) }),
12371
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12372
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12373
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12374
- ] }) })
12375
- ]
12376
- }
12377
- ) });
12378
- };
12379
- const schema$2 = addressSchema;
12380
- const TransferOwnership = () => {
12381
- const { id } = reactRouterDom.useParams();
12382
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12383
- fields: "id,customer_id,customer.*"
12384
- });
12385
- if (isError) {
12386
- throw error;
12387
- }
12388
- const isReady = !isPending && !!draft_order;
12389
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12390
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12391
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12392
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12393
- ] }),
12394
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12395
- ] });
12396
- };
12397
- const TransferOwnershipForm = ({ order }) => {
12398
- var _a, _b;
12399
- const form = reactHookForm.useForm({
12400
- defaultValues: {
12401
- customer_id: order.customer_id || ""
12402
- },
12403
- resolver: zod.zodResolver(schema$1)
12404
- });
12405
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12406
- const { handleSuccess } = useRouteModal();
12407
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12408
- const currentCustomer = order.customer ? {
12409
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12410
- value: order.customer.id
12411
- } : null;
12412
- const onSubmit = form.handleSubmit(async (data) => {
12413
- await mutateAsync(
12414
- { customer_id: data.customer_id },
12415
- {
12416
- onSuccess: () => {
12417
- ui.toast.success("Customer updated");
12418
- handleSuccess();
12419
- },
12420
- onError: (error) => {
12421
- ui.toast.error(error.message);
12422
- }
12423
- }
12424
- );
12425
- });
12426
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12427
- KeyboundForm,
12428
- {
12429
- className: "flex flex-1 flex-col overflow-hidden",
12430
- onSubmit,
12431
- children: [
12432
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12433
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12434
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12435
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12437
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12438
- ] }),
12439
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12440
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12441
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12442
- ] })
12443
- ] }),
12444
- /* @__PURE__ */ jsxRuntime.jsx(
12445
- CustomerField,
12446
- {
12447
- control: form.control,
12448
- currentCustomerId: order.customer_id
12532
+ currentCustomerId: order.customer_id
12449
12533
  }
12450
12534
  )
12451
12535
  ] }),
@@ -12853,37 +12937,33 @@ const Illustration = () => {
12853
12937
  const schema$1 = objectType({
12854
12938
  customer_id: stringType().min(1)
12855
12939
  });
12856
- const BillingAddress = () => {
12940
+ const SalesChannel = () => {
12857
12941
  const { id } = reactRouterDom.useParams();
12858
- const { order, isPending, isError, error } = useOrder(id, {
12859
- fields: "+billing_address"
12860
- });
12942
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12943
+ id,
12944
+ {
12945
+ fields: "+sales_channel_id"
12946
+ },
12947
+ {
12948
+ enabled: !!id
12949
+ }
12950
+ );
12861
12951
  if (isError) {
12862
12952
  throw error;
12863
12953
  }
12864
- const isReady = !isPending && !!order;
12954
+ const ISrEADY = !!draft_order && !isPending;
12865
12955
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12866
12956
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12867
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12868
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
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" }) })
12869
12959
  ] }),
12870
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12960
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12871
12961
  ] });
12872
12962
  };
12873
- const BillingAddressForm = ({ order }) => {
12874
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12963
+ const SalesChannelForm = ({ order }) => {
12875
12964
  const form = reactHookForm.useForm({
12876
12965
  defaultValues: {
12877
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12878
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12879
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12880
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12881
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12882
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12883
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12884
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12885
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12886
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12966
+ sales_channel_id: order.sales_channel_id || ""
12887
12967
  },
12888
12968
  resolver: zod.zodResolver(schema)
12889
12969
  });
@@ -12891,9 +12971,12 @@ const BillingAddressForm = ({ order }) => {
12891
12971
  const { handleSuccess } = useRouteModal();
12892
12972
  const onSubmit = form.handleSubmit(async (data) => {
12893
12973
  await mutateAsync(
12894
- { billing_address: data },
12974
+ {
12975
+ sales_channel_id: data.sales_channel_id
12976
+ },
12895
12977
  {
12896
12978
  onSuccess: () => {
12979
+ ui.toast.success("Sales channel updated");
12897
12980
  handleSuccess();
12898
12981
  },
12899
12982
  onError: (error) => {
@@ -12908,132 +12991,7 @@ const BillingAddressForm = ({ order }) => {
12908
12991
  className: "flex flex-1 flex-col overflow-hidden",
12909
12992
  onSubmit,
12910
12993
  children: [
12911
- /* @__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: [
12912
- /* @__PURE__ */ jsxRuntime.jsx(
12913
- Form$2.Field,
12914
- {
12915
- control: form.control,
12916
- name: "country_code",
12917
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12918
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12919
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12921
- ] })
12922
- }
12923
- ),
12924
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12925
- /* @__PURE__ */ jsxRuntime.jsx(
12926
- Form$2.Field,
12927
- {
12928
- control: form.control,
12929
- name: "first_name",
12930
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12931
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12934
- ] })
12935
- }
12936
- ),
12937
- /* @__PURE__ */ jsxRuntime.jsx(
12938
- Form$2.Field,
12939
- {
12940
- control: form.control,
12941
- name: "last_name",
12942
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12943
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12944
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
- ] })
12947
- }
12948
- )
12949
- ] }),
12950
- /* @__PURE__ */ jsxRuntime.jsx(
12951
- Form$2.Field,
12952
- {
12953
- control: form.control,
12954
- name: "company",
12955
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12956
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
- ] })
12960
- }
12961
- ),
12962
- /* @__PURE__ */ jsxRuntime.jsx(
12963
- Form$2.Field,
12964
- {
12965
- control: form.control,
12966
- name: "address_1",
12967
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12968
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12971
- ] })
12972
- }
12973
- ),
12974
- /* @__PURE__ */ jsxRuntime.jsx(
12975
- Form$2.Field,
12976
- {
12977
- control: form.control,
12978
- name: "address_2",
12979
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12980
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12981
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12983
- ] })
12984
- }
12985
- ),
12986
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12987
- /* @__PURE__ */ jsxRuntime.jsx(
12988
- Form$2.Field,
12989
- {
12990
- control: form.control,
12991
- name: "postal_code",
12992
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12993
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12994
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12996
- ] })
12997
- }
12998
- ),
12999
- /* @__PURE__ */ jsxRuntime.jsx(
13000
- Form$2.Field,
13001
- {
13002
- control: form.control,
13003
- name: "city",
13004
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13005
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13006
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
- ] })
13009
- }
13010
- )
13011
- ] }),
13012
- /* @__PURE__ */ jsxRuntime.jsx(
13013
- Form$2.Field,
13014
- {
13015
- control: form.control,
13016
- name: "province",
13017
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
- ] })
13022
- }
13023
- ),
13024
- /* @__PURE__ */ jsxRuntime.jsx(
13025
- Form$2.Field,
13026
- {
13027
- control: form.control,
13028
- name: "phone",
13029
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
- ] })
13034
- }
13035
- )
13036
- ] }) }),
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 }) }),
13037
12995
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
12996
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
12997
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13042,7 +13000,49 @@ const BillingAddressForm = ({ order }) => {
13042
13000
  }
13043
13001
  ) });
13044
13002
  };
13045
- const schema = addressSchema;
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
+ };
13043
+ const schema = objectType({
13044
+ sales_channel_id: stringType().min(1)
13045
+ });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13063,6 +13063,10 @@ const routeModule = {
13063
13063
  handle,
13064
13064
  loader,
13065
13065
  children: [
13066
+ {
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13069
+ },
13066
13070
  {
13067
13071
  Component: CustomItems,
13068
13072
  path: "/draft-orders/:id/custom-items"
@@ -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: BillingAddress,
13104
- path: "/draft-orders/:id/billing-address"
13103
+ Component: SalesChannel,
13104
+ path: "/draft-orders/:id/sales-channel"
13105
13105
  }
13106
13106
  ]
13107
13107
  }