index.tsx 12 KB

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