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.jsx 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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: '75px',
  22. backgroundColor: '#F5ECD4',
  23. }}
  24. >
  25. <Box width="100%">
  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 fontSize="24px" align="center" pt={1} pb={3}>
  47. {product.name}
  48. </Typography>
  49. <Typography align="center" fontSize="18px" m={2}>
  50. {product.description}
  51. </Typography>
  52. <Typography fontSize="24px" align="center" pt={4}>
  53. ${product.price}
  54. </Typography>
  55. <Box textAlign="center" mt={1}>
  56. <Button
  57. disabled={inCart}
  58. onClick={() => addProductToCart(1)}
  59. sx={{
  60. backgroundColor: '#CBA213',
  61. height: 50,
  62. width: 150,
  63. color: 'white',
  64. }}
  65. >
  66. {inCart ? 'In Cart' : 'Add to cart'}
  67. </Button>
  68. </Box>
  69. </Box>
  70. </Box>
  71. );
  72. };
  73. export default ProductCard;