diff --git a/packages/hoppscotch-sh-admin/locales/en.json b/packages/hoppscotch-sh-admin/locales/en.json index 0427a80cb..cb06e5e59 100644 --- a/packages/hoppscotch-sh-admin/locales/en.json +++ b/packages/hoppscotch-sh-admin/locales/en.json @@ -164,6 +164,7 @@ "privacy_policy": "Privacy Policy", "reenter_email": "Re-enter email", "remove_admin_failure": "Failed to remove admin status!!", + "remove_admin_failure_only_one_admin": "Failed to remove admin status. There should be at least one admin!!", "remove_admin_success": "Admin status removed!!", "remove_admin_from_users_failure": "Failed to remove admin status from selected users!!", "remove_admin_from_users_success": "Admin status removed from selected users!!", diff --git a/packages/hoppscotch-sh-admin/src/helpers/errors.ts b/packages/hoppscotch-sh-admin/src/helpers/errors.ts index d1ba9bdfe..fb7f8f2a3 100644 --- a/packages/hoppscotch-sh-admin/src/helpers/errors.ts +++ b/packages/hoppscotch-sh-admin/src/helpers/errors.ts @@ -8,8 +8,8 @@ export const UNAUTHORIZED = 'Unauthorized' as const; // Sometimes the backend returns Unauthorized error message as follows: export const GRAPHQL_UNAUTHORIZED = '[GraphQL] Unauthorized' as const; -export const DELETE_USER_FAILED_ONLY_ONE_ADMIN = - 'admin/only_one_admin_account_found' as const; +export const ONLY_ONE_ADMIN_ACCOUNT_FOUND = + '[GraphQL] admin/only_one_admin_account_found' as const; export const ADMIN_CANNOT_BE_DELETED = 'admin/admin_can_not_be_deleted' as const; diff --git a/packages/hoppscotch-sh-admin/src/pages/users/index.vue b/packages/hoppscotch-sh-admin/src/pages/users/index.vue index 88aa9f503..1db77d937 100644 --- a/packages/hoppscotch-sh-admin/src/pages/users/index.vue +++ b/packages/hoppscotch-sh-admin/src/pages/users/index.vue @@ -258,7 +258,10 @@ import { UsersListQuery, UsersListV2Document, } from '~/helpers/backend/graphql'; -import { USER_ALREADY_INVITED } from '~/helpers/errors'; +import { + ONLY_ONE_ADMIN_ACCOUNT_FOUND, + USER_ALREADY_INVITED, +} from '~/helpers/errors'; import { handleUserDeletion } from '~/helpers/userManagement'; import IconCheck from '~icons/lucide/check'; import IconLeft from '~icons/lucide/chevron-left'; @@ -525,6 +528,10 @@ const makeAdminsToUsers = async (id: string | null) => { const variables = { userUIDs }; const result = await adminsToUser.executeMutation(variables); if (result.error) { + if (result.error.message === ONLY_ONE_ADMIN_ACCOUNT_FOUND) { + return toast.error(t('state.remove_admin_failure_only_one_admin')); + } + toast.error( areMultipleUsersSelected.value ? t('state.remove_admin_from_users_failure')