Skip to content

Commit

Permalink
chore: more specific error message while removing Admin status
Browse files Browse the repository at this point in the history
The case where there is only one Admin.
  • Loading branch information
jamesgeorge007 committed Mar 27, 2024
1 parent 17db483 commit 5eb047b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/hoppscotch-sh-admin/locales/en.json
Expand Up @@ -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!!",
Expand Down
4 changes: 2 additions & 2 deletions packages/hoppscotch-sh-admin/src/helpers/errors.ts
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion packages/hoppscotch-sh-admin/src/pages/users/index.vue
Expand Up @@ -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';
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 5eb047b

Please sign in to comment.