From 33720c9d28ede9be8ae634203f7d8bfdc0a9f969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 8 Jul 2024 16:47:15 -0600 Subject: [PATCH] Refactor getLastMessageTextForReport function to handle IOU approval action --- src/libs/OptionsListUtils.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f20d27ffdf22..2e3760845136 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -653,10 +653,11 @@ function isSearchStringMatchUserDetails(personalDetail: PersonalDetails, searchV * Get the last message text from the report directly or from other sources for special cases. */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { - const lastReportAction = visibleReportActionItems[report?.reportID ?? '-1'] ?? null; + const reportID = report?.reportID ?? '-1'; + const lastReportAction = visibleReportActionItems[reportID] ?? null; // some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action - const lastOriginalReportAction = lastReportActions[report?.reportID ?? '-1'] ?? null; + const lastOriginalReportAction = lastReportActions[reportID] ?? null; let lastMessageTextFromReport = ''; if (ReportUtils.isArchivedRoom(report)) { @@ -716,8 +717,10 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(TaskUtils.getTaskReportActionMessage(lastReportAction).text); } else if (ReportActionUtils.isCreatedTaskReportAction(lastReportAction)) { lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); - } else if (ReportActionUtils.isApprovedOrSubmittedReportAction(lastReportAction)) { - lastMessageTextFromReport = ReportActionUtils.getReportActionMessageText(lastReportAction); + } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { + lastMessageTextFromReport = ReportUtils.getIOUSubmittedMessage(reportID); + } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { + lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(reportID); } return lastMessageTextFromReport || (report?.lastMessageText ?? '');