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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { destroyCookie } from 'nookies';
  4. import { useEffect } from 'react';
  5. import { useStore, useStoreUpdate } from '../../store/cart-context';
  6. import CartCard from '../cards/cart-card/CartCard';
  7. import OrderSummaryCard from '../cards/order-summary-card/OrderSummaryCard';
  8. import StepTitle from '../layout/steps-title/StepTitle';
  9. const CartContent = () => {
  10. const { cartStorage, totalPrice, totalQuantity } = useStore();
  11. const { removeCartValue, updateItemQuantity } = useStoreUpdate();
  12. useEffect(() => {
  13. destroyCookie(null, 'checkout-session', {
  14. path: '/',
  15. });
  16. }, []);
  17. const mapProductsToDom = () => {
  18. if (cartStorage?.length) {
  19. return cartStorage.map((element, i) => (
  20. <CartCard
  21. key={i}
  22. product={element?.product}
  23. initialQuantity={element?.quantity}
  24. remove={removeCartValue}
  25. updateQuantity={updateItemQuantity}
  26. ></CartCard>
  27. ));
  28. } else {
  29. return (
  30. <Typography
  31. sx={{
  32. mr: { sm: 10, lg: 1 },
  33. pl: 12,
  34. mt: 6,
  35. height: '100%',
  36. textAlign: 'center',
  37. fontSize: 45,
  38. }}
  39. >
  40. Your cart is currently empty
  41. </Typography>
  42. );
  43. }
  44. };
  45. return (
  46. <Box sx={{ py: 10, height: '100%', width: '100%' }}>
  47. <StepTitle title="Items in Your Cart" breadcrumbsArray={['Cart']} />
  48. <Box
  49. sx={{
  50. display: 'flex',
  51. flexDirection: { xs: 'column', lg: 'row' },
  52. mr: { xs: 2, md: 12 },
  53. ml: { xs: 2, md: 12 },
  54. }}
  55. >
  56. <Box sx={{ mt: 2, mr: { lg: 2, minWidth: '65%' } }}>
  57. {mapProductsToDom()}
  58. </Box>
  59. <Box sx={{ mt: 2 }}>
  60. <OrderSummaryCard
  61. data={{ totalPrice: totalPrice, totalQuantity: totalQuantity }}
  62. ></OrderSummaryCard>
  63. </Box>
  64. </Box>
  65. </Box>
  66. );
  67. };
  68. export default CartContent;