index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 Button from '@mui/material/Button';
  6. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  7. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  8. import Menu from '@mui/material/Menu';
  9. import MenuItem from '@mui/material/MenuItem';
  10. import Divider from '@mui/material/Divider';
  11. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  12. import Checkbox from '@mui/material/Checkbox';
  13. import PushPinIcon from '@mui/icons-material/PushPin';
  14. import CloseIcon from '@mui/icons-material/Close';
  15. import ReplyIcon from '@mui/icons-material/Reply';
  16. import VisibilityIcon from '@mui/icons-material/Visibility';
  17. import SouthWestIcon from '@mui/icons-material/SouthWest';
  18. import NorthEastIcon from '@mui/icons-material/NorthEast';
  19. import PhoneIcon from '@mui/icons-material/Phone';
  20. import Avatar from '@mui/material/Avatar';
  21. import { CopyToClipboard } from 'react-copy-to-clipboard';
  22. import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  23. import { firstLetter,slicedWord,timeStampMessage,copied,emojisArr,prodAwsS3,getTimeBySeconds } from '../../../../../../helpers'
  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-start',
  63. alignContent: 'flex-start',
  64. flexDirection:'column',
  65. borderRadius: 7,
  66. position: 'relative',
  67. padding:'4px 0px 4px 22px'
  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. justifyContent: 'space-between',
  88. flexWrap: "nowrap",
  89. width: '100%',
  90. marginBottom:10
  91. },
  92. informationWrapper: {
  93. display: 'flex',
  94. alignItems: 'center',
  95. alignContent: 'center',
  96. justifyContent: 'flex-end',
  97. width: '100%',
  98. paddingRight:3,
  99. },
  100. time: {
  101. fontSize: ".65em",
  102. fontWeight:600,
  103. color: '#414141',
  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. right: -40,
  134. },
  135. emojiCompanionTitle: {
  136. position: "absolute",
  137. fontSize: "1.7em",
  138. fontWeight:600,
  139. bottom: '2.2rem',
  140. right: -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. left: -64,
  173. top: -10,
  174. pointerEvents: 'auto'
  175. },
  176. avatarIcon: {
  177. position: 'absolute',
  178. left: -54,
  179. bottom: 0,
  180. },
  181. tongueOne: {
  182. content: "''",
  183. position: "absolute",
  184. width: "0",
  185. height: "0",
  186. borderLeft: "15px solid transparent",
  187. borderRight: "15px solid transparent",
  188. bottom: '0px',
  189. left: "-15px",
  190. },
  191. tongueTwo: {
  192. content: "''",
  193. position: "absolute",
  194. width: "0",
  195. height: "0",
  196. borderLeft: "16px solid transparent",
  197. borderRight: "16px solid transparent",
  198. bottom: "0px",
  199. left: "-17px",
  200. },
  201. });
  202. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  203. interface IMessageLeftCall {
  204. message: string,
  205. initiator: boolean,
  206. reject: boolean,
  207. duration: number,
  208. tongue: boolean,
  209. watched: boolean,
  210. edited: boolean,
  211. avatarUrl: string,
  212. color: string,
  213. name:string,
  214. lastName:string,
  215. createdAt: string,
  216. caption: string,
  217. emoji: string,
  218. emojiCompanion: string,
  219. pinned: boolean,
  220. isSomeSelected: boolean,
  221. isSelected:(_id:string) => boolean,
  222. handleSelected: (_id:string) => void,
  223. _id: string,
  224. nightMode: boolean,
  225. handleReply: (_id: string) => void,
  226. handleForward: (_id: string) => void,
  227. }
  228. const MessageLeftCall = ({message,initiator,reject,duration,tongue,watched,edited,avatarUrl,color,name,lastName,createdAt,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward}:IMessageLeftCall) => {
  229. const classes = useStyles();
  230. const [anchorEl, setAnchorEl] = useState<any>(null);
  231. const [selected, setSelected] = useState<boolean>(false);
  232. const [modal,setModal] = useState<boolean>(false)
  233. const open = Boolean(anchorEl);
  234. const checked = isSelected(_id)
  235. const handleClose = (type: string | undefined): void => {
  236. if (type === 'copy') copied('Text')
  237. if (type === 'delete') setModal(true)
  238. setAnchorEl(null)
  239. setSelected(false)
  240. }
  241. const handleDeleteModal = (e: any) => {
  242. const id = e.target.id
  243. if (id === 'overlay' || id === 'cancel') return setModal(false)
  244. if (id === 'delete') {
  245. removeMessageById(_id)
  246. setModal(false)
  247. }
  248. }
  249. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  250. e.preventDefault()
  251. setAnchorEl(e.currentTarget)
  252. setSelected(true)
  253. }
  254. const handleEmojiMenu = ({ target }: any): void => {
  255. const idEmoji = target.id
  256. if (idEmoji === emoji) {updateMessageById(_id,'')
  257. } else updateMessageById(_id,idEmoji)
  258. }
  259. return (
  260. <div className={classes.container} style={{marginBottom:tongue?12:0}}>
  261. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  262. style={{backgroundColor:selected?'#babdbc':"#ffffff",pointerEvents:isSomeSelected?'none':'auto'}}>
  263. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  264. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  265. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  266. </Typography>
  267. <div className={classes.wrapperInner}>
  268. <Typography style={{color: "#26afee"}} variant="h6" align="right">
  269. {message}
  270. </Typography>
  271. <PhoneIcon style={{color:'#26afee'}} fontSize='large' />
  272. </div>
  273. <div className={classes.informationWrapper}>
  274. {!initiator ? <SouthWestIcon style={{ color: reject?'#f02a2a':'#959595', marginRight: 5 }} fontSize='small' /> :
  275. <NorthEastIcon style={{ color: reject?'#f02a2a':'#959595',marginRight:5}} fontSize='small' />}
  276. <div className={classes.time} style={{ color: '#959595'}}>{`${edited?'edited ':''}${timeStampMessage(createdAt)}${duration?', '+getTimeBySeconds(duration):''}`}</div>
  277. {watched&&<VisibilityIcon style={{ color: '#959595', marginLeft: 5 }} fontSize='small' />}
  278. </div>
  279. {tongue&&<div className={classes.avatarIcon}>
  280. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  281. sx={{ background: color, width: 40, height: 40 }}>
  282. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  283. </Avatar>
  284. </div>}
  285. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  286. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  287. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  288. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  289. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  290. onClick={() => handleSelected(_id)}/></div>}
  291. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  292. anchorEl={anchorEl} open={open} onClose={handleClose}>
  293. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  294. {emojisArr.map((el:string, i:number) =>
  295. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  296. </MenuItem>
  297. <Divider />
  298. <MenuItem onClick={() => {
  299. handleReply(_id)
  300. handleClose(undefined)
  301. }}>
  302. <ReplyIcon />
  303. Reply
  304. </MenuItem>
  305. <MenuItem onClick={() => {
  306. handleForward(_id)
  307. handleClose(undefined)
  308. }}>
  309. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  310. Forward
  311. </MenuItem>
  312. <CopyToClipboard onCopy={() => handleClose('copy')} text={`${message?message:''} ${caption?caption:''}`}>
  313. <MenuItem>
  314. <ContentCopyIcon />
  315. Copy Text
  316. </MenuItem>
  317. </CopyToClipboard>
  318. <MenuItem onClick={() => {
  319. pinMessageById(_id, !pinned)
  320. handleClose(undefined)
  321. }}>
  322. {pinned ?
  323. <CloseIcon className={classes.iconClose} /> :
  324. <PushPinIcon />}
  325. {pinned?'Unpin':'Pin'}
  326. </MenuItem>
  327. <MenuItem onClick={() => {
  328. handleSelected(_id)
  329. handleClose(undefined)
  330. }}>
  331. <CheckBoxIcon />
  332. Select
  333. </MenuItem>
  334. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  335. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  336. Delete
  337. </MenuItem>
  338. </StyledMenu>
  339. {modal &&
  340. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  341. <div className={classes.modalDelete}>
  342. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  343. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  344. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  345. DELETE MESSAGE
  346. </Button>
  347. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  348. CANCEL
  349. </Button>
  350. </div>
  351. </div>}
  352. </div>
  353. </div>
  354. )};
  355. export default MessageLeftCall