diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index 2466a262b4b9..edc24bf94720 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,13 @@ 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 c290c9378e65..fdf267125da2 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