You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReviewContent.jsx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import { Button, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useRouter } from 'next/router';
  4. import { destroyCookie } from 'nookies';
  5. import { useEffect, useState } from 'react';
  6. import { postOrder } from '../../requests/products/postOrderRequest';
  7. import { useStoreUpdate } from '../../store/cart-context';
  8. import {
  9. useCheckoutData,
  10. useCheckoutDataUpdate,
  11. } from '../../store/checkout-context';
  12. import StepTitle from '../layout/steps-title/StepTitle';
  13. let initialRender = true;
  14. const ReviewContent = () => {
  15. const { checkoutStorage } = useCheckoutData();
  16. const { parseCheckoutValue, clearCheckout } = useCheckoutDataUpdate();
  17. const { clearCart } = useStoreUpdate();
  18. const [orderData, setOrderData] = useState({});
  19. const router = useRouter();
  20. useEffect(() => {
  21. if (initialRender) {
  22. setOrderData(parseCheckoutValue());
  23. postOrder(parseCheckoutValue());
  24. initialRender = false;
  25. return () => {
  26. clearCheckout();
  27. clearCart();
  28. destroyCookie(null, 'checkout-session', {
  29. path: '/',
  30. });
  31. destroyCookie(null, 'shipping-session', {
  32. path: '/',
  33. });
  34. destroyCookie(null, 'review-session', {
  35. path: '/',
  36. });
  37. };
  38. }
  39. }, [checkoutStorage]);
  40. return (
  41. <Box sx={{ py: 10, height: '100%', width: '100%' }}>
  42. <StepTitle
  43. title="Review"
  44. breadcrumbsArray={['Cart', 'Checkout', 'Shipping', 'Payment', 'Review']}
  45. />
  46. <Box sx={{ ml: { xs: 2 }, mr: { xs: 2 }, mt: 6 }}>
  47. <Box>
  48. <Typography
  49. sx={{
  50. width: '100%',
  51. textAlign: 'center',
  52. color: 'primary.main',
  53. fontWeight: 600,
  54. fontSize: 22,
  55. }}
  56. >
  57. ORDER COMPLETE SUCCESSFULLY
  58. </Typography>
  59. </Box>
  60. <Box sx={{ mt: 1 }}>
  61. <Typography
  62. sx={{
  63. width: '100%',
  64. fontWeight: 600,
  65. mt: 2,
  66. textAlign: 'center',
  67. }}
  68. >
  69. Thank you for placing your order with us. We wll get to work on
  70. sending your order as soon as possible
  71. </Typography>
  72. </Box>
  73. <Box sx={{ mt: 1 }}>
  74. <Typography
  75. sx={{
  76. width: '100%',
  77. textAlign: 'center',
  78. mt: 4,
  79. mb: 4,
  80. fontSize: 44,
  81. fontWeight: 600,
  82. }}
  83. >
  84. Order Summary
  85. </Typography>
  86. </Box>
  87. <Box
  88. sx={{
  89. backgroundColor: '#f2f2f2',
  90. my: 1,
  91. ml: { md: 12 },
  92. mr: { md: 12 },
  93. borderRadius: 2,
  94. p: 2,
  95. }}
  96. >
  97. <Typography sx={{ fontSize: 18, fontWeight: 600 }}>
  98. Order placed on: {orderData.time}
  99. </Typography>
  100. </Box>
  101. <Box
  102. sx={{
  103. backgroundColor: '#f2f2f2',
  104. ml: { md: 12 },
  105. mr: { md: 12 },
  106. borderRadius: 2,
  107. p: 2,
  108. my: 1,
  109. }}
  110. >
  111. <Typography sx={{ fontSize: 18, fontWeight: 600 }}>
  112. Email: {orderData?.shippingAddress?.email}
  113. </Typography>
  114. </Box>
  115. <Box
  116. sx={{
  117. backgroundColor: '#f2f2f2',
  118. ml: { md: 12 },
  119. mr: { md: 12 },
  120. borderRadius: 2,
  121. p: 2,
  122. my: 1,
  123. }}
  124. >
  125. <Typography sx={{ fontSize: 18, fontWeight: 600 }}>
  126. Total: ${orderData?.totalPrice}
  127. </Typography>
  128. </Box>
  129. <Box
  130. sx={{
  131. backgroundColor: '#f2f2f2',
  132. ml: { md: 12 },
  133. mr: { md: 12 },
  134. borderRadius: 2,
  135. p: 2,
  136. my: 1,
  137. }}
  138. >
  139. <Typography sx={{ fontSize: 18, fontWeight: 600 }}>
  140. Shipping Address: {orderData?.shippingAddress?.address},{' '}
  141. {orderData?.shippingAddress?.city},{' '}
  142. {orderData?.shippingAddress?.country},{' '}
  143. {orderData?.shippingAddress?.postcode}
  144. </Typography>
  145. </Box>
  146. <Box sx={{ mt: 1 }}>
  147. <Box
  148. sx={{
  149. width: '100%',
  150. display: 'flex',
  151. justifyContent: 'center',
  152. mt: 2,
  153. borderRadius: 2,
  154. p: 1,
  155. }}
  156. >
  157. <Button
  158. variant="contained"
  159. sx={{
  160. mt: 3,
  161. mb: 2,
  162. height: 50,
  163. width: 150,
  164. textTransform: 'none',
  165. backgroundColor: '#CBA213',
  166. color: 'white',
  167. mr: 2,
  168. fontSize: 16,
  169. }}
  170. onClick={() => {
  171. router.push('/');
  172. }}
  173. >
  174. Back to Home
  175. </Button>
  176. </Box>
  177. </Box>
  178. </Box>
  179. </Box>
  180. );
  181. };
  182. export default ReviewContent;