Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ProductCard.jsx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. '&.Mui-disabled': {
  76. backgroundColor: '#f2d675',
  77. color: '#464646',
  78. },
  79. '&:hover': {
  80. backgroundColor: '#f2d675',
  81. color: '#464646',
  82. boxShadow: 'none',
  83. },
  84. backgroundColor: '#CBA213',
  85. height: 50,
  86. width: 150,
  87. color: 'white',
  88. }}
  89. >
  90. {inCart ? 'In Cart' : 'Add to cart'}
  91. </Button>
  92. </Box>
  93. </Box>
  94. </Box>
  95. );
  96. };
  97. export default ProductCard;