MainWishList.jsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {Box, Container, Divider, Typography, useMediaQuery} from "@mui/material";
  2. import {TableLine} from "../../components/TableLine";
  3. import {NotFoundBlock} from "../../components/NotFoundBlock";
  4. import imgUrl from "../../img/not-found/2.png";
  5. import FavoriteBorderIcon from "@mui/icons-material/FavoriteBorder";
  6. import {connect} from "react-redux";
  7. import {actionCardChange} from "../../reducers/CartReducer";
  8. import {actionWishListRemove} from "../../reducers/WishListReducer";
  9. const MainWishList = ({wishlist, addToCart, onWishListRemove, color='#f3f3f3'}) => {
  10. const matches = useMediaQuery('(max-width:899px)')
  11. let rows = []
  12. for (const key of Object.values(wishlist)) {
  13. for (const item in key) {
  14. rows.push(key[item])
  15. }
  16. }
  17. return (
  18. <>
  19. {Object.values(wishlist).length > 0 ?
  20. <main
  21. style={{
  22. backgroundColor: {color},
  23. padding: matches ? "20px 0" : "50px 0",
  24. minHeight:'300px'
  25. }}
  26. >
  27. <Container maxWidth="lg">
  28. <TableLine columnName={['PRODUCT', 'PRICE', 'REMOVE', 'ADD TO CART']}/>
  29. <Divider sx={{marginBottom: '20px'}}/>
  30. {rows.map(item =>
  31. <TableLine
  32. key={item?._id}
  33. columnName={[[item?._id, item?.name, item?.images], item?.price,
  34. onWishListRemove, addToCart]}
  35. role={'item'}
  36. />)
  37. }
  38. <Divider/>
  39. </Container>
  40. </main>
  41. :
  42. <NotFoundBlock
  43. img={imgUrl}
  44. headerText={'YOUR WISHLIST IS CURRENTLY EMPTY'}
  45. text={
  46. <Box
  47. display='flex'
  48. alignItems='center'
  49. >
  50. <Typography
  51. component='span'
  52. >
  53. Click the
  54. </Typography>
  55. <FavoriteBorderIcon sx={{margin: '0 10px'}}/>
  56. <Typography
  57. component='span'
  58. >
  59. icons to add products
  60. </Typography>
  61. </Box>
  62. }
  63. />
  64. }
  65. </>
  66. )
  67. }
  68. export const CMainWishList = connect(state => ({wishlist: state.wishlist}),
  69. {addToCart: actionCardChange, onWishListRemove: actionWishListRemove})(MainWishList)