diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index a734890a1f38..568839d6c9ae 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -22,6 +22,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {PersonalDetails} from '@src/types/onyx'; import OptionRowLHNData from './OptionRowLHNData'; import type {LHNOptionsListProps, RenderItemProps} from './types'; @@ -148,6 +149,20 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio } const lastReportActionTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportActionTransactionID}`]; + // SidebarUtils.getOptionData in OptionRowLHNData does not get re-evaluated when the linked task report changes, so we have the lastMessageTextFromReport evaluation logic here + let lastActorDetails: Partial | null = + itemFullReport?.lastActorAccountID && personalDetails?.[itemFullReport.lastActorAccountID] ? personalDetails[itemFullReport.lastActorAccountID] : null; + if (!lastActorDetails && lastReportAction) { + const lastActorDisplayName = lastReportAction?.person?.[0]?.text; + lastActorDetails = lastActorDisplayName + ? { + displayName: lastActorDisplayName, + accountID: itemFullReport?.lastActorAccountID, + } + : null; + } + const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(itemFullReport, lastActorDetails, itemPolicy); + return ( ) => void; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 0e8447635098..6f3ea1152e22 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -240,6 +240,7 @@ function getOptionData({ policy, parentReportAction, hasViolations, + lastMessageTextFromReport: lastMessageTextFromReportProp, transactionViolations, invoiceReceiverPolicy, }: { @@ -250,6 +251,7 @@ function getOptionData({ policy: OnyxEntry | undefined; parentReportAction: OnyxEntry | undefined; hasViolations: boolean; + lastMessageTextFromReport?: string; invoiceReceiverPolicy?: OnyxEntry; transactionViolations?: OnyxCollection; }): ReportUtils.OptionData | undefined { @@ -384,7 +386,11 @@ function getOptionData({ } const lastActorDisplayName = OptionsListUtils.getLastActorDisplayName(lastActorDetails, hasMultipleParticipants); - const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy); + + let lastMessageTextFromReport = lastMessageTextFromReportProp; + if (!lastMessageTextFromReport) { + lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy); + } // We need to remove sms domain in case the last message text has a phone number mention with sms domain. let lastMessageText = Str.removeSMSDomain(lastMessageTextFromReport);