index.tsx 11 KB

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