From 2f7103a1df18d3662cbf7222ad7888de9c693643 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 8 May 2024 15:21:01 +0700 Subject: [PATCH 1/7] feature: Implement offline behavior and error handling for UpdateGroupChatName --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/libs/actions/Report.ts | 29 +++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index bebb12ddd49d..1f5bd1a49927 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1267,6 +1267,7 @@ export default { lastMemberTitle: 'Heads up!', lastMemberWarning: "Since you're the last person here, leaving will make this chat inaccessible to all users. Are you sure you want to leave?", defaultReportName: ({displayName}: {displayName: string}) => `${displayName}'s group chat`, + invalidGroupChatName: 'Invalid group chat name', }, languagePage: { language: 'Language', diff --git a/src/languages/es.ts b/src/languages/es.ts index 6c9fe2746ca0..278cc823f4b4 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1266,6 +1266,7 @@ export default { lastMemberTitle: '¡Atención!', lastMemberWarning: 'Ya que eres la última persona aquí, si te vas, este chat quedará inaccesible para todos los usuarios. ¿Estás seguro de que quieres salir del chat?', defaultReportName: ({displayName}: {displayName: string}) => `Chat de group de ${displayName}`, + invalidGroupChatName: 'Nombre de chat grupal no válido', }, languagePage: { language: 'Idioma', diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 3154ae218d72..dabf9c69eade 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -57,6 +57,7 @@ import {prepareDraftComment} from '@libs/DraftCommentUtils'; import * as EmojiUtils from '@libs/EmojiUtils'; import * as Environment from '@libs/Environment/Environment'; import * as ErrorUtils from '@libs/ErrorUtils'; +import * as Localize from '@libs/Localize'; import Log from '@libs/Log'; import * as LoginUtils from '@libs/LoginUtils'; import Navigation from '@libs/Navigation/Navigation'; @@ -635,14 +636,38 @@ function updateGroupChatName(reportID: string, reportName: string) { key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { reportName, - errorFields: { + pendingFields: { + reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + pendingFields: { reportName: null, }, }, }, ]; + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + reportName: ReportUtils.getReport(reportID)?.reportName, + errors: { + reportName: Localize.translateLocal('groupChat.invalidGroupChatName'), + }, + }, + }, + ]; const parameters: UpdateGroupChatNameParams = {reportName, reportID}; - API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME, parameters, {optimisticData}); + API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME, parameters, {optimisticData, successData, failureData}); } function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageManipulatorResult) { From 084e45edbd2ddfe90b8ec840bb5b240bc0dba43b Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 13 May 2024 09:59:46 +0700 Subject: [PATCH 2/7] update logic update group chat name --- src/libs/actions/Report.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index dabf9c69eade..8b23b245df58 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -639,6 +639,9 @@ function updateGroupChatName(reportID: string, reportName: string) { pendingFields: { reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, + errorFields: { + reportName: null, + }, }, }, ]; @@ -659,10 +662,13 @@ function updateGroupChatName(reportID: string, reportName: string) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { - reportName: ReportUtils.getReport(reportID)?.reportName, + reportName: currentReportData?.[reportID]?.reportName, errors: { reportName: Localize.translateLocal('groupChat.invalidGroupChatName'), }, + pendingFields: { + reportName: null, + }, }, }, ]; From b9a0c25d8e779883f491898ced437c813f370863 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Tue, 14 May 2024 10:15:37 +0700 Subject: [PATCH 3/7] Update src/libs/actions/Report.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/libs/actions/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 8b23b245df58..8cfc4d23a755 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -662,7 +662,7 @@ function updateGroupChatName(reportID: string, reportName: string) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { - reportName: currentReportData?.[reportID]?.reportName, + reportName: currentReportData?.[reportID]?.reportName ?? null, errors: { reportName: Localize.translateLocal('groupChat.invalidGroupChatName'), }, From c91742f314e2ad8fb4c869143cb09b305a5520a8 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 14 May 2024 10:37:00 +0700 Subject: [PATCH 4/7] add new error --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/libs/actions/Report.ts | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 1f5bd1a49927..13f5da2dfceb 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1268,6 +1268,7 @@ export default { lastMemberWarning: "Since you're the last person here, leaving will make this chat inaccessible to all users. Are you sure you want to leave?", defaultReportName: ({displayName}: {displayName: string}) => `${displayName}'s group chat`, invalidGroupChatName: 'Invalid group chat name', + genericErrorMessage: 'An error occurred while updating group chat name, please try again.', }, languagePage: { language: 'Language', diff --git a/src/languages/es.ts b/src/languages/es.ts index 278cc823f4b4..fd7542d95cf7 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1267,6 +1267,7 @@ export default { lastMemberWarning: 'Ya que eres la última persona aquí, si te vas, este chat quedará inaccesible para todos los usuarios. ¿Estás seguro de que quieres salir del chat?', defaultReportName: ({displayName}: {displayName: string}) => `Chat de group de ${displayName}`, invalidGroupChatName: 'Nombre de chat grupal no válido', + genericErrorMessage: 'Se ha producido un error al actualizar el nombre del chat de grupo, inténtalo de nuevo.', }, languagePage: { language: 'Idioma', diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 8cfc4d23a755..5ce321c6c69b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -664,7 +664,7 @@ function updateGroupChatName(reportID: string, reportName: string) { value: { reportName: currentReportData?.[reportID]?.reportName ?? null, errors: { - reportName: Localize.translateLocal('groupChat.invalidGroupChatName'), + reportName: Localize.translateLocal('groupChat.genericErrorMessage'), }, pendingFields: { reportName: null, From a102435dc11bd297f74546113f02e65ac683b701 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 14 May 2024 10:57:51 +0700 Subject: [PATCH 5/7] fix: logic check is valid report name --- src/libs/ValidationUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index d5a87fc07e28..13fe326c2c1c 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -337,7 +337,7 @@ function isValidCompanyName(name: string) { } function isValidReportName(name: string) { - return name.trim().length < CONST.REPORT_NAME_LIMIT; + return name.trim().length <= CONST.REPORT_NAME_LIMIT; } /** From 02f9472c931cf7ee918033de849ea33c7ee33d80 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 15 May 2024 10:28:06 +0700 Subject: [PATCH 6/7] Update src/libs/actions/Report.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/libs/actions/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 5ce321c6c69b..f467009c7db4 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -664,7 +664,7 @@ function updateGroupChatName(reportID: string, reportName: string) { value: { reportName: currentReportData?.[reportID]?.reportName ?? null, errors: { - reportName: Localize.translateLocal('groupChat.genericErrorMessage'), + reportName: Localize.translateLocal('common.genericErrorMessage'), }, pendingFields: { reportName: null, From 320cb6e3bd292e5c8470cd6b08e4d5c0b1191c13 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 15 May 2024 10:35:06 +0700 Subject: [PATCH 7/7] fix: update group name limit --- src/CONST.ts | 2 +- src/languages/en.ts | 2 -- src/languages/es.ts | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 95cb4f94b169..8705c8ad34d4 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2028,7 +2028,7 @@ const CONST = { LOGIN_CHARACTER_LIMIT: 254, CATEGORY_NAME_LIMIT: 256, TAG_NAME_LIMIT: 256, - REPORT_NAME_LIMIT: 256, + REPORT_NAME_LIMIT: 100, TITLE_CHARACTER_LIMIT: 100, DESCRIPTION_LIMIT: 500, WORKSPACE_NAME_CHARACTER_LIMIT: 80, diff --git a/src/languages/en.ts b/src/languages/en.ts index 13f5da2dfceb..bebb12ddd49d 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1267,8 +1267,6 @@ export default { lastMemberTitle: 'Heads up!', lastMemberWarning: "Since you're the last person here, leaving will make this chat inaccessible to all users. Are you sure you want to leave?", defaultReportName: ({displayName}: {displayName: string}) => `${displayName}'s group chat`, - invalidGroupChatName: 'Invalid group chat name', - genericErrorMessage: 'An error occurred while updating group chat name, please try again.', }, languagePage: { language: 'Language', diff --git a/src/languages/es.ts b/src/languages/es.ts index fd7542d95cf7..6c9fe2746ca0 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1266,8 +1266,6 @@ export default { lastMemberTitle: '¡Atención!', lastMemberWarning: 'Ya que eres la última persona aquí, si te vas, este chat quedará inaccesible para todos los usuarios. ¿Estás seguro de que quieres salir del chat?', defaultReportName: ({displayName}: {displayName: string}) => `Chat de group de ${displayName}`, - invalidGroupChatName: 'Nombre de chat grupal no válido', - genericErrorMessage: 'Se ha producido un error al actualizar el nombre del chat de grupo, inténtalo de nuevo.', }, languagePage: { language: 'Idioma',