// material-ui import { FormControl, IconButton, Grid, InputAdornment, Typography, FormLabel, OutlinedInput, } from '@mui/material'; import MainCard from "../../components/MainCard"; import * as React from "react"; import {useForm} from "react-hook-form"; import {useEffect, useState} from "react"; import Checkbox from "@mui/material/Checkbox"; import Loadable from 'components/Loadable'; import { lazy } from 'react'; const LoadingComponent = Loadable(lazy(() => import('../extra-pages/LoadingComponent'))); //import {useParams} from "react-router-dom"; import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; // ==============================|| DASHBOARD - DEFAULT ||============================== // const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewRecord}) => { //const params = useParams(); const [currentUserData, setCurrentUserData] = React.useState({}); const [locked, setLocked] = useState(false); const [showPassword, setShowPassword] = React.useState(false); const [onReady, setOnReady] = useState(false); const {register, getValues} = useForm() const handleClickShowPassword = () => setShowPassword((show) => !show); const handleMouseDownPassword = () => setShowPassword(!showPassword); useEffect(() => { //if user data from parent are not null if (Object.keys(userData).length > 0 && userData !== undefined) { setCurrentUserData(userData.data); } }, [userData]); useEffect(() => { //if state data are ready and assign to different field if (Object.keys(userData).length > 0 &¤tUserData !== undefined&¤tUserData.id!==undefined) { setLocked(currentUserData.locked); setOnReady(true); }else if(isNewRecord){ setLocked(false); setOnReady(true); } }, [currentUserData]); useEffect(() => { //upload latest data to parent const values = getValues(); const objectData ={ ...values, locked: locked, } updateUserObject(objectData); }, [isCollectData]); return ( !onReady ? : Information
Username: Password: {showPassword ? : } } /> Full Name: {/* */} Post: Email: {/* Phone: */} Locked: setLocked(event.target.checked)} name="checked" color="primary" size="small" />
); }; export default UserInformationCard;