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

ReviewContent.jsx 4.8KB

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