MainWishList.jsx 2.9 KB

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