index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Card, CardActionArea, CardActions, CardContent, CardMedia, Typography } from "@mui/material";
  2. import { connect } from "react-redux";
  3. import { Link } from "react-router-dom";
  4. import { backendURL, mediaURL } from "../../../helpers";
  5. import defaultGoodImage from "../../../images/default-good-image.png";
  6. import { actionCartAdd } from "../../../reducers";
  7. import { CBuyButton } from "../BuyButton";
  8. const GoodCard = ({ good = {} }) => {
  9. return (
  10. <Card className="GoodCard">
  11. <CardActionArea component={Link} to={`/good/${good._id}`}>
  12. <CardMedia
  13. component="img"
  14. height="200"
  15. image={`${backendURL}${mediaURL}${good.images ? good.images[0]?.url : defaultGoodImage}`}
  16. onError={({ currentTarget }) => {
  17. currentTarget.onerror = null;
  18. currentTarget.src = defaultGoodImage;
  19. }}
  20. />
  21. <CardContent>
  22. <Typography gutterBottom variant="body1" component="div" color="#1C1B1F" textAlign="left">
  23. Назва: {good.name?.length > 10 ? `${good.name.slice(0, 10)}...` : good.name}
  24. </Typography>
  25. <Typography variant="body2" color="text.secondary" textAlign="left">
  26. Ціна: {good.price} ₴
  27. </Typography>
  28. </CardContent>
  29. </CardActionArea>
  30. <CardActions>
  31. <CBuyButton good={good} key={good._id} />
  32. </CardActions>
  33. </Card>
  34. );
  35. };
  36. const CGoodCard = connect(null, {
  37. handleOnClick: (good) => actionCartAdd(good),
  38. })(GoodCard);
  39. export { GoodCard, CGoodCard };