Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { Container } from '@mui/material';
  2. import useMediaQuery from '@mui/material/useMediaQuery';
  3. import { Box } from '@mui/system';
  4. import PropType from 'prop-types';
  5. import { useStore, useStoreUpdate } from '../../../store/cart-context';
  6. import ProductImage from './ProductImage';
  7. import ProductInfo from './ProductInfo';
  8. const FeaturedProduct = ({ product, bColor, image, side }) => {
  9. const matches = useMediaQuery('(min-width: 900px)');
  10. const data = { name: product.name, description: product.description };
  11. const { addCartValue } = useStoreUpdate();
  12. const { cartStorage } = useStore();
  13. const addProductToCart = (quantity) => addCartValue(product, quantity);
  14. const inCart = cartStorage?.some(
  15. (item) => item.product.customID === product.customID
  16. )
  17. ? true
  18. : false;
  19. return (
  20. <Box
  21. sx={{
  22. width: '100%',
  23. backgroundColor: bColor === 'dark' ? 'primary.main' : 'primary.light',
  24. display: 'flex',
  25. flexDirection: { xs: 'column', md: 'row' },
  26. padding: '30px 0 30px 0',
  27. alignItems: { md: 'center' },
  28. }}
  29. >
  30. <Container
  31. maxWidth="xl"
  32. sx={{ display: { md: 'flex' }, alignItems: { md: 'center' } }}
  33. >
  34. {side === 'left' ? (
  35. <ProductImage image={image}></ProductImage>
  36. ) : !matches ? (
  37. <ProductImage image={image}></ProductImage>
  38. ) : (
  39. <ProductInfo
  40. bColor={bColor}
  41. side={side}
  42. data={data}
  43. addProductToCart={addProductToCart}
  44. inCart={inCart}
  45. ></ProductInfo>
  46. )}
  47. {side === 'left' ? (
  48. <ProductInfo
  49. bColor={bColor}
  50. side={side}
  51. data={data}
  52. addProductToCart={addProductToCart}
  53. inCart={inCart}
  54. ></ProductInfo>
  55. ) : !matches ? (
  56. <ProductInfo
  57. bColor={bColor}
  58. side={side}
  59. data={data}
  60. addProductToCart={addProductToCart}
  61. inCart={inCart}
  62. ></ProductInfo>
  63. ) : (
  64. <ProductImage image={image}></ProductImage>
  65. )}
  66. </Container>
  67. </Box>
  68. );
  69. };
  70. FeaturedProduct.propTypes = {
  71. product: PropType.shape({
  72. category: PropType.string,
  73. name: PropType.string,
  74. image: PropType.string,
  75. description: PropType.string,
  76. place: PropType.string,
  77. people: PropType.string,
  78. process: PropType.string,
  79. pairing: PropType.string,
  80. available: PropType.Boolean,
  81. isFeatured: PropType.Boolean,
  82. price: PropType.number,
  83. customID: PropType.string,
  84. }),
  85. bColor: PropType.string,
  86. image: PropType.string,
  87. side: PropType.string,
  88. };
  89. export default FeaturedProduct;