Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CheckoutContent.jsx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { Grid, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useSession } from 'next-auth/react';
  4. import { useRouter } from 'next/router';
  5. import { setCookie } from 'nookies';
  6. import { useStore } from '../../store/cart-context';
  7. import { useCheckoutDataUpdate } from '../../store/checkout-context';
  8. import DataCard from '../cards/data-card/DataCard';
  9. import ShippingDetailsForm from '../forms/shipping-details/ShippingDetailsForm';
  10. import StepTitle from '../layout/steps-title/StepTitle';
  11. const CheckoutContent = () => {
  12. const { cartStorage } = useStore();
  13. const { addCheckoutValue } = useCheckoutDataUpdate();
  14. const { data: session } = useSession();
  15. const router = useRouter();
  16. const submitHandler = (formValues) => {
  17. addCheckoutValue(
  18. cartStorage,
  19. { ...formValues, email: session.user.email },
  20. session.user._id
  21. );
  22. setCookie(null, 'shipping-session', 'active', {
  23. maxAge: 3600,
  24. expires: new Date(Date.now() + 3600),
  25. path: '/',
  26. });
  27. router.push('/shipping');
  28. };
  29. const mapProductsToDom = () => {
  30. return cartStorage?.map((entry, i) => (
  31. <DataCard
  32. key={i}
  33. data={entry.product}
  34. quantity={entry.quantity}
  35. ></DataCard>
  36. ));
  37. };
  38. return (
  39. <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  40. <StepTitle
  41. title="Items in Your Cart"
  42. breadcrumbsArray={['Cart', 'Checkout']}
  43. />
  44. <Grid item xs={12} sx={{ mt: 1 }}>
  45. <Typography sx={{ pl: 12, fontSize: 20 }}>
  46. The following fields will be used as the shipping details for your
  47. order
  48. </Typography>
  49. </Grid>
  50. <Grid item lg={8} xs={12}>
  51. <ShippingDetailsForm
  52. backBtn={true}
  53. isCheckout={true}
  54. submitHandler={submitHandler}
  55. ></ShippingDetailsForm>
  56. </Grid>
  57. <Grid item lg={4} xs={12}>
  58. <Box
  59. sx={{
  60. width: '80%',
  61. mt: 2,
  62. height: '100%',
  63. ml: { xs: 12, lg: 0 },
  64. display: { lg: 'block', xs: 'flex' },
  65. flexWrap: { xs: 'wrap', lg: 'none' },
  66. justifyContent: { xs: 'center', lg: 'none' },
  67. }}
  68. >
  69. {mapProductsToDom()}
  70. </Box>
  71. </Grid>
  72. </Grid>
  73. );
  74. };
  75. export default CheckoutContent;