@@ -2774,11 +2774,22 @@ function leaveGroupChat(reportID: string) {
2774
2774
return ;
2775
2775
}
2776
2776
2777
+ // Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear.
2778
+ // The remaining parts of the report object will be removed after the API call is successful.
2777
2779
const optimisticData : OnyxUpdate [ ] = [
2778
2780
{
2779
- onyxMethod : Onyx . METHOD . SET ,
2781
+ onyxMethod : Onyx . METHOD . MERGE ,
2780
2782
key : `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ,
2781
- value : null ,
2783
+ value : {
2784
+ reportID : null ,
2785
+ stateNum : CONST . REPORT . STATE_NUM . APPROVED ,
2786
+ statusNum : CONST . REPORT . STATUS_NUM . CLOSED ,
2787
+ participants : {
2788
+ [ currentUserAccountID ] : {
2789
+ notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
2790
+ } ,
2791
+ } ,
2792
+ } ,
2782
2793
} ,
2783
2794
] ;
2784
2795
// Clean up any quick actions for the report we're leaving from
@@ -2790,8 +2801,27 @@ function leaveGroupChat(reportID: string) {
2790
2801
} ) ;
2791
2802
}
2792
2803
2804
+ const successData : OnyxUpdate [ ] = [
2805
+ {
2806
+ onyxMethod : Onyx . METHOD . MERGE ,
2807
+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ,
2808
+ value : Object . keys ( report ) . reduce < Record < string , null > > ( ( acc , key ) => {
2809
+ acc [ key ] = null ;
2810
+ return acc ;
2811
+ } , { } ) ,
2812
+ } ,
2813
+ ] ;
2814
+
2815
+ const failureData : OnyxUpdate [ ] = [
2816
+ {
2817
+ onyxMethod : Onyx . METHOD . MERGE ,
2818
+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ,
2819
+ value : report ,
2820
+ } ,
2821
+ ] ;
2822
+
2793
2823
navigateToMostRecentReport ( report ) ;
2794
- API . write ( WRITE_COMMANDS . LEAVE_GROUP_CHAT , { reportID} , { optimisticData} ) ;
2824
+ API . write ( WRITE_COMMANDS . LEAVE_GROUP_CHAT , { reportID} , { optimisticData, successData , failureData } ) ;
2795
2825
}
2796
2826
2797
2827
/** Leave a report by setting the state to submitted and closed */
0 commit comments