| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import { Container } from '@mui/material';
- import useMediaQuery from '@mui/material/useMediaQuery';
- import { Box } from '@mui/system';
- import PropType from 'prop-types';
- import { useStore, useStoreUpdate } from '../../../store/cart-context';
- import ProductImage from './ProductImage';
- import ProductInfo from './ProductInfo';
-
- const FeaturedProduct = ({ product, bColor, image, side }) => {
- const matches = useMediaQuery('(min-width: 900px)');
- const data = { name: product.name, description: product.description };
- const { addCartValue } = useStoreUpdate();
- const { cartStorage } = useStore();
- const addProductToCart = (quantity) => addCartValue(product, quantity);
- const inCart = cartStorage?.some(
- (item) => item.product.customID === product.customID
- )
- ? true
- : false;
-
- return (
- <Box
- sx={{
- width: '100%',
- backgroundColor: bColor === 'dark' ? 'primary.main' : 'primary.light',
- display: 'flex',
- flexDirection: { xs: 'column', md: 'row' },
- padding: '30px 0 30px 0',
- alignItems: { md: 'center' },
- }}
- >
- <Container
- maxWidth="xl"
- sx={{ display: { md: 'flex' }, alignItems: { md: 'center' } }}
- >
- {side === 'left' ? (
- <ProductImage image={image}></ProductImage>
- ) : !matches ? (
- <ProductImage image={image}></ProductImage>
- ) : (
- <ProductInfo
- bColor={bColor}
- side={side}
- data={data}
- addProductToCart={addProductToCart}
- inCart={inCart}
- ></ProductInfo>
- )}
- {side === 'left' ? (
- <ProductInfo
- bColor={bColor}
- side={side}
- data={data}
- addProductToCart={addProductToCart}
- inCart={inCart}
- ></ProductInfo>
- ) : !matches ? (
- <ProductInfo
- bColor={bColor}
- side={side}
- data={data}
- addProductToCart={addProductToCart}
- inCart={inCart}
- ></ProductInfo>
- ) : (
- <ProductImage image={image}></ProductImage>
- )}
- </Container>
- </Box>
- );
- };
-
- FeaturedProduct.propTypes = {
- product: PropType.shape({
- category: PropType.string,
- name: PropType.string,
- image: PropType.string,
- description: PropType.string,
- place: PropType.string,
- people: PropType.string,
- process: PropType.string,
- pairing: PropType.string,
- available: PropType.Boolean,
- isFeatured: PropType.Boolean,
- price: PropType.number,
- customID: PropType.string,
- }),
- bColor: PropType.string,
- image: PropType.string,
- side: PropType.string,
- };
- export default FeaturedProduct;
|