您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReviewContent.tsx 5.2KB

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