Skip to content

Commit

Permalink
Refactor getLastMessageTextForReport function to handle IOU approval …
Browse files Browse the repository at this point in the history
…action
  • Loading branch information
marcochavezf committed Jul 8, 2024
1 parent c404d29 commit 33720c9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Report>, lastActorDetails: Partial<PersonalDetails> | null, policy?: OnyxEntry<Policy>): 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)) {
Expand Down Expand Up @@ -716,8 +717,10 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, 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 ?? '');
Expand Down

0 comments on commit 33720c9

Please sign in to comment.