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.

ProductCard.tsx 2.8KB

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