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.

FeaturedProduct.tsx 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Container } from '@mui/material';
  2. import useMediaQuery from '@mui/material/useMediaQuery';
  3. import { Box } from '@mui/system';
  4. import { useEffect, useState } from 'react';
  5. import { useStore, useStoreUpdate } from '../../../store/cart-context';
  6. import { ProductDataDB } from '../../../utils/interface/productInterface';
  7. import ProductImage from './ProductImage';
  8. import ProductInfo from './ProductInfo';
  9. interface FeaturedProductProps {
  10. side: string;
  11. bColor: string;
  12. product: ProductDataDB;
  13. }
  14. const FeaturedProduct: React.FC<FeaturedProductProps> = ({ product, bColor, side }) => {
  15. const matches = useMediaQuery('(min-width: 900px)');
  16. const data = { name: product.name, description: product.description };
  17. const { addCartValue } = useStoreUpdate();
  18. const { cartStorage } = useStore();
  19. const addProductToCart = (quantity: number) => addCartValue(product, quantity);
  20. const [inCart, setInCart] = useState(false);
  21. useEffect(() => {
  22. if (cartStorage) {
  23. if (
  24. cartStorage?.some((item: FeaturedProductProps) => item.product.customID === product.customID)
  25. )
  26. setInCart(true);
  27. }
  28. }, [cartStorage, product.customID]);
  29. return (
  30. <Box
  31. sx={{
  32. width: '100%',
  33. backgroundColor: bColor === 'dark' ? 'primary.main' : 'primary.light',
  34. display: 'flex',
  35. flexDirection: { xs: 'column', md: 'row' },
  36. padding: '30px 0 30px 0',
  37. alignItems: { md: 'center' },
  38. }}
  39. >
  40. <Container
  41. maxWidth="xl"
  42. sx={{ display: { md: 'flex' }, alignItems: { md: 'center' } }}
  43. >
  44. {side === 'left' ? (
  45. <ProductImage image={product.image}></ProductImage>
  46. ) : !matches ? (
  47. <ProductImage image={product.image}></ProductImage>
  48. ) : (
  49. <ProductInfo
  50. bColor={bColor}
  51. data={data}
  52. addProductToCart={addProductToCart}
  53. inCart={inCart}
  54. ></ProductInfo>
  55. )}
  56. {side === 'left' ? (
  57. <ProductInfo
  58. bColor={bColor}
  59. data={data}
  60. addProductToCart={addProductToCart}
  61. inCart={inCart}
  62. ></ProductInfo>
  63. ) : !matches ? (
  64. <ProductInfo
  65. bColor={bColor}
  66. data={data}
  67. addProductToCart={addProductToCart}
  68. inCart={inCart}
  69. ></ProductInfo>
  70. ) : (
  71. <ProductImage image={product.image}></ProductImage>
  72. )}
  73. </Container>
  74. </Box>
  75. );
  76. };
  77. export default FeaturedProduct;