WishListPage.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import Breadcrumb from "../components/Breadcrumbs";
  2. import {Box, Container, Divider, Typography, useMediaQuery} from "@mui/material";
  3. import {connect} from 'react-redux';
  4. import {actionWishListRemove} from "../reducers/WishListReducer";
  5. import {actionCardChange} from "../reducers/CartReducer";
  6. import {NotFoundBlock} from "../components/NotFoundBlock";
  7. import imgUrl from "../img/not-found/2.png"
  8. import FavoriteBorderIcon from "@mui/icons-material/FavoriteBorder";
  9. import {TableLine} from "../components/TableLine";
  10. const WishListPage = ({wishlist, addToCart, onWishListRemove}) => {
  11. const matches = useMediaQuery('(max-width:899px)')
  12. let rows = []
  13. for (const key of Object.values(wishlist)) {
  14. for (const item in key) {
  15. rows.push(key[item])
  16. }
  17. }
  18. console.log(rows)
  19. return (
  20. <>
  21. <Breadcrumb links={['wish list']}/>
  22. {Object.values(wishlist).length > 0 ?
  23. <main style={{backgroundColor: "#f3f3f3", padding: matches ? "20px 0" : "50px 0"}}>
  24. <Container maxWidth="lg">
  25. <TableLine columnName={['PRODUCT', 'PRICE', 'REMOVE', 'ADD TO CART']}/>
  26. <Divider sx={{marginBottom: '20px'}}/>
  27. {rows.map(item => <TableLine columnName={[[item?._id, item?.name, item?.images], item?.price, onWishListRemove, addToCart]} role={'item'}/>)}
  28. <Divider/>
  29. </Container>
  30. </main> :
  31. <NotFoundBlock img={imgUrl} headerText={'YOUR WISHLIST IS CURRENTLY EMPTY'} text={<Box display='flex' alignItems='center'><Typography component='span'>Click the</Typography><FavoriteBorderIcon sx={{margin: '0 10px'}}/><Typography component='span'>icons to add products</Typography></Box>}/>
  32. }
  33. </>
  34. )
  35. }
  36. const CWishListPage = connect(state => ({wishlist: state.wishlist}), {addToCart: actionCardChange, onWishListRemove: actionWishListRemove})(WishListPage)
  37. export default CWishListPage
  38. // TODO MOBILE VERSION