WishListPage.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import Breadcrumb from "../components/Breadcrumbs";
  2. import {Box, Button, Container, Divider, Grid, 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 Link from "react-router-dom/es/Link";
  7. import {backURL} from "../actions/PathDB";
  8. import imgNotFound from "../img/catalog/imgNotFound.png";
  9. import CloseIcon from '@mui/icons-material/Close';
  10. import {NotFoundBlock} from "../components/NotFoundBlock";
  11. import imgUrl from "../img/not-found/2.png"
  12. import FavoriteBorderIcon from "@mui/icons-material/FavoriteBorder";
  13. const ItemHeaderLine = ({text, align='left'}) => {
  14. return (
  15. <Typography
  16. color='#616161'
  17. variant='body1'
  18. letterSpacing='1px'
  19. textAlign={align}
  20. >
  21. {text || ''}
  22. </Typography>
  23. )
  24. }
  25. const LinkProductItem = ({item: [_id, name, images]}) => {
  26. return (
  27. <Link style={{textDecoration: 'none', display: 'flex', alignItems: 'center'}} to={`/good/${_id}`}>
  28. <Box width='60px' height='60px' borderRadius='10px' overflow='hidden' marginRight='20px'>
  29. <img style={{width: '100%', height: '100%', objectFit: 'cover'}} src={images[0]?.url ? backURL + '/' + images[0]?.url : imgNotFound} alt={name}/>
  30. </Box>
  31. <ItemHeaderLine text={name}/>
  32. </Link>
  33. )
  34. }
  35. const AddToCart = ({good, addToCart}) => {
  36. return (
  37. <Button
  38. sx={{height: '40px', width: '70%', borderRadius: '0', color: '#000', borderColor: '#000', fontSize: '16px', fontWeight: '300'}}
  39. variant="outlined"
  40. color={"inherit"}
  41. onClick={() => addToCart(good)}
  42. >
  43. ADD TO CART
  44. </Button>
  45. )
  46. }
  47. const RemoveFromWishList = ({good, onWishListRemove}) => {
  48. return (
  49. <Button
  50. size="small"
  51. color="inherit"
  52. onClick={() => onWishListRemove(good)}
  53. >
  54. <CloseIcon/>
  55. </Button>
  56. )
  57. }
  58. const TableLine = ({columnName, role='header'}) => {
  59. const good = {'_id': columnName[0][0], 'name': columnName[0][1], 'images': columnName[0][2], 'price': columnName[1]};
  60. return (
  61. <Grid container justifyContent='space-between' marginBottom='20px' alignItems='center'>
  62. <Grid item xs={3} md={5}>
  63. {role === 'header' ? <ItemHeaderLine text={columnName[0]}/> : <LinkProductItem item={columnName[0]}/>}
  64. </Grid>
  65. <Grid item xs={3} md={2}>
  66. <ItemHeaderLine text={role === 'header' ? columnName[1] : '$'+columnName[1]} align={'center'}/>
  67. </Grid>
  68. <Grid item xs={3} md={3} display='flex' justifyContent='center'>
  69. {role === 'header' ? <ItemHeaderLine text={columnName[3]} align={'center'}/> : <AddToCart good={good} addToCart={columnName[3]}/>}
  70. </Grid>
  71. <Grid item xs={3} md={1} display='flex' justifyContent='center'>
  72. {role === 'header' ? <ItemHeaderLine text={columnName[2]} align={'center'}/> : <RemoveFromWishList good={good} onWishListRemove={columnName[2]}/>}
  73. </Grid>
  74. </Grid>
  75. )
  76. }
  77. const WishListPage = ({wishlist, addToCart, onWishListRemove}) => {
  78. const matches = useMediaQuery('(max-width:899px)')
  79. let rows = []
  80. for (const key of Object.values(wishlist)) {
  81. for (const item in key) {
  82. rows.push(key[item])
  83. }
  84. }
  85. return (
  86. <>
  87. <Breadcrumb links={['wish list']}/>
  88. {Object.values(wishlist).length > 0 ?
  89. <main style={{backgroundColor: "#f3f3f3", padding: matches ? "20px 0" : "50px 0"}}>
  90. <Container maxWidth="lg">
  91. <TableLine columnName={['PRODUCT', 'PRICE', 'REMOVE', 'ADD TO CART']}/>
  92. <Divider sx={{marginBottom: '20px'}}/>
  93. {rows.map(item => <TableLine columnName={[[item?._id, item?.name, item?.images], item?.price, onWishListRemove, addToCart]} role={'item'}/>)}
  94. <Divider/>
  95. </Container>
  96. </main> :
  97. <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>}/>
  98. }
  99. </>
  100. )
  101. }
  102. const CWishListPage = connect(state => ({wishlist: state.wishlist}), {addToCart: actionCardChange, onWishListRemove: actionWishListRemove})(WishListPage)
  103. export default CWishListPage
  104. // TODO MOBILE VERSION