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 DoneAllIcon from '@mui/icons-material/DoneAll';
  14. import DoneIcon from '@mui/icons-material/Done';
  15. import SouthWestIcon from '@mui/icons-material/SouthWest';
  16. import NorthEastIcon from '@mui/icons-material/NorthEast';
  17. import PhoneIcon from '@mui/icons-material/Phone';
  18. import Avatar from '@mui/material/Avatar';
  19. import { firstLetter, slicedWord, timeStampMessage,emojisArr,prodAwsS3,getTimeBySeconds } from '../../../../../../helpers'
  20. import { removeMessageById,updateMessageById } from "../../../../../../api-data";
  21. const StyledMenu = styled((props:any) => (
  22. <Menu
  23. elevation={0}
  24. anchorOrigin={{
  25. vertical: 'top',
  26. horizontal: 'right',
  27. }}
  28. transformOrigin={{
  29. vertical: 'bottom',
  30. horizontal: 'right',
  31. }}
  32. {...props}
  33. />
  34. ))(({ theme }:any) => ({
  35. '& .MuiPaper-root': {
  36. borderRadius: 10,
  37. marginTop: theme.spacing(0),
  38. minWidth: 220,
  39. color:
  40. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  41. boxShadow:
  42. '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',
  43. '& .MuiMenu-list': {
  44. padding: '4px 4px',
  45. },
  46. '& .MuiMenuItem-root': {
  47. marginBottom: theme.spacing(1),
  48. '& .MuiSvgIcon-root': {
  49. fontSize: 21,
  50. color: theme.palette.text.secondary,
  51. marginRight: theme.spacing(2),
  52. }
  53. },
  54. },
  55. }));
  56. const useStyles = makeStyles({
  57. container: {
  58. display: "flex",
  59. alignItems: 'flex-end',
  60. alignContent: 'flex-end',
  61. flexDirection:'column',
  62. borderRadius: 7,
  63. position: 'relative',
  64. padding:'4px 22px 4px 0px'
  65. },
  66. wrapper: {
  67. position: 'relative',
  68. display: 'flex',
  69. alignItems: 'start',
  70. alignContent: 'start',
  71. flexDirection: 'column',
  72. maxWidth: 450,
  73. minWidth:200,
  74. padding: 5,
  75. borderRadius: 7,
  76. wordBreak:'break-word',
  77. textAlign: "left",
  78. font: "400 .9em 'Open Sans', sans-serif",
  79. },
  80. wrapperInner: {
  81. display: 'flex',
  82. alignItems: 'center',
  83. alignContent: 'center',
  84. justifyContent: 'space-between',
  85. flexWrap: "nowrap",
  86. width: '100%',
  87. marginBottom:10
  88. },
  89. informationWrapper: {
  90. display: 'flex',
  91. alignItems: 'center',
  92. alignContent: 'center',
  93. justifyContent: 'flex-end',
  94. width: '100%',
  95. paddingRight:3,
  96. },
  97. time: {
  98. fontSize: ".65em",
  99. fontWeight:600,
  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. left: -40,
  130. },
  131. emojiCompanionTitle: {
  132. position: "absolute",
  133. fontSize: "1.7em",
  134. fontWeight:600,
  135. bottom: '2.2rem',
  136. left: -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. right: -64,
  169. top: -10,
  170. pointerEvents: 'auto'
  171. },
  172. avatarIcon: {
  173. position: 'absolute',
  174. right: -54,
  175. bottom: 0,
  176. },
  177. tongueOne: {
  178. content: "''",
  179. position: "absolute",
  180. width: "0",
  181. height: "0",
  182. borderRight: "15px solid transparent",
  183. borderLeft: "15px solid transparent",
  184. bottom: '0px',
  185. right: "-15px",
  186. },
  187. tongueTwo: {
  188. content: "''",
  189. position: "absolute",
  190. width: "0",
  191. height: "0",
  192. borderRight: "16px solid transparent",
  193. borderLeft: "16px solid transparent",
  194. bottom: "0px",
  195. right: "-17px",
  196. },
  197. });
  198. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  199. interface IMessageRightCall {
  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 MessageRightCall = ({message,initiator,duration,tongue,watched,avatarUrl,color,name,lastName,createdAt,emoji,emojiCompanion,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply}:IMessageRightCall) => {
  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?'#ced8d7':"#deffa9",pointerEvents:isSomeSelected?'none':'auto'}}>
  253. <Typography style={{color: "#26afee"}} 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:'#18bd03'}} fontSize='large' />
  262. </div>
  263. <div className={classes.informationWrapper}>
  264. {initiator ? <NorthEastIcon style={{ color: duration ?'#18bd03':'#f02a2a', marginRight: 5 }} fontSize='small' /> :
  265. <SouthWestIcon style={{ color: duration?'#18bd03':'#f02a2a', marginRight: 5 }} fontSize='small' />}
  266. <div className={classes.time} style={{ color: '#18bd03' }}>
  267. {`${timeStampMessage(createdAt)}${duration ? ', ' + getTimeBySeconds(duration) : ''}`}</div>
  268. {watched ? <DoneAllIcon style={{ color: '#18bd03', marginLeft: 5 }} fontSize='small' /> :
  269. <DoneIcon style={{ color: '#18bd03',marginLeft:5}} fontSize='small' />}
  270. </div>
  271. {tongue&&<div className={classes.avatarIcon}>
  272. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  273. sx={{ background: color, width: 40, height: 40 }}>
  274. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  275. </Avatar>
  276. </div>}
  277. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  278. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  279. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  280. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  281. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  282. onClick={() => handleSelected(_id)}/></div>}
  283. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  284. anchorEl={anchorEl} open={open} onClose={handleClose}>
  285. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  286. {emojisArr.map((el:string, i:number) =>
  287. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  288. </MenuItem>
  289. <Divider />
  290. <MenuItem onClick={() => {
  291. handleReply(_id)
  292. handleClose(undefined)
  293. }}>
  294. <ReplyIcon />
  295. Reply
  296. </MenuItem>
  297. <MenuItem onClick={() => {
  298. handleSelected(_id)
  299. handleClose(undefined)
  300. }}>
  301. <CheckBoxIcon />
  302. Select
  303. </MenuItem>
  304. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  305. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  306. Delete
  307. </MenuItem>
  308. </StyledMenu>
  309. {modal &&
  310. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  311. <div className={classes.modalDelete}>
  312. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  313. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  314. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  315. DELETE MESSAGE
  316. </Button>
  317. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  318. CANCEL
  319. </Button>
  320. </div>
  321. </div>}
  322. </div>
  323. </div>
  324. )};
  325. export default MessageRightCall