Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

273 řádky
11 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Autocomplete,
  5. Grid, TextField,
  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_Organization = ({applySearch, orgComboData, onGridReady, searchCriteria}) => {
  15. const [type, setType] = useState([]);
  16. const [accountFilter, setAccountFilter] = useState("All");
  17. const [orgCombo, setOrgCombo] = useState();
  18. const [orgSelected, setOrgSelected] = useState({});
  19. const { reset, register, handleSubmit } = useForm()
  20. useEffect(() => {
  21. if(searchCriteria.accountFilter!=undefined){
  22. if(searchCriteria.accountFilter === ""){
  23. setAccountFilter("All")
  24. }else{
  25. setAccountFilter(searchCriteria.accountFilter)
  26. }
  27. }else{
  28. setAccountFilter("All")
  29. }
  30. }, [searchCriteria]);
  31. const onSubmit = (data) => {
  32. let typeArray = [];
  33. for(let i =0; i < type.length; i++){
  34. typeArray.push(type[i].label);
  35. }
  36. const temp = {
  37. username: data.userName,
  38. fullenName: data.fullenName,
  39. email: data.email,
  40. contactTel: data.phone,
  41. contactPerson: data.contactPerson,
  42. brNoStr: data.brNoStr,
  43. orgName: orgSelected?.name ? orgSelected?.name : "",
  44. accountFilter: accountFilter=="All"?null:accountFilter,
  45. };
  46. applySearch(temp);
  47. };
  48. useEffect(() => {
  49. if (orgComboData && orgComboData.length > 0) {
  50. setOrgCombo(orgComboData);
  51. if(searchCriteria.orgName!=undefined){
  52. setOrgSelected(orgComboData.find(item => item.name === searchCriteria.orgName))
  53. }
  54. }
  55. }, [orgComboData]);
  56. function resetForm(){
  57. setType([]);
  58. setAccountFilter("All");
  59. setOrgSelected({});
  60. reset({
  61. userName:"",
  62. fullenName:"",
  63. email:"",
  64. phone:"",
  65. contactPerson:"",
  66. brNoStr:"",
  67. });
  68. }
  69. return (
  70. <MainCard xs={12} md={12} lg={12}
  71. border={false}
  72. content={false}>
  73. <form onSubmit={handleSubmit(onSubmit)} >
  74. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  75. {/*row 1*/}
  76. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  77. <Typography variant="pnspsFormHeader" >
  78. Search
  79. </Typography>
  80. </Grid>
  81. {/*row 2*/}
  82. <Grid container display="flex" alignItems={"center"}>
  83. {
  84. orgCombo ?
  85. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  86. <Autocomplete
  87. {...register("orgId")}
  88. disablePortal
  89. id="orgId"
  90. options={orgCombo}
  91. groupBy={(option) => option.groupType}
  92. size="small"
  93. value={orgSelected}
  94. getOptionLabel={(option) => option.name? option.name : ""}
  95. inputValue={orgSelected ? orgSelected.name!=undefined?orgSelected.name:"" : ""}
  96. onChange={(event, newValue) => {
  97. if (newValue !== null) {
  98. setOrgSelected(newValue);
  99. }else{
  100. setOrgSelected({});
  101. }
  102. }}
  103. renderInput={(params) => (
  104. <TextField {...params}
  105. label="Organisation"
  106. InputLabelProps={{
  107. shrink: true
  108. }}
  109. />
  110. )}
  111. renderGroup={(params) => (
  112. <Grid item key={params.key}>
  113. <Typography fontSize={20} fontStyle="italic" p={1}>
  114. {params.group}
  115. </Typography>
  116. {params.children}
  117. </Grid>
  118. )}
  119. />
  120. </Grid>
  121. : <></>
  122. }
  123. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  124. <TextField
  125. fullWidth
  126. {...register("brNoStr")}
  127. id="brNoStr"
  128. label="BR No."
  129. defaultValue={searchCriteria.brNoStr}
  130. InputLabelProps={{
  131. shrink: true
  132. }}
  133. />
  134. </Grid>
  135. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  136. <TextField
  137. fullWidth
  138. {...register("userName")}
  139. id='userName'
  140. label="Username"
  141. defaultValue={searchCriteria.username}
  142. InputLabelProps={{
  143. shrink: true
  144. }}
  145. />
  146. </Grid>
  147. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  148. <TextField
  149. fullWidth
  150. {...register("contactPerson")}
  151. id="contactPerson"
  152. label="Name"
  153. defaultValue={searchCriteria.contactPerson}
  154. InputLabelProps={{
  155. shrink: true
  156. }}
  157. />
  158. </Grid>
  159. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  160. <TextField
  161. fullWidth
  162. {...register("email")}
  163. id="email"
  164. label="Email"
  165. defaultValue={searchCriteria.email}
  166. InputLabelProps={{
  167. shrink: true
  168. }}
  169. />
  170. </Grid>
  171. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  172. <TextField
  173. fullWidth
  174. {...register("phone")}
  175. id="phone"
  176. label="Phone"
  177. defaultValue={searchCriteria.contactTel}
  178. InputLabelProps={{
  179. shrink: true
  180. }}
  181. />
  182. </Grid>
  183. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  184. <Autocomplete
  185. {...register("accountFilter")}
  186. disablePortal={false}
  187. id="accountFilter"
  188. size="small"
  189. options={["All", "Active","Locked","Not Verified"]}
  190. value={accountFilter}
  191. onChange={(event, newValue) => {
  192. if (newValue !== null){
  193. setAccountFilter(newValue);
  194. }else{
  195. setAccountFilter("All");
  196. }
  197. }}
  198. renderInput={(params) => (
  199. <TextField {...params}
  200. label="Status"
  201. InputLabelProps={{
  202. shrink: true
  203. }}
  204. />
  205. )}
  206. />
  207. </Grid>
  208. {/*<Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>*/}
  209. {/* <TextField*/}
  210. {/* fullWidth*/}
  211. {/* {...register("subDivisionId")}*/}
  212. {/* id="subDivision"*/}
  213. {/* label="Sub-Division"*/}
  214. {/* />*/}
  215. {/*</Grid>*/}
  216. </Grid>
  217. {/*last row*/}
  218. <Grid container maxWidth justifyContent="flex-end">
  219. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  220. <Grid item sx={{ml:3, mr:3, mb:3}}>
  221. <Button
  222. variant="contained"
  223. color="cancel"
  224. onClick={resetForm}
  225. >
  226. Reset
  227. </Button>
  228. </Grid>
  229. <Grid item sx={{mb:3}}>
  230. <Button
  231. variant="contained"
  232. type="submit"
  233. disabled={onGridReady}
  234. >
  235. Submit
  236. </Button>
  237. </Grid>
  238. </ThemeProvider>
  239. </Grid>
  240. </Grid>
  241. </form>
  242. </MainCard>
  243. );
  244. };
  245. export default UserSearchForm_Organization;