FindCategoryEdit.jsx 3.4 KB

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