UserInfoButton.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { store } from "../../../store";
  2. import { privateMessage } from "../../../reducers/userDataReducer";
  3. import { useSelector } from "react-redux";
  4. import { StyledAvatar } from "../messageForm/StyledAvatar";
  5. import { Avatar } from "@mui/material";
  6. export const UserInfoButton = ({item, i}) => {
  7. const SERVER_URL = process.env.REACT_APP_SERVER_URL
  8. const user = useSelector(state => state.getUserSocketReducer.socketUserData)
  9. const socket = useSelector(state => state.getUserSocketReducer.socket)
  10. const isPrivatChat = useSelector(state => state.userDataReducer.isPrivatChat)
  11. const chatId = useSelector(state => state.userDataReducer.chatId)
  12. const storeUserAvatar = useSelector(state => state.userDataReducer.avatar)
  13. let userAvatarUrl = storeUserAvatar || user.avatar;
  14. return (
  15. <div
  16. className={isPrivatChat&&(chatId === item._id)? 'online active' :'online' }
  17. onClick={() => {
  18. console.log(item._id, user._id)
  19. store.dispatch(privateMessage({chatId: item._id}))
  20. socket.emit('privat chat', {
  21. user,
  22. to: item._id,
  23. })
  24. }
  25. }
  26. >
  27. <div style={{color: item.color}}>
  28. <StyledAvatar key={i} sx={{ marginRight:2}}
  29. >
  30. <Avatar
  31. src= {SERVER_URL + '/'+ item?.avatar}
  32. sx={{ alignSelf: 'flex-end'}}
  33. >
  34. {item?.userName.slice(0, 1)}
  35. </Avatar>
  36. </StyledAvatar>
  37. {item.userName}
  38. </div>
  39. <span style={{color: 'green'}}>
  40. online
  41. </span>
  42. </div>
  43. )
  44. }