|
|
@@ -19,8 +19,10 @@ import { useUpdateUserGroupConfirmModal } from '~/stores/modal';
|
|
|
import {
|
|
|
useSWRxUserGroupPages, useSWRxUserGroupRelationList, useSWRxChildUserGroupList, useSWRxUserGroup,
|
|
|
useSWRxSelectableParentUserGroups, useSWRxSelectableChildUserGroups, useSWRxAncestorUserGroups,
|
|
|
+ useSWRxUserGroupRelations,
|
|
|
} from '~/stores/user-group';
|
|
|
|
|
|
+
|
|
|
import styles from './UserGroupDetailPage.module.scss';
|
|
|
|
|
|
const UserGroupPageList = dynamic(() => import('./UserGroupPageList'), { ssr: false });
|
|
|
@@ -47,6 +49,7 @@ const UserGroupDetailPage = (props: Props): JSX.Element => {
|
|
|
const { userGroupId: currentUserGroupId } = props;
|
|
|
|
|
|
const { data: currentUserGroup } = useSWRxUserGroup(currentUserGroupId);
|
|
|
+ const { data: userGroupRelations, mutate: mutateUserGroupRelations } = useSWRxUserGroupRelations(currentUserGroupId);
|
|
|
const [searchType, setSearchType] = useState<SearchType>(SearchTypes.PARTIAL);
|
|
|
const [isAlsoMailSearched, setAlsoMailSearched] = useState<boolean>(false);
|
|
|
const [isAlsoNameSearched, setAlsoNameSearched] = useState<boolean>(false);
|
|
|
@@ -71,13 +74,12 @@ const UserGroupDetailPage = (props: Props): JSX.Element => {
|
|
|
*/
|
|
|
const { data: userGroupPages } = useSWRxUserGroupPages(currentUserGroupId, 10, 0);
|
|
|
|
|
|
-
|
|
|
const { data: childUserGroupsList, mutate: mutateChildUserGroups } = useSWRxChildUserGroupList(currentUserGroupId ? [currentUserGroupId] : [], true);
|
|
|
const childUserGroups = childUserGroupsList != null ? childUserGroupsList.childUserGroups : [];
|
|
|
const grandChildUserGroups = childUserGroupsList != null ? childUserGroupsList.grandChildUserGroups : [];
|
|
|
const childUserGroupIds = childUserGroups.map(group => group._id);
|
|
|
|
|
|
- const { data: userGroupRelationList, mutate: mutateUserGroupRelations } = useSWRxUserGroupRelationList(childUserGroupIds);
|
|
|
+ const { data: userGroupRelationList } = useSWRxUserGroupRelationList(childUserGroupIds);
|
|
|
const childUserGroupRelations = userGroupRelationList != null ? userGroupRelationList : [];
|
|
|
|
|
|
const { data: selectableParentUserGroups, mutate: mutateSelectableParentUserGroups } = useSWRxSelectableParentUserGroups(currentUserGroupId);
|
|
|
@@ -171,16 +173,23 @@ const UserGroupDetailPage = (props: Props): JSX.Element => {
|
|
|
}, [currentUserGroupId, searchType, isAlsoMailSearched, isAlsoNameSearched]);
|
|
|
|
|
|
const addUserByUsername = useCallback(async(username: string) => {
|
|
|
- await apiv3Post(`/user-groups/${currentUserGroupId}/users/${username}`);
|
|
|
- setIsUserGroupUserModalShown(false);
|
|
|
- mutateUserGroupRelations();
|
|
|
- }, [currentUserGroupId, mutateUserGroupRelations]);
|
|
|
+ try {
|
|
|
+ await apiv3Post(`/user-groups/${currentUserGroupId}/users/${username}`);
|
|
|
+ setIsUserGroupUserModalShown(false);
|
|
|
+
|
|
|
+ mutateUserGroupRelations();
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ toastError(new Error(`Unable to add "${username}" from "${currentUserGroup?.name}"`));
|
|
|
+ }
|
|
|
+ }, [currentUserGroup?.name, currentUserGroupId, mutateUserGroupRelations]);
|
|
|
|
|
|
// Fix: invalid csrf token => https://redmine.weseek.co.jp/issues/102704
|
|
|
const removeUserByUsername = useCallback(async(username: string) => {
|
|
|
try {
|
|
|
await apiv3Delete(`/user-groups/${currentUserGroupId}/users/${username}`);
|
|
|
toastSuccess(`Removed "${xss.process(username)}" from "${xss.process(currentUserGroup?.name)}"`);
|
|
|
+
|
|
|
mutateUserGroupRelations();
|
|
|
}
|
|
|
catch (err) {
|
|
|
@@ -348,8 +357,7 @@ const UserGroupDetailPage = (props: Props): JSX.Element => {
|
|
|
</div>
|
|
|
<h2 className="admin-setting-header mt-4">{t('user_group_management.user_list')}</h2>
|
|
|
<UserGroupUserTable
|
|
|
- userGroup={currentUserGroup}
|
|
|
- userGroupRelations={childUserGroupRelations}
|
|
|
+ userGroupRelations={userGroupRelations}
|
|
|
onClickPlusBtn={() => setIsUserGroupUserModalShown(true)}
|
|
|
onClickRemoveUserBtn={removeUserByUsername}
|
|
|
/>
|