Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CheckoutContent.jsx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { Breadcrumbs, Divider, 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 { useStore } from '../../store/cart-context';
  6. import { useCheckoutDataUpdate } from '../../store/checkout-context';
  7. import DataCard from '../cards/data-card/DataCard';
  8. import ShippingDetailsForm from '../forms/shipping-details/ShippingDetailsForm';
  9. const CheckoutContent = () => {
  10. const { cartStorage } = useStore();
  11. const { addCheckoutValue } = useCheckoutDataUpdate();
  12. const { data: session } = useSession();
  13. const router = useRouter();
  14. const submitHandler = (formValues) => {
  15. addCheckoutValue(
  16. cartStorage,
  17. { ...formValues, email: session.user.email },
  18. session.user._id
  19. );
  20. router.push('/shipping');
  21. };
  22. return (
  23. <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  24. <Grid item xs={12}>
  25. <Typography
  26. variant="h3"
  27. sx={{ pl: 12, mt: 12, height: '100%', color: 'primary.main' }}
  28. >
  29. Checkout
  30. </Typography>
  31. </Grid>
  32. <Grid item xs={12}>
  33. <Divider sx={{ backgroundColor: 'primary.main', mx: 12 }} />
  34. </Grid>
  35. <Grid item xs={12} sx={{ mt: 4 }}>
  36. <Breadcrumbs
  37. aria-label="breadcrumb"
  38. separator="›"
  39. sx={{ pl: 12, fontSize: 20 }}
  40. >
  41. <Typography>Cart</Typography>
  42. <Typography color="red">Checkout</Typography>
  43. </Breadcrumbs>
  44. </Grid>
  45. <Grid item xs={12} sx={{ mt: 1 }}>
  46. <Typography sx={{ pl: 12, fontSize: 20 }}>
  47. The following fields will be used as the shipping details for your
  48. order
  49. </Typography>
  50. </Grid>
  51. <Grid item xs={8}>
  52. <ShippingDetailsForm
  53. backBtn={true}
  54. isCheckout={true}
  55. submitHandler={submitHandler}
  56. ></ShippingDetailsForm>
  57. </Grid>
  58. <Grid item xs={4}>
  59. <Box sx={{ width: '80%', mt: 2 }}>
  60. {cartStorage?.map((entry, i) => {
  61. return (
  62. <DataCard
  63. key={i}
  64. data={entry.product}
  65. quantity={entry.quantity}
  66. ></DataCard>
  67. );
  68. })}
  69. </Box>
  70. </Grid>
  71. </Grid>
  72. );
  73. };
  74. export default CheckoutContent;