Skip to content

Commit

Permalink
Merge pull request #8816 from Expensify/jules-fixIOUBadgeLostAfterSen…
Browse files Browse the repository at this point in the history
…dingMoney

Fix IOU badge disappearing after sending money to same user
  • Loading branch information
marcochavezf authored Apr 29, 2022
2 parents 419d35b + 4cd800d commit f174c32
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,10 @@ function fetchIOUReportByID(iouReportID, chatReportID, shouldRedirectIfEmpty = f
* fetching the iouReport and therefore should only be called if we are certain that the fetched iouReport is currently
* open - else we would overwrite the existing open iouReportID with a closed iouReportID.
*
* Examples of usage include 'receieving a push notification', or 'paying an IOU', because both of these cases can only
* occur for an iouReport that is currently open (notifications are not sent for closed iouReports, and you cannot pay a
* closed IOU).
* Examples of correct usage include 'receieving a push notification', or 'paying an IOU', because both of these cases can only
* occur for an iouReport that is currently open (notifications are not sent for closed iouReports, and you cannot pay a closed
* IOU). Send Money is an incorrect use case, because these IOUReports are never associated with the chatReport and this would
* prevent outstanding IOUs from showing.
*
* @param {Number} iouReportID - ID of the report we are fetching
* @param {Number} chatReportID - associated chatReportID, used to sync the reports
Expand Down Expand Up @@ -647,11 +648,12 @@ function updateReportWithNewAction(
if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction.originalMessage.IOUReportID) {
const iouReportID = reportAction.originalMessage.IOUReportID;

// We know this iouReport is open because reportActions of type CONST.REPORT.ACTIONS.TYPE.IOU can only be
// triggered for an open iouReport (an open iouReport has an IOU, but is not yet paid). After fetching the
// iouReport we must update the chatReport with the correct iouReportID. If we don't, then new IOUs would not
// be displayed and paid IOUs would show as unpaid.
fetchIOUReportByIDAndUpdateChatReport(iouReportID, reportID);
// If the IOUDetails object exists we are in the Send Money flow, and we should not fetch and update the chatReport
// as this would overwrite any existing IOUs. For all other cases we must update the chatReport with the iouReportID as
// if we don't, new IOUs would not be displayed and paid IOUs would still show as unpaid.
if (reportAction.originalMessage.IOUDetails === undefined) {
fetchIOUReportByIDAndUpdateChatReport(iouReportID, reportID);
}
}

if (!ActiveClientManager.isClientTheLeader()) {
Expand Down

0 comments on commit f174c32

Please sign in to comment.