index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 DoneAllIcon from '@mui/icons-material/DoneAll';
  17. import DoneIcon from '@mui/icons-material/Done';
  18. import EditIcon from '@mui/icons-material/Edit';
  19. import SouthWestIcon from '@mui/icons-material/SouthWest';
  20. import NorthEastIcon from '@mui/icons-material/NorthEast';
  21. import PhoneIcon from '@mui/icons-material/Phone';
  22. import Avatar from '@mui/material/Avatar';
  23. import { CopyToClipboard } from 'react-copy-to-clipboard';
  24. import { firstLetter, slicedWord, timeStampMessage, copied,emojisArr,prodAwsS3,getTimeBySeconds } from '../../../../../../helpers'
  25. import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  26. const StyledMenu = styled((props:any) => (
  27. <Menu
  28. elevation={0}
  29. anchorOrigin={{
  30. vertical: 'top',
  31. horizontal: 'right',
  32. }}
  33. transformOrigin={{
  34. vertical: 'bottom',
  35. horizontal: 'right',
  36. }}
  37. {...props}
  38. />
  39. ))(({ theme }:any) => ({
  40. '& .MuiPaper-root': {
  41. borderRadius: 10,
  42. marginTop: theme.spacing(0),
  43. minWidth: 220,
  44. color:
  45. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  46. boxShadow:
  47. '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',
  48. '& .MuiMenu-list': {
  49. padding: '4px 4px',
  50. },
  51. '& .MuiMenuItem-root': {
  52. marginBottom: theme.spacing(1),
  53. '& .MuiSvgIcon-root': {
  54. fontSize: 21,
  55. color: theme.palette.text.secondary,
  56. marginRight: theme.spacing(2),
  57. }
  58. },
  59. },
  60. }));
  61. const useStyles = makeStyles({
  62. container: {
  63. display: "flex",
  64. alignItems: 'flex-end',
  65. alignContent: 'flex-end',
  66. flexDirection:'column',
  67. borderRadius: 7,
  68. position: 'relative',
  69. padding:'4px 22px 4px 0px'
  70. },
  71. wrapper: {
  72. position: 'relative',
  73. display: 'flex',
  74. alignItems: 'start',
  75. alignContent: 'start',
  76. flexDirection: 'column',
  77. maxWidth: 450,
  78. minWidth:200,
  79. padding: 5,
  80. borderRadius: 7,
  81. wordBreak:'break-word',
  82. textAlign: "left",
  83. font: "400 .9em 'Open Sans', sans-serif",
  84. },
  85. wrapperInner: {
  86. display: 'flex',
  87. alignItems: 'center',
  88. alignContent: 'center',
  89. justifyContent: 'space-between',
  90. flexWrap: "nowrap",
  91. width: '100%',
  92. marginBottom:10
  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. avatarIcon: {
  178. position: 'absolute',
  179. right: -54,
  180. bottom: 0,
  181. },
  182. tongueOne: {
  183. content: "''",
  184. position: "absolute",
  185. width: "0",
  186. height: "0",
  187. borderRight: "15px solid transparent",
  188. borderLeft: "15px solid transparent",
  189. bottom: '0px',
  190. right: "-15px",
  191. },
  192. tongueTwo: {
  193. content: "''",
  194. position: "absolute",
  195. width: "0",
  196. height: "0",
  197. borderRight: "16px solid transparent",
  198. borderLeft: "16px solid transparent",
  199. bottom: "0px",
  200. right: "-17px",
  201. },
  202. });
  203. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  204. interface IMessageRightCall {
  205. message: string,
  206. initiator: 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. handleEdit:(_id: string) => void,
  228. }
  229. const MessageRightCall = ({message,initiator,duration,tongue,watched,edited,avatarUrl,color,name,lastName,createdAt,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward,handleEdit}:IMessageRightCall) => {
  230. const classes = useStyles();
  231. const [anchorEl, setAnchorEl] = useState<any>(null);
  232. const [selected, setSelected] = useState<boolean>(false);
  233. const [modal,setModal] = useState<boolean>(false)
  234. const open = Boolean(anchorEl);
  235. const checked = isSelected(_id)
  236. const handleClose = (type: string | undefined): void => {
  237. if (type === 'copy') copied('Text')
  238. if (type === 'delete') setModal(true)
  239. setAnchorEl(null)
  240. setSelected(false)
  241. }
  242. const handleDeleteModal = (e: any) => {
  243. const id = e.target.id
  244. if (id === 'overlay' || id === 'cancel') return setModal(false)
  245. if (id === 'delete') {
  246. removeMessageById(_id)
  247. setModal(false)
  248. }
  249. }
  250. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  251. e.preventDefault()
  252. setAnchorEl(e.currentTarget)
  253. setSelected(true)
  254. }
  255. const handleEmojiMenu = ({ target }: any): void => {
  256. const idEmoji = target.id
  257. if (idEmoji === emoji) {updateMessageById(_id,'')
  258. } else updateMessageById(_id,idEmoji)
  259. }
  260. return (
  261. <div className={classes.container} style={{marginBottom:tongue?12:0}}>
  262. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  263. style={{backgroundColor:selected?'#ced8d7':"#deffa9",pointerEvents:isSomeSelected?'none':'auto'}}>
  264. <Typography style={{color: "#26afee"}} variant="h6" align="right">
  265. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  266. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  267. </Typography>
  268. <div className={classes.wrapperInner}>
  269. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  270. {message}
  271. </Typography>
  272. <PhoneIcon style={{color:'#18bd03'}} fontSize='large' />
  273. </div>
  274. <div className={classes.informationWrapper}>
  275. {initiator ? <NorthEastIcon style={{ color: duration ?'#18bd03':'#f02a2a', marginRight: 5 }} fontSize='small' /> :
  276. <SouthWestIcon style={{ color: duration?'#18bd03':'#f02a2a', marginRight: 5 }} fontSize='small' />}
  277. <div className={classes.time} style={{ color: '#18bd03' }}>
  278. {`${timeStampMessage(createdAt)}${duration ? ', ' + getTimeBySeconds(duration) : ''}`}</div>
  279. {watched ? <DoneAllIcon style={{ color: '#18bd03', marginLeft: 5 }} fontSize='small' /> :
  280. <DoneIcon style={{ color: '#18bd03',marginLeft:5}} fontSize='small' />}
  281. </div>
  282. {tongue&&<div className={classes.avatarIcon}>
  283. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  284. sx={{ background: color, width: 40, height: 40 }}>
  285. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  286. </Avatar>
  287. </div>}
  288. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  289. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  290. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  291. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  292. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  293. onClick={() => handleSelected(_id)}/></div>}
  294. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  295. anchorEl={anchorEl} open={open} onClose={handleClose}>
  296. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  297. {emojisArr.map((el:string, i:number) =>
  298. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  299. </MenuItem>
  300. <Divider />
  301. <MenuItem onClick={() => {
  302. handleReply(_id)
  303. handleClose(undefined)
  304. }}>
  305. <ReplyIcon />
  306. Reply
  307. </MenuItem>
  308. <MenuItem onClick={() => {
  309. handleForward(_id)
  310. handleClose(undefined)
  311. }}>
  312. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  313. Forward
  314. </MenuItem>
  315. <MenuItem onClick={() => {
  316. handleEdit(_id)
  317. handleClose(undefined)
  318. }}>
  319. <EditIcon/>
  320. Edit
  321. </MenuItem>
  322. <CopyToClipboard onCopy={() => handleClose('copy')} text={`${message ? message : ''} ${caption ? caption : ''}`}>
  323. <MenuItem>
  324. <ContentCopyIcon />
  325. Copy Text
  326. </MenuItem>
  327. </CopyToClipboard>
  328. <MenuItem onClick={() => {
  329. pinMessageById(_id, !pinned)
  330. handleClose(undefined)
  331. }}>
  332. {pinned ?
  333. <CloseIcon className={classes.iconClose} /> :
  334. <PushPinIcon />}
  335. {pinned?'Unpin':'Pin'}
  336. </MenuItem>
  337. <MenuItem onClick={() => {
  338. handleSelected(_id)
  339. handleClose(undefined)
  340. }}>
  341. <CheckBoxIcon />
  342. Select
  343. </MenuItem>
  344. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  345. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  346. Delete
  347. </MenuItem>
  348. </StyledMenu>
  349. {modal &&
  350. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  351. <div className={classes.modalDelete}>
  352. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  353. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  354. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  355. DELETE MESSAGE
  356. </Button>
  357. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  358. CANCEL
  359. </Button>
  360. </div>
  361. </div>}
  362. </div>
  363. </div>
  364. )};
  365. export default MessageRightCall