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.
 
 

200 lines
6.8 KiB

  1. // material-uisubDivision
  2. import {
  3. Button,
  4. FormControlLabel,
  5. Grid, TextField,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "../../../components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import {
  11. // useEffect,
  12. useState
  13. } from "react";
  14. import Checkbox from "@mui/material/Checkbox";
  15. import * as React from "react";
  16. import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
  17. import { useNavigate } from "react-router";
  18. import axios from "axios";
  19. import { GET_EMAIL_LIST } from 'utils/ApiPathConst';
  20. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  21. import {ThemeProvider} from "@emotion/react";
  22. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  23. const UserSearchForm = ({ applySearch }) => {
  24. const navigate = useNavigate();
  25. const [type, setType] = useState([]);
  26. const [locked, setLocked] = useState(false);
  27. const { reset, register, handleSubmit } = useForm()
  28. const onSubmit = (data) => {
  29. let typeArray = [];
  30. for (let i = 0; i < type.length; i++) {
  31. typeArray.push(type[i].label);
  32. }
  33. const temp = {
  34. username: data.userName,
  35. enName: data.fullenName,
  36. post: data.post,
  37. email: data.email,
  38. locked: locked,
  39. };
  40. applySearch(temp);
  41. };
  42. function resetForm() {
  43. setType([]);
  44. setLocked(false);
  45. reset();
  46. axios.get(`${GET_EMAIL_LIST}`)
  47. .then(r => {
  48. console.log(r)
  49. })
  50. .catch(err => {
  51. console.log(err)
  52. })
  53. }
  54. const handleNewUserClick = () => {
  55. // console.log(id)
  56. navigate('/user/-1');
  57. // navigate('/user/' + id);
  58. };
  59. return (
  60. <MainCard xs={12} md={12} lg={12}
  61. border={false}
  62. content={false}>
  63. <form onSubmit={handleSubmit(onSubmit)}>
  64. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  65. {/*row 1*/}
  66. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  67. <Typography variant="pnspsFormHeader" >
  68. Search
  69. </Typography>
  70. </Grid>
  71. {/*row 2*/}
  72. <Grid container display="flex" alignItems={"center"}>
  73. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  74. <TextField
  75. fullWidth
  76. {...register("userName")}
  77. id='userName'
  78. label="Username"
  79. InputLabelProps={{
  80. shrink: true
  81. }}
  82. />
  83. </Grid>
  84. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  85. <TextField
  86. fullWidth
  87. {...register("fullenName")}
  88. id="fullenName"
  89. label="Full Name"
  90. InputLabelProps={{
  91. shrink: true
  92. }}
  93. />
  94. </Grid>
  95. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  96. <TextField
  97. fullWidth
  98. {...register("post")}
  99. id="post"
  100. label="Post"
  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("email")}
  110. id="email"
  111. label="Email"
  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. <FormControlLabel
  119. control={
  120. <Checkbox
  121. checked={locked}
  122. onChange={(event) => setLocked(event.target.checked)}
  123. name="checked"
  124. color="primary"
  125. size="small"
  126. />
  127. }
  128. label={<Typography variant="h6">Locked</Typography>}
  129. />
  130. </Grid>
  131. </Grid>
  132. {/*last row*/}
  133. <Grid container direction="row"
  134. justifyContent="space-between"
  135. alignItems="center">
  136. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  137. <Grid item xs={3} md={3} sx={{ ml: 3,mb: 3 }}>
  138. <Button
  139. variant="contained"
  140. onClick={handleNewUserClick}
  141. startIcon={<AddCircleOutlineIcon/>}
  142. >
  143. New User
  144. </Button>
  145. </Grid>
  146. <Grid item xs={8} md={8}>
  147. <Grid container maxWidth justifyContent="flex-end">
  148. <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
  149. <Button
  150. variant="contained"
  151. color="cancel"
  152. onClick={resetForm}
  153. >
  154. Reset
  155. </Button>
  156. </Grid>
  157. <Grid item sx={{ mb: 3 }}>
  158. <Button
  159. variant="contained"
  160. type="submit"
  161. >
  162. Search
  163. </Button>
  164. </Grid>
  165. </Grid>
  166. </Grid>
  167. </ThemeProvider>
  168. </Grid>
  169. </Grid>
  170. </form>
  171. </MainCard>
  172. );
  173. };
  174. export default UserSearchForm;