Skip to content

Commit 857eb7f

Browse files
authored
Merge pull request Expensify#84480 from dukenv0307/fix/73662-part-6
refactor leaveGroup and leaveRoom to use introSelected from useOnyx
2 parents c029c6c + 1f78460 commit 857eb7f

3 files changed

Lines changed: 401 additions & 20 deletions

File tree

src/libs/actions/Report/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4141,7 +4141,7 @@ function doneCheckingPublicRoom() {
41414141
Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false);
41424142
}
41434143

4144-
function navigateToMostRecentReport(currentReport: OnyxEntry<Report>, conciergeReportID: string | undefined, currentUserAccountID: number) {
4144+
function navigateToMostRecentReport(currentReport: OnyxEntry<Report>, conciergeReportID: string | undefined, currentUserAccountID: number, introSelected: OnyxEntry<IntroSelected>) {
41454145
const lastAccessedReportID = findLastAccessedReport(false, false, currentReport?.reportID)?.reportID;
41464146

41474147
if (lastAccessedReportID) {
@@ -4162,7 +4162,7 @@ function navigateToMostRecentReport(currentReport: OnyxEntry<Report>, conciergeR
41624162
Navigation.goBack();
41634163
}
41644164

4165-
navigateToConciergeChat(conciergeReportID, deprecatedIntroSelected, currentUserAccountID, false, () => true, {forceReplace: true});
4165+
navigateToConciergeChat(conciergeReportID, introSelected, currentUserAccountID, false, () => true, {forceReplace: true});
41664166
}
41674167
}
41684168

@@ -4185,7 +4185,7 @@ function joinRoom(report: OnyxEntry<Report>, currentUserAccountID: number) {
41854185
);
41864186
}
41874187

4188-
function leaveGroupChat(report: Report, shouldClearQuickAction: boolean, currentUserAccountID: number, conciergeReportID: string | undefined) {
4188+
function leaveGroupChat(report: Report, shouldClearQuickAction: boolean, currentUserAccountID: number, conciergeReportID: string | undefined, introSelected: OnyxEntry<IntroSelected>) {
41894189
const reportID = report.reportID;
41904190
// Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear.
41914191
// The remaining parts of the report object will be removed after the API call is successful.
@@ -4232,12 +4232,18 @@ function leaveGroupChat(report: Report, shouldClearQuickAction: boolean, current
42324232
},
42334233
];
42344234

4235-
navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID);
4235+
navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected);
42364236
API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData, successData, failureData});
42374237
}
42384238

42394239
/** Leave a report by setting the state to submitted and closed */
4240-
function leaveRoom(report: Report, currentUserAccountID: number, conciergeReportID: string | undefined, isWorkspaceMemberLeavingWorkspaceRoom = false) {
4240+
function leaveRoom(
4241+
report: Report,
4242+
currentUserAccountID: number,
4243+
conciergeReportID: string | undefined,
4244+
introSelected: OnyxEntry<IntroSelected>,
4245+
isWorkspaceMemberLeavingWorkspaceRoom = false,
4246+
) {
42414247
const reportID = report.reportID;
42424248
const isChatThread = isChatThreadReportUtils(report);
42434249

@@ -4341,7 +4347,7 @@ function leaveRoom(report: Report, currentUserAccountID: number, conciergeReport
43414347
return;
43424348
}
43434349
// In other cases, the report is deleted and we should move the user to another report.
4344-
navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID);
4350+
navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected);
43454351
}
43464352

43474353
function buildInviteToRoomOnyxData(report: Report, inviteeEmailsToAccountIDs: InvitedEmailsToAccountIDs, formatPhoneNumber: LocaleContextProps['formatPhoneNumber']) {

src/pages/ReportDetailsPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
328328

329329
const leaveChat = useCallback(() => {
330330
if (isRootGroupChat) {
331-
leaveGroupChat(report, quickAction?.chatReportID?.toString() === report.reportID, currentUserPersonalDetails.accountID, conciergeReportID);
331+
leaveGroupChat(report, quickAction?.chatReportID?.toString() === report.reportID, currentUserPersonalDetails.accountID, conciergeReportID, introSelected);
332332
return;
333333
}
334334

335335
const isWorkspaceMemberLeavingWorkspaceRoom = isWorkspaceMemberLeavingWorkspaceRoomUtil(report, isPolicyEmployee, isPolicyAdmin);
336-
leaveRoom(report, currentUserPersonalDetails.accountID, conciergeReportID, isWorkspaceMemberLeavingWorkspaceRoom);
337-
}, [isRootGroupChat, isPolicyEmployee, isPolicyAdmin, quickAction?.chatReportID, report, currentUserPersonalDetails.accountID, conciergeReportID]);
336+
leaveRoom(report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, isWorkspaceMemberLeavingWorkspaceRoom);
337+
}, [isRootGroupChat, isPolicyEmployee, isPolicyAdmin, quickAction?.chatReportID, report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected]);
338338

339339
const showLastMemberLeavingModal = useCallback(async () => {
340340
const {action} = await showConfirmModal({

0 commit comments

Comments
 (0)