From f838825644214ed7a7744bde7db4049fc978345c Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Fri, 27 Aug 2021 13:34:38 -0300 Subject: [PATCH] [FIX] Evaluate values in handle failure (#3235) * [FIX] HEvaluating proper the error for channel, team and undefined * Added some team errors in i18n * Added unauthorized to i18n * Test if there is channel name too, to prevent to show {missing roomName} * Refactor the treatment error to check if exists before translate with i18n * Remove some check conditional points * Minor tweak * Added array with error inside the createChannel * Moved error array to inside the handleFailure * added creating_discussion Co-authored-by: Gerzon Z Co-authored-by: Gerzon Z Co-authored-by: Diego Mello --- app/i18n/locales/en.json | 6 +++++- app/i18n/locales/pt-BR.json | 3 +++ app/sagas/createChannel.js | 17 ++++++++++++++++- app/views/CreateDiscussionView/index.js | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index 194031660..114478bb6 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -762,11 +762,15 @@ "Load_More": "Load More", "Load_Newer": "Load Newer", "Load_Older": "Load Older", + "room-name-already-exists": "Room name already exists", + "error-team-creation": "Error team creation", + "unauthorized": "Unauthorized", "Left_The_Room_Successfully": "Left the room successfully", "Deleted_The_Team_Successfully": "Team deleted successfully", "Deleted_The_Room_Successfully": "Room deleted successfully", "Convert_to_Channel": "Convert to Channel", "Converting_Team_To_Channel": "Converting Team to Channel", "Select_Team_Channels_To_Delete": "Select the Team’s Channels you would like to delete, the ones you do not select will be moved to the Workspace. \n\nNotice that public Channels will be public and visible to everyone.", - "You_are_converting_the_team": "You are converting this Team to a Channel" + "You_are_converting_the_team": "You are converting this Team to a Channel", + "creating_discussion": "creating discussion" } \ No newline at end of file diff --git a/app/i18n/locales/pt-BR.json b/app/i18n/locales/pt-BR.json index a6fed1be2..074b10efb 100644 --- a/app/i18n/locales/pt-BR.json +++ b/app/i18n/locales/pt-BR.json @@ -666,6 +666,9 @@ "Left_The_Team_Successfully": "Saiu do time com sucesso", "Add_Existing_Channel": "Adicionar Canal Existente", "invalid-room": "Sala inválida", + "room-name-already-exists": "Nome da sala já existe", + "error-team-creation": "Erro na criação do time", + "unauthorized": "Não autorizado", "Left_The_Room_Successfully": "Saiu da sala com sucesso", "Deleted_The_Team_Successfully": "Time deletado com sucesso", "Deleted_The_Room_Successfully": "Sala deletada com sucesso", diff --git a/app/sagas/createChannel.js b/app/sagas/createChannel.js index 9493d5405..6e244d904 100644 --- a/app/sagas/createChannel.js +++ b/app/sagas/createChannel.js @@ -109,8 +109,23 @@ const handleSuccess = function* handleSuccess({ data }) { }; const handleFailure = function handleFailure({ err, isTeam }) { + const errorArray = [ + 'room-name-already-exists', + 'error-team-creation', + 'unauthorized', + 'error-duplicate-channel-name', + 'error-invalid-room-name', + 'team-name-already-exists' + ]; + setTimeout(() => { - const msg = err.data.errorType ? I18n.t(err.data.errorType, { room_name: err.data.details.channel_name }) : err.reason || I18n.t('There_was_an_error_while_action', { action: isTeam ? I18n.t('creating_team') : I18n.t('creating_channel') }); + let msg = ''; + const actionError = I18n.t('There_was_an_error_while_action', { action: isTeam ? I18n.t('creating_team') : I18n.t('creating_channel') }); + if (err?.data?.errorType && err?.data?.details?.channel_name) { + msg = errorArray.includes(err.data.errorType) ? I18n.t(err.data.errorType, { room_name: err.data.details.channel_name }) : actionError; + } else { + msg = err?.reason || (errorArray.includes(err?.data?.error) ? I18n.t(err.data.error) : err.data.error || actionError); + } showErrorAlert(msg, isTeam ? I18n.t('Create_Team') : I18n.t('Create_Channel')); }, 300); }; diff --git a/app/views/CreateDiscussionView/index.js b/app/views/CreateDiscussionView/index.js index 46b2d6cde..a70caff9b 100644 --- a/app/views/CreateDiscussionView/index.js +++ b/app/views/CreateDiscussionView/index.js @@ -74,7 +74,7 @@ class CreateChannelView extends React.Component { if (!loading && loading !== prevProps.loading) { setTimeout(() => { if (failure) { - const msg = error.reason || I18n.t('There_was_an_error_while_action', { action: I18n.t('creating_channel') }); + const msg = error.reason || I18n.t('There_was_an_error_while_action', { action: I18n.t('creating_discussion') }); showErrorAlert(msg); } else { const { rid, t, prid } = result;