index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { CBuyButton } from "../common/BuyButton";
  2. import { useSelector } from "react-redux";
  3. import defaultGoodImage from "../../images/default-good-image.png";
  4. import { Divider, Grid, Stack, Typography } from "@mui/material";
  5. import { Box } from "@mui/system";
  6. import { Carousel } from "react-responsive-carousel";
  7. import { backendURL, mediaURL } from "../../helpers";
  8. export const GoodPage = () => {
  9. const good = useSelector((state) => state.promise?.goodById?.payload || {});
  10. const { _id = "", name = "", price = "", description = "", images = [] } = good || {};
  11. return (
  12. <Box className="GoodPage">
  13. <Grid container spacing={4} className="images">
  14. <Grid item xs={12} md={4}>
  15. <Carousel showIndicators={false} showStatus={false} showArrows={true}>
  16. {(!!good?.images?.length ? good?.images : [{ _id: 0, url: defaultGoodImage }]).map((image) => (
  17. <img
  18. key={image?._id}
  19. src={image?.url ? `${backendURL}${mediaURL}${image?.url}` : defaultGoodImage}
  20. onError={({ currentTarget }) => {
  21. currentTarget.onerror = null;
  22. currentTarget.src = defaultGoodImage;
  23. }}
  24. />
  25. ))}
  26. </Carousel>
  27. </Grid>
  28. <Grid item xs={12} md={8} className="content">
  29. <Stack spacing={2}>
  30. <Stack direction="row" alignItems="center" spacing={2}>
  31. <Typography variant="body1" color="#1C1B1F">
  32. <b>Ціна:</b> {price} ₴
  33. </Typography>
  34. <CBuyButton good={good} />
  35. </Stack>
  36. <Divider />
  37. <Typography variant="h5">
  38. <b>Назва: {name}</b>
  39. </Typography>
  40. <Typography variant="body1">
  41. Опис:
  42. <br />
  43. {description}
  44. </Typography>
  45. </Stack>
  46. </Grid>
  47. </Grid>
  48. </Box>
  49. );
  50. };