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.tsx 6.8KB

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