|
@@ -9,9 +9,10 @@ import { toastSuccess, toastError } from '~/client/util/apiNotification';
|
|
|
import { IUserGroup, IUserGroupHasId } from '~/interfaces/user';
|
|
import { IUserGroup, IUserGroupHasId } from '~/interfaces/user';
|
|
|
import Xss from '~/services/xss';
|
|
import Xss from '~/services/xss';
|
|
|
import { CustomWindow } from '~/interfaces/global';
|
|
import { CustomWindow } from '~/interfaces/global';
|
|
|
-import { apiv3Delete, apiv3Post } from '~/client/util/apiv3-client';
|
|
|
|
|
|
|
+import { apiv3Delete, apiv3Post, apiv3Put } from '~/client/util/apiv3-client';
|
|
|
import { useSWRxUserGroupList, useSWRxChildUserGroupList, useSWRxUserGroupRelationList } from '~/stores/user-group';
|
|
import { useSWRxUserGroupList, useSWRxChildUserGroupList, useSWRxUserGroupRelationList } from '~/stores/user-group';
|
|
|
import { useIsAclEnabled } from '~/stores/context';
|
|
import { useIsAclEnabled } from '~/stores/context';
|
|
|
|
|
+import userGroup from '~/server/models/user-group';
|
|
|
|
|
|
|
|
const UserGroupPage: FC = () => {
|
|
const UserGroupPage: FC = () => {
|
|
|
const xss: Xss = (window as CustomWindow).xss;
|
|
const xss: Xss = (window as CustomWindow).xss;
|
|
@@ -37,6 +38,7 @@ const UserGroupPage: FC = () => {
|
|
|
*/
|
|
*/
|
|
|
const [selectedUserGroup, setSelectedUserGroup] = useState<IUserGroupHasId | undefined>(undefined); // not null but undefined (to use defaultProps in UserGroupDeleteModal)
|
|
const [selectedUserGroup, setSelectedUserGroup] = useState<IUserGroupHasId | undefined>(undefined); // not null but undefined (to use defaultProps in UserGroupDeleteModal)
|
|
|
const [isCreateModalShown, setCreateModalShown] = useState<boolean>(false);
|
|
const [isCreateModalShown, setCreateModalShown] = useState<boolean>(false);
|
|
|
|
|
+ const [isUpdateModalShown, setUpdateModalShown] = useState<boolean>(false);
|
|
|
const [isDeleteModalShown, setDeleteModalShown] = useState<boolean>(false);
|
|
const [isDeleteModalShown, setDeleteModalShown] = useState<boolean>(false);
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -50,6 +52,16 @@ const UserGroupPage: FC = () => {
|
|
|
setCreateModalShown(false);
|
|
setCreateModalShown(false);
|
|
|
}, [setCreateModalShown]);
|
|
}, [setCreateModalShown]);
|
|
|
|
|
|
|
|
|
|
+ const showUpdateModal = useCallback((group: IUserGroupHasId) => {
|
|
|
|
|
+ setUpdateModalShown(true);
|
|
|
|
|
+ setSelectedUserGroup(group);
|
|
|
|
|
+ }, [setUpdateModalShown]);
|
|
|
|
|
+
|
|
|
|
|
+ const hideUpdateModal = useCallback(() => {
|
|
|
|
|
+ setUpdateModalShown(false);
|
|
|
|
|
+ setSelectedUserGroup(undefined);
|
|
|
|
|
+ }, [setUpdateModalShown]);
|
|
|
|
|
+
|
|
|
const syncUserGroupAndRelations = useCallback(async() => {
|
|
const syncUserGroupAndRelations = useCallback(async() => {
|
|
|
try {
|
|
try {
|
|
|
await mutateUserGroups();
|
|
await mutateUserGroups();
|
|
@@ -90,6 +102,20 @@ const UserGroupPage: FC = () => {
|
|
|
}
|
|
}
|
|
|
}, [t, mutateUserGroups]);
|
|
}, [t, mutateUserGroups]);
|
|
|
|
|
|
|
|
|
|
+ const updateUserGroup = useCallback(async(userGroupData: IUserGroupHasId) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await apiv3Put(`/user-groups/${userGroupData._id}`, {
|
|
|
|
|
+ name: userGroupData.name,
|
|
|
|
|
+ description: userGroupData.description,
|
|
|
|
|
+ });
|
|
|
|
|
+ toastSuccess(t('toaster.update_successed', { target: t('UserGroup') }));
|
|
|
|
|
+ await mutateUserGroups();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ toastError(err);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [t, mutateUserGroups]);
|
|
|
|
|
+
|
|
|
const deleteUserGroupById = useCallback(async(deleteGroupId: string, actionName: string, transferToUserGroupId: string) => {
|
|
const deleteUserGroupById = useCallback(async(deleteGroupId: string, actionName: string, transferToUserGroupId: string) => {
|
|
|
try {
|
|
try {
|
|
|
const res = await apiv3Delete(`/user-groups/${deleteGroupId}`, {
|
|
const res = await apiv3Delete(`/user-groups/${deleteGroupId}`, {
|
|
@@ -123,19 +149,32 @@ const UserGroupPage: FC = () => {
|
|
|
t('admin:user_group_management.deny_create_group')
|
|
t('admin:user_group_management.deny_create_group')
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
<UserGroupModal
|
|
<UserGroupModal
|
|
|
- onClickCreateButton={createUserGroup}
|
|
|
|
|
|
|
+ buttonLabel={t('Create')}
|
|
|
|
|
+ onClickButton={createUserGroup}
|
|
|
isShow={isCreateModalShown}
|
|
isShow={isCreateModalShown}
|
|
|
onHide={hideCreateModal}
|
|
onHide={hideCreateModal}
|
|
|
/>
|
|
/>
|
|
|
|
|
+
|
|
|
|
|
+ <UserGroupModal
|
|
|
|
|
+ userGroup={selectedUserGroup}
|
|
|
|
|
+ buttonLabel={t('Update')}
|
|
|
|
|
+ onClickButton={updateUserGroup}
|
|
|
|
|
+ isShow={isUpdateModalShown}
|
|
|
|
|
+ onHide={hideUpdateModal}
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
<UserGroupTable
|
|
<UserGroupTable
|
|
|
headerLabel={t('admin:user_group_management.group_list')}
|
|
headerLabel={t('admin:user_group_management.group_list')}
|
|
|
userGroups={userGroups}
|
|
userGroups={userGroups}
|
|
|
childUserGroups={childUserGroups}
|
|
childUserGroups={childUserGroups}
|
|
|
isAclEnabled={isAclEnabled ?? false}
|
|
isAclEnabled={isAclEnabled ?? false}
|
|
|
|
|
+ onEdit={showUpdateModal}
|
|
|
onDelete={showDeleteModal}
|
|
onDelete={showDeleteModal}
|
|
|
userGroupRelations={userGroupRelations}
|
|
userGroupRelations={userGroupRelations}
|
|
|
/>
|
|
/>
|
|
|
|
|
+
|
|
|
<UserGroupDeleteModal
|
|
<UserGroupDeleteModal
|
|
|
userGroups={userGroups}
|
|
userGroups={userGroups}
|
|
|
deleteUserGroup={selectedUserGroup}
|
|
deleteUserGroup={selectedUserGroup}
|