index.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { useDispatch } from "react-redux";
  3. import CloseIcon from '@mui/icons-material/Close';
  4. import ReplyIcon from '@mui/icons-material/Reply';
  5. import MenuItem from '@mui/material/MenuItem';
  6. import ListItemText from '@mui/material/ListItemText';
  7. import { firstLetter,slicedWord } from "../../../../../../helpers";
  8. import { TMessage } from "../../../../../../typescript/redux/messages/types";
  9. import { asyncGetChatById } from '../../../../../../redux/chat/operations'
  10. import { actionRightIsOpen, actionOpenPinned } from '../../../../../../redux/control/action'
  11. const useStyles = makeStyles({
  12. forwardTop : {
  13. position: 'absolute',
  14. left: 0,
  15. top: '-7vh',
  16. height: '6vh',
  17. width: '100%',
  18. borderRadius: 8,
  19. display: 'flex',
  20. flexWrap: 'nowrap',
  21. alignContent: 'center',
  22. alignItems: 'center',
  23. color: '#6b6b6b',
  24. border:'solid 2px rgb(41, 139, 231)',
  25. backgroundColor: '#ffffff',
  26. padding: '0px 5px',
  27. zIndex:2,
  28. },
  29. forwardIconClose: {
  30. cursor: 'pointer',
  31. marginLeft: 5,
  32. marginRight: 5,
  33. '&:hover': {
  34. color:'#f02a2a',
  35. transform: 'rotate(180deg)',
  36. transition: 'all 250ms ease-out ',
  37. }
  38. },
  39. forwardListWrapper: {
  40. width: '100%',
  41. },
  42. forwardColumn: {
  43. height: '80%',
  44. width: 2,
  45. backgroundColor: 'rgb(41, 139, 231)',
  46. marginRight:10
  47. },
  48. });
  49. interface IForwardBar {
  50. companionId: string,
  51. isForward:TMessage,
  52. handleCloseForward: () => void,
  53. handleScrollToTheMessage: (_id: string) => void,
  54. setIsForward: React.Dispatch<React.SetStateAction<TMessage | undefined>>,
  55. }
  56. const ForwardBar = ({ companionId,isForward, handleCloseForward,handleScrollToTheMessage,setIsForward }: IForwardBar) => {
  57. const classes = useStyles();
  58. const dispatch = useDispatch()
  59. const handleScrollHereOrBack = () => {
  60. if (companionId === isForward.companionId) return handleScrollToTheMessage(isForward._id)
  61. setIsForward(undefined)
  62. dispatch(actionRightIsOpen(''))
  63. dispatch(actionOpenPinned(false))
  64. dispatch(asyncGetChatById(isForward.companionId))
  65. setTimeout(() => handleScrollToTheMessage(isForward._id), 2000)
  66. }
  67. return (
  68. <div className={classes.forwardTop}>
  69. <ReplyIcon style={{margin:'0px 7px',color: "rgb(41, 139, 231)",transform :'rotateY(180deg)'}} />
  70. <div className={classes.forwardColumn}></div>
  71. <ul className={classes.forwardListWrapper}>
  72. <MenuItem onClick={handleScrollHereOrBack}>
  73. <ListItemText
  74. primary={`${firstLetter(isForward.name)}${slicedWord(isForward.name, 15, 1)}
  75. ${firstLetter(isForward.lastName)}${slicedWord(isForward.lastName, 15, 1)}`}
  76. primaryTypographyProps={{ color: "rgb(41, 139, 231)",fontSize:16 }}
  77. secondary={`Type : ${isForward.type.toUpperCase()}`}
  78. secondaryTypographyProps={{ fontSize:16 }}/>
  79. </MenuItem>
  80. </ul>
  81. <CloseIcon onClick={handleCloseForward} className={classes.forwardIconClose} />
  82. </div>
  83. )
  84. }
  85. export default ForwardBar