@@ -387,19 +387,23 @@ function cleanUpMoneyRequest(
387387 value : updatedReportAction ,
388388 } ) ;
389389 }
390- onyxUpdates . push (
391- // @ts -expect-error - will be solved in https://github.com/Expensify/App/issues/73830
392- {
393- onyxMethod : Onyx . METHOD . MERGE ,
394- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport ?. reportID } ` ,
395- value : updatedIOUReport ,
396- } ,
397- {
398- onyxMethod : Onyx . METHOD . MERGE ,
399- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport ?. reportID } ` ,
400- value : getOutstandingChildRequest ( updatedIOUReport ) ,
401- } ,
402- ) ;
390+
391+ if ( updatedIOUReport ) {
392+ if ( iouReport ?. reportID ) {
393+ onyxUpdates . push ( {
394+ onyxMethod : Onyx . METHOD . MERGE ,
395+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport . reportID } ` ,
396+ value : updatedIOUReport ,
397+ } ) ;
398+ }
399+ if ( chatReport ?. reportID ) {
400+ onyxUpdates . push ( {
401+ onyxMethod : Onyx . METHOD . MERGE ,
402+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport . reportID } ` ,
403+ value : getOutstandingChildRequest ( updatedIOUReport ) ,
404+ } ) ;
405+ }
406+ }
403407
404408 if ( ! shouldDeleteIOUReport && updatedReportPreviewAction . childMoneyRequestCount === 0 ) {
405409 onyxUpdates . push ( {
@@ -695,24 +699,28 @@ function deleteMoneyRequest({
695699
696700 removeTransactionFromDuplicateTransactionViolation ( { optimisticData, failureData} , transactionID , transactions , violations ) ;
697701
698- optimisticData . push (
699- {
700- onyxMethod : Onyx . METHOD . MERGE ,
701- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport ?. reportID } ` ,
702- value : updatedReportAction ,
703- } ,
704- // @ts -expect-error - will be solved in https://github.com/Expensify/App/issues/73830
705- {
706- onyxMethod : Onyx . METHOD . MERGE ,
707- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport ?. reportID } ` ,
708- value : updatedIOUReport ,
709- } ,
710- {
711- onyxMethod : Onyx . METHOD . MERGE ,
712- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport ?. reportID } ` ,
713- value : getOutstandingChildRequest ( updatedIOUReport ) ,
714- } ,
715- ) ;
702+ optimisticData . push ( {
703+ onyxMethod : Onyx . METHOD . MERGE ,
704+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport ?. reportID } ` ,
705+ value : updatedReportAction ,
706+ } ) ;
707+
708+ if ( updatedIOUReport ) {
709+ if ( iouReport ?. reportID ) {
710+ optimisticData . push ( {
711+ onyxMethod : Onyx . METHOD . MERGE ,
712+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport . reportID } ` ,
713+ value : updatedIOUReport ,
714+ } ) ;
715+ }
716+ if ( chatReport ?. reportID ) {
717+ optimisticData . push ( {
718+ onyxMethod : Onyx . METHOD . MERGE ,
719+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport . reportID } ` ,
720+ value : getOutstandingChildRequest ( updatedIOUReport ) ,
721+ } ) ;
722+ }
723+ }
716724
717725 if ( reportPreviewAction ?. reportActionID ) {
718726 optimisticData . push ( {
@@ -844,10 +852,11 @@ function deleteMoneyRequest({
844852 } ;
845853 }
846854 }
847- failureData . push (
848- {
855+
856+ if ( iouReport ?. reportID ) {
857+ failureData . push ( {
849858 onyxMethod : Onyx . METHOD . MERGE ,
850- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport ? .reportID } ` ,
859+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . reportID } ` ,
851860 value : {
852861 ...originalReportActionsUpdate ,
853862 [ reportAction . reportActionID ] : {
@@ -856,20 +865,22 @@ function deleteMoneyRequest({
856865 errors : getMicroSecondOnyxErrorWithTranslationKey ( 'iou.error.genericDeleteFailureMessage' , errorKey ) ,
857866 } ,
858867 } ,
859- } ,
860- // @ts -expect-error - will be solved in https://github.com/Expensify/App/issues/73830
861- shouldDeleteIOUReport
862- ? {
863- onyxMethod : Onyx . METHOD . SET ,
864- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport ?. reportID } ` ,
865- value : iouReport ,
866- }
867- : {
868- onyxMethod : Onyx . METHOD . MERGE ,
869- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport ?. reportID } ` ,
870- value : iouReport ,
871- } ,
872- ) ;
868+ } ) ;
869+
870+ failureData . push (
871+ shouldDeleteIOUReport
872+ ? {
873+ onyxMethod : Onyx . METHOD . SET ,
874+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport . reportID } ` ,
875+ value : iouReport ,
876+ }
877+ : {
878+ onyxMethod : Onyx . METHOD . MERGE ,
879+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport . reportID } ` ,
880+ value : iouReport ,
881+ } ,
882+ ) ;
883+ }
873884
874885 if ( reportPreviewAction ?. reportActionID ) {
875886 failureData . push ( {
0 commit comments