From f3ee2dc7d970b9ff826da9660d6513c555a0279f Mon Sep 17 00:00:00 2001 From: Gleidson Daniel Silva Date: Wed, 28 Feb 2024 08:40:11 -0300 Subject: [PATCH] feat: improve login error message (#5594) * feat: improve login error message * action: organized translations * Update app/i18n/locales/en.json Co-authored-by: Diego Mello * Update app/i18n/locales/en.json Co-authored-by: Diego Mello * wip * action: organized translations --------- Co-authored-by: GleidsonDaniel Co-authored-by: Diego Mello --- app/i18n/locales/en.json | 7 +++++ app/i18n/locales/pt-BR.json | 7 +++++ app/views/LoginView/UserForm.tsx | 3 +- app/views/LoginView/handleLoginErrors.ts | 35 ++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/views/LoginView/handleLoginErrors.ts diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index 9ca7b315c..b4ccbb8e7 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -26,6 +26,7 @@ "Allow_Reactions": "Allow reactions", "Also_send_thread_message_to_channel_behavior": "Also send thread message to channel", "Announcement": "Announcement", + "App_users_are_not_allowed_to_log_in_directly": "App users are not allowed to log in directly.", "Apply_Your_Certificate": "Apply your certificate", "Are_you_sure_question_mark": "Are you sure?", "Are_you_sure_you_want_to_delete_your_account": "Are you sure you want to delete your account?", @@ -39,6 +40,7 @@ "Avatar_changed_successfully": "Avatar changed successfully!", "Avatars": "Avatars", "Away": "Away", + "Before_you_can_login": "Before you can login, your account must be manually activated by an administrator.", "Bio": "Bio", "Black": "Black", "Block": "Block", @@ -256,6 +258,7 @@ "Incoming_call_from": "Incoming call from", "Inline_code": "Inline code", "Insert_Join_Code": "Insert join code", + "Invalid_Email": "Invalid email", "Invalid_or_expired_invite_token": "Invalid or expired invite token", "Invalid_server_version": "The workspace you're trying to connect is using a version that's not supported by the app anymore: {{currentVersion}}.\n\nWe require version {{minVersion}}", "Invisible": "Invisible", @@ -312,6 +315,8 @@ "Logging_out": "Logging out.", "Login": "Login", "Login_error": "Your credentials were rejected! Please try again.", + "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", "Logout": "Logout", "Logout_failed": "Logout failed!", "Logout_from_other_logged_in_locations": "Logout from other logged in locations", @@ -600,6 +605,7 @@ "Team_not_found": "Team not found", "Teams": "Teams", "Terms_of_Service": " Terms of service ", + "The_maximum_number_of_users_has_been_reached": "The maximum number of users has been reached.", "The_room_does_not_exist": "The room does not exist or you may not have access permission", "The_user_will_be_able_to_type_in_roomName": "The user will be able to type in {{roomName}}", "The_user_will_be_removed_from_s": "The user will be removed from {{s}}", @@ -660,6 +666,7 @@ "User_joined_the_conversation": "joined the conversation", "User_joined_the_team": "joined this team", "User_left_this_channel": "left the channel", + "User_not_found_or": "User not found or incorrect password", "User_sent_an_attachment": "{{user}} sent an attachment", "Username": "Username", "Username_or_email": "Username or email", diff --git a/app/i18n/locales/pt-BR.json b/app/i18n/locales/pt-BR.json index 0ad610ebd..e6fd6d850 100644 --- a/app/i18n/locales/pt-BR.json +++ b/app/i18n/locales/pt-BR.json @@ -25,6 +25,7 @@ "Allow_Reactions": "Permitir reagir", "Also_send_thread_message_to_channel_behavior": "Também enviar mensagem do tópico para o canal", "Announcement": "Anúncio", + "App_users_are_not_allowed_to_log_in_directly": "Usuários do aplicativo não estão autorizados a fazer login diretamente.", "Apply_Your_Certificate": "Aplicar certificado", "Are_you_sure_question_mark": "Você tem certeza?", "Are_you_sure_you_want_to_delete_your_account": "Tem certeza de que deseja excluir sua conta?", @@ -38,6 +39,7 @@ "Avatar_changed_successfully": "Avatar alterado com sucesso!", "Avatars": "Avatars", "Away": "Ausente", + "Before_you_can_login": "Antes que você possa fazer login, sua conta precisa ser ativada manualmente por um administrador.", "Bio": "Biografia", "Black": "Preto", "Block": "Bloquear", @@ -252,6 +254,7 @@ "In_app_message_notifications": "Notificações de mensagens in-app", "Incoming_call_from": "Chamada recebida de", "Insert_Join_Code": "Insira o código para entrar na sala", + "Invalid_Email": "E-mail inválido", "Invalid_or_expired_invite_token": "Token de convite inválido ou vencido", "Invalid_server_version": "O servidor que você está conectando não é suportado mais por esta versão do aplicativo: {{currentVersion}}.\n\nEsta versão do aplicativo requer a versão {{minVersion}} da workspace para funcionar corretamente.", "Invisible": "Invisível", @@ -307,6 +310,8 @@ "Logging_out": "Saindo.", "Login": "Entrar", "Login_error": "Suas credenciais foram rejeitadas. Tente novamente por favor!", + "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", "Logout": "Sair", "Logout_failed": "Falha ao desconectar!", "Logout_from_other_logged_in_locations": "Sair de outros locais logados", @@ -588,6 +593,7 @@ "Team_not_found": "Time não encontrado", "Teams": "Times", "Terms_of_Service": " Termos de serviço ", + "The_maximum_number_of_users_has_been_reached": "O número máximo de usuários foi atingido.", "The_room_does_not_exist": "A sala não existe ou você pode não ter permissão de acesso", "The_user_will_be_able_to_type_in_roomName": "O usuário poderá digitar em {{roomName}}", "The_user_will_be_removed_from_s": "O usuário será removido de {{s}}", @@ -648,6 +654,7 @@ "User_joined_the_conversation": "entrou na conversa", "User_joined_the_team": "entrou no time", "User_left_this_channel": "saiu da conversa", + "User_not_found_or": "Usuário não encontrado ou senha incorreta", "User_sent_an_attachment": "{{user}} enviou um anexo", "Username": "Usuário", "Username_or_email": "Usuário ou email", diff --git a/app/views/LoginView/UserForm.tsx b/app/views/LoginView/UserForm.tsx index f3f0ae9b4..e334f6c6f 100644 --- a/app/views/LoginView/UserForm.tsx +++ b/app/views/LoginView/UserForm.tsx @@ -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; @@ -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]); diff --git a/app/views/LoginView/handleLoginErrors.ts b/app/views/LoginView/handleLoginErrors.ts new file mode 100644 index 000000000..37f1b2080 --- /dev/null +++ b/app/views/LoginView/handleLoginErrors.ts @@ -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'); +};