index.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import Button from '@mui/material/Button';
  2. import Avatar from '@mui/material/Avatar';
  3. import { makeStyles } from '@material-ui/core'
  4. import { useSelector,useDispatch } from 'react-redux';
  5. import { getChat } from '../../../../../../redux/chat/selector';
  6. import { actionRemoveChat } from '../../../../../../redux/chat/action';
  7. import { actionRightIsOpen } from '../../../../../../redux/control/action'
  8. import { removeChatForBoth } from '../../../../../../api-data';
  9. import { firstLetter,slicedWord,prodAwsS3 } from '../../../../../../helpers';
  10. const useStyles = makeStyles({
  11. modalDelete: {
  12. background: '#ffffff',
  13. position: 'absolute',
  14. content:'',
  15. width: '20%',
  16. height:'auto',
  17. left: '40%',
  18. bottom: '48.5%',
  19. borderRadius: 10,
  20. padding: 10,
  21. display: 'flex',
  22. flexDirection:'column'
  23. },
  24. overlay: {
  25. position: 'fixed',
  26. top: 0,
  27. left: 0,
  28. width: '100vw',
  29. height: '100vh',
  30. zIndex: 100,
  31. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  32. overflowY: 'hidden',
  33. },
  34. titleWrapper: {
  35. display: 'flex',
  36. justifyContent: 'flex-start',
  37. alignContent: 'center',
  38. alignItems:'center'
  39. },
  40. })
  41. const DeleteModal = ({setModalDelete}:{setModalDelete:any}) => {
  42. const classes = useStyles()
  43. const dispatch = useDispatch()
  44. const {name,lastName,avatarUrl,color,companionId} = useSelector(getChat)
  45. const handleDeleteModal = (e: any) => {
  46. const id = e.target.id
  47. if (id === 'overlay' || id === 'cancel') return setModalDelete(false)
  48. if (id === 'delete') {
  49. removeChatForBoth(companionId)
  50. setModalDelete(false)
  51. dispatch(actionRemoveChat())
  52. dispatch(actionRightIsOpen(''))
  53. }
  54. }
  55. return (
  56. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  57. <div className={classes.modalDelete}>
  58. <div className={classes.titleWrapper}>
  59. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  60. sx={{ background: color, width: 38, height: 38,marginRight:2}}>
  61. {`${firstLetter(name)}${firstLetter(lastName)}`}
  62. </Avatar>
  63. <h3 style={{color: '#2c2c2c'}}>Delete chat</h3>
  64. </div>
  65. <p style={{color: '#050505'}}>{`Are you sure you want to delete the
  66. chat with ${`${firstLetter(name)}${slicedWord(name, 15, 1)}
  67. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}?`}</p>
  68. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  69. DELETE CHAT
  70. </Button>
  71. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  72. CANCEL
  73. </Button>
  74. </div>
  75. </div>
  76. )
  77. }
  78. export default DeleteModal