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 3.6KB

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