Goods.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import {Box, CircularProgress, Divider, Grid, useMediaQuery} from "@mui/material";
  2. import Link from "react-router-dom/es/Link";
  3. import {connect} from "react-redux";
  4. import {CarouselItem} from "./CarouselItem";
  5. import {ImageItem} from "./ImageItem";
  6. import {ProductDescription} from "./ProductDescription";
  7. import {ProductTitle} from "./ProductTitle";
  8. import {ProductPrice} from "./ProductPrice";
  9. import {CAddToCart} from "./AddToCart";
  10. import {CAddToWishList} from "./AddToWishList";
  11. import {ProductTags} from "./ProductTags";
  12. import {timeCalc} from "./timeCalc";
  13. const Goods = ({good}) => {
  14. const matches = useMediaQuery('(max-width:768px)')
  15. return (
  16. good && Object.values(good).length > 0 ?
  17. <Grid
  18. container
  19. justifyContent='space-around'
  20. padding={matches ? "20px 0" : "50px 0"}
  21. >
  22. <Grid xs={12} md={6}
  23. item
  24. padding='5px 70px 5px 10px'
  25. >
  26. {Array.isArray(good?.images) && good?.images.length > 1 ?
  27. <CarouselItem images={good?.images}/>
  28. :
  29. <Box
  30. sx={{
  31. width: '100%',
  32. display: 'flex',
  33. justifyContent: 'center',
  34. height: '340px'
  35. }}
  36. >
  37. <ImageItem images={Array.isArray(good?.images) && good?.images[0]}/>
  38. </Box>
  39. }
  40. <Divider sx={{margin: '20px 0'}}/>
  41. <ProductDescription description={good?.description}/>
  42. </Grid>
  43. <Grid xs={12} md={6}
  44. item
  45. padding='5px 110px 5px 10px'
  46. >
  47. <ProductTitle title={good?.name}/>
  48. <ProductPrice price={good?.price}/>
  49. <CAddToCart good={good}/>
  50. <CAddToWishList good={good}/>
  51. <Box>
  52. {good?._id &&
  53. <ProductTags
  54. key={'SKU'}
  55. title={'SKU'}
  56. subtitle={good?._id}
  57. />
  58. }
  59. {Array.isArray(good?.categories) &&
  60. <ProductTags
  61. key={'CATEGORY'}
  62. title={'CATEGORY'}
  63. subtitle={good?.categories.map(item => {
  64. return (
  65. <Link
  66. key={item?._id}
  67. style={{
  68. color: "#000",
  69. textDecoration: 'none'
  70. }}
  71. to={`/catalog/category/${item?._id}`}
  72. >
  73. {item?.name}
  74. </Link>
  75. )
  76. })}
  77. />
  78. }
  79. {good?.createdAt &&
  80. <ProductTags
  81. key={'TIMEOFCREATION'}
  82. title={'TIME OF CREATION'}
  83. subtitle={timeCalc(good?.createdAt)}
  84. />
  85. }
  86. </Box>
  87. </Grid>
  88. </Grid>:
  89. <Box
  90. sx={{
  91. height: '100%',
  92. width: '100%',
  93. display: 'flex',
  94. justifyContent:'center',
  95. alignItems:'center'
  96. }}
  97. >
  98. <CircularProgress color="inherit"/>
  99. </Box>
  100. )
  101. }
  102. export const CGoods = connect(state => ({good: state.promise['goodFindOne']?.payload}))(Goods)