index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import InputBase from '@mui/material/InputBase';
  2. import Toolbar from '@mui/material/Toolbar'
  3. import SearchIcon from '@mui/icons-material/Search';
  4. import CloseIcon from '@mui/icons-material/Close';
  5. import IconButton from '@mui/material/IconButton';
  6. import Switch from '@mui/material/Switch';
  7. import CalendarTodayIcon from '@mui/icons-material/CalendarToday';
  8. import { styled } from '@mui/material/styles';
  9. import { makeStyles } from '@material-ui/core'
  10. import { useDispatch } from 'react-redux';
  11. import StaticDatePicker from "./StaticDatePicker";
  12. import { updateUser } from '../../../../../../../api-data';
  13. import { asyncCurrentUser } from '../../../../../../../redux/authorization/operations';
  14. const SearchBar = styled('div')(() => ({
  15. position: 'relative',
  16. borderRadius: '20px',
  17. backgroundColor: '#f1f0f0',
  18. width: '100%',
  19. marginLeft: 5,
  20. }));
  21. const SearchIconWrapper = styled('div')(({ theme }) => ({
  22. padding: theme.spacing(0, 2),
  23. height: '100%',
  24. position: 'absolute',
  25. pointerEvents: 'none',
  26. display: 'flex',
  27. alignItems: 'center',
  28. justifyContent: 'center',
  29. }));
  30. const StyledInputBase = styled(InputBase)(({ theme }) => ({
  31. color: 'inherit',
  32. '& .MuiInputBase-input': {
  33. fontWeight: 500,
  34. borderRadius: '20px',
  35. padding: theme.spacing(1, 1, 1, 0),
  36. paddingLeft: `calc(1em + ${theme.spacing(4)})`,
  37. transition: theme.transitions.create('width'),
  38. width: '100%',
  39. },
  40. }));
  41. const useStyles = makeStyles({
  42. toolBar: {
  43. color: '#b1aeae',
  44. height: '7vh',
  45. width: '100%',
  46. },
  47. searchBarActive: {
  48. outline: '2px solid #2184f7',
  49. color: '#2184f7',
  50. },
  51. iconClose: {
  52. '&:hover': {
  53. transform: 'rotate(180deg)',
  54. transition: 'all 250ms ease-out ',
  55. }
  56. },
  57. })
  58. const label = { inputProps: { 'aria-label': 'Switch demo' } };
  59. interface IForwardSearch {
  60. handleSearch: (e: React.ChangeEvent<HTMLInputElement>) => void,
  61. value: string,
  62. total: string,
  63. sort: boolean,
  64. setDate: React.Dispatch<any>,
  65. date:any,
  66. }
  67. const ForwardSearch = ({handleSearch,value,total,sort,setDate,date}:IForwardSearch) => {
  68. const classes = useStyles()
  69. const dispatch = useDispatch()
  70. const disabled = total === '0' ? true : false
  71. const handleSort = () => {
  72. updateUser({ sort: !sort })
  73. setTimeout(() => {
  74. dispatch(asyncCurrentUser())
  75. }, 1000);
  76. }
  77. const handleOnOpen = () => setDate('')
  78. return (
  79. <Toolbar className={classes.toolBar} >
  80. <IconButton aria-label="delete" size="medium">
  81. <CloseIcon id='cancel' className={classes.iconClose} fontSize='medium'/>
  82. </IconButton>
  83. <SearchBar className={!value||disabled?undefined:classes.searchBarActive}>
  84. <SearchIconWrapper>
  85. <SearchIcon />
  86. </SearchIconWrapper>
  87. <StyledInputBase
  88. disabled={disabled}
  89. onChange={handleSearch}
  90. placeholder={disabled?'Disabled':'Search'}
  91. value={value}
  92. inputProps={{ 'aria-label': 'search' }}
  93. />
  94. </SearchBar>
  95. <IconButton aria-label="delete" size="medium" disabled={disabled}>
  96. <StaticDatePicker date={date} disabled={disabled}
  97. changeDate={setDate} handleOnOpen={handleOnOpen} />
  98. <CalendarTodayIcon fontSize='medium' style={{color:date?'#2184f7':'#b1aeae'}}/>
  99. </IconButton>
  100. <Switch onClick={handleSort} checked={sort} {...label} disabled={disabled} />
  101. </Toolbar>
  102. )
  103. }
  104. export default ForwardSearch