FindCategoryEdit.jsx 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {useState} from "react";
  2. import {CircularProgress, Container, IconButton, InputAdornment, TextField} from "@mui/material";
  3. import Typography from "@mui/material/Typography";
  4. import SearchIcon from "@material-ui/icons/Search";
  5. import {NotFound} from "../GoodsTab/NotFound";
  6. import {connect} from "react-redux";
  7. import {actionSearchRemove} from "../../../reducers/SearchReducer";
  8. import {actionFullSearchCategory} from "../../../actions/ActionCategory";
  9. import {CategoryFound} from "./CategoryFound";
  10. const FindCategoryEdit = ({searchResult, onSearch, onSearchRemove}) => {
  11. const [value, setValue] = useState('')
  12. const [click, setClick] = useState(false)
  13. return (
  14. <>
  15. <Container maxWidth="md">
  16. <Typography
  17. variant='h5'
  18. fontFamily='sarif'
  19. letterSpacing='3px'
  20. marginBottom='30px'
  21. marginTop='30px'
  22. textAlign='center'
  23. >
  24. WHICH ITEM TO EDIT?
  25. </Typography>
  26. <TextField
  27. color={'primary'}
  28. fullWidth
  29. variant="standard"
  30. value={value}
  31. placeholder="Start typing..."
  32. onChange={(event) => {
  33. setClick(false);
  34. setValue(event.target.value);
  35. onSearchRemove()
  36. }}
  37. InputProps={{
  38. sx: {
  39. padding: '10px',
  40. outline:'none',
  41. color: '#616161',
  42. fontWeight: '300',
  43. letterSpacing: '1px',
  44. marginBottom: '50px'
  45. },
  46. endAdornment: (
  47. <InputAdornment position="end">
  48. <IconButton
  49. onClick={() => {
  50. setClick(true);
  51. onSearchRemove();
  52. onSearch(value)
  53. }}
  54. >
  55. <SearchIcon />
  56. </IconButton>
  57. </InputAdornment>
  58. )
  59. }}
  60. />
  61. {(value !== '' && click) && (searchResult?.searchResult ?
  62. Object.values(searchResult.searchResult).length > 0 ?
  63. Object.values(searchResult.searchResult)
  64. .map(item =>
  65. <CategoryFound
  66. key={item?._id}
  67. item={item}
  68. />
  69. )
  70. :
  71. <NotFound/>
  72. :
  73. <CircularProgress color="inherit"/>
  74. )}
  75. </Container>
  76. </>
  77. )
  78. }
  79. export const CFindCategoryEdit = connect(state=> ({
  80. searchResult: state.search}),
  81. {
  82. onSearch: actionFullSearchCategory,
  83. onSearchRemove: actionSearchRemove})
  84. (FindCategoryEdit)