index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import Button from '@mui/material/Button';
  2. import { makeStyles } from '@material-ui/core'
  3. import { useDispatch } from 'react-redux';
  4. import { removeUserAvatar } from '../../../../../../api-data';
  5. import { asyncCurrentUser } from '../../../../../../redux/authorization/operations';
  6. const useStyles = makeStyles({
  7. modalDelete: {
  8. background: '#ffffff',
  9. position: 'absolute',
  10. content:'',
  11. width: '20%',
  12. height:'auto',
  13. left: '40%',
  14. bottom: '48.5%',
  15. borderRadius: 10,
  16. padding: 10,
  17. display: 'flex',
  18. flexDirection:'column'
  19. },
  20. overlay: {
  21. position: 'fixed',
  22. top: 0,
  23. left: 0,
  24. width: '100vw',
  25. height: '100vh',
  26. zIndex: 100,
  27. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  28. overflowY: 'hidden',
  29. },
  30. titleWrapper: {
  31. display: 'flex',
  32. justifyContent: 'flex-start',
  33. alignContent: 'center',
  34. alignItems:'center'
  35. },
  36. })
  37. interface IDeleteModal {
  38. setModal: (a: boolean) => void,
  39. index: number,
  40. setIndex: any
  41. }
  42. const DeleteModal = ({setModal,index,setIndex}:IDeleteModal) => {
  43. const classes = useStyles()
  44. const dispatch = useDispatch()
  45. const handleDeleteModal = (e: any) => {
  46. const id = e.target.id
  47. if (id === 'overlay' || id === 'cancel') return setModal(false)
  48. if (id === 'delete') {
  49. removeUserAvatar(index)
  50. setIndex(index-1)
  51. setModal(false)
  52. dispatch(asyncCurrentUser())
  53. }
  54. }
  55. return (
  56. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  57. <div className={classes.modalDelete}>
  58. <div className={classes.titleWrapper}>
  59. <h3 style={{color: '#2c2c2c'}}>Delete image</h3>
  60. </div>
  61. <p style={{color: '#050505'}}>{`Are you sure you want to delete the Image?`}</p>
  62. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  63. DELETE IMAGE
  64. </Button>
  65. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  66. CANCEL
  67. </Button>
  68. </div>
  69. </div>
  70. )
  71. }
  72. export default DeleteModal