Skip to content

Commit 733cb1d

Browse files
committed
fix: major bug of not active of bulk MFA setting
Signed-off-by: 이승연 <[email protected]>
1 parent 8e60970 commit 733cb1d

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

apps/web/src/services/iam/components/mfa/UserBulkMFASettingModal.vue

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<script setup lang="ts">
22
import { computed, ref, watch } from 'vue';
33
4+
import { useQueryClient } from '@tanstack/vue-query';
5+
46
import {
57
PButtonModal, PScopedNotification,
68
} from '@cloudforet/mirinae';
79
810
import { MFA_STATE } from '@/api-clients/identity/user-profile/schema/constant';
911
import type { MultiFactorAuthType } from '@/api-clients/identity/user-profile/schema/type';
12+
import { useUserApi } from '@/api-clients/identity/user/composables/use-user-api';
1013
import type { UserUpdateParameters } from '@/api-clients/identity/user/schema/api-verbs/update';
14+
import { useServiceQueryKey } from '@/query/core/query-key/use-service-query-key';
1115
import { i18n } from '@/translations';
1216
1317
import { useUserStore } from '@/store/user/user-store';
@@ -17,7 +21,6 @@ import { showErrorMessage, showSuccessMessage } from '@/lib/helper/notice-alert-
1721
import ErrorHandler from '@/common/composables/error/errorHandler';
1822
1923
import UserMFASettingFormLayout from '@/services/iam/components/mfa/UserMFASettingFormLayout.vue';
20-
import { useUserUpdateMutation } from '@/services/iam/composables/mutations/use-user-update-mutation';
2124
import { useUserListQuery } from '@/services/iam/composables/use-user-list-query';
2225
import { USER_MODAL_MAP } from '@/services/iam/constants/modal.constant';
2326
import { MULTI_FACTOR_AUTH_ITEMS } from '@/services/iam/constants/user-constant';
@@ -56,13 +59,21 @@ const isIncludedExternalAuthTypeUser = computed<boolean>(() => selectedUsers.val
5659
// Store failed user IDs
5760
const failedUserIds = new Set<string>();
5861
59-
const { mutateAsync: updateUser, isPending: isUpdateUserPending } = useUserUpdateMutation({
60-
onError: (error: any, variables: UserUpdateParameters) => {
61-
// Store failed user IDs for logging failed users
62-
failedUserIds.add(variables.user_id);
62+
const queryClient = useQueryClient();
63+
const { key: userListKey } = useServiceQueryKey('identity', 'user', 'list');
64+
65+
const { userAPI } = useUserApi();
66+
const isUpdateUserPending = ref(false);
67+
68+
const updateUser = async (params: UserUpdateParameters) => {
69+
try {
70+
const result = await userAPI.update(params);
71+
return result;
72+
} catch (error: any) {
73+
failedUserIds.add(params.user_id);
6374
throw new Error(error.message);
64-
},
65-
});
75+
}
76+
};
6677
6778
/* Utils */
6879
const closeModal = () => {
@@ -82,6 +93,8 @@ const handleClose = () => {
8293
const handleConfirm = async () => {
8394
if (isUpdateUserPending.value) return;
8495
96+
isUpdateUserPending.value = true;
97+
8598
// Update MFA Promise for each user (Bulk)
8699
const userUpdatePromises = selectedMFAControllableUsers.value.map(async (user) => {
87100
if (!user.user_id) {
@@ -95,21 +108,29 @@ const handleConfirm = async () => {
95108
else throw new Error('[User MFA Setting] Something went wrong! Try again later. If the problem persists, please contact support.');
96109
}
97110
98-
return updateUser({
111+
const updateParams: UserUpdateParameters = {
99112
user_id: user.user_id,
100113
enforce_mfa_state: isRequiredMfa.value ? MFA_STATE.ENABLED : MFA_STATE.DISABLED,
101-
enforce_mfa_type: selectedMfaType.value,
102-
});
114+
};
115+
116+
if (isRequiredMfa.value) {
117+
updateParams.enforce_mfa_type = selectedMfaType.value;
118+
}
119+
120+
return updateUser(updateParams);
103121
});
104122
105123
if (userUpdatePromises.length === 0) {
106124
showErrorMessage('[User MFA Setting] There are no users to update.', '');
125+
isUpdateUserPending.value = false;
107126
return;
108127
}
109128
110129
try {
111130
const results = await Promise.allSettled(userUpdatePromises);
112131
if (results.every((result) => result.status === 'fulfilled')) {
132+
await queryClient.invalidateQueries({ queryKey: userListKey.value });
133+
113134
showSuccessMessage(i18n.t('IAM.USER.MAIN.MODAL.MFA.SET_MFA_SUCCESS_MESSAGE'), '');
114135
closeModal();
115136
emit('confirm');
@@ -125,6 +146,7 @@ const handleConfirm = async () => {
125146
} finally {
126147
// Clear failed user IDs
127148
failedUserIds.clear();
149+
isUpdateUserPending.value = false;
128150
}
129151
};
130152
@@ -134,6 +156,12 @@ watch(() => userStore.state.mfa, (mfa) => {
134156
selectedMfaType.value = mfa.mfa_type || MULTI_FACTOR_AUTH_ITEMS[0].type;
135157
}
136158
}, { immediate: true });
159+
160+
watch(() => userPageModalState.bulkMfaSettingModalVisible, async (visible) => {
161+
if (visible) {
162+
await userStore.getUserInfo();
163+
}
164+
});
137165
</script>
138166

139167
<template>

0 commit comments

Comments
 (0)