index.tsx 3.4 KB

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