index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 styles = {
  9. media: {
  10. height: 250,
  11. objectFit: "contain",
  12. },
  13. };
  14. const GoodCard = ({ good = {} }) => {
  15. return (
  16. <Card className="GoodCard">
  17. <CardActionArea component={Link} to={`/good/${good._id}`}>
  18. <CardMedia
  19. component="img"
  20. image={`${backendURL}${mediaURL}${good.images ? good.images[0]?.url : defaultGoodImage}`}
  21. onError={({ currentTarget }) => {
  22. currentTarget.onerror = null;
  23. currentTarget.src = defaultGoodImage;
  24. }}
  25. style={styles.media}
  26. />
  27. <CardContent>
  28. <Typography gutterBottom variant="body1" component="div" color="#1C1B1F" textAlign="left">
  29. Назва: {good.name?.length > 10 ? `${good.name.slice(0, 10)}...` : good.name}
  30. </Typography>
  31. <Typography variant="body2" color="text.secondary" textAlign="left">
  32. Ціна: {good.price} ₴
  33. </Typography>
  34. </CardContent>
  35. </CardActionArea>
  36. <CardActions>
  37. <CBuyButton good={good} key={good._id} />
  38. </CardActions>
  39. </Card>
  40. );
  41. };
  42. const CGoodCard = connect(null, {
  43. handleOnClick: (good) => actionCartAdd(good),
  44. })(GoodCard);
  45. export { GoodCard, CGoodCard };