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: Cannot remove RBR when invite an invalid member to workspace #23157

Merged
Changes from 4 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
37 changes: 37 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {escapeRegExp} from 'lodash';
import * as API from '../API';
import ONYXKEYS from '../../ONYXKEYS';
import CONST from '../../CONST';
import * as LocalePhoneNumber from '../LocalePhoneNumber';
import * as OptionsListUtils from '../OptionsListUtils';
import * as ErrorUtils from '../ErrorUtils';
import * as ReportUtils from '../ReportUtils';
import Log from '../Log';
import Permissions from '../Permissions';
import * as UserUtils from '../UserUtils';

const allPolicies = {};
Onyx.connect({
Expand Down Expand Up @@ -355,6 +357,24 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID,
// create onyx data for policy expense chats for each new member
const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs, betas);

// Optimistic personal details for the new accounts invited
const optimisticPersonalDetails = _.chain(invitedEmailsToAccountIDs)
.map(
(accountID, memberLogin) =>
!_.has(allPersonalDetails, accountID) && [
accountID,
{
accountID,
avatar: UserUtils.getDefaultAvatarURL(accountID),
displayName: LocalePhoneNumber.formatPhoneNumber(memberLogin),
login: OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin),
},
],
)
.compact()
.object()
.value();

const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -364,6 +384,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID,
value: _.object(accountIDs, Array(accountIDs.length).fill({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})),
},
...membersChats.onyxOptimisticData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticPersonalDetails,
},
];

const successData = [
Expand All @@ -376,6 +401,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID,
value: _.object(accountIDs, Array(accountIDs.length).fill({pendingAction: null, errors: null})),
},
...membersChats.onyxSuccessData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: _.object(_.keys(optimisticPersonalDetails), Array(_.size(optimisticPersonalDetails)).fill(null)),
},
];

const failureData = [
Expand Down Expand Up @@ -743,6 +773,13 @@ function clearAddMemberError(policyID, accountID) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`, {
[accountID]: null,
});

// Remove draft accountID
if (accountID.toString().length >= 15) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@tienifr, why do we delete it only if accountID.length >= 15?

Copy link
Contributor Author

@tienifr tienifr Jul 21, 2023

Choose a reason for hiding this comment

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

It's a "dummy" accountID, generated locally by

function generateAccountID(searchValue) {

In other words, they're invalid account that we've just invited. Otherwise, even after dismissing the error, the invalid accounts still appear in the suggested invite list.

I don't know if there's already a function for checking "dummy" accountID so I manually check based on length.

Copy link
Contributor

@eVoloshchak eVoloshchak Jul 21, 2023

Choose a reason for hiding this comment

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

What would happen if we deleted accountID here no matter if it's the dummy one or not?
We will remove a valid accountID from PERSONAL_DETAILS_LIST, but will it be there after a refresh?
I'm basically wondering what would happen if in the future we had accountID's longer than 15

Copy link
Contributor Author

@tienifr tienifr Jul 21, 2023

Choose a reason for hiding this comment

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

How about adding isDummyAccount (or sth else) into these account personal details when we create the optimisticPersonalDetails?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that would be better, let's do that instead

Copy link
Contributor Author

@tienifr tienifr Jul 21, 2023

Choose a reason for hiding this comment

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

I've updated that. Please check again.

dummy-account-compressed.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that I think about it more, we shouldn't delete the account info when we dismiss an error. The error doesn't necessarily mean "This account is invalid", just that there was some kind of a problem when inviting the user.
We might want to add the ability to "clear" recent users if this is considered a problem, but I don't think this should be a part of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that we're good with showing the invalid accounts in the invite suggestion list; and will implement another feature to clear that later?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Well that didn't get a lot of traction 😄
But still, it's 2 vs 1 in favor of removing the user, so let's leave it as it is, no changes needed, I'll finish the checklist shortly

Onyx.merge(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, {
[accountID]: null,
});
}
}

/**
Expand Down