|
- // 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 ?
- <LoadingComponent/>
- :
- <MainCard elevation={0}
- border={false}
- content={false}
- >
- <Typography variant="h5" sx={{mt: 3, ml: 3, mb: 1}}>
- Information
- </Typography>
-
-
- <form>
- <Grid container>
- <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
- <Grid container alignItems={"center"}>
- <Grid item xs={4} s={4} md={4} lg={4}
- sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
- <FormLabel required>Username:</FormLabel>
- </Grid>
-
- <Grid item xs={7} s={7} md={7} lg={6}>
- <FormControl variant="outlined" fullWidth required>
- <OutlinedInput
- required
- fullWidth
- size="small"
- {...register("username",
- {
- value: currentUserData.username,
- })}
- id='username'
- disabled={!isNewRecord}
- />
- </FormControl>
- </Grid>
- </Grid>
- </Grid>
-
- <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
- <Grid container alignItems={"center"}>
- <Grid item xs={4} s={4} md={4} lg={4}
- sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
- Password:
- </Grid>
-
- <Grid item xs={7} s={7} md={7} lg={6}>
- <FormControl variant="outlined" fullWidth required>
- <OutlinedInput
- fullWidth
- size="small"
- {...register("password")}
- id='password'
- type={showPassword ? 'text' : 'password'}
- disabled
- endAdornment={
- <InputAdornment position="end">
- <IconButton
- aria-label="toggle password visibility"
- onClick={handleClickShowPassword}
- onMouseDown={handleMouseDownPassword}
- edge="end"
- >
- {showPassword ? <VisibilityOff /> : <Visibility />}
- </IconButton>
- </InputAdornment>
- }
- />
- </FormControl>
- </Grid>
- </Grid>
- </Grid>
-
- <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
- <Grid container alignItems={"center"}>
- <Grid item xs={4} s={4} md={4} lg={4}
- sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
- <FormLabel required >Full Name:</FormLabel>
- </Grid>
-
- <Grid item xs={7} s={7} md={7} lg={6}>
- {/* <TextField
- fullWidth
- {...register("enName",
- {
- value: currentUserData.enName,
- })}
- id='enName'
- /> */}
- <FormControl variant="outlined" fullWidth required>
- <OutlinedInput
- required
- fullWidth
- size="small"
- {...register("enName",
- {
- value: currentUserData.enName,
- })}
- id='enName'
- />
- </FormControl>
- </Grid>
- </Grid>
- </Grid>
-
- <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
- <Grid container alignItems={"center"}>
- <Grid item xs={4} s={4} md={4} lg={4}
- sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
- <FormLabel>Post:</FormLabel>
- </Grid>
-
- <Grid item xs={7} s={7} md={7} lg={6}>
- <FormControl variant="outlined" fullWidth required>
- <OutlinedInput
- fullWidth
- size="small"
- {...register("post",
- {
- value: currentUserData.post,
- })}
- id='post'
- />
- </FormControl>
- </Grid>
- </Grid>
- </Grid>
-
- <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
- <Grid container alignItems={"center"}>
- <Grid item xs={4} s={4} md={4} lg={4}
- sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
- <FormLabel required>Email:</FormLabel>
- </Grid>
-
- <Grid item xs={7} s={7} md={7} lg={6}>
- <FormControl variant="outlined" fullWidth required>
- <OutlinedInput
- fullWidth
- size="small"
- {...register("emailAddress",
- {
- value: currentUserData.emailAddress,
- })}
- id='emailAddress'
- />
- </FormControl>
- </Grid>
- </Grid>
- </Grid>
-
- {/* <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
- <Grid container alignItems={"center"}>
- <Grid item xs={4} s={4} md={4} lg={4}
- sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
- <FormLabel>Phone:</FormLabel>
- </Grid>
-
- <Grid item xs={7} s={7} md={7} lg={6}>
- <FormControl variant="outlined" fullWidth required>
- <OutlinedInput
- fullWidth
- size="small"
- {...register("phone",
- {
- value: currentUserData.phone,
- })}
- id='phone'
- />
- </FormControl>
- </Grid>
- </Grid>
- </Grid> */}
-
- <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
- <Grid container>
- <Grid item xs={4} s={4} md={4} lg={4}
- sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
- <FormLabel required>Locked:</FormLabel>
- </Grid>
-
- <Grid item xs={7} s={7} md={7} lg={6}>
- <Checkbox
- checked={locked}
- onChange={(event) => setLocked(event.target.checked)}
- name="checked"
- color="primary"
- size="small"
- />
- </Grid>
- </Grid>
- </Grid>
-
- </Grid>
-
- </form>
- </MainCard>
- );
- };
-
- export default UserInformationCard;
|