diff --git a/src/pages/User/DetailPage/UserInformationCard.js b/src/pages/User/DetailPage/UserInformationCard.js index 07b5cab..6b72383 100644 --- a/src/pages/User/DetailPage/UserInformationCard.js +++ b/src/pages/User/DetailPage/UserInformationCard.js @@ -1,16 +1,16 @@ // material-ui import { - FormControl, + FormControl, IconButton, - Grid, - InputAdornment, + 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 { 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'; @@ -20,13 +20,13 @@ import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; // ==============================|| DASHBOARD - DEFAULT ||============================== // -const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewRecord}) => { +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 { register, getValues, formState: { errors }, } = useForm() const handleClickShowPassword = () => setShowPassword((show) => !show); const handleMouseDownPassword = () => setShowPassword(!showPassword); @@ -40,10 +40,10 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewReco useEffect(() => { //if state data are ready and assign to different field - if (Object.keys(userData).length > 0 &¤tUserData !== undefined&¤tUserData.id!==undefined) { + if (Object.keys(userData).length > 0 && currentUserData !== undefined && currentUserData.id !== undefined) { setLocked(currentUserData.locked); setOnReady(true); - }else if(isNewRecord){ + } else if (isNewRecord) { setLocked(false); setOnReady(true); } @@ -52,7 +52,7 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewReco useEffect(() => { //upload latest data to parent const values = getValues(); - const objectData ={ + const objectData = { ...values, locked: locked, } @@ -62,23 +62,23 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewReco return ( !onReady ? - + : - + Information
- + + sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'center' }}> Username: @@ -100,46 +100,53 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewReco { - isNewRecord? - - - - Password: - + isNewRecord ? + + + + Password: + - - - - - {showPassword ? : } - - - } - /> - + + + value % 2 === 0 || "The number of servings must be an even number", + })} + id='password' + type={showPassword ? 'text' : 'password'} + disabled={!isNewRecord} + endAdornment={ + + + {showPassword ? : } + + + } + /> + + + {errors.password?.message} - - : null + : null } - + + sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'center' }}> Full Name: @@ -168,10 +175,10 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewReco - + + sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'center' }}> Post: @@ -191,10 +198,10 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewReco - + + sx={{ ml: 3, mr: 3, display: 'flex', alignItems: 'center' }}> Email: @@ -237,10 +244,10 @@ const UserInformationCard = ({isCollectData, updateUserObject,userData,isNewReco */} - + + sx={{ ml: 3, mr: 3, mb: 3, display: 'flex', alignItems: 'center' }}> Locked: