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.
 
 

208 lines
7.4 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import { useState,useEffect } from "react";
  11. import {PNSPS_BUTTON_THEME} from "themes/buttonConst";
  12. import {ThemeProvider} from "@emotion/react";
  13. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  14. const UserSearchForm_Individual = ({ applySearch, onGridReady, searchCriteria }) => {
  15. const [type, setType] = useState([]);
  16. const [accountFilter, setAccountFilter] = useState("All");
  17. const { reset, register, handleSubmit } = useForm()
  18. useEffect(() => {
  19. if(searchCriteria.accountFilter!=undefined){
  20. if(searchCriteria.accountFilter === ""){
  21. setAccountFilter("All")
  22. }else{
  23. setAccountFilter(searchCriteria.accountFilter)
  24. }
  25. }else{
  26. setAccountFilter("All")
  27. }
  28. }, [searchCriteria]);
  29. const onSubmit = (data) => {
  30. let typeArray = [];
  31. for (let i = 0; i < type.length; i++) {
  32. typeArray.push(type[i].label);
  33. }
  34. const temp = {
  35. username: data.userName,
  36. fullName: data.fullenName,
  37. email: data.email,
  38. phone: data.phone,
  39. };
  40. if(accountFilter!="All"){
  41. temp["accountFilter"] = accountFilter;
  42. }
  43. applySearch(temp);
  44. };
  45. function resetForm() {
  46. setType([]);
  47. setAccountFilter("All");
  48. reset({
  49. userName:"",
  50. fullenName:"",
  51. email:"",
  52. phone:"",
  53. });
  54. localStorage.setItem('searchCriteria',"")
  55. }
  56. return (
  57. <MainCard xs={12} md={12} lg={12}
  58. border={false}
  59. content={false}>
  60. <form onSubmit={handleSubmit(onSubmit)}>
  61. <Grid container sx={{ ml: 2, mt: 1}} width="98%">
  62. {/*row 1*/}
  63. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  64. <Typography variant="pnspsFormHeader" >
  65. Search
  66. </Typography>
  67. </Grid>
  68. {/*row 2*/}
  69. <Grid container display="flex" alignItems={"center"}>
  70. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  71. <TextField
  72. fullWidth
  73. {...register("userName")}
  74. id='userName'
  75. label="Username"
  76. defaultValue={searchCriteria.username}
  77. InputLabelProps={{
  78. shrink: true
  79. }}
  80. />
  81. </Grid>
  82. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  83. <TextField
  84. fullWidth
  85. {...register("fullenName")}
  86. id="fullenName"
  87. label="Full Name"
  88. defaultValue={searchCriteria.fullName}
  89. InputLabelProps={{
  90. shrink: true
  91. }}
  92. />
  93. </Grid>
  94. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  95. <TextField
  96. fullWidth
  97. {...register("email")}
  98. id="email"
  99. label="Email"
  100. defaultValue={searchCriteria.email}
  101. InputLabelProps={{
  102. shrink: true
  103. }}
  104. />
  105. </Grid>
  106. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  107. <TextField
  108. fullWidth
  109. {...register("phone")}
  110. id="phone"
  111. label="Phone"
  112. defaultValue={searchCriteria.phone}
  113. InputLabelProps={{
  114. shrink: true
  115. }}
  116. />
  117. </Grid>
  118. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  119. <Autocomplete
  120. {...register("accountFilter")}
  121. disablePortal
  122. id="accountFilter"
  123. size="small"
  124. options={["All","Active", "Locked", "Not Verified"]}
  125. value={accountFilter}
  126. onChange={(event, newValue) => {
  127. if (newValue !== null) {
  128. setAccountFilter(newValue);
  129. }else{
  130. setAccountFilter("All");
  131. }
  132. }}
  133. sx={{
  134. '& .MuiInputBase-root': { alignItems: 'center' },
  135. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  136. '& .MuiOutlinedInput-root': { height: 40 }
  137. }}
  138. renderInput={(params) => (
  139. <TextField {...params}
  140. label="Status"
  141. InputLabelProps={{
  142. shrink: true
  143. }}
  144. />
  145. )}
  146. />
  147. </Grid>
  148. {/*<Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>*/}
  149. {/* <TextField*/}
  150. {/* fullWidth*/}
  151. {/* {...register("subDivisionId")}*/}
  152. {/* id="subDivision"*/}
  153. {/* label="Sub-Division"*/}
  154. {/* />*/}
  155. {/*</Grid>*/}
  156. </Grid>
  157. {/*last row*/}
  158. <Grid container maxWidth justifyContent="flex-end">
  159. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  160. <Grid item sx={{ ml: 3, mr: 3, mb: 3 }}>
  161. <Button
  162. variant="contained"
  163. color="cancel"
  164. onClick={resetForm}
  165. >
  166. Reset
  167. </Button>
  168. </Grid>
  169. <Grid item sx={{ mb: 3}}>
  170. <Button
  171. variant="contained"
  172. type="submit"
  173. disabled={onGridReady}
  174. >
  175. Submit
  176. </Button>
  177. </Grid>
  178. </ThemeProvider>
  179. </Grid>
  180. </Grid>
  181. </form>
  182. </MainCard>
  183. );
  184. };
  185. export default UserSearchForm_Individual;