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.jsx 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import { Button, Grid, 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. <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  37. <StepTitle
  38. title="Review"
  39. breadcrumbsArray={['Cart', 'Checkout', 'Shipping', 'Payment', 'Review']}
  40. />
  41. <Grid item xs={12} sx={{ mt: 1 }}>
  42. <Typography
  43. sx={{
  44. width: '100%',
  45. textAlign: 'center',
  46. color: 'primary.main',
  47. fontWeight: 600,
  48. fontSize: 22,
  49. }}
  50. >
  51. ORDER COMPLETE SUCCESSFULLY
  52. </Typography>
  53. </Grid>
  54. <Grid item xs={12} sx={{ mt: 1 }}>
  55. <Typography
  56. sx={{
  57. width: '100%',
  58. fontWeight: 600,
  59. mt: 2,
  60. textAlign: 'center',
  61. }}
  62. >
  63. Thank you for placing your order with us. We wll get to work on
  64. sending your order as soon as possible
  65. </Typography>
  66. </Grid>
  67. <Grid item xs={12} sx={{ mt: 1 }}>
  68. <Typography
  69. sx={{
  70. width: '100%',
  71. textAlign: 'center',
  72. mt: 2,
  73. fontSize: 44,
  74. fontWeight: 600,
  75. }}
  76. >
  77. Order Summary
  78. </Typography>
  79. </Grid>
  80. <Grid item xs={12}>
  81. <Box
  82. sx={{
  83. backgroundColor: '#f2f2f2',
  84. mt: 4,
  85. ml: 12,
  86. width: '85%',
  87. borderRadius: 2,
  88. p: 1,
  89. }}
  90. >
  91. <Typography sx={{ fontSize: 18, fontWeight: 600 }}>
  92. Order placed on: {orderData.time}
  93. </Typography>
  94. </Box>
  95. </Grid>
  96. <Grid item xs={12}>
  97. <Box
  98. sx={{
  99. backgroundColor: '#f2f2f2',
  100. ml: 12,
  101. width: '85%',
  102. borderRadius: 2,
  103. p: 1,
  104. }}
  105. >
  106. <Typography sx={{ fontSize: 18, fontWeight: 600 }}>
  107. Email: {orderData?.shippingAddress?.email}
  108. </Typography>
  109. </Box>
  110. </Grid>
  111. <Grid item xs={12}>
  112. <Box
  113. sx={{
  114. backgroundColor: '#f2f2f2',
  115. ml: 12,
  116. width: '85%',
  117. borderRadius: 2,
  118. p: 1,
  119. }}
  120. >
  121. <Typography sx={{ fontSize: 18, fontWeight: 600 }}>
  122. Total: ${orderData?.totalPrice.toFixed(2)}
  123. </Typography>
  124. </Box>
  125. </Grid>
  126. <Grid item xs={12}>
  127. <Box
  128. sx={{
  129. backgroundColor: '#f2f2f2',
  130. ml: 12,
  131. width: '85%',
  132. borderRadius: 2,
  133. p: 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. </Grid>
  144. <Grid item xs={12} sx={{ mt: 1 }}>
  145. <Box
  146. sx={{
  147. width: '100%',
  148. display: 'flex',
  149. justifyContent: 'center',
  150. mt: 2,
  151. borderRadius: 2,
  152. p: 1,
  153. }}
  154. >
  155. <Button
  156. variant="contained"
  157. sx={{
  158. mt: 3,
  159. mb: 2,
  160. height: 50,
  161. width: 150,
  162. textTransform: 'none',
  163. backgroundColor: '#CBA213',
  164. color: 'white',
  165. mr: 2,
  166. fontSize: 16,
  167. }}
  168. onClick={() => {
  169. router.push('/');
  170. }}
  171. >
  172. Back to Home
  173. </Button>
  174. </Box>
  175. </Grid>
  176. </Grid>
  177. );
  178. };
  179. export default ReviewContent;