index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import ListItemButton from '@mui/material/ListItemButton';
  2. import Avatar from '@mui/material/Avatar';
  3. import ListItemText from '@mui/material/ListItemText';
  4. import ListItemIcon from '@mui/material/ListItemIcon';
  5. import { useDispatch, useSelector } from 'react-redux';
  6. import { useEffect,useRef } from 'react';
  7. import { actionIsOpen } from '../../../../../redux/control/action'
  8. import { getChat } from '../../../../../redux/chat/selector'
  9. import { asyncGetChatById } from '../../../../../redux/chat/operations'
  10. import { firstLetter,slicedWord,timeStampEU,prodBaseURL } from '../../../../../helpers'
  11. const Credentials = () => {
  12. const dispatch = useDispatch()
  13. const { name, lastName, avatarUrl, color, online, companionId,seen,total,mute } = useSelector(getChat)
  14. const ref = useRef<any>(null)
  15. useEffect(() => {
  16. const handleReset = () => companionId&&dispatch(asyncGetChatById(companionId))
  17. const idInterval = setInterval(handleReset, 3000);
  18. return () => clearInterval(idInterval);
  19. }, [dispatch, companionId]);
  20. useEffect(() => {
  21. if (ref.current) {
  22. localStorage.setItem('isNew', JSON.stringify({ new: total - seen, mute }))
  23. }
  24. ref.current = { seen,total}
  25. }, [seen, total, mute]);
  26. return (
  27. <ListItemButton onClick={() => dispatch(actionIsOpen('credentials'))}>
  28. <ListItemIcon >
  29. <Avatar alt={name} src={avatarUrl?`${prodBaseURL}/${avatarUrl}`:undefined}
  30. sx={{ background: color, width: 44, height: 44 }}>
  31. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  32. </Avatar>
  33. </ListItemIcon>
  34. <ListItemText primary={`${firstLetter(name)}${slicedWord(name, 15, 1)}
  35. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  36. secondaryTypographyProps={{ color: '#0379af' }} secondary={online === 'true' ?
  37. 'online' : `last seen ${timeStampEU(online)}`} />
  38. </ListItemButton>
  39. )
  40. }
  41. export default Credentials