Skip to content

Commit 4aa19bf

Browse files
authored
Merge pull request #50846 from wildan-m/wildan/fix/49468-group-chat-not-found-appear
Fixes "Not here" page briefly showing when last member leaves group chat.
2 parents 9f97734 + 0851b74 commit 4aa19bf

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/libs/actions/Report.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,11 +2774,22 @@ function leaveGroupChat(reportID: string) {
27742774
return;
27752775
}
27762776

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.
27772779
const optimisticData: OnyxUpdate[] = [
27782780
{
2779-
onyxMethod: Onyx.METHOD.SET,
2781+
onyxMethod: Onyx.METHOD.MERGE,
27802782
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+
},
27822793
},
27832794
];
27842795
// Clean up any quick actions for the report we're leaving from
@@ -2790,8 +2801,27 @@ function leaveGroupChat(reportID: string) {
27902801
});
27912802
}
27922803

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+
27932823
navigateToMostRecentReport(report);
2794-
API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData});
2824+
API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData, successData, failureData});
27952825
}
27962826

27972827
/** Leave a report by setting the state to submitted and closed */

0 commit comments

Comments
 (0)