goodCardCharacteristic.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Card, Image, Button, Space } from 'antd';
  2. import { useEffect, useState } from 'react';
  3. import { connect } from 'react-redux';
  4. import { actionCartAdd } from '../action';
  5. const backendURL = 'http://shop-roles.asmer.fs.a-level.com.ua';
  6. const Good = ({good: {name, images, description, price, _id}, onAdd}) => {
  7. const [dopImg, setDopImg] = useState([]);
  8. useEffect(() => {
  9. if (images && images.length > 1) {
  10. const newImages = [...images];
  11. newImages.shift();
  12. setDopImg(newImages);
  13. }
  14. }, [images])
  15. return (
  16. <Card title={name} style={{ width: 400}} hoverable>
  17. {images && images[0] && images[0].url && <Image width={350} src={backendURL + '/' + images[0].url} />}
  18. {(dopImg.length >= 1) && dopImg.map((item) =>
  19. <div key={item._id} className='additionalImg'>
  20. <Image width={110} height={110} src={backendURL + '/' + item.url} />
  21. </div>
  22. )}
  23. <p>{description}</p>
  24. <p>{price} грн</p>
  25. <Button onClick={() => onAdd({_id, name, price, images})}>Купить</Button>
  26. </Card>
  27. )
  28. }
  29. const mapStateToProps = state => ({good: state.promise.goodById?.payload || {}})
  30. const GoodCardCharacteristic = connect(mapStateToProps, {onAdd: actionCartAdd})(Good);
  31. export default GoodCardCharacteristic;