You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

90 regels
2.6 KiB

  1. // material-ui
  2. import {
  3. Grid
  4. } from '@mui/material';
  5. import MainCard from "../../components/MainCard";
  6. import SearchForm from "./UserSearchForm";
  7. import EventTable from "./UserTable";
  8. import {useEffect, useState} from "react";
  9. import axios from "axios";
  10. import {apiPath} from "../../auth/utils";
  11. import {GET_USER_PATH} from "../../utils/ApiPathConst";
  12. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  13. const UserSettingPage = () => {
  14. const [record,setRecord] = useState([]);
  15. const [searchCriteria, setSearchCriteria] = useState({});
  16. const [sortedRecord, setSortedRecord] = useState([]);
  17. useEffect(() => {
  18. axios.get(`${apiPath}${GET_USER_PATH}`)
  19. .then((response) => {
  20. if (response.status === 200) {
  21. setRecord(response.data);
  22. setSortedRecord(response.data);
  23. }
  24. })
  25. .catch(error => {
  26. console.log(error);
  27. return false;
  28. });
  29. }, [])
  30. const filterSearchName = (array) => {
  31. return array.filter((item) => item.name.toLowerCase().includes(searchCriteria.eventName));
  32. };
  33. const filterSearchType = (array) => {
  34. return array.filter((item) => item.category.includes(searchCriteria.type));
  35. };
  36. function sortData(record) {
  37. let sortedRecord = record;
  38. sortedRecord = filterSearchName(sortedRecord);
  39. sortedRecord = filterSearchType(sortedRecord);
  40. return sortedRecord;
  41. }
  42. function applySearch(input) {
  43. setSearchCriteria(input);
  44. }
  45. useEffect(() => {
  46. //console.log(searchCriteria);
  47. if (Object.keys(searchCriteria).length !== 0) {
  48. const tempSortedRecord = sortData(record);
  49. console.log(tempSortedRecord);
  50. setSortedRecord(tempSortedRecord);
  51. } else {
  52. setSortedRecord(record);
  53. }
  54. }, [searchCriteria]);
  55. return (
  56. <Grid container rowSpacing={4.5} columnSpacing={2.75}>
  57. {/*row 1*/}
  58. <Grid item xs={12} md={12} lg={12}>
  59. <SearchForm applySearch={applySearch}/>
  60. </Grid>
  61. {/*row 2*/}
  62. <Grid item xs={12} md={12} lg={12}>
  63. <MainCard elevation={0}
  64. border={false}
  65. content={false}
  66. >
  67. <EventTable
  68. recordList={sortedRecord}
  69. />
  70. </MainCard>
  71. </Grid>
  72. </Grid>
  73. );
  74. };
  75. export default UserSettingPage;