diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8231886e8632..d1cd77a29971 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1041,6 +1041,16 @@ function getReportName(report) { return _.map(participantsWithoutCurrentUser, (login) => getDisplayNameForParticipant(login, isMultipleParticipantReport)).join(', '); } +/** + * Get the report for a reportID + * + * @param {String} reportID + * @returns {Object} + */ +function getReport(reportID) { + return allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; +} + /** * Navigate to the details page of a given report * @@ -2182,6 +2192,7 @@ export { getRoomWelcomeMessage, getDisplayNamesWithTooltips, getReportName, + getReport, getReportIDFromLink, getRouteFromLink, navigateToDetailsPage, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 7910f0e5e798..dddbf703d6b0 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -380,6 +380,16 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent params.shouldRetry = false; } + // If we open an exist report, but it is not present in Onyx yet, we should change the method to set for this report + // and we need data to be available when we navigate to the chat page + if (_.isEmpty(ReportUtils.getReport(reportID))) { + optimisticReportData.onyxMethod = Onyx.METHOD.SET; + optimisticReportData.value = { + ...optimisticReportData.value, + reportID: reportID.toString(), + }; + } + // If we are creating a new report, we need to add the optimistic report data and a report action if (!_.isEmpty(newReportObject)) { // Change the method to set for new reports because it doesn't exist yet, is faster,