Browse Source

populate parent

Shun Miyazawa 4 years ago
parent
commit
50eeae15d2

+ 2 - 14
packages/app/src/components/Admin/UserGroup/UserGroupForm.tsx

@@ -1,11 +1,8 @@
-import React, {
-  FC, useCallback, useState, useEffect,
-} from 'react';
+import React, { FC, useCallback, useState } from 'react';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import dateFnsFormat from 'date-fns/format';
 import dateFnsFormat from 'date-fns/format';
 import { TFunctionResult } from 'i18next';
 import { TFunctionResult } from 'i18next';
 
 
-import { useSWRxUserGroup } from '~/stores/user-group';
 import { IUserGroup, IUserGroupHasId } from '~/interfaces/user';
 import { IUserGroup, IUserGroupHasId } from '~/interfaces/user';
 import { CustomWindow } from '~/interfaces/global';
 import { CustomWindow } from '~/interfaces/global';
 import Xss from '~/services/xss';
 import Xss from '~/services/xss';
@@ -31,12 +28,7 @@ const UserGroupForm: FC<Props> = (props: Props) => {
    */
    */
   const [currentName, setName] = useState(userGroup != null ? userGroup.name : '');
   const [currentName, setName] = useState(userGroup != null ? userGroup.name : '');
   const [currentDescription, setDescription] = useState(userGroup != null ? userGroup.description : '');
   const [currentDescription, setDescription] = useState(userGroup != null ? userGroup.description : '');
-  const [selectedParent, setSelectedParent] = useState<IUserGroupHasId | null>(null);
-
-  /*
-   * Fetch
-   */
-  const { data: parentUserGroup } = useSWRxUserGroup(userGroup?.parent as string);
+  const [selectedParent, setSelectedParent] = useState<IUserGroupHasId | undefined>(userGroup?.parent as IUserGroupHasId);
 
 
   /*
   /*
    * Function
    * Function
@@ -65,10 +57,6 @@ const UserGroupForm: FC<Props> = (props: Props) => {
     await onSubmit({ name: currentName, description: currentDescription, parent: selectedParent?._id });
     await onSubmit({ name: currentName, description: currentDescription, parent: selectedParent?._id });
   }, [currentName, currentDescription, selectedParent, onSubmit]);
   }, [currentName, currentDescription, selectedParent, onSubmit]);
 
 
-  useEffect(() => {
-    setSelectedParent(parentUserGroup ?? null);
-  }, [parentUserGroup]);
-
   return (
   return (
     <form onSubmit={onSubmitHandler}>
     <form onSubmit={onSubmitHandler}>
 
 

+ 1 - 1
packages/app/src/server/routes/admin.js

@@ -284,7 +284,7 @@ module.exports = function(crowi, app) {
   // グループ詳細
   // グループ詳細
   actions.userGroup.detail = async function(req, res) {
   actions.userGroup.detail = async function(req, res) {
     const userGroupId = req.params.id;
     const userGroupId = req.params.id;
-    const userGroup = await UserGroup.findOne({ _id: userGroupId });
+    const userGroup = await UserGroup.findOne({ _id: userGroupId }).populate('parent');
 
 
     if (userGroup == null) {
     if (userGroup == null) {
       logger.error('no userGroup is exists. ', userGroupId);
       logger.error('no userGroup is exists. ', userGroupId);