Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FeaturedProduct.jsx 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Box } from '@mui/system';
  2. import PropType from 'prop-types';
  3. import { useStore, useStoreUpdate } from '../../../store/cart-context';
  4. import ProductImage from './ProductImage';
  5. import ProductInfo from './ProductInfo';
  6. const FeaturedProduct = ({ product, bColor, image, side }) => {
  7. const data = { name: product.name, description: product.description };
  8. const { addCartValue } = useStoreUpdate();
  9. const { cartStorage } = useStore();
  10. const addProductToCart = (quantity) => addCartValue(product, quantity);
  11. const inCart = cartStorage?.some(
  12. (item) => item.product.customID === product.customID
  13. )
  14. ? true
  15. : false;
  16. return (
  17. <Box
  18. sx={{
  19. width: '100%',
  20. maxHeight: 500,
  21. height: 500,
  22. backgroundColor: bColor === 'dark' ? 'primary.main' : 'primary.light',
  23. display: 'flex',
  24. }}
  25. >
  26. {side === 'left' ? (
  27. <ProductImage image={image}></ProductImage>
  28. ) : (
  29. <ProductInfo
  30. bColor={bColor}
  31. side={side}
  32. data={data}
  33. addProductToCart={addProductToCart}
  34. inCart={inCart}
  35. ></ProductInfo>
  36. )}
  37. {side === 'left' ? (
  38. <ProductInfo
  39. bColor={bColor}
  40. side={side}
  41. data={data}
  42. addProductToCart={addProductToCart}
  43. inCart={inCart}
  44. ></ProductInfo>
  45. ) : (
  46. <ProductImage image={image}></ProductImage>
  47. )}
  48. </Box>
  49. );
  50. };
  51. FeaturedProduct.propTypes = {
  52. product: PropType.shape({
  53. category: PropType.string,
  54. name: PropType.string,
  55. image: PropType.string,
  56. description: PropType.string,
  57. place: PropType.string,
  58. people: PropType.string,
  59. process: PropType.string,
  60. pairing: PropType.string,
  61. available: PropType.Boolean,
  62. isFeatured: PropType.Boolean,
  63. price: PropType.number,
  64. customID: PropType.string,
  65. }),
  66. bColor: PropType.string,
  67. image: PropType.string,
  68. side: PropType.string,
  69. };
  70. export default FeaturedProduct;