index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 LibraryMusicIcon from '@mui/icons-material/LibraryMusic';
  8. import FolderIcon from '@mui/icons-material/Folder';
  9. import ImageIcon from '@mui/icons-material/Image';
  10. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  11. import VideoLibraryIcon from '@mui/icons-material/VideoLibrary';
  12. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  13. import Menu from '@mui/material/Menu';
  14. import MenuItem from '@mui/material/MenuItem';
  15. import Divider from '@mui/material/Divider';
  16. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  17. import Checkbox from '@mui/material/Checkbox';
  18. import PushPinIcon from '@mui/icons-material/PushPin';
  19. import CloseIcon from '@mui/icons-material/Close';
  20. import ReplyIcon from '@mui/icons-material/Reply';
  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. modalDelete: {
  116. background: '#ffffff',
  117. position: 'absolute',
  118. content:'',
  119. width: '20%',
  120. height:'auto',
  121. left: '40%',
  122. bottom: '48.5%',
  123. borderRadius: 10,
  124. padding: 10,
  125. display: 'flex',
  126. flexDirection:'column'
  127. },
  128. overlay: {
  129. position: 'fixed',
  130. top: 0,
  131. left: 0,
  132. width: '100vw',
  133. height: '100vh',
  134. zIndex: 100,
  135. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  136. overflowY: 'hidden',
  137. },
  138. emojiTitle: {
  139. position: "absolute",
  140. fontSize: "1.7em",
  141. fontWeight:600,
  142. bottom: '0.2rem',
  143. right: -40,
  144. },
  145. emojiCompanionTitle: {
  146. position: "absolute",
  147. fontSize: "1.7em",
  148. fontWeight:600,
  149. bottom: '2.2rem',
  150. right: -40,
  151. },
  152. emoji: {
  153. cursor: 'pointer',
  154. fontSize: '1.7rem',
  155. transition: 'all 0.3s',
  156. '&:hover': {
  157. transform: 'scale(1.5)'
  158. }
  159. },
  160. emojiActive: {
  161. cursor: 'pointer',
  162. fontSize: '1.2rem',
  163. animation: `$emoji 0.6s ease-out`,
  164. animationDirection: 'forwards',
  165. animationIterationCount: 1,
  166. },
  167. '@keyframes emoji': {
  168. '5%': { transform: 'translateY(1rem)'},
  169. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  170. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  171. '80%': {opacity: 0},
  172. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  173. },
  174. iconClose: {
  175. '&:hover': {
  176. transform: 'rotate(180deg)',
  177. transition: 'all 250ms ease-out ',
  178. }
  179. },
  180. checkboxSelect: {
  181. position: 'absolute',
  182. left: -64,
  183. top: -10,
  184. pointerEvents: 'auto'
  185. },
  186. folderIcon: {
  187. color: '#26afee',
  188. cursor: 'pointer',
  189. '&:hover': {
  190. color: '#49c1f8'
  191. },
  192. },
  193. column: {
  194. position: 'absolute',
  195. content: '',
  196. width: 2,
  197. left:43,
  198. top:'10%',
  199. height:'80%',
  200. backgroundColor: '#26afee',
  201. },
  202. avatarIcon: {
  203. position: 'absolute',
  204. left: -54,
  205. bottom: 0,
  206. },
  207. tongueOne: {
  208. content: "''",
  209. position: "absolute",
  210. width: "0",
  211. height: "0",
  212. borderLeft: "15px solid transparent",
  213. borderRight: "15px solid transparent",
  214. bottom: '0px',
  215. left: "-15px",
  216. },
  217. tongueTwo: {
  218. content: "''",
  219. position: "absolute",
  220. width: "0",
  221. height: "0",
  222. borderLeft: "16px solid transparent",
  223. borderRight: "16px solid transparent",
  224. bottom: "0px",
  225. left: "-17px",
  226. },
  227. });
  228. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  229. interface IMessageLeftForward {
  230. url: string,
  231. companionIdForwardToAndFrom: string,
  232. oldId: string,
  233. tongue: boolean,
  234. avatarUrl: string,
  235. color: string,
  236. message: string,
  237. name: string,
  238. lastName: string,
  239. forwardName:string,
  240. forwardLastName: string,
  241. forwardMessage: string,
  242. forwardCaption: 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. handleScrollToTheChat: (companionIdForwardToAndFrom:string,oldId:string) => void,
  256. fullType: string
  257. }
  258. const MessageLeftForward = ({url,companionIdForwardToAndFrom,oldId,tongue,avatarUrl,color,message,name,lastName,forwardName,forwardLastName,forwardMessage,forwardCaption,createdAt,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward,handleScrollToTheChat,fullType}:IMessageLeftForward) => {
  259. const classes = useStyles();
  260. const [anchorEl, setAnchorEl] = useState<any>(null);
  261. const [selected, setSelected] = useState<boolean>(false);
  262. const [modal,setModal] = useState<boolean>(false)
  263. const open = Boolean(anchorEl);
  264. const checked = isSelected(_id)
  265. const handleClose = (type: string | undefined): void => {
  266. if (type === 'copy') copied('Message')
  267. if (type === 'delete') setModal(true)
  268. setAnchorEl(null)
  269. setSelected(false)
  270. }
  271. const handleDeleteModal = (e: any) => {
  272. const id = e.target.id
  273. if (id === 'overlay' || id === 'cancel') return setModal(false)
  274. if (id === 'delete') {
  275. removeMessageById(_id)
  276. setModal(false)
  277. }
  278. }
  279. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  280. e.preventDefault()
  281. setAnchorEl(e.currentTarget)
  282. setSelected(true)
  283. }
  284. const handleEmojiMenu = ({ target }: any): void => {
  285. const idEmoji = target.id
  286. if (idEmoji === emoji) {updateMessageById(_id,'')
  287. } else updateMessageById(_id,idEmoji)
  288. }
  289. const handleClickIcon = (e: any) => {
  290. e.stopPropagation()
  291. handleDownload(url, fullType)
  292. }
  293. return (
  294. <div className={classes.container} style={{marginBottom:tongue?12:0}}>
  295. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  296. style={{backgroundColor:selected?'#babdbc':'#ffffff',pointerEvents:isSomeSelected?'none':'auto'}}>
  297. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  298. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  299. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  300. </Typography>
  301. <div className={classes.wrapperInner}>
  302. {fullType === null &&<CopyToClipboard onCopy={() => copied('ForwardMessage')} text={`ForwardMessage: ${forwardMessage} , ForwardCaption: ${forwardCaption}`}>
  303. <ContentCopyIcon className={classes.folderIcon} fontSize='large'/>
  304. </CopyToClipboard>}
  305. {fullType&&fullType.includes('audio') &&<LibraryMusicIcon onClick={handleClickIcon}
  306. className={classes.folderIcon} fontSize='large' />}
  307. {fullType&&fullType.includes('video') &&<VideoLibraryIcon onClick={handleClickIcon}
  308. className={classes.folderIcon} fontSize='large' />}
  309. {fullType&&fullType.includes('image') &&<ImageIcon onClick={handleClickIcon}
  310. className={classes.folderIcon} fontSize='large' />}
  311. {fullType && fullType.includes('application') && <FolderIcon onClick={handleClickIcon}
  312. className={classes.folderIcon} fontSize='large' />}
  313. <div className={classes.column}></div>
  314. <div className={classes.wrapperInnerMessage} onClick={() => handleScrollToTheChat(companionIdForwardToAndFrom,oldId)}>
  315. <Typography style={{color: "#26afee"}} variant="h6" align="right">
  316. {`Forwarded from ${firstLetter(forwardName)}${slicedWord(forwardName, 15, 1)}
  317. ${firstLetter(forwardLastName)}${slicedWord(forwardLastName, 15, 1)}`}
  318. </Typography>
  319. <ListItemText primary={forwardMessage} primaryTypographyProps={{ color: "#535353" }} />
  320. <ListItemText secondary={forwardCaption} secondaryTypographyProps={{color: "#535353"}}/>
  321. </div>
  322. </div>
  323. <ListItemText primary={message} primaryTypographyProps={{ color: "#000000" }} />
  324. <ListItemText secondary={caption} secondaryTypographyProps={{color: "#000000"}}/>
  325. <div className={classes.informationWrapper}>
  326. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  327. </div>
  328. {tongue&&<div className={classes.avatarIcon}>
  329. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  330. sx={{ background: color, width: 40, height: 40 }}>
  331. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  332. </Avatar>
  333. </div>}
  334. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  335. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  336. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  337. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  338. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  339. onClick={() => handleSelected(_id)}/></div>}
  340. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  341. anchorEl={anchorEl} open={open} onClose={handleClose}>
  342. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  343. {emojisArr.map((el:string, i:number) =>
  344. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  345. </MenuItem>
  346. <Divider />
  347. <MenuItem onClick={() => {
  348. handleReply(_id)
  349. handleClose(undefined)
  350. }}>
  351. <ReplyIcon />
  352. Reply
  353. </MenuItem>
  354. <MenuItem onClick={() => {
  355. handleForward(_id)
  356. handleClose(undefined)
  357. }}>
  358. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  359. Forward
  360. </MenuItem>
  361. <CopyToClipboard onCopy={() => handleClose('copy')} text={`Message: ${message} , Caption: ${caption}`}>
  362. <MenuItem>
  363. <ContentCopyIcon />
  364. Copy Text
  365. </MenuItem>
  366. </CopyToClipboard>
  367. <MenuItem onClick={() => {
  368. pinMessageById(_id, !pinned)
  369. handleClose(undefined)
  370. }}>
  371. {pinned ?
  372. <CloseIcon className={classes.iconClose} /> :
  373. <PushPinIcon />}
  374. {pinned?'Unpin':'Pin'}
  375. </MenuItem>
  376. <MenuItem onClick={() => {
  377. handleSelected(_id)
  378. handleClose(undefined)
  379. }}>
  380. <CheckBoxIcon />
  381. Select
  382. </MenuItem>
  383. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  384. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  385. Delete
  386. </MenuItem>
  387. </StyledMenu>
  388. {modal &&
  389. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  390. <div className={classes.modalDelete}>
  391. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  392. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  393. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  394. DELETE MESSAGE
  395. </Button>
  396. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  397. CANCEL
  398. </Button>
  399. </div>
  400. </div>}
  401. </div>
  402. </div>
  403. )};
  404. export default MessageLeftForward