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.

CartContent.jsx 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Breadcrumbs, Divider, Grid, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useStore, useStoreUpdate } from '../../store/cart-context';
  4. import CartCard from '../cards/cart-card/CartCard';
  5. import OrderSummaryCard from '../cards/order-summary-card/OrderSummaryCard';
  6. const CartContent = () => {
  7. const { cartStorage, totalPrice, totalQuantity } = useStore();
  8. const { removeCartValue, updateItemQuantity } = useStoreUpdate();
  9. const mapProductsToDom = () => {
  10. if (cartStorage?.length) {
  11. return cartStorage.map((element, i) => (
  12. <CartCard
  13. key={i}
  14. product={element?.product}
  15. initialQuantity={element?.quantity}
  16. remove={removeCartValue}
  17. updateQuantity={updateItemQuantity}
  18. ></CartCard>
  19. ));
  20. } else {
  21. return (
  22. <Typography
  23. sx={{
  24. pl: 12,
  25. mt: 6,
  26. height: '100%',
  27. textAlign: 'center',
  28. fontSize: 45,
  29. }}
  30. >
  31. Your cart is currently empty
  32. </Typography>
  33. );
  34. }
  35. };
  36. return (
  37. <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  38. <Grid item xs={12}>
  39. <Typography
  40. variant="h3"
  41. sx={{ pl: 12, mt: 12, height: '100%', color: 'primary.main' }}
  42. >
  43. Items in Your Cart
  44. </Typography>
  45. </Grid>
  46. <Grid item xs={12}>
  47. <Divider sx={{ backgroundColor: 'primary.main', mx: 12 }} />
  48. </Grid>
  49. <Grid item xs={12} sx={{ mt: 4 }}>
  50. <Breadcrumbs
  51. aria-label="breadcrumb"
  52. separator="›"
  53. sx={{ pl: 12, fontSize: 20 }}
  54. >
  55. <Typography color="red">Cart</Typography>
  56. <Typography></Typography>
  57. </Breadcrumbs>
  58. </Grid>
  59. <Grid item xs={8}>
  60. {mapProductsToDom()}
  61. </Grid>
  62. <Grid item xs={4}>
  63. <Box sx={{ width: '80%', mt: 2 }}>
  64. <OrderSummaryCard
  65. data={{ totalPrice: totalPrice, totalQuantity: totalQuantity }}
  66. ></OrderSummaryCard>
  67. </Box>
  68. </Grid>
  69. </Grid>
  70. );
  71. };
  72. export default CartContent;