index.tsx 14 KB

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