index.tsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { makeStyles } from '@material-ui/core'
  2. import Button from '@mui/material/Button';
  3. import Avatar from '@mui/material/Avatar';
  4. import MenuItem from '@mui/material/MenuItem';
  5. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  6. import { useState } from 'react';
  7. import { useDispatch } from 'react-redux';
  8. import { actionIsOpen } from '../../../../../../redux/control/action'
  9. import { removeContact } from '../../../../../../api-data';
  10. import { TContact } from '../../../../../../typescript/redux/contacts/types';
  11. import { slicedWord,firstLetter,prodBaseURL } from '../../../../../../helpers';
  12. const useStyles = makeStyles({
  13. container: {
  14. width: '100%',
  15. padding: '20px 10px 20px 10px',
  16. backgroundColor: '#ffffff',
  17. },
  18. modalDelete: {
  19. background: '#ffffff',
  20. position: 'absolute',
  21. content:'',
  22. width: '20%',
  23. height:'auto',
  24. left: '40%',
  25. bottom: '48.5%',
  26. borderRadius: 10,
  27. padding: 10,
  28. display: 'flex',
  29. flexDirection:'column'
  30. },
  31. overlay: {
  32. position: 'fixed',
  33. top: 0,
  34. left: 0,
  35. width: '100vw',
  36. height: '100vh',
  37. zIndex: 100,
  38. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  39. overflowY: 'hidden',
  40. },
  41. titleWrapper: {
  42. display: 'flex',
  43. justifyContent: 'flex-start',
  44. alignContent: 'center',
  45. alignItems:'center'
  46. },
  47. })
  48. const Delete = ({isContact}:{isContact:TContact}) => {
  49. const classes = useStyles()
  50. const dispatch = useDispatch()
  51. const {_id,avatarUrl,color,name,lastName} = isContact
  52. const [modal,setModal] = useState<boolean>(false)
  53. const handleDeleteModal = (e: any) => {
  54. const id = e.target.id
  55. if (id === 'overlay' || id === 'cancel') return setModal(false)
  56. if (id === 'delete') {
  57. dispatch(actionIsOpen('credentials'))
  58. removeContact(_id)
  59. setModal(false)
  60. }
  61. }
  62. const handleOpenModal = () => setModal(true)
  63. return (
  64. <>
  65. <ul className={classes.container}>
  66. <MenuItem onClick={handleOpenModal} style={{fontSize:19,color:'#f02a2a'}} >
  67. <DeleteOutlineIcon fontSize='medium' style={{marginRight:27}}/>
  68. Delete contact
  69. </MenuItem>
  70. </ul>
  71. {modal&&<div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  72. <div className={classes.modalDelete}>
  73. <div className={classes.titleWrapper}>
  74. <Avatar alt={name} src={avatarUrl?`${prodBaseURL}/${avatarUrl}`:undefined}
  75. sx={{ background: color, width: 38, height: 38,marginRight:2}}>
  76. {`${firstLetter(name)}${firstLetter(lastName)}`}
  77. </Avatar>
  78. <h3 style={{color: '#2c2c2c'}}>Delete contact</h3>
  79. </div>
  80. <p style={{ color: '#050505' }}>{`Are you sure you want to delete contact
  81. ${`${firstLetter(name)}${slicedWord(name, 15, 1)}
  82. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}?`}</p>
  83. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  84. DELETE CONTACT
  85. </Button>
  86. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  87. CANCEL
  88. </Button>
  89. </div>
  90. </div>}
  91. </>
  92. );
  93. }
  94. export default Delete