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

refactor: workspace-invite-page to function component #22646

Merged
merged 18 commits into from
Jul 25, 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
29 changes: 27 additions & 2 deletions src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const isPolicyAdmin = (policy) => lodashGet(policy, 'role') === CONST.POLICY.ROL
*
* We only return members without errors. Otherwise, the members with errors would immediately be removed before the user has a chance to read the error.
*/
function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails) {
function getMemberAccountIDsForWorkspace(policyMembers, personalDetails) {
const memberEmailsToAccountIDs = {};
_.each(policyMembers, (member, accountID) => {
if (!_.isEmpty(member.errors)) {
Expand All @@ -142,6 +142,30 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails)
return memberEmailsToAccountIDs;
}

/**
* Get login list that we should not show in the workspace invite options
s-alves10 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {Object} policyMembers
* @param {Object} personalDetails
* @returns {Array}
*/
function getIneligibleInvitees(policyMembers, personalDetails) {
const memberEmailsToExclude = [...CONST.EXPENSIFY_EMAILS];
_.each(policyMembers, (policyMember, accountID) => {
// Policy members that are pending delete or have errors are not valid and we should show them in the invite options (don't exclude them).
if (policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || !_.isEmpty(policyMember.errors)) {
return;
}
const memberEmail = lodashGet(personalDetails, `[${accountID}].login`);
if (!memberEmail) {
return;
}
memberEmailsToExclude.push(memberEmail);
});

return memberEmailsToExclude;
}

export {
getActivePolicies,
hasPolicyMemberError,
Expand All @@ -153,5 +177,6 @@ export {
isExpensifyTeam,
isExpensifyGuideTeam,
isPolicyAdmin,
getClientPolicyMemberEmailsToAccountIDs,
getMemberAccountIDsForWorkspace,
getIneligibleInvitees,
};
9 changes: 9 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,14 @@ function setWorkspaceInviteMembersDraft(policyID, invitedEmailsToAccountIDs) {
Onyx.set(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${policyID}`, invitedEmailsToAccountIDs);
}

/**
* @param {String} policyID
*/
function clearErrors(policyID) {
setWorkspaceErrors(policyID, {});
hideWorkspaceAlertMessage(policyID);
}

export {
removeMembers,
addMembersToWorkspace,
Expand Down Expand Up @@ -1131,4 +1139,5 @@ export {
removeWorkspace,
setWorkspaceInviteMembersDraft,
isPolicyOwner,
clearErrors,
};
Loading