diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 264fefac8753..93fe4fe9934e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -799,6 +799,18 @@ function hasAutomatedExpensifyAccountIDs(accountIDs) { return _.intersection(accountIDs, CONST.EXPENSIFY_ACCOUNT_IDS).length > 0; } +/** + * @param {Object} report + * @param {Number} currentLoginAccountID + * @returns {Array} + */ +function getReportRecipientAccountIDs(report, currentLoginAccountID) { + const participantAccountIDs = isTaskReport(report) ? [report.managerID] : lodashGet(report, 'participantAccountIDs'); + const reportParticipants = _.without(participantAccountIDs, currentLoginAccountID); + const participantsWithoutExpensifyAccountIDs = _.difference(reportParticipants, CONST.EXPENSIFY_ACCOUNT_IDS); + return participantsWithoutExpensifyAccountIDs; +} + /** * Whether the time row should be shown for a report. * @param {Array} personalDetails @@ -807,10 +819,9 @@ function hasAutomatedExpensifyAccountIDs(accountIDs) { * @return {Boolean} */ function canShowReportRecipientLocalTime(personalDetails, report, accountID) { - const reportParticipants = _.without(lodashGet(report, 'participantAccountIDs', []), accountID); - const participantsWithoutExpensifyAccountIDs = _.difference(reportParticipants, CONST.EXPENSIFY_ACCOUNT_IDS); - const hasMultipleParticipants = participantsWithoutExpensifyAccountIDs.length > 1; - const reportRecipient = personalDetails[participantsWithoutExpensifyAccountIDs[0]]; + const reportRecipientAccountIDs = getReportRecipientAccountIDs(report, accountID); + const hasMultipleParticipants = reportRecipientAccountIDs.length > 1; + const reportRecipient = personalDetails[reportRecipientAccountIDs[0]]; const reportRecipientTimezone = lodashGet(reportRecipient, 'timezone', CONST.DEFAULT_TIME_ZONE); const isReportParticipantValidated = lodashGet(reportRecipient, 'validated', false); return Boolean( @@ -3494,6 +3505,7 @@ export { shouldDisableSettings, shouldDisableRename, hasSingleParticipant, + getReportRecipientAccountIDs, isOneOnOneChat, getTransactionReportName, getTransactionDetails, diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index aa4ecfd4218e..2ef0a9d7b8f4 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -149,7 +149,6 @@ function ReportActionCompose({ () => _.without(lodashGet(report, 'participantAccountIDs', []), currentUserPersonalDetails.accountID), [currentUserPersonalDetails.accountID, report], ); - const participantsWithoutExpensifyAccountIDs = useMemo(() => _.difference(reportParticipantIDs, CONST.EXPENSIFY_ACCOUNT_IDS), [reportParticipantIDs]); const shouldShowReportRecipientLocalTime = useMemo( () => ReportUtils.canShowReportRecipientLocalTime(personalDetails, report, currentUserPersonalDetails.accountID) && !isComposerFullSize, @@ -309,7 +308,8 @@ function ReportActionCompose({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - const reportRecipient = personalDetails[participantsWithoutExpensifyAccountIDs[0]]; + const reportRecipientAcountIDs = ReportUtils.getReportRecipientAccountIDs(report, currentUserPersonalDetails.accountID); + const reportRecipient = personalDetails[reportRecipientAcountIDs[0]]; const shouldUseFocusedColor = !isBlockedFromConcierge && !disabled && isFocused; const hasReportRecipient = _.isObject(reportRecipient) && !_.isEmpty(reportRecipient);