Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ReviewContent.jsx 5.0KB

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