From 9ad0e5f94c691e333c97c59e544ea9502e732dde Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sun, 28 Jan 2024 22:27:51 +0700 Subject: [PATCH 1/3] only display one message --- src/components/DotIndicatorMessage.tsx | 57 +++++++++++--------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/src/components/DotIndicatorMessage.tsx b/src/components/DotIndicatorMessage.tsx index d18704fdfb05..f3e9b5d786d0 100644 --- a/src/components/DotIndicatorMessage.tsx +++ b/src/components/DotIndicatorMessage.tsx @@ -52,13 +52,9 @@ function DotIndicatorMessage({messages = {}, style, type, textStyles}: DotIndica return null; } - // Fetch the keys, sort them, and map through each key to get the corresponding message - const sortedMessages = Object.keys(messages) - .sort() - .map((key) => messages[key]); - - // Removing duplicates using Set and transforming the result into an array - const uniqueMessages = [...new Set(sortedMessages)].map((message) => Localize.translateIfPhraseKey(message)); + // Fetch the keys, sort them, and reverse to get the last message + const lastKey = Object.keys(messages).sort().reverse()[0]; + const message = messages[lastKey] as string; const isErrorMessage = type === 'error'; @@ -71,34 +67,27 @@ function DotIndicatorMessage({messages = {}, style, type, textStyles}: DotIndica /> - {uniqueMessages.map((message, i) => - isReceiptError(message) ? ( - { - fileDownload(message.source, message.filename); - }} - > - - {Localize.translateLocal('iou.error.receiptFailureMessage')} - {Localize.translateLocal('iou.error.saveFileMessage')} - {Localize.translateLocal('iou.error.loseFileMessage')} - - - ) : ( - - {message} + {isReceiptError(message) ? ( + { + fileDownload(message.source, message.filename); + }} + > + + {Localize.translateLocal('iou.error.receiptFailureMessage')} + {Localize.translateLocal('iou.error.saveFileMessage')} + {Localize.translateLocal('iou.error.loseFileMessage')} - ), + + ) : ( + + {message} + )} From e98f17145ef803ebe85406ac7e88d0d8a8d7f691 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 1 Feb 2024 17:18:26 +0700 Subject: [PATCH 2/3] only display one error message for report action --- src/components/DotIndicatorMessage.tsx | 57 ++++++++++++++--------- src/libs/ErrorUtils.ts | 14 +++++- src/pages/home/report/ReportActionItem.js | 3 +- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/components/DotIndicatorMessage.tsx b/src/components/DotIndicatorMessage.tsx index f3e9b5d786d0..d18704fdfb05 100644 --- a/src/components/DotIndicatorMessage.tsx +++ b/src/components/DotIndicatorMessage.tsx @@ -52,9 +52,13 @@ function DotIndicatorMessage({messages = {}, style, type, textStyles}: DotIndica return null; } - // Fetch the keys, sort them, and reverse to get the last message - const lastKey = Object.keys(messages).sort().reverse()[0]; - const message = messages[lastKey] as string; + // Fetch the keys, sort them, and map through each key to get the corresponding message + const sortedMessages = Object.keys(messages) + .sort() + .map((key) => messages[key]); + + // Removing duplicates using Set and transforming the result into an array + const uniqueMessages = [...new Set(sortedMessages)].map((message) => Localize.translateIfPhraseKey(message)); const isErrorMessage = type === 'error'; @@ -67,27 +71,34 @@ function DotIndicatorMessage({messages = {}, style, type, textStyles}: DotIndica /> - {isReceiptError(message) ? ( - { - fileDownload(message.source, message.filename); - }} - > - - {Localize.translateLocal('iou.error.receiptFailureMessage')} - {Localize.translateLocal('iou.error.saveFileMessage')} - {Localize.translateLocal('iou.error.loseFileMessage')} + {uniqueMessages.map((message, i) => + isReceiptError(message) ? ( + { + fileDownload(message.source, message.filename); + }} + > + + {Localize.translateLocal('iou.error.receiptFailureMessage')} + {Localize.translateLocal('iou.error.saveFileMessage')} + {Localize.translateLocal('iou.error.loseFileMessage')} + + + ) : ( + + {message} - - ) : ( - - {message} - + ), )} diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index 2466a262b4b9..0cbf335a690e 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -66,6 +66,18 @@ function getLatestErrorMessage(onyxData: T return errors[key]; } +function getLatestErrorMessageField(onyxData: TOnyxData): Record { + const errors = onyxData.errors ?? {}; + + if (Object.keys(errors).length === 0) { + return {}; + } + + const key = Object.keys(errors).sort().reverse()[0]; + + return {key: errors[key]}; +} + type OnyxDataWithErrorFields = { errorFields?: ErrorFields; }; @@ -119,4 +131,4 @@ function addErrorMessage(errors: ErrorsList, inpu } } -export {getAuthenticateErrorMessage, getMicroSecondOnyxError, getMicroSecondOnyxErrorObject, getLatestErrorMessage, getLatestErrorField, getEarliestErrorField, addErrorMessage}; +export {getAuthenticateErrorMessage, getMicroSecondOnyxError, getMicroSecondOnyxErrorObject, getLatestErrorMessage, getLatestErrorField, getEarliestErrorField, addErrorMessage, getLatestErrorMessageField}; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index c8b9c25965b6..f0856e8ca456 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -40,6 +40,7 @@ import compose from '@libs/compose'; import ControlSelection from '@libs/ControlSelection'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import * as ErrorUtils from '@libs/ErrorUtils'; import focusTextInputAfterAnimation from '@libs/focusTextInputAfterAnimation'; import ModifiedExpenseMessage from '@libs/ModifiedExpenseMessage'; import Navigation from '@libs/Navigation/Navigation'; @@ -733,7 +734,7 @@ function ReportActionItem(props) { !_.isUndefined(props.draftMessage) ? null : props.action.pendingAction || (props.action.isOptimisticAction ? CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD : '') } shouldHideOnDelete={!ReportActionsUtils.isThreadParentMessage(props.action, props.report.reportID)} - errors={props.action.errors} + errors={ErrorUtils.getLatestErrorMessageField(props.action)} errorRowStyles={[styles.ml10, styles.mr2]} needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(props.action)} shouldDisableStrikeThrough From f95ddead935f3184b3f437241d4af5dacabcb7d8 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 1 Feb 2024 17:37:44 +0700 Subject: [PATCH 3/3] fix lint --- src/libs/ErrorUtils.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index 0cbf335a690e..edc24bf94720 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -131,4 +131,13 @@ function addErrorMessage(errors: ErrorsList, inpu } } -export {getAuthenticateErrorMessage, getMicroSecondOnyxError, getMicroSecondOnyxErrorObject, getLatestErrorMessage, getLatestErrorField, getEarliestErrorField, addErrorMessage, getLatestErrorMessageField}; +export { + getAuthenticateErrorMessage, + getMicroSecondOnyxError, + getMicroSecondOnyxErrorObject, + getLatestErrorMessage, + getLatestErrorField, + getEarliestErrorField, + addErrorMessage, + getLatestErrorMessageField, +};