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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { Button, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import Image from 'next/image';
  4. import NextLink from 'next/link';
  5. import { useStore, useStoreUpdate } from '../../store/cart-context';
  6. const ProductCard = ({ product }) => {
  7. const { addCartValue } = useStoreUpdate();
  8. const { cartStorage } = useStore();
  9. const addProductToCart = (quantity) => addCartValue(product, quantity);
  10. const inCart = cartStorage?.some(
  11. (item) => item.product.customID === product.customID
  12. )
  13. ? true
  14. : false;
  15. return (
  16. <Box
  17. sx={{
  18. width: '100%',
  19. height: '100%',
  20. border: 'none',
  21. mb: '15px',
  22. backgroundColor: '#F5ECD4',
  23. }}
  24. >
  25. <Box width="100%" sx={{ cursor: 'pointer' }}>
  26. <NextLink
  27. style={{ cursor: 'pointer' }}
  28. href={`/products/${product.customID}`}
  29. passHref
  30. >
  31. <a>
  32. <Image
  33. src={product.image}
  34. alt="product image"
  35. width={500}
  36. height={390}
  37. />
  38. </a>
  39. </NextLink>
  40. </Box>
  41. <Box
  42. width="100%"
  43. sx={{
  44. display: 'flex',
  45. flexDirection: 'column',
  46. }}
  47. >
  48. <Typography
  49. sx={{ height: '100px' }}
  50. fontSize="24px"
  51. align="center"
  52. pt={1}
  53. pb={3}
  54. >
  55. {product.name}
  56. </Typography>
  57. <Typography
  58. sx={{
  59. height: { xs: '200px', sm: '250px', md: '250px', lg: '200px' },
  60. }}
  61. align="center"
  62. fontSize="18px"
  63. m={2}
  64. >
  65. {product.description.length > 250
  66. ? product.description.slice(0, 250) + '...'
  67. : product.description}
  68. </Typography>
  69. <Typography fontSize="24px" align="center" pt={4}>
  70. ${product.price}
  71. </Typography>
  72. <Box textAlign="center" mt={1}>
  73. <Button
  74. disableRipple
  75. disableFocusRipple
  76. disabled={inCart}
  77. onClick={() => addProductToCart(1)}
  78. sx={{
  79. '&.Mui-disabled': {
  80. backgroundColor: '#f2d675',
  81. color: '#464646',
  82. },
  83. '&:hover': {
  84. backgroundColor: '#f2d675',
  85. color: '#464646',
  86. boxShadow: 'none',
  87. },
  88. backgroundColor: '#CBA213',
  89. height: 50,
  90. width: 150,
  91. color: 'white',
  92. }}
  93. >
  94. {inCart ? 'In Cart' : 'Add to cart'}
  95. </Button>
  96. </Box>
  97. </Box>
  98. </Box>
  99. );
  100. };
  101. export default ProductCard;