Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: invite and remove member when offline in workspace #30627

Merged
merged 8 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4156,6 +4156,17 @@ function shouldUseFullTitleToDisplay(report) {
return isMoneyRequestReport(report) || isPolicyExpenseChat(report) || isChatRoom(report) || isChatThread(report) || isTaskReport(report);
}

/**
*
* @param {String} type
* @param {String} policyID
* @returns {Object}
*/
function getRoom(type, policyID) {
const room = _.find(allReports, (report) => report && report.policyID === policyID && report.chatType === type && !isThread(report));
return room;
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -4315,4 +4326,5 @@ export {
parseReportRouteParams,
getReimbursementQueuedActionMessage,
getPersonalDetailsForAccountID,
getRoom,
};
71 changes: 71 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,69 @@ function isAdminOfFreePolicy(policies) {
return _.some(policies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN);
}

/**
* Build optimistic data for adding members to the announce room
* @param {String} policyID
* @param {Array} accountIDs
* @returns {Object}
*/
function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) {
const announceReport = ReportUtils.getRoom(CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, policyID);
const announceRoomMembers = {
onyxOptimisticData: [],
onyxFailureData: [],
};

announceRoomMembers.onyxOptimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: [...announceReport.participantAccountIDs, ...accountIDs],
},
});

announceRoomMembers.onyxFailureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: announceReport.participantAccountIDs,
},
});
return announceRoomMembers;
}

/**
* Build optimistic data for removing users from the announce room
* @param {String} policyID
* @param {Array} accountIDs
* @returns {Object}
*/
function removeOptimisticAnnounceRoomMembers(policyID, accountIDs) {
const announceReport = ReportUtils.getRoom(CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, policyID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

announceReport can be undefined when focus mode is active which will crash the app at line 287 causing #32682

const announceRoomMembers = {
onyxOptimisticData: [],
onyxFailureData: [],
};

const remainUsers = _.difference(announceReport.participantAccountIDs, accountIDs);
announceRoomMembers.onyxOptimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: [...remainUsers],
},
});

announceRoomMembers.onyxFailureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`,
value: {
participantAccountIDs: announceReport.participantAccountIDs,
},
});
return announceRoomMembers;
}

/**
* Remove the passed members from the policy employeeList
*
Expand All @@ -260,6 +323,8 @@ function removeMembers(accountIDs, policyID) {
ReportUtils.buildOptimisticClosedReportAction(sessionEmail, policy.name, CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY),
);

const announceRoomMembers = removeOptimisticAnnounceRoomMembers(policyID, accountIDs);

const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -281,6 +346,7 @@ function removeMembers(accountIDs, policyID) {
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats[index].reportID}`,
value: {[reportAction.reportActionID]: reportAction},
})),
...announceRoomMembers.onyxOptimisticData,
];

// If the policy has primaryLoginsInvited, then it displays informative messages on the members page about which primary logins were added by secondary logins.
Expand Down Expand Up @@ -332,6 +398,7 @@ function removeMembers(accountIDs, policyID) {
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats[index].reportID}`,
value: {[reportAction.reportActionID]: null},
})),
...announceRoomMembers.onyxFailureData,
];
API.write(
'DeleteMembersFromWorkspace',
Expand Down Expand Up @@ -447,6 +514,8 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID)
const accountIDs = _.values(invitedEmailsToAccountIDs);
const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, accountIDs);

const announceRoomMembers = buildAnnounceRoomMembersOnyxData(policyID, accountIDs);

// create onyx data for policy expense chats for each new member
const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs);

Expand All @@ -460,6 +529,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID)
},
...newPersonalDetailsOnyxData.optimisticData,
...membersChats.onyxOptimisticData,
...announceRoomMembers.onyxOptimisticData,
];

const successData = [
Expand Down Expand Up @@ -507,6 +577,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID)
},
...newPersonalDetailsOnyxData.failureData,
...membersChats.onyxFailureData,
...announceRoomMembers.onyxFailureData,
];

const params = {
Expand Down
4 changes: 2 additions & 2 deletions src/styles/fontFamily/multiFontFamily.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getOperatingSystem from '@libs/getOperatingSystem';
import CONST from '@src/CONST';
import {multiBold} from './bold';
import FontFamilyStyles from './types';
import CONST from '../../CONST';
import getOperatingSystem from '../../libs/getOperatingSystem';

// In windows and ubuntu, we need some extra system fonts for emojis to work properly
// otherwise few of them will appear as black and white
Expand Down
Loading