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

ReviewContent.jsx 5.0KB

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