index.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Stack from '@mui/material/Stack';
  2. import IconButton from '@mui/material/IconButton';
  3. import ArrowBackIcon from '@mui/icons-material/ArrowBack';
  4. import CloseIcon from '@mui/icons-material/Close';
  5. import { makeStyles, Typography } from '@material-ui/core'
  6. import { useDispatch, useSelector } from 'react-redux';
  7. import { useState,useEffect } from 'react';
  8. import { actionIsOpen } from '../../../../../../../redux/control/action'
  9. import { getContacts } from '../../../../../../../redux/contacts/selector'
  10. import { getChat } from '../../../../../../../redux/chat/selector'
  11. import { asyncGetContacts,asyncAddContact } from '../../../../../../../redux/contacts/operations';
  12. const useStyles = makeStyles({
  13. container: {
  14. borderLeft: 'solid 0.5px #9c9c9c',
  15. paddingLeft: 10,
  16. paddingBottom: 3,
  17. width: 482,
  18. display: 'flex',
  19. alignContent: 'center',
  20. alignItems: 'center',
  21. },
  22. iconArrow: {
  23. '&:hover': {
  24. transform: 'rotate(360deg)',
  25. transition: 'all 250ms ease-out ',
  26. }
  27. },
  28. })
  29. const ToolBar = () => {
  30. const dispatch = useDispatch()
  31. const classes = useStyles()
  32. const contacts = useSelector(getContacts)
  33. const { number } = useSelector(getChat)
  34. const [isContact, setIsContact] = useState<boolean>(false)
  35. useEffect(() => {
  36. dispatch(asyncGetContacts())
  37. }, [dispatch])
  38. useEffect(() => {
  39. const isExist = contacts.some((el) => el.number === number)
  40. isExist&&setIsContact(true)
  41. }, [contacts,number])
  42. return (
  43. <Stack className={classes.container} direction="row" spacing={21}>
  44. <IconButton onClick={() => dispatch(actionIsOpen('credentials'))} aria-label="delete" size="medium">
  45. <ArrowBackIcon className={classes.iconArrow} fontSize='medium'/>
  46. </IconButton>
  47. <Typography variant="h6" color="initial" style={{marginLeft:20}}>Edit</Typography>
  48. </Stack>
  49. )
  50. }
  51. export default ToolBar