@medusajs/draft-order 2.11.4-preview-20251121060132 → 2.11.4-preview-20251121120142

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.
@@ -9776,74 +9776,6 @@ const CustomItemsForm = () => {
9776
9776
  const schema$4 = objectType({
9777
9777
  email: stringType().email()
9778
9778
  });
9779
- const Email = () => {
9780
- const { id } = useParams();
9781
- const { order, isPending, isError, error } = useOrder(id, {
9782
- fields: "+email"
9783
- });
9784
- if (isError) {
9785
- throw error;
9786
- }
9787
- const isReady = !isPending && !!order;
9788
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9789
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9790
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9791
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9792
- ] }),
9793
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9794
- ] });
9795
- };
9796
- const EmailForm = ({ order }) => {
9797
- const form = useForm({
9798
- defaultValues: {
9799
- email: order.email ?? ""
9800
- },
9801
- resolver: zodResolver(schema$3)
9802
- });
9803
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9804
- const { handleSuccess } = useRouteModal();
9805
- const onSubmit = form.handleSubmit(async (data) => {
9806
- await mutateAsync(
9807
- { email: data.email },
9808
- {
9809
- onSuccess: () => {
9810
- handleSuccess();
9811
- },
9812
- onError: (error) => {
9813
- toast.error(error.message);
9814
- }
9815
- }
9816
- );
9817
- });
9818
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9819
- KeyboundForm,
9820
- {
9821
- className: "flex flex-1 flex-col overflow-hidden",
9822
- onSubmit,
9823
- children: [
9824
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9825
- Form$2.Field,
9826
- {
9827
- control: form.control,
9828
- name: "email",
9829
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9830
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9831
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9832
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9833
- ] })
9834
- }
9835
- ) }),
9836
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9837
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9838
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9839
- ] }) })
9840
- ]
9841
- }
9842
- ) });
9843
- };
9844
- const schema$3 = objectType({
9845
- email: stringType().email()
9846
- });
9847
9779
  const NumberInput = forwardRef(
9848
9780
  ({
9849
9781
  value,
@@ -11473,7 +11405,7 @@ const SalesChannelForm = ({ order }) => {
11473
11405
  defaultValues: {
11474
11406
  sales_channel_id: order.sales_channel_id || ""
11475
11407
  },
11476
- resolver: zodResolver(schema$2)
11408
+ resolver: zodResolver(schema$3)
11477
11409
  });
11478
11410
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
11411
  const { handleSuccess } = useRouteModal();
@@ -11548,7 +11480,7 @@ const SalesChannelField = ({ control, order }) => {
11548
11480
  }
11549
11481
  );
11550
11482
  };
11551
- const schema$2 = objectType({
11483
+ const schema$3 = objectType({
11552
11484
  sales_channel_id: stringType().min(1)
11553
11485
  });
11554
11486
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12358,60 +12290,44 @@ const CustomAmountField = ({
12358
12290
  }
12359
12291
  );
12360
12292
  };
12361
- const ShippingAddress = () => {
12293
+ const TransferOwnership = () => {
12362
12294
  const { id } = useParams();
12363
- const { order, isPending, isError, error } = useOrder(id, {
12364
- fields: "+shipping_address"
12295
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12296
+ fields: "id,customer_id,customer.*"
12365
12297
  });
12366
12298
  if (isError) {
12367
12299
  throw error;
12368
12300
  }
12369
- const isReady = !isPending && !!order;
12301
+ const isReady = !isPending && !!draft_order;
12370
12302
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12371
12303
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12372
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12304
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12305
+ /* @__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" }) })
12374
12306
  ] }),
12375
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12307
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12376
12308
  ] });
12377
12309
  };
12378
- const ShippingAddressForm = ({ order }) => {
12379
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12310
+ const TransferOwnershipForm = ({ order }) => {
12311
+ var _a, _b;
12380
12312
  const form = useForm({
12381
12313
  defaultValues: {
12382
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12314
+ customer_id: order.customer_id || ""
12392
12315
  },
12393
- resolver: zodResolver(schema$1)
12316
+ resolver: zodResolver(schema$2)
12394
12317
  });
12395
12318
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12396
12319
  const { handleSuccess } = useRouteModal();
12320
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12321
+ const currentCustomer = order.customer ? {
12322
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12323
+ value: order.customer.id
12324
+ } : null;
12397
12325
  const onSubmit = form.handleSubmit(async (data) => {
12398
12326
  await mutateAsync(
12399
- {
12400
- shipping_address: {
12401
- first_name: data.first_name,
12402
- last_name: data.last_name,
12403
- company: data.company,
12404
- address_1: data.address_1,
12405
- address_2: data.address_2,
12406
- city: data.city,
12407
- province: data.province,
12408
- country_code: data.country_code,
12409
- postal_code: data.postal_code,
12410
- phone: data.phone
12411
- }
12412
- },
12327
+ { customer_id: data.customer_id },
12413
12328
  {
12414
12329
  onSuccess: () => {
12330
+ toast.success("Customer updated");
12415
12331
  handleSuccess();
12416
12332
  },
12417
12333
  onError: (error) => {
@@ -12426,210 +12342,23 @@ const ShippingAddressForm = ({ order }) => {
12426
12342
  className: "flex flex-1 flex-col overflow-hidden",
12427
12343
  onSubmit,
12428
12344
  children: [
12429
- /* @__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: [
12430
- /* @__PURE__ */ jsx(
12431
- Form$2.Field,
12432
- {
12433
- control: form.control,
12434
- name: "country_code",
12435
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
- ] })
12440
- }
12441
- ),
12442
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
- /* @__PURE__ */ jsx(
12444
- Form$2.Field,
12445
- {
12446
- control: form.control,
12447
- name: "first_name",
12448
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
- ] })
12453
- }
12454
- ),
12455
- /* @__PURE__ */ jsx(
12456
- Form$2.Field,
12457
- {
12458
- control: form.control,
12459
- name: "last_name",
12460
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
- ] })
12465
- }
12466
- )
12467
- ] }),
12468
- /* @__PURE__ */ jsx(
12469
- Form$2.Field,
12470
- {
12471
- control: form.control,
12472
- name: "company",
12473
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
- ] })
12478
- }
12479
- ),
12480
- /* @__PURE__ */ jsx(
12481
- Form$2.Field,
12482
- {
12483
- control: form.control,
12484
- name: "address_1",
12485
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
- ] })
12490
- }
12491
- ),
12492
- /* @__PURE__ */ jsx(
12493
- Form$2.Field,
12494
- {
12495
- control: form.control,
12496
- name: "address_2",
12497
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
- ] })
12502
- }
12503
- ),
12504
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
- /* @__PURE__ */ jsx(
12506
- Form$2.Field,
12507
- {
12508
- control: form.control,
12509
- name: "postal_code",
12510
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
- ] })
12515
- }
12516
- ),
12517
- /* @__PURE__ */ jsx(
12518
- Form$2.Field,
12519
- {
12520
- control: form.control,
12521
- name: "city",
12522
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
- ] })
12527
- }
12528
- )
12345
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12346
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12347
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12348
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12349
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12350
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12351
+ ] }),
12352
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12353
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12354
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12355
+ ] })
12529
12356
  ] }),
12530
12357
  /* @__PURE__ */ jsx(
12531
- Form$2.Field,
12532
- {
12533
- control: form.control,
12534
- name: "province",
12535
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
- ] })
12540
- }
12541
- ),
12542
- /* @__PURE__ */ jsx(
12543
- Form$2.Field,
12358
+ CustomerField,
12544
12359
  {
12545
12360
  control: form.control,
12546
- name: "phone",
12547
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
- ] })
12552
- }
12553
- )
12554
- ] }) }),
12555
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
- ] }) })
12559
- ]
12560
- }
12561
- ) });
12562
- };
12563
- const schema$1 = addressSchema;
12564
- const TransferOwnership = () => {
12565
- const { id } = useParams();
12566
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12567
- fields: "id,customer_id,customer.*"
12568
- });
12569
- if (isError) {
12570
- throw error;
12571
- }
12572
- const isReady = !isPending && !!draft_order;
12573
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12574
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12575
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12576
- /* @__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" }) })
12577
- ] }),
12578
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12579
- ] });
12580
- };
12581
- const TransferOwnershipForm = ({ order }) => {
12582
- var _a, _b;
12583
- const form = useForm({
12584
- defaultValues: {
12585
- customer_id: order.customer_id || ""
12586
- },
12587
- resolver: zodResolver(schema)
12588
- });
12589
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
- const { handleSuccess } = useRouteModal();
12591
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12592
- const currentCustomer = order.customer ? {
12593
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12594
- value: order.customer.id
12595
- } : null;
12596
- const onSubmit = form.handleSubmit(async (data) => {
12597
- await mutateAsync(
12598
- { customer_id: data.customer_id },
12599
- {
12600
- onSuccess: () => {
12601
- toast.success("Customer updated");
12602
- handleSuccess();
12603
- },
12604
- onError: (error) => {
12605
- toast.error(error.message);
12606
- }
12607
- }
12608
- );
12609
- });
12610
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12611
- KeyboundForm,
12612
- {
12613
- className: "flex flex-1 flex-col overflow-hidden",
12614
- onSubmit,
12615
- children: [
12616
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12617
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12618
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12619
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12620
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12621
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12622
- ] }),
12623
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12624
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12625
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12626
- ] })
12627
- ] }),
12628
- /* @__PURE__ */ jsx(
12629
- CustomerField,
12630
- {
12631
- control: form.control,
12632
- currentCustomerId: order.customer_id
12361
+ currentCustomerId: order.customer_id
12633
12362
  }
12634
12363
  )
12635
12364
  ] }),
@@ -13034,9 +12763,280 @@ const Illustration = () => {
13034
12763
  }
13035
12764
  );
13036
12765
  };
13037
- const schema = objectType({
12766
+ const schema$2 = objectType({
13038
12767
  customer_id: stringType().min(1)
13039
12768
  });
12769
+ const ShippingAddress = () => {
12770
+ const { id } = useParams();
12771
+ const { order, isPending, isError, error } = useOrder(id, {
12772
+ fields: "+shipping_address"
12773
+ });
12774
+ if (isError) {
12775
+ throw error;
12776
+ }
12777
+ const isReady = !isPending && !!order;
12778
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12779
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12780
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12781
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12782
+ ] }),
12783
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12784
+ ] });
12785
+ };
12786
+ const ShippingAddressForm = ({ order }) => {
12787
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12788
+ const form = useForm({
12789
+ defaultValues: {
12790
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12791
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12792
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12793
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12794
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12795
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12796
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12797
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12798
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12799
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12800
+ },
12801
+ resolver: zodResolver(schema$1)
12802
+ });
12803
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12804
+ const { handleSuccess } = useRouteModal();
12805
+ const onSubmit = form.handleSubmit(async (data) => {
12806
+ await mutateAsync(
12807
+ {
12808
+ shipping_address: {
12809
+ first_name: data.first_name,
12810
+ last_name: data.last_name,
12811
+ company: data.company,
12812
+ address_1: data.address_1,
12813
+ address_2: data.address_2,
12814
+ city: data.city,
12815
+ province: data.province,
12816
+ country_code: data.country_code,
12817
+ postal_code: data.postal_code,
12818
+ phone: data.phone
12819
+ }
12820
+ },
12821
+ {
12822
+ onSuccess: () => {
12823
+ handleSuccess();
12824
+ },
12825
+ onError: (error) => {
12826
+ toast.error(error.message);
12827
+ }
12828
+ }
12829
+ );
12830
+ });
12831
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12832
+ KeyboundForm,
12833
+ {
12834
+ className: "flex flex-1 flex-col overflow-hidden",
12835
+ onSubmit,
12836
+ children: [
12837
+ /* @__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: [
12838
+ /* @__PURE__ */ jsx(
12839
+ Form$2.Field,
12840
+ {
12841
+ control: form.control,
12842
+ name: "country_code",
12843
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12844
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12845
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12846
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12847
+ ] })
12848
+ }
12849
+ ),
12850
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12851
+ /* @__PURE__ */ jsx(
12852
+ Form$2.Field,
12853
+ {
12854
+ control: form.control,
12855
+ name: "first_name",
12856
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12857
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12858
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12859
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12860
+ ] })
12861
+ }
12862
+ ),
12863
+ /* @__PURE__ */ jsx(
12864
+ Form$2.Field,
12865
+ {
12866
+ control: form.control,
12867
+ name: "last_name",
12868
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12869
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12870
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12871
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12872
+ ] })
12873
+ }
12874
+ )
12875
+ ] }),
12876
+ /* @__PURE__ */ jsx(
12877
+ Form$2.Field,
12878
+ {
12879
+ control: form.control,
12880
+ name: "company",
12881
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12882
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12883
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12884
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12885
+ ] })
12886
+ }
12887
+ ),
12888
+ /* @__PURE__ */ jsx(
12889
+ Form$2.Field,
12890
+ {
12891
+ control: form.control,
12892
+ name: "address_1",
12893
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12894
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12895
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12896
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12897
+ ] })
12898
+ }
12899
+ ),
12900
+ /* @__PURE__ */ jsx(
12901
+ Form$2.Field,
12902
+ {
12903
+ control: form.control,
12904
+ name: "address_2",
12905
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12906
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12907
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12908
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12909
+ ] })
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12913
+ /* @__PURE__ */ jsx(
12914
+ Form$2.Field,
12915
+ {
12916
+ control: form.control,
12917
+ name: "postal_code",
12918
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12919
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12920
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12921
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12922
+ ] })
12923
+ }
12924
+ ),
12925
+ /* @__PURE__ */ jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "city",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12932
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ )
12937
+ ] }),
12938
+ /* @__PURE__ */ jsx(
12939
+ Form$2.Field,
12940
+ {
12941
+ control: form.control,
12942
+ name: "province",
12943
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12944
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12945
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12946
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12947
+ ] })
12948
+ }
12949
+ ),
12950
+ /* @__PURE__ */ jsx(
12951
+ Form$2.Field,
12952
+ {
12953
+ control: form.control,
12954
+ name: "phone",
12955
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12956
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12957
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12958
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12959
+ ] })
12960
+ }
12961
+ )
12962
+ ] }) }),
12963
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12964
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12965
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12966
+ ] }) })
12967
+ ]
12968
+ }
12969
+ ) });
12970
+ };
12971
+ const schema$1 = addressSchema;
12972
+ const Email = () => {
12973
+ const { id } = useParams();
12974
+ const { order, isPending, isError, error } = useOrder(id, {
12975
+ fields: "+email"
12976
+ });
12977
+ if (isError) {
12978
+ throw error;
12979
+ }
12980
+ const isReady = !isPending && !!order;
12981
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12982
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12983
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12984
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12985
+ ] }),
12986
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12987
+ ] });
12988
+ };
12989
+ const EmailForm = ({ order }) => {
12990
+ const form = useForm({
12991
+ defaultValues: {
12992
+ email: order.email ?? ""
12993
+ },
12994
+ resolver: zodResolver(schema)
12995
+ });
12996
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12997
+ const { handleSuccess } = useRouteModal();
12998
+ const onSubmit = form.handleSubmit(async (data) => {
12999
+ await mutateAsync(
13000
+ { email: data.email },
13001
+ {
13002
+ onSuccess: () => {
13003
+ handleSuccess();
13004
+ },
13005
+ onError: (error) => {
13006
+ toast.error(error.message);
13007
+ }
13008
+ }
13009
+ );
13010
+ });
13011
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
13012
+ KeyboundForm,
13013
+ {
13014
+ className: "flex flex-1 flex-col overflow-hidden",
13015
+ onSubmit,
13016
+ children: [
13017
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
13018
+ Form$2.Field,
13019
+ {
13020
+ control: form.control,
13021
+ name: "email",
13022
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13023
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
13024
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13025
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13026
+ ] })
13027
+ }
13028
+ ) }),
13029
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13030
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13031
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13032
+ ] }) })
13033
+ ]
13034
+ }
13035
+ ) });
13036
+ };
13037
+ const schema = objectType({
13038
+ email: stringType().email()
13039
+ });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13065,10 +13065,6 @@ const routeModule = {
13065
13065
  Component: CustomItems,
13066
13066
  path: "/draft-orders/:id/custom-items"
13067
13067
  },
13068
- {
13069
- Component: Email,
13070
- path: "/draft-orders/:id/email"
13071
- },
13072
13068
  {
13073
13069
  Component: Items,
13074
13070
  path: "/draft-orders/:id/items"
@@ -13089,13 +13085,17 @@ const routeModule = {
13089
13085
  Component: Shipping,
13090
13086
  path: "/draft-orders/:id/shipping"
13091
13087
  },
13088
+ {
13089
+ Component: TransferOwnership,
13090
+ path: "/draft-orders/:id/transfer-ownership"
13091
+ },
13092
13092
  {
13093
13093
  Component: ShippingAddress,
13094
13094
  path: "/draft-orders/:id/shipping-address"
13095
13095
  },
13096
13096
  {
13097
- Component: TransferOwnership,
13098
- path: "/draft-orders/:id/transfer-ownership"
13097
+ Component: Email,
13098
+ path: "/draft-orders/:id/email"
13099
13099
  }
13100
13100
  ]
13101
13101
  }