index.tsx 13 KB

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