Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. <Image
  32. src="/images/product-card-image.jpg"
  33. alt="product image"
  34. width={630}
  35. height={390}
  36. />
  37. </NextLink>
  38. </Box>
  39. <Box
  40. width="100%"
  41. sx={{
  42. display: 'flex',
  43. flexDirection: 'column',
  44. }}
  45. >
  46. <Typography
  47. sx={{ height: '100px' }}
  48. fontSize="24px"
  49. align="center"
  50. pt={1}
  51. pb={3}
  52. >
  53. {product.name}
  54. </Typography>
  55. <Typography
  56. sx={{ height: '200px' }}
  57. align="center"
  58. fontSize="18px"
  59. m={2}
  60. >
  61. {product.description.length > 250
  62. ? product.description.slice(0, 250) + '...'
  63. : product.description}
  64. </Typography>
  65. <Typography fontSize="24px" align="center" pt={4}>
  66. ${product.price}
  67. </Typography>
  68. <Box textAlign="center" mt={1}>
  69. <Button
  70. disableRipple
  71. disableFocusRipple
  72. disabled={inCart}
  73. onClick={() => addProductToCart(1)}
  74. sx={{
  75. backgroundColor: '#CBA213',
  76. height: 50,
  77. width: 150,
  78. color: 'white',
  79. }}
  80. >
  81. {inCart ? 'In Cart' : 'Add to cart'}
  82. </Button>
  83. </Box>
  84. </Box>
  85. </Box>
  86. );
  87. };
  88. export default ProductCard;