@@ -9248,29 +9248,24 @@ function canSubmitReport(
92489248 ) ;
92499249}
92509250
9251- function getIOUReportActionToApproveOrPay ( chatReport : OnyxEntry < OnyxTypes . Report > , excludedIOUReportID : string | undefined ) : OnyxEntry < ReportAction > {
9251+ function getIOUReportActionToApproveOrPay ( chatReport : OnyxEntry < OnyxTypes . Report > , updatedIouReport : OnyxEntry < OnyxTypes . Report > ) : OnyxEntry < ReportAction > {
92529252 const chatReportActions = allReportActions ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReport ?. reportID } ` ] ?? { } ;
92539253
92549254 return Object . values ( chatReportActions ) . find ( ( action ) => {
92559255 if ( ! action ) {
92569256 return false ;
92579257 }
9258- const iouReport = getReportOrDraftReport ( action . childReportID ) ;
9258+ const iouReport = updatedIouReport ?. reportID === action . childReportID ? updatedIouReport : getReportOrDraftReport ( action . childReportID ) ;
92599259 // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
92609260 // eslint-disable-next-line deprecation/deprecation
92619261 const policy = getPolicy ( iouReport ?. policyID ) ;
92629262 const shouldShowSettlementButton = canIOUBePaid ( iouReport , chatReport , policy ) || canApproveIOU ( iouReport , policy ) ;
9263- return (
9264- action . childReportID ?. toString ( ) !== excludedIOUReportID &&
9265- action . actionName === CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW &&
9266- shouldShowSettlementButton &&
9267- ! isDeletedAction ( action )
9268- ) ;
9263+ return action . actionName === CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW && shouldShowSettlementButton && ! isDeletedAction ( action ) ;
92699264 } ) ;
92709265}
92719266
9272- function hasIOUToApproveOrPay ( chatReport : OnyxEntry < OnyxTypes . Report > , excludedIOUReportID : string | undefined ) : boolean {
9273- return ! ! getIOUReportActionToApproveOrPay ( chatReport , excludedIOUReportID ) ;
9267+ function hasIOUToApproveOrPay ( chatReport : OnyxEntry < OnyxTypes . Report > , updatedIouReport : OnyxEntry < OnyxTypes . Report > ) : boolean {
9268+ return ! ! getIOUReportActionToApproveOrPay ( chatReport , updatedIouReport ) ;
92749269}
92759270
92769271function isLastApprover ( approvalChain : string [ ] ) : boolean {
@@ -9320,27 +9315,28 @@ function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?:
93209315 } ,
93219316 } ,
93229317 } ;
9318+ const updatedExpenseReport = {
9319+ ...expenseReport ,
9320+ lastMessageText : getReportActionText ( optimisticApprovedReportAction ) ,
9321+ lastMessageHtml : getReportActionHtml ( optimisticApprovedReportAction ) ,
9322+ stateNum : predictedNextState ,
9323+ statusNum : predictedNextStatus ,
9324+ managerID,
9325+ pendingFields : {
9326+ partial : full ? null : CONST . RED_BRICK_ROAD_PENDING_ACTION . UPDATE ,
9327+ } ,
9328+ } ;
93239329 const optimisticIOUReportData : OnyxUpdate = {
93249330 onyxMethod : Onyx . METHOD . MERGE ,
93259331 key : `${ ONYXKEYS . COLLECTION . REPORT } ${ expenseReport . reportID } ` ,
9326- value : {
9327- ...expenseReport ,
9328- lastMessageText : getReportActionText ( optimisticApprovedReportAction ) ,
9329- lastMessageHtml : getReportActionHtml ( optimisticApprovedReportAction ) ,
9330- stateNum : predictedNextState ,
9331- statusNum : predictedNextStatus ,
9332- managerID,
9333- pendingFields : {
9334- partial : full ? null : CONST . RED_BRICK_ROAD_PENDING_ACTION . UPDATE ,
9335- } ,
9336- } ,
9332+ value : updatedExpenseReport ,
93379333 } ;
93389334
93399335 const optimisticChatReportData : OnyxUpdate = {
93409336 onyxMethod : Onyx . METHOD . MERGE ,
93419337 key : `${ ONYXKEYS . COLLECTION . REPORT } ${ expenseReport . chatReportID } ` ,
93429338 value : {
9343- hasOutstandingChildRequest : hasIOUToApproveOrPay ( chatReport , expenseReport . reportID ) ,
9339+ hasOutstandingChildRequest : hasIOUToApproveOrPay ( chatReport , updatedExpenseReport ) ,
93449340 } ,
93459341 } ;
93469342
0 commit comments