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.
 
 

262 line
13 KiB

  1. // material-ui
  2. import {
  3. FormControl, IconButton,
  4. Grid, InputAdornment, Typography, FormLabel,
  5. OutlinedInput,
  6. } from '@mui/material';
  7. import MainCard from "../../components/MainCard";
  8. import * as React from "react";
  9. import {useForm} from "react-hook-form";
  10. import {useEffect, useState} from "react";
  11. import Checkbox from "@mui/material/Checkbox";
  12. import Loadable from 'components/Loadable';
  13. import { lazy } from 'react';
  14. const LoadingComponent = Loadable(lazy(() => import('../extra-pages/LoadingComponent')));
  15. //import {useParams} from "react-router-dom";
  16. import Visibility from '@mui/icons-material/Visibility';
  17. import VisibilityOff from '@mui/icons-material/VisibilityOff';
  18. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  19. const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewRecord}) => {
  20. //const params = useParams();
  21. const [currentUserData, setCurrentUserData] = React.useState({});
  22. const [locked, setLocked] = useState(false);
  23. const [showPassword, setShowPassword] = React.useState(false);
  24. const [onReady, setOnReady] = useState(false);
  25. const {register, getValues} = useForm()
  26. const handleClickShowPassword = () => setShowPassword((show) => !show);
  27. const handleMouseDownPassword = () => setShowPassword(!showPassword);
  28. useEffect(() => {
  29. //if user data from parent are not null
  30. if (Object.keys(userData).length > 0 && userData !== undefined) {
  31. setCurrentUserData(userData.data);
  32. }
  33. }, [userData]);
  34. useEffect(() => {
  35. //if state data are ready and assign to different field
  36. if (Object.keys(userData).length > 0 &&currentUserData !== undefined&&currentUserData.id!==undefined) {
  37. setLocked(currentUserData.locked);
  38. setOnReady(true);
  39. }else if(isNewRecord){
  40. setLocked(false);
  41. setOnReady(true);
  42. }
  43. }, [currentUserData]);
  44. useEffect(() => {
  45. //upload latest data to parent
  46. const values = getValues();
  47. const objectData ={
  48. ...values,
  49. locked: locked,
  50. }
  51. updateUserObject(objectData);
  52. }, [isCollectData]);
  53. return (
  54. !onReady ?
  55. <LoadingComponent/>
  56. :
  57. <MainCard elevation={0}
  58. border={false}
  59. content={false}
  60. >
  61. <Typography variant="h5" sx={{mt: 3, ml: 3, mb: 1}}>
  62. Information
  63. </Typography>
  64. <form>
  65. <Grid container>
  66. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  67. <Grid container alignItems={"center"}>
  68. <Grid item xs={4} s={4} md={4} lg={4}
  69. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  70. <FormLabel required>Username:</FormLabel>
  71. </Grid>
  72. <Grid item xs={7} s={7} md={7} lg={6}>
  73. <FormControl variant="outlined" fullWidth required>
  74. <OutlinedInput
  75. required
  76. fullWidth
  77. size="small"
  78. {...register("username",
  79. {
  80. value: currentUserData.username,
  81. })}
  82. id='username'
  83. disabled={!isNewRecord}
  84. />
  85. </FormControl>
  86. </Grid>
  87. </Grid>
  88. </Grid>
  89. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  90. <Grid container alignItems={"center"}>
  91. <Grid item xs={4} s={4} md={4} lg={4}
  92. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  93. Password:
  94. </Grid>
  95. <Grid item xs={7} s={7} md={7} lg={6}>
  96. <FormControl variant="outlined" fullWidth required>
  97. <OutlinedInput
  98. fullWidth
  99. size="small"
  100. {...register("password")}
  101. id='password'
  102. type={showPassword ? 'text' : 'password'}
  103. disabled
  104. endAdornment={
  105. <InputAdornment position="end">
  106. <IconButton
  107. aria-label="toggle password visibility"
  108. onClick={handleClickShowPassword}
  109. onMouseDown={handleMouseDownPassword}
  110. edge="end"
  111. >
  112. {showPassword ? <VisibilityOff /> : <Visibility />}
  113. </IconButton>
  114. </InputAdornment>
  115. }
  116. />
  117. </FormControl>
  118. </Grid>
  119. </Grid>
  120. </Grid>
  121. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  122. <Grid container alignItems={"center"}>
  123. <Grid item xs={4} s={4} md={4} lg={4}
  124. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  125. <FormLabel required >Full Name:</FormLabel>
  126. </Grid>
  127. <Grid item xs={7} s={7} md={7} lg={6}>
  128. {/* <TextField
  129. fullWidth
  130. {...register("enName",
  131. {
  132. value: currentUserData.enName,
  133. })}
  134. id='enName'
  135. /> */}
  136. <FormControl variant="outlined" fullWidth required>
  137. <OutlinedInput
  138. required
  139. fullWidth
  140. size="small"
  141. {...register("enName",
  142. {
  143. value: currentUserData.enName,
  144. })}
  145. id='enName'
  146. />
  147. </FormControl>
  148. </Grid>
  149. </Grid>
  150. </Grid>
  151. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  152. <Grid container alignItems={"center"}>
  153. <Grid item xs={4} s={4} md={4} lg={4}
  154. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  155. <FormLabel>Post:</FormLabel>
  156. </Grid>
  157. <Grid item xs={7} s={7} md={7} lg={6}>
  158. <FormControl variant="outlined" fullWidth required>
  159. <OutlinedInput
  160. fullWidth
  161. size="small"
  162. {...register("post",
  163. {
  164. value: currentUserData.post,
  165. })}
  166. id='post'
  167. />
  168. </FormControl>
  169. </Grid>
  170. </Grid>
  171. </Grid>
  172. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  173. <Grid container alignItems={"center"}>
  174. <Grid item xs={4} s={4} md={4} lg={4}
  175. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  176. <FormLabel required>Email:</FormLabel>
  177. </Grid>
  178. <Grid item xs={7} s={7} md={7} lg={6}>
  179. <FormControl variant="outlined" fullWidth required>
  180. <OutlinedInput
  181. fullWidth
  182. size="small"
  183. {...register("emailAddress",
  184. {
  185. value: currentUserData.emailAddress,
  186. })}
  187. id='emailAddress'
  188. />
  189. </FormControl>
  190. </Grid>
  191. </Grid>
  192. </Grid>
  193. {/* <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  194. <Grid container alignItems={"center"}>
  195. <Grid item xs={4} s={4} md={4} lg={4}
  196. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  197. <FormLabel>Phone:</FormLabel>
  198. </Grid>
  199. <Grid item xs={7} s={7} md={7} lg={6}>
  200. <FormControl variant="outlined" fullWidth required>
  201. <OutlinedInput
  202. fullWidth
  203. size="small"
  204. {...register("phone",
  205. {
  206. value: currentUserData.phone,
  207. })}
  208. id='phone'
  209. />
  210. </FormControl>
  211. </Grid>
  212. </Grid>
  213. </Grid> */}
  214. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  215. <Grid container>
  216. <Grid item xs={4} s={4} md={4} lg={4}
  217. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  218. <FormLabel required>Locked:</FormLabel>
  219. </Grid>
  220. <Grid item xs={7} s={7} md={7} lg={6}>
  221. <Checkbox
  222. checked={locked}
  223. onChange={(event) => setLocked(event.target.checked)}
  224. name="checked"
  225. color="primary"
  226. size="small"
  227. />
  228. </Grid>
  229. </Grid>
  230. </Grid>
  231. </Grid>
  232. </form>
  233. </MainCard>
  234. );
  235. };
  236. export default UserInformationCard;