Skip to content

Commit

Permalink
Merge pull request Expensify#50846 from wildan-m/wildan/fix/49468-gro…
Browse files Browse the repository at this point in the history
…up-chat-not-found-appear

Fixes "Not here" page briefly showing when last member leaves group chat.
  • Loading branch information
tgolen authored Oct 28, 2024
2 parents 9f97734 + 0851b74 commit 4aa19bf
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2774,11 +2774,22 @@ function leaveGroupChat(reportID: string) {
return;
}

// Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear.
// The remaining parts of the report object will be removed after the API call is successful.
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.SET,
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: null,
value: {
reportID: null,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
participants: {
[currentUserAccountID]: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
},
},
},
];
// Clean up any quick actions for the report we're leaving from
Expand All @@ -2790,8 +2801,27 @@ function leaveGroupChat(reportID: string) {
});
}

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: Object.keys(report).reduce<Record<string, null>>((acc, key) => {
acc[key] = null;
return acc;
}, {}),
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: report,
},
];

navigateToMostRecentReport(report);
API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData});
API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData, successData, failureData});
}

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

0 comments on commit 4aa19bf

Please sign in to comment.