Goods.jsx 4.2 KB

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