@medusajs/draft-order 2.10.4-snapshot-20251009080820 → 2.10.4-snapshot-20251009094748

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.
@@ -11453,37 +11453,33 @@ function getPromotionIds(items, shippingMethods) {
11453
11453
  }
11454
11454
  return Array.from(promotionIds);
11455
11455
  }
11456
- const ShippingAddress = () => {
11456
+ const SalesChannel = () => {
11457
11457
  const { id } = reactRouterDom.useParams();
11458
- const { order, isPending, isError, error } = useOrder(id, {
11459
- fields: "+shipping_address"
11460
- });
11458
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11459
+ id,
11460
+ {
11461
+ fields: "+sales_channel_id"
11462
+ },
11463
+ {
11464
+ enabled: !!id
11465
+ }
11466
+ );
11461
11467
  if (isError) {
11462
11468
  throw error;
11463
11469
  }
11464
- const isReady = !isPending && !!order;
11470
+ const ISrEADY = !!draft_order && !isPending;
11465
11471
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11466
11472
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11467
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11468
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11474
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
11475
  ] }),
11470
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11476
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11471
11477
  ] });
11472
11478
  };
11473
- const ShippingAddressForm = ({ order }) => {
11474
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11479
+ const SalesChannelForm = ({ order }) => {
11475
11480
  const form = reactHookForm.useForm({
11476
11481
  defaultValues: {
11477
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11478
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11479
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11480
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11481
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11482
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11483
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11484
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11485
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11486
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11482
+ sales_channel_id: order.sales_channel_id || ""
11487
11483
  },
11488
11484
  resolver: zod.zodResolver(schema$2)
11489
11485
  });
@@ -11492,21 +11488,11 @@ const ShippingAddressForm = ({ order }) => {
11492
11488
  const onSubmit = form.handleSubmit(async (data) => {
11493
11489
  await mutateAsync(
11494
11490
  {
11495
- shipping_address: {
11496
- first_name: data.first_name,
11497
- last_name: data.last_name,
11498
- company: data.company,
11499
- address_1: data.address_1,
11500
- address_2: data.address_2,
11501
- city: data.city,
11502
- province: data.province,
11503
- country_code: data.country_code,
11504
- postal_code: data.postal_code,
11505
- phone: data.phone
11506
- }
11491
+ sales_channel_id: data.sales_channel_id
11507
11492
  },
11508
11493
  {
11509
11494
  onSuccess: () => {
11495
+ ui.toast.success("Sales channel updated");
11510
11496
  handleSuccess();
11511
11497
  },
11512
11498
  onError: (error) => {
@@ -11521,132 +11507,7 @@ const ShippingAddressForm = ({ order }) => {
11521
11507
  className: "flex flex-1 flex-col overflow-hidden",
11522
11508
  onSubmit,
11523
11509
  children: [
11524
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11525
- /* @__PURE__ */ jsxRuntime.jsx(
11526
- Form$2.Field,
11527
- {
11528
- control: form.control,
11529
- name: "country_code",
11530
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11534
- ] })
11535
- }
11536
- ),
11537
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11538
- /* @__PURE__ */ jsxRuntime.jsx(
11539
- Form$2.Field,
11540
- {
11541
- control: form.control,
11542
- name: "first_name",
11543
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11546
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11547
- ] })
11548
- }
11549
- ),
11550
- /* @__PURE__ */ jsxRuntime.jsx(
11551
- Form$2.Field,
11552
- {
11553
- control: form.control,
11554
- name: "last_name",
11555
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11558
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11559
- ] })
11560
- }
11561
- )
11562
- ] }),
11563
- /* @__PURE__ */ jsxRuntime.jsx(
11564
- Form$2.Field,
11565
- {
11566
- control: form.control,
11567
- name: "company",
11568
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11569
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11570
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11571
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11572
- ] })
11573
- }
11574
- ),
11575
- /* @__PURE__ */ jsxRuntime.jsx(
11576
- Form$2.Field,
11577
- {
11578
- control: form.control,
11579
- name: "address_1",
11580
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11581
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11582
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11583
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11584
- ] })
11585
- }
11586
- ),
11587
- /* @__PURE__ */ jsxRuntime.jsx(
11588
- Form$2.Field,
11589
- {
11590
- control: form.control,
11591
- name: "address_2",
11592
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11593
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11594
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11595
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11596
- ] })
11597
- }
11598
- ),
11599
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11600
- /* @__PURE__ */ jsxRuntime.jsx(
11601
- Form$2.Field,
11602
- {
11603
- control: form.control,
11604
- name: "postal_code",
11605
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11606
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11607
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11608
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11609
- ] })
11610
- }
11611
- ),
11612
- /* @__PURE__ */ jsxRuntime.jsx(
11613
- Form$2.Field,
11614
- {
11615
- control: form.control,
11616
- name: "city",
11617
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11619
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11620
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11621
- ] })
11622
- }
11623
- )
11624
- ] }),
11625
- /* @__PURE__ */ jsxRuntime.jsx(
11626
- Form$2.Field,
11627
- {
11628
- control: form.control,
11629
- name: "province",
11630
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11632
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11633
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11634
- ] })
11635
- }
11636
- ),
11637
- /* @__PURE__ */ jsxRuntime.jsx(
11638
- Form$2.Field,
11639
- {
11640
- control: form.control,
11641
- name: "phone",
11642
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11643
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11644
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11645
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11646
- ] })
11647
- }
11648
- )
11649
- ] }) }),
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11650
11511
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11651
11512
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11652
11513
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11655,7 +11516,49 @@ const ShippingAddressForm = ({ order }) => {
11655
11516
  }
11656
11517
  ) });
11657
11518
  };
11658
- const schema$2 = addressSchema;
11519
+ const SalesChannelField = ({ control, order }) => {
11520
+ const salesChannels = useComboboxData({
11521
+ queryFn: async (params) => {
11522
+ return await sdk.admin.salesChannel.list(params);
11523
+ },
11524
+ queryKey: ["sales-channels"],
11525
+ getOptions: (data) => {
11526
+ return data.sales_channels.map((salesChannel) => ({
11527
+ label: salesChannel.name,
11528
+ value: salesChannel.id
11529
+ }));
11530
+ },
11531
+ defaultValue: order.sales_channel_id || void 0
11532
+ });
11533
+ return /* @__PURE__ */ jsxRuntime.jsx(
11534
+ Form$2.Field,
11535
+ {
11536
+ control,
11537
+ name: "sales_channel_id",
11538
+ render: ({ field }) => {
11539
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Combobox,
11543
+ {
11544
+ options: salesChannels.options,
11545
+ fetchNextPage: salesChannels.fetchNextPage,
11546
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
+ searchValue: salesChannels.searchValue,
11548
+ onSearchValueChange: salesChannels.onSearchValueChange,
11549
+ placeholder: "Select sales channel",
11550
+ ...field
11551
+ }
11552
+ ) }),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
+ ] });
11555
+ }
11556
+ }
11557
+ );
11558
+ };
11559
+ const schema$2 = objectType({
11560
+ sales_channel_id: stringType().min(1)
11561
+ });
11659
11562
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11660
11563
  const Shipping = () => {
11661
11564
  var _a;
@@ -12463,147 +12366,41 @@ const CustomAmountField = ({
12463
12366
  }
12464
12367
  );
12465
12368
  };
12466
- const SalesChannel = () => {
12369
+ const TransferOwnership = () => {
12467
12370
  const { id } = reactRouterDom.useParams();
12468
- const { draft_order, isPending, isError, error } = useDraftOrder(
12469
- id,
12470
- {
12471
- fields: "+sales_channel_id"
12472
- },
12473
- {
12474
- enabled: !!id
12475
- }
12476
- );
12371
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12372
+ fields: "id,customer_id,customer.*"
12373
+ });
12477
12374
  if (isError) {
12478
12375
  throw error;
12479
12376
  }
12480
- const ISrEADY = !!draft_order && !isPending;
12377
+ const isReady = !isPending && !!draft_order;
12481
12378
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12482
12379
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12483
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12484
- /* @__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" }) })
12380
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12381
+ /* @__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" }) })
12485
12382
  ] }),
12486
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12383
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12487
12384
  ] });
12488
12385
  };
12489
- const SalesChannelForm = ({ order }) => {
12386
+ const TransferOwnershipForm = ({ order }) => {
12387
+ var _a, _b;
12490
12388
  const form = reactHookForm.useForm({
12491
12389
  defaultValues: {
12492
- sales_channel_id: order.sales_channel_id || ""
12390
+ customer_id: order.customer_id || ""
12493
12391
  },
12494
12392
  resolver: zod.zodResolver(schema$1)
12495
12393
  });
12496
12394
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12497
12395
  const { handleSuccess } = useRouteModal();
12396
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12397
+ const currentCustomer = order.customer ? {
12398
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12399
+ value: order.customer.id
12400
+ } : null;
12498
12401
  const onSubmit = form.handleSubmit(async (data) => {
12499
12402
  await mutateAsync(
12500
- {
12501
- sales_channel_id: data.sales_channel_id
12502
- },
12503
- {
12504
- onSuccess: () => {
12505
- ui.toast.success("Sales channel updated");
12506
- handleSuccess();
12507
- },
12508
- onError: (error) => {
12509
- ui.toast.error(error.message);
12510
- }
12511
- }
12512
- );
12513
- });
12514
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12515
- KeyboundForm,
12516
- {
12517
- className: "flex flex-1 flex-col overflow-hidden",
12518
- onSubmit,
12519
- children: [
12520
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12521
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12522
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12523
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12524
- ] }) })
12525
- ]
12526
- }
12527
- ) });
12528
- };
12529
- const SalesChannelField = ({ control, order }) => {
12530
- const salesChannels = useComboboxData({
12531
- queryFn: async (params) => {
12532
- return await sdk.admin.salesChannel.list(params);
12533
- },
12534
- queryKey: ["sales-channels"],
12535
- getOptions: (data) => {
12536
- return data.sales_channels.map((salesChannel) => ({
12537
- label: salesChannel.name,
12538
- value: salesChannel.id
12539
- }));
12540
- },
12541
- defaultValue: order.sales_channel_id || void 0
12542
- });
12543
- return /* @__PURE__ */ jsxRuntime.jsx(
12544
- Form$2.Field,
12545
- {
12546
- control,
12547
- name: "sales_channel_id",
12548
- render: ({ field }) => {
12549
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12550
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12551
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12552
- Combobox,
12553
- {
12554
- options: salesChannels.options,
12555
- fetchNextPage: salesChannels.fetchNextPage,
12556
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12557
- searchValue: salesChannels.searchValue,
12558
- onSearchValueChange: salesChannels.onSearchValueChange,
12559
- placeholder: "Select sales channel",
12560
- ...field
12561
- }
12562
- ) }),
12563
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12564
- ] });
12565
- }
12566
- }
12567
- );
12568
- };
12569
- const schema$1 = objectType({
12570
- sales_channel_id: stringType().min(1)
12571
- });
12572
- const TransferOwnership = () => {
12573
- const { id } = reactRouterDom.useParams();
12574
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12575
- fields: "id,customer_id,customer.*"
12576
- });
12577
- if (isError) {
12578
- throw error;
12579
- }
12580
- const isReady = !isPending && !!draft_order;
12581
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12582
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12583
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12584
- /* @__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" }) })
12585
- ] }),
12586
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12587
- ] });
12588
- };
12589
- const TransferOwnershipForm = ({ order }) => {
12590
- var _a, _b;
12591
- const form = reactHookForm.useForm({
12592
- defaultValues: {
12593
- customer_id: order.customer_id || ""
12594
- },
12595
- resolver: zod.zodResolver(schema)
12596
- });
12597
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12598
- const { handleSuccess } = useRouteModal();
12599
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12600
- const currentCustomer = order.customer ? {
12601
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12602
- value: order.customer.id
12603
- } : null;
12604
- const onSubmit = form.handleSubmit(async (data) => {
12605
- await mutateAsync(
12606
- { customer_id: data.customer_id },
12403
+ { customer_id: data.customer_id },
12607
12404
  {
12608
12405
  onSuccess: () => {
12609
12406
  ui.toast.success("Customer updated");
@@ -13042,9 +12839,212 @@ const Illustration = () => {
13042
12839
  }
13043
12840
  );
13044
12841
  };
13045
- const schema = objectType({
12842
+ const schema$1 = objectType({
13046
12843
  customer_id: stringType().min(1)
13047
12844
  });
12845
+ const ShippingAddress = () => {
12846
+ const { id } = reactRouterDom.useParams();
12847
+ const { order, isPending, isError, error } = useOrder(id, {
12848
+ fields: "+shipping_address"
12849
+ });
12850
+ if (isError) {
12851
+ throw error;
12852
+ }
12853
+ const isReady = !isPending && !!order;
12854
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12855
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12857
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12858
+ ] }),
12859
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12860
+ ] });
12861
+ };
12862
+ const ShippingAddressForm = ({ order }) => {
12863
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12864
+ const form = reactHookForm.useForm({
12865
+ defaultValues: {
12866
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12867
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12868
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12869
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12870
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12871
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12872
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12873
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12874
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12875
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12876
+ },
12877
+ resolver: zod.zodResolver(schema)
12878
+ });
12879
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12880
+ const { handleSuccess } = useRouteModal();
12881
+ const onSubmit = form.handleSubmit(async (data) => {
12882
+ await mutateAsync(
12883
+ {
12884
+ shipping_address: {
12885
+ first_name: data.first_name,
12886
+ last_name: data.last_name,
12887
+ company: data.company,
12888
+ address_1: data.address_1,
12889
+ address_2: data.address_2,
12890
+ city: data.city,
12891
+ province: data.province,
12892
+ country_code: data.country_code,
12893
+ postal_code: data.postal_code,
12894
+ phone: data.phone
12895
+ }
12896
+ },
12897
+ {
12898
+ onSuccess: () => {
12899
+ handleSuccess();
12900
+ },
12901
+ onError: (error) => {
12902
+ ui.toast.error(error.message);
12903
+ }
12904
+ }
12905
+ );
12906
+ });
12907
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
+ KeyboundForm,
12909
+ {
12910
+ className: "flex flex-1 flex-col overflow-hidden",
12911
+ onSubmit,
12912
+ children: [
12913
+ /* @__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: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "country_code",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
+ /* @__PURE__ */ jsxRuntime.jsx(
12928
+ Form$2.Field,
12929
+ {
12930
+ control: form.control,
12931
+ name: "first_name",
12932
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
+ ] })
12937
+ }
12938
+ ),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "last_name",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ )
12951
+ ] }),
12952
+ /* @__PURE__ */ jsxRuntime.jsx(
12953
+ Form$2.Field,
12954
+ {
12955
+ control: form.control,
12956
+ name: "company",
12957
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
+ ] })
12962
+ }
12963
+ ),
12964
+ /* @__PURE__ */ jsxRuntime.jsx(
12965
+ Form$2.Field,
12966
+ {
12967
+ control: form.control,
12968
+ name: "address_1",
12969
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
+ ] })
12974
+ }
12975
+ ),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "address_2",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsx(
12990
+ Form$2.Field,
12991
+ {
12992
+ control: form.control,
12993
+ name: "postal_code",
12994
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
+ ] })
12999
+ }
13000
+ ),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "city",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ )
13013
+ ] }),
13014
+ /* @__PURE__ */ jsxRuntime.jsx(
13015
+ Form$2.Field,
13016
+ {
13017
+ control: form.control,
13018
+ name: "province",
13019
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
+ ] })
13024
+ }
13025
+ ),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Form$2.Field,
13028
+ {
13029
+ control: form.control,
13030
+ name: "phone",
13031
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
+ ] })
13036
+ }
13037
+ )
13038
+ ] }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
+ ] }) })
13043
+ ]
13044
+ }
13045
+ ) });
13046
+ };
13047
+ const schema = addressSchema;
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13090,20 +13090,20 @@ const routeModule = {
13090
13090
  path: "/draft-orders/:id/promotions"
13091
13091
  },
13092
13092
  {
13093
- Component: ShippingAddress,
13094
- path: "/draft-orders/:id/shipping-address"
13093
+ Component: SalesChannel,
13094
+ path: "/draft-orders/:id/sales-channel"
13095
13095
  },
13096
13096
  {
13097
13097
  Component: Shipping,
13098
13098
  path: "/draft-orders/:id/shipping"
13099
13099
  },
13100
- {
13101
- Component: SalesChannel,
13102
- path: "/draft-orders/:id/sales-channel"
13103
- },
13104
13100
  {
13105
13101
  Component: TransferOwnership,
13106
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
+ },
13104
+ {
13105
+ Component: ShippingAddress,
13106
+ path: "/draft-orders/:id/shipping-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }