SearchGoodResultItem.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Link } from "react-router-dom";
  2. import defaultGoodImage from "../../../images/default-good-image.png";
  3. import { Grid, Box, Typography } from "@mui/material";
  4. import { backendURL, mediaURL } from "../../../helpers";
  5. export const SearchGoodResultItem = ({ good, onClick, link = "" } = {}) => {
  6. const { _id = 0, images = [], name = "", description = "", price = "" } = good || {};
  7. return (
  8. <Grid
  9. container
  10. component={Link}
  11. to={`${link}${_id}/`}
  12. className="SearchGoodResultItem Link"
  13. onClick={() => onClick && onClick()}
  14. spacing={1}
  15. >
  16. <Grid item xs={3}>
  17. <Box
  18. component="img"
  19. src={images ? `${backendURL}${mediaURL}${images[0]?.url}` : defaultGoodImage}
  20. onError={({ currentTarget }) => {
  21. currentTarget.onerror = null;
  22. currentTarget.src = defaultGoodImage;
  23. }}
  24. />
  25. </Grid>
  26. <Grid item xs={6}>
  27. <Box sx={{ p: 1 }}>
  28. <Typography variant="body1" sx={{ flexGrow: 1 }}>
  29. {name.length > 30 ? `${name.substring(0, 30)}...` : name}
  30. </Typography>
  31. <Typography variant="body2">{description.length > 70 ? `${description.substring(0, 70)}...` : description}</Typography>
  32. </Box>
  33. </Grid>
  34. <Grid item xs={3} sx={{ display: "flex", alignItems: "center", justifyContent: "flex-end" }}>
  35. <Typography variant="body1">{price} ₴</Typography>
  36. </Grid>
  37. </Grid>
  38. );
  39. };