Skip to content

Commit

Permalink
Merge pull request #42512 from tienifr/fix/42204
Browse files Browse the repository at this point in the history
fix user is not prompted with a warning message when leaving group
  • Loading branch information
dangrous authored Jun 4, 2024
2 parents df03f27 + 0e5d5fb commit 1865aa8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1851,13 +1851,18 @@ function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = f
return shouldUseShortForm ? shortName : longName;
}

function getParticipantAccountIDs(reportID: string) {
function getParticipantAccountIDs(reportID: string, includeOnlyActiveMembers = false) {
const report = getReport(reportID);
if (!report || !report.participants) {
return [];
}

const accountIDStrings = Object.keys(report.participants);
const accountIDStrings = Object.keys(report.participants).filter((accountID) => {
if (!includeOnlyActiveMembers) {
return true;
}
const pendingMember = report?.pendingChatMembers?.findLast((member) => member.accountID === accountID.toString());
return !pendingMember || pendingMember.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
});
return accountIDStrings.map((accountID) => Number(accountID));
}

Expand Down
7 changes: 6 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2736,12 +2736,17 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: InvitedEmails
...newPersonalDetailsOnyxData.optimisticData,
];

const successPendingChatMembers = report?.pendingChatMembers
? report?.pendingChatMembers?.filter(
(pendingMember) => !(inviteeAccountIDs.includes(Number(pendingMember.accountID)) && pendingMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE),
)
: null;
const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
pendingChatMembers: report?.pendingChatMembers ?? null,
pendingChatMembers: successPendingChatMembers,
},
},
...newPersonalDetailsOnyxData.finallyData,
Expand Down
5 changes: 4 additions & 1 deletion src/pages/InviteReportParticipantsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ function InviteReportParticipantsPage({betas, personalDetails, report, didScreen
const [userToInvite, setUserToInvite] = useState<ReportUtils.OptionData | null>(null);

// Any existing participants and Expensify emails should not be eligible for invitation
const excludedUsers = useMemo(() => [...PersonalDetailsUtils.getLoginsByAccountIDs(ReportUtils.getParticipantAccountIDs(report?.reportID ?? '')), ...CONST.EXPENSIFY_EMAILS], [report]);
const excludedUsers = useMemo(
() => [...PersonalDetailsUtils.getLoginsByAccountIDs(ReportUtils.getParticipantAccountIDs(report?.reportID ?? '', true)), ...CONST.EXPENSIFY_EMAILS],
[report],
);

useEffect(() => {
const inviteOptions = OptionsListUtils.getMemberInviteOptions(options.personalDetails, betas ?? [], searchTerm, excludedUsers, false, options.reports, true);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
icon: Expensicons.Exit,
isAnonymousAction: true,
action: () => {
if (Object.keys(report?.participants ?? {}).length === 1 && isGroupChat) {
if (ReportUtils.getParticipantAccountIDs(report.reportID, true).length === 1 && isGroupChat) {
setIsLastMemberLeavingGroupModalVisible(true);
return;
}
Expand Down

0 comments on commit 1865aa8

Please sign in to comment.