index.tsx 14 KB

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