index.tsx 12 KB

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