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.
 
 

202 rivejä
7.1 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. }
  55. return (
  56. <MainCard xs={12} md={12} lg={12}
  57. border={false}
  58. content={false}>
  59. <form onSubmit={handleSubmit(onSubmit)}>
  60. <Grid container sx={{ ml: 2, mt: 1}} width="98%">
  61. {/*row 1*/}
  62. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  63. <Typography variant="pnspsFormHeader" >
  64. Search
  65. </Typography>
  66. </Grid>
  67. {/*row 2*/}
  68. <Grid container display="flex" alignItems={"center"}>
  69. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  70. <TextField
  71. fullWidth
  72. {...register("userName")}
  73. id='userName'
  74. label="Username"
  75. defaultValue={searchCriteria.username}
  76. InputLabelProps={{
  77. shrink: true
  78. }}
  79. />
  80. </Grid>
  81. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  82. <TextField
  83. fullWidth
  84. {...register("fullenName")}
  85. id="fullenName"
  86. label="Full Name"
  87. defaultValue={searchCriteria.fullName}
  88. InputLabelProps={{
  89. shrink: true
  90. }}
  91. />
  92. </Grid>
  93. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  94. <TextField
  95. fullWidth
  96. {...register("email")}
  97. id="email"
  98. label="Email"
  99. defaultValue={searchCriteria.email}
  100. InputLabelProps={{
  101. shrink: true
  102. }}
  103. />
  104. </Grid>
  105. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  106. <TextField
  107. fullWidth
  108. {...register("phone")}
  109. id="phone"
  110. label="Phone"
  111. defaultValue={searchCriteria.phone}
  112. InputLabelProps={{
  113. shrink: true
  114. }}
  115. />
  116. </Grid>
  117. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  118. <Autocomplete
  119. {...register("accountFilter")}
  120. disablePortal
  121. id="accountFilter"
  122. size="small"
  123. options={["All","Active", "Locked", "Not Verified"]}
  124. value={accountFilter}
  125. onChange={(event, newValue) => {
  126. if (newValue !== null) {
  127. setAccountFilter(newValue);
  128. }else{
  129. setAccountFilter("All");
  130. }
  131. }}
  132. renderInput={(params) => (
  133. <TextField {...params}
  134. label="Status"
  135. InputLabelProps={{
  136. shrink: true
  137. }}
  138. />
  139. )}
  140. />
  141. </Grid>
  142. {/*<Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>*/}
  143. {/* <TextField*/}
  144. {/* fullWidth*/}
  145. {/* {...register("subDivisionId")}*/}
  146. {/* id="subDivision"*/}
  147. {/* label="Sub-Division"*/}
  148. {/* />*/}
  149. {/*</Grid>*/}
  150. </Grid>
  151. {/*last row*/}
  152. <Grid container maxWidth justifyContent="flex-end">
  153. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  154. <Grid item sx={{ ml: 3, mr: 3, mb: 3 }}>
  155. <Button
  156. variant="contained"
  157. color="cancel"
  158. onClick={resetForm}
  159. >
  160. Reset
  161. </Button>
  162. </Grid>
  163. <Grid item sx={{ mb: 3}}>
  164. <Button
  165. variant="contained"
  166. type="submit"
  167. disabled={onGridReady}
  168. >
  169. Submit
  170. </Button>
  171. </Grid>
  172. </ThemeProvider>
  173. </Grid>
  174. </Grid>
  175. </form>
  176. </MainCard>
  177. );
  178. };
  179. export default UserSearchForm_Individual;