index.tsx 14 KB

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