選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

109 行
4.2 KiB

  1. // material-ui
  2. import {
  3. Grid, TextField, Typography
  4. } from '@mui/material';
  5. import MainCard from "../../components/MainCard";
  6. import * as React from "react";
  7. import {useForm} from "react-hook-form";
  8. import {useEffect, useState} from "react";
  9. //import LoadingComponent from "../extra-pages/LoadingComponent";
  10. //import {useParams} from "react-router-dom";
  11. import Loadable from 'components/Loadable';
  12. import { lazy } from 'react';
  13. const LoadingComponent = Loadable(lazy(() => import('../extra-pages/LoadingComponent')));
  14. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  15. const UserGroupInfoCard = ({isCollectData, updateGroupObject,userGroupData}) => {
  16. //const params = useParams();
  17. const [currentUserGroupData, setCurrentUserGroupData] = React.useState({});
  18. const [onReady, setOnReady] = useState(false);
  19. const {register, getValues} = useForm()
  20. useEffect(() => {
  21. //if user data from parent are not null
  22. if (Object.keys(userGroupData).length > 0 && userGroupData !== undefined) {
  23. setCurrentUserGroupData(userGroupData.data);
  24. }
  25. }, [userGroupData]);
  26. useEffect(() => {
  27. //if state data are ready and assign to different field
  28. if (Object.keys(userGroupData).length > 0 &&currentUserGroupData !== undefined) {
  29. setOnReady(true);
  30. }
  31. }, [currentUserGroupData]);
  32. useEffect(() => {
  33. //upload latest data to parent
  34. const values = getValues();
  35. const objectData ={
  36. ...values,
  37. }
  38. updateGroupObject(objectData);
  39. }, [isCollectData]);
  40. return (
  41. !onReady ?
  42. <LoadingComponent/>
  43. :
  44. <MainCard elevation={0}
  45. border={false}
  46. content={false}
  47. >
  48. <Typography variant="h5" sx={{mt: 3, ml: 3, mb: 1}}>
  49. Information
  50. </Typography>
  51. <form>
  52. <Grid container>
  53. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  54. <Grid container alignItems={"center"}>
  55. <Grid item xs={4} s={4} md={4} lg={4}
  56. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  57. User Group Name:
  58. </Grid>
  59. <Grid item xs={7} s={7} md={7} lg={6}>
  60. <TextField
  61. fullWidth
  62. {...register("userGroupName",
  63. {
  64. value: currentUserGroupData.name,
  65. })}
  66. id='groupName'
  67. required
  68. />
  69. </Grid>
  70. </Grid>
  71. </Grid>
  72. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml: 3, mr: 3, mb: 3}}>
  73. <Grid container alignItems={"center"}>
  74. <Grid item xs={4} s={4} md={4} lg={4}
  75. sx={{ml: 3, mr: 3, mb:3, display: 'flex', alignItems: 'center'}}>
  76. User Group Description:
  77. </Grid>
  78. <Grid item xs={7} s={7} md={7} lg={6}>
  79. <TextField
  80. fullWidth
  81. {...register("description",
  82. {
  83. value: currentUserGroupData.description,
  84. })
  85. }
  86. id='description'
  87. />
  88. </Grid>
  89. </Grid>
  90. </Grid>
  91. </Grid>
  92. </form>
  93. </MainCard>
  94. );
  95. };
  96. export default UserGroupInfoCard;