OrderReview.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. "use client";
  2. import { useForm } from "react-hook-form";
  3. import {
  4. AddressDataTypes,
  5. } from "@/types/types";
  6. import { isObject } from "@/utils/type-guards";
  7. import { useCheckout } from "@utils/hooks/useCheckout";
  8. import { ProceedToCheckout } from "../ProceedToCheckout";
  9. export default function OrderReview({
  10. selectedPaymentTitle,
  11. shippingAddress,
  12. billingAddress,
  13. selectedShipping : _selectedShipping,
  14. selectedShippingRateTitle,
  15. }: {
  16. selectedPaymentTitle?: string;
  17. shippingAddress?: AddressDataTypes;
  18. billingAddress?: AddressDataTypes;
  19. selectedShipping?: string;
  20. selectedShippingRateTitle?: string;
  21. }) {
  22. const { isPlaceOrder, savePlaceOrder } = useCheckout();
  23. const { handleSubmit } = useForm();
  24. const onSubmit = () => {
  25. savePlaceOrder();
  26. };
  27. return (
  28. <div className="mt-4 flex-col mb-20 sm:mb-0">
  29. <div className="relative">
  30. {isObject(shippingAddress) && (
  31. <table className="w-full text-left text-sm text-gray-500 dark:text-gray-400">
  32. <tbody>
  33. <tr className="">
  34. <td className="py-4">Contact</td>
  35. <th
  36. className="break-all px-6 py-4 font-medium text-gray-900 dark:text-white"
  37. scope="row"
  38. >
  39. {shippingAddress?.email}
  40. </th>
  41. </tr>
  42. <tr className="">
  43. <td className="py-4">Billing to</td>
  44. <th
  45. className="break-all px-6 py-4 font-medium text-gray-900 dark:text-white"
  46. scope="row"
  47. >
  48. {billingAddress?.firstName}, {billingAddress?.lastName},{" "}
  49. {billingAddress?.address}, {billingAddress?.city},{" "}
  50. {billingAddress?.state}, {billingAddress?.postcode},{" "}
  51. {billingAddress?.country}
  52. </th>
  53. </tr>
  54. <tr className="">
  55. <td className="py-4">Ship to</td>
  56. <th
  57. className="break-all px-6 py-4 font-medium text-gray-900 dark:text-white"
  58. scope="row"
  59. >
  60. {shippingAddress?.firstName}, {shippingAddress?.lastName},{" "}
  61. {shippingAddress?.address}, {shippingAddress?.city},{" "}
  62. {shippingAddress?.state}, {shippingAddress?.postcode},{" "}
  63. {shippingAddress?.country}
  64. </th>
  65. </tr>
  66. <tr className="">
  67. <td className="py-4">Method</td>
  68. <th
  69. className="break-all px-6 py-4 font-medium text-gray-900 dark:text-white"
  70. scope="row"
  71. >
  72. {selectedShippingRateTitle}
  73. </th>
  74. </tr>
  75. <tr className="">
  76. <td className="py-4">Payment</td>
  77. <th
  78. className="break-all px-6 py-4 font-medium text-gray-900 dark:text-white"
  79. scope="row"
  80. >
  81. {selectedPaymentTitle}
  82. </th>
  83. </tr>
  84. </tbody>
  85. </table>
  86. )}
  87. </div>
  88. <div className="flex flex-col gap-6">
  89. <form onSubmit={handleSubmit(onSubmit)}>
  90. <div className="justify-self-end">
  91. <ProceedToCheckout
  92. buttonName="Place Order"
  93. pending={isPlaceOrder}
  94. />
  95. </div>
  96. </form>
  97. </div>
  98. </div>
  99. );
  100. }