index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { styled } from '@mui/material/styles';
  3. import { useState } from "react";
  4. import Typography from '@mui/material/Typography';
  5. import ListItemText from '@mui/material/ListItemText';
  6. import Button from '@mui/material/Button';
  7. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  8. import Menu from '@mui/material/Menu';
  9. import MenuItem from '@mui/material/MenuItem';
  10. import Divider from '@mui/material/Divider';
  11. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  12. import Checkbox from '@mui/material/Checkbox';
  13. import PushPinIcon from '@mui/icons-material/PushPin';
  14. import CloseIcon from '@mui/icons-material/Close';
  15. import ReplyIcon from '@mui/icons-material/Reply';
  16. import LibraryMusicIcon from '@mui/icons-material/LibraryMusic';
  17. import FolderIcon from '@mui/icons-material/Folder';
  18. import ImageIcon from '@mui/icons-material/Image';
  19. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  20. import VideoLibraryIcon from '@mui/icons-material/VideoLibrary';
  21. import DoneAllIcon from '@mui/icons-material/DoneAll';
  22. import DoneIcon from '@mui/icons-material/Done';
  23. import Avatar from '@mui/material/Avatar';
  24. import { CopyToClipboard } from 'react-copy-to-clipboard';
  25. import { firstLetter, slicedWord, timeStampMessage, copied,emojisArr,handleDownload,prodAwsS3 } from '../../../../../../helpers'
  26. import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  27. const StyledMenu = styled((props:any) => (
  28. <Menu
  29. elevation={0}
  30. anchorOrigin={{
  31. vertical: 'top',
  32. horizontal: 'right',
  33. }}
  34. transformOrigin={{
  35. vertical: 'bottom',
  36. horizontal: 'right',
  37. }}
  38. {...props}
  39. />
  40. ))(({ theme }:any) => ({
  41. '& .MuiPaper-root': {
  42. borderRadius: 10,
  43. marginTop: theme.spacing(0),
  44. minWidth: 220,
  45. color:
  46. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  47. boxShadow:
  48. 'rgb(255, 255, 255) 0px 0px 0px 0px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px, rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px',
  49. '& .MuiMenu-list': {
  50. padding: '4px 4px',
  51. },
  52. '& .MuiMenuItem-root': {
  53. marginBottom: theme.spacing(1),
  54. '& .MuiSvgIcon-root': {
  55. fontSize: 21,
  56. color: theme.palette.text.secondary,
  57. marginRight: theme.spacing(2),
  58. }
  59. },
  60. },
  61. }));
  62. const useStyles = makeStyles({
  63. container: {
  64. display: "flex",
  65. alignItems: 'flex-end',
  66. alignContent: 'flex-end',
  67. flexDirection:'column',
  68. borderRadius: 7,
  69. position: 'relative',
  70. padding:'4px 22px 4px 0px'
  71. },
  72. wrapper: {
  73. position: 'relative',
  74. display: 'flex',
  75. alignItems: 'start',
  76. alignContent: 'start',
  77. flexDirection: 'column',
  78. maxWidth: 450,
  79. minWidth:200,
  80. padding: 5,
  81. borderRadius: 7,
  82. wordBreak:'break-word',
  83. textAlign: "left",
  84. font: "400 .9em 'Open Sans', sans-serif",
  85. },
  86. wrapperInner: {
  87. position: 'relative',
  88. display: 'flex',
  89. alignItems: 'center',
  90. alignContent: 'center',
  91. width: '100%',
  92. cursor: 'pointer',
  93. '&:hover': {
  94. backgroundColor: 'rgba(104, 105, 104, 0.2)'
  95. }
  96. },
  97. wrapperInnerMessage: {
  98. display: 'flex',
  99. alignItems: 'start',
  100. alignContent: 'start',
  101. flexDirection: 'column',
  102. marginLeft:20,
  103. },
  104. informationWrapper: {
  105. display: 'flex',
  106. alignItems: 'center',
  107. alignContent: 'center',
  108. justifyContent: 'flex-end',
  109. width: '100%',
  110. paddingRight:3,
  111. },
  112. time: {
  113. fontSize: ".65em",
  114. fontWeight:600,
  115. },
  116. modalDelete: {
  117. background: '#ffffff',
  118. position: 'absolute',
  119. content:'',
  120. width: '20%',
  121. height:'auto',
  122. left: '40%',
  123. bottom: '48.5%',
  124. borderRadius: 10,
  125. padding: 10,
  126. display: 'flex',
  127. flexDirection:'column'
  128. },
  129. overlay: {
  130. position: 'fixed',
  131. top: 0,
  132. left: 0,
  133. width: '100vw',
  134. height: '100vh',
  135. zIndex: 100,
  136. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  137. overflowY: 'hidden',
  138. },
  139. emojiTitle: {
  140. position: "absolute",
  141. fontSize: "1.7em",
  142. fontWeight:600,
  143. bottom: '0.2rem',
  144. left: -40,
  145. },
  146. emojiCompanionTitle: {
  147. position: "absolute",
  148. fontSize: "1.7em",
  149. fontWeight:600,
  150. bottom: '2.2rem',
  151. left: -40,
  152. },
  153. emoji: {
  154. cursor: 'pointer',
  155. fontSize: '1.7rem',
  156. transition: 'all 0.3s',
  157. '&:hover': {
  158. transform: 'scale(1.5)'
  159. }
  160. },
  161. emojiActive: {
  162. cursor: 'pointer',
  163. fontSize: '1.2rem',
  164. animation: `$emoji 0.6s ease-out`,
  165. animationDirection: 'forwards',
  166. animationIterationCount: 1,
  167. },
  168. '@keyframes emoji': {
  169. '5%': { transform: 'translateY(1rem)'},
  170. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  171. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  172. '80%': {opacity: 0},
  173. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  174. },
  175. iconClose: {
  176. '&:hover': {
  177. transform: 'rotate(180deg)',
  178. transition: 'all 250ms ease-out ',
  179. }
  180. },
  181. folderIcon: {
  182. color: '#00b333',
  183. cursor: 'pointer',
  184. '&:hover': {
  185. color: '#00e040'
  186. },
  187. },
  188. checkboxSelect: {
  189. position: 'absolute',
  190. right: -64,
  191. top: -10,
  192. pointerEvents: 'auto'
  193. },
  194. column: {
  195. position: 'absolute',
  196. content: '',
  197. width: 2,
  198. left:43,
  199. top:'10%',
  200. height:'80%',
  201. backgroundColor: '#00b333',
  202. },
  203. avatarIcon: {
  204. position: 'absolute',
  205. right: -54,
  206. bottom: 0,
  207. },
  208. tongueOne: {
  209. content: "''",
  210. position: "absolute",
  211. width: "0",
  212. height: "0",
  213. borderRight: "15px solid transparent",
  214. borderLeft: "15px solid transparent",
  215. bottom: '0px',
  216. right: "-15px",
  217. },
  218. tongueTwo: {
  219. content: "''",
  220. position: "absolute",
  221. width: "0",
  222. height: "0",
  223. borderRight: "16px solid transparent",
  224. borderLeft: "16px solid transparent",
  225. bottom: "0px",
  226. right: "-17px",
  227. },
  228. });
  229. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  230. interface IMessageRightReply {
  231. url: string,
  232. tongue: boolean,
  233. watched: boolean,
  234. avatarUrl: string,
  235. color: string,
  236. replyMessage: string,
  237. message: string,
  238. name: string,
  239. lastName: string,
  240. replyName:string,
  241. replyLastName: string,
  242. replyCaption: string,
  243. createdAt: string,
  244. caption: string,
  245. emoji: string,
  246. emojiCompanion: string,
  247. pinned: boolean,
  248. isSomeSelected: boolean,
  249. isSelected:(_id:string) => boolean,
  250. handleSelected: (_id:string) => void,
  251. _id: string,
  252. nightMode: boolean,
  253. handleReply: (_id: string) => void,
  254. handleForward: (_id: string) => void,
  255. fullType: string,
  256. handleScrollToTheMessage: (_id: string) => void,
  257. oldId: string
  258. }
  259. const MessageRightReply = ({url,tongue,watched,avatarUrl,color,replyMessage,message,name,lastName,replyName,replyLastName,replyCaption,createdAt,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward,fullType,handleScrollToTheMessage,oldId}:IMessageRightReply) => {
  260. const classes = useStyles();
  261. const [anchorEl, setAnchorEl] = useState<any>(null);
  262. const [selected, setSelected] = useState<boolean>(false);
  263. const [modal,setModal] = useState<boolean>(false)
  264. const open = Boolean(anchorEl);
  265. const checked = isSelected(_id)
  266. const handleClose = (type: string | undefined): void => {
  267. if (type === 'copy') copied('Message')
  268. if (type === 'delete') setModal(true)
  269. setAnchorEl(null)
  270. setSelected(false)
  271. }
  272. const handleDeleteModal = (e: any) => {
  273. const id = e.target.id
  274. if (id === 'overlay' || id === 'cancel') return setModal(false)
  275. if (id === 'delete') {
  276. removeMessageById(_id)
  277. setModal(false)
  278. }
  279. }
  280. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  281. e.preventDefault()
  282. setAnchorEl(e.currentTarget)
  283. setSelected(true)
  284. }
  285. const handleEmojiMenu = ({ target }: any): void => {
  286. const idEmoji = target.id
  287. if (idEmoji === emoji) {updateMessageById(_id,'')
  288. } else updateMessageById(_id,idEmoji)
  289. }
  290. const handleClickIcon = (e: any) => {
  291. e.stopPropagation()
  292. handleDownload(url, fullType)
  293. }
  294. return (
  295. <div className={classes.container} style={{marginBottom:tongue?12:0}}>
  296. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  297. style={{backgroundColor:selected?'#ced8d7':'#deffa9',pointerEvents:isSomeSelected?'none':'auto'}}>
  298. <Typography style={{color: "#26afee"}} variant="h6" align="right">
  299. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  300. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  301. </Typography>
  302. <div className={classes.wrapperInner}>
  303. {fullType === null &&<CopyToClipboard onCopy={() => copied('ReplyMessage')} text={`ReplyMessage: ${replyMessage} , ReplyCaption: ${replyCaption}`}>
  304. <ContentCopyIcon className={classes.folderIcon} fontSize='large'/>
  305. </CopyToClipboard>}
  306. {fullType&&fullType.includes('audio') &&<LibraryMusicIcon onClick={handleClickIcon}
  307. className={classes.folderIcon} fontSize='large' />}
  308. {fullType&&fullType.includes('video') &&<VideoLibraryIcon onClick={handleClickIcon}
  309. className={classes.folderIcon} fontSize='large' />}
  310. {fullType&&fullType.includes('image') &&<ImageIcon onClick={handleClickIcon}
  311. className={classes.folderIcon} fontSize='large' />}
  312. {fullType&&fullType.includes('application') && <FolderIcon onClick={handleClickIcon}
  313. className={classes.folderIcon} fontSize='large' />}
  314. <div className={classes.column}></div>
  315. <div className={classes.wrapperInnerMessage} onClick={() => handleScrollToTheMessage(oldId)}>
  316. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  317. {`Replied to ${firstLetter(replyName)}${slicedWord(replyName, 15, 1)}
  318. ${firstLetter(replyLastName)}${slicedWord(replyLastName, 15, 1)}`}
  319. </Typography>
  320. <ListItemText primary={replyMessage} primaryTypographyProps={{ color: "#535353" }} />
  321. <ListItemText secondary={replyCaption} secondaryTypographyProps={{color: "#535353"}}/>
  322. </div>
  323. </div>
  324. <ListItemText primary={message} primaryTypographyProps={{ color: "#000000" }} />
  325. <ListItemText secondary={caption} secondaryTypographyProps={{color: "#000000"}}/>
  326. <div className={classes.informationWrapper}>
  327. <div className={classes.time} style={{ color: '#18bd03'}}>{timeStampMessage(createdAt)}</div>
  328. {watched ? <DoneAllIcon style={{ color: '#18bd03', marginLeft: 5 }} fontSize='small' /> :
  329. <DoneIcon style={{ color: '#18bd03',marginLeft:5}} fontSize='small' />}
  330. </div>
  331. {tongue&&<div className={classes.avatarIcon}>
  332. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  333. sx={{ background: color, width: 40, height: 40 }}>
  334. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  335. </Avatar>
  336. </div>}
  337. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  338. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  339. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  340. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  341. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  342. onClick={() => handleSelected(_id)}/></div>}
  343. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  344. anchorEl={anchorEl} open={open} onClose={handleClose}>
  345. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  346. {emojisArr.map((el:string, i:number) =>
  347. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  348. </MenuItem>
  349. <Divider />
  350. <MenuItem onClick={() => {
  351. handleReply(_id)
  352. handleClose(undefined)
  353. }}>
  354. <ReplyIcon />
  355. Reply
  356. </MenuItem>
  357. <MenuItem onClick={() => {
  358. handleForward(_id)
  359. handleClose(undefined)
  360. }}>
  361. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  362. Forward
  363. </MenuItem>
  364. <CopyToClipboard onCopy={() => handleClose('copy')} text={`Message: ${message} , Caption: ${caption}`}>
  365. <MenuItem>
  366. <ContentCopyIcon />
  367. Copy Text
  368. </MenuItem>
  369. </CopyToClipboard>
  370. <MenuItem onClick={() => {
  371. pinMessageById(_id, !pinned)
  372. handleClose(undefined)
  373. }}>
  374. {pinned ?
  375. <CloseIcon className={classes.iconClose} /> :
  376. <PushPinIcon />}
  377. {pinned?'Unpin':'Pin'}
  378. </MenuItem>
  379. <MenuItem onClick={() => {
  380. handleSelected(_id)
  381. handleClose(undefined)
  382. }}>
  383. <CheckBoxIcon />
  384. Select
  385. </MenuItem>
  386. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  387. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  388. Delete
  389. </MenuItem>
  390. </StyledMenu>
  391. {modal &&
  392. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  393. <div className={classes.modalDelete}>
  394. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  395. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  396. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  397. DELETE MESSAGE
  398. </Button>
  399. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  400. CANCEL
  401. </Button>
  402. </div>
  403. </div>}
  404. </div>
  405. </div>
  406. )};
  407. export default MessageRightReply