Skip to content

Commit

Permalink
feat: improve login error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlsilva committed Feb 26, 2024
1 parent 55f3de5 commit 50c0342
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,5 +807,12 @@
"video-conf-provider-not-configured-body": "A workspace admin needs to enable the conference calls feature first.",
"video-conf-provider-not-configured-header": "Conference call not enabled",
"you": "you",
"you_were_mentioned": "you were mentioned"
"you_were_mentioned": "you were mentioned",
"User_not_found_or": "User not found or incorrect password",
"Invalid_Email": "Invalid Email",
"Login_has_been_temporarily_blocked_for_this_IP": "Login has been temporarily blocked for this IP",
"Login_has_been_temporarily_blocked_for_this_User": "Login has been temporarily blocked for this User",
"The_maximum_number_of_users_has_been_reached": "The maximum number of users has been reached.",
"App_users_are_not_allowed_to_log_in_directly": "App users are not allowed to log in directly.",
"Before_you_can_login": "Before you can login, your account must be manually activated by an administrator."
}
12 changes: 10 additions & 2 deletions app/i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -795,5 +795,13 @@
"video-conf-provider-not-configured-body": "Um administrador do workspace precisa ativar o recurso de chamadas de conferência primeiro.",
"video-conf-provider-not-configured-header": "Video conferência não ativada",
"you": "você",
"you_were_mentioned": "você foi mencionado"
}
"you_were_mentioned": "você foi mencionado",
"User_not_found_or": "Usuário não encontrado ou senha incorreta",
"Invalid_Email": "E-mail inválido",
"Login_has_been_temporarily_blocked_for_this_IP": "Login foi temporariamente bloqueado para este IP",
"Login_has_been_temporarily_blocked_for_this_User": "Login foi temporariamente bloqueado para este usuário",
"The_maximum_number_of_users_has_been_reached": "O número máximo de usuários foi atingido.",
"App_users_are_not_allowed_to_log_in_directly": "Usuários do aplicativo não estão autorizados a fazer login diretamente.",
"Before_you_can_login": "Antes que você possa fazer login, sua conta precisa ser ativada manualmente por um administrador."
}

3 changes: 2 additions & 1 deletion app/views/LoginView/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import sharedStyles from '../Styles';
import UGCRules from '../../containers/UserGeneratedContentRules';
import { useAppSelector } from '../../lib/hooks';
import styles from './styles';
import { handleLoginErrors } from './handleLoginErrors';

interface ISubmit {
user: string;
Expand Down Expand Up @@ -75,7 +76,7 @@ const UserForm = () => {
const user = getValues('user');
navigation.navigate('SendEmailConfirmationView', { user });
} else {
Alert.alert(I18n.t('Oops'), I18n.t('Login_error'));
Alert.alert(I18n.t('Oops'), handleLoginErrors(error?.error));
}
}
}, [error?.error, failure, getValues, navigation]);
Expand Down
35 changes: 35 additions & 0 deletions app/views/LoginView/handleLoginErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import i18n from '../../i18n';

// https://github.com/RocketChat/Rocket.Chat/blob/cd5cbe2ac60939d4d94a62926b43322be9168ce0/packages/web-ui-registration/src/LoginForm.tsx#L28
const LOGIN_SUBMIT_ERRORS = {
'error-user-is-not-activated': {
i18n: 'Before_you_can_login'
},
'error-app-user-is-not-allowed-to-login': {
i18n: 'App_users_are_not_allowed_to_log_in_directly'
},
'user-not-found': {
i18n: 'User_not_found_or'
},
'error-login-blocked-for-ip': {
i18n: 'Login_has_been_temporarily_blocked_for_this_IP'
},
'error-login-blocked-for-user': {
i18n: 'Login_has_been_temporarily_blocked_for_this_User'
},
'error-license-user-limit-reached': {
i18n: 'The_maximum_number_of_users_has_been_reached'
},
'error-invalid-email': {
i18n: 'Invalid_Email'
}
};

export const handleLoginErrors = (error: keyof typeof LOGIN_SUBMIT_ERRORS): string => {
const errorKey = Object.keys(LOGIN_SUBMIT_ERRORS).find(key => error.includes(key)) as keyof typeof LOGIN_SUBMIT_ERRORS;
const e = errorKey ? LOGIN_SUBMIT_ERRORS[errorKey].i18n : 'Login_error';
if (i18n.isTranslated(e)) {
return i18n.t(e);
}
return i18n.t('Login_error');
};

0 comments on commit 50c0342

Please sign in to comment.