Skip to content

Commit

Permalink
Merge pull request #30859 from eh2077/29701-fix-incorrect-search-term…
Browse files Browse the repository at this point in the history
…-validation-msg

Fix incorrect email validation msg caused comma separated search term
  • Loading branch information
danieldoglas authored Nov 7, 2023
2 parents 8d6fc37 + cf357fb commit 2868f68
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,49 +85,36 @@ function WorkspaceInvitePage(props) {
const excludedUsers = useMemo(() => PolicyUtils.getIneligibleInvitees(props.policyMembers, props.personalDetails), [props.policyMembers, props.personalDetails]);

useEffect(() => {
let emails = _.compact(
searchTerm
.trim()
.replace(/\s*,\s*/g, ',')
.split(','),
);

if (emails.length === 0) {
emails = [''];
}

const newUsersToInviteDict = {};
const newPersonalDetailsDict = {};
const newSelectedOptionsDict = {};

_.each(emails, (email) => {
const inviteOptions = OptionsListUtils.getMemberInviteOptions(props.personalDetails, props.betas, email, excludedUsers);
const inviteOptions = OptionsListUtils.getMemberInviteOptions(props.personalDetails, props.betas, searchTerm, excludedUsers);

// Update selectedOptions with the latest personalDetails and policyMembers information
const detailsMap = {};
_.each(inviteOptions.personalDetails, (detail) => (detailsMap[detail.login] = OptionsListUtils.formatMemberForList(detail)));
// Update selectedOptions with the latest personalDetails and policyMembers information
const detailsMap = {};
_.each(inviteOptions.personalDetails, (detail) => (detailsMap[detail.login] = OptionsListUtils.formatMemberForList(detail)));

const newSelectedOptions = [];
_.each(selectedOptions, (option) => {
newSelectedOptions.push(_.has(detailsMap, option.login) ? {...detailsMap[option.login], isSelected: true} : option);
});
const newSelectedOptions = [];
_.each(selectedOptions, (option) => {
newSelectedOptions.push(_.has(detailsMap, option.login) ? {...detailsMap[option.login], isSelected: true} : option);
});

const userToInvite = inviteOptions.userToInvite;
const userToInvite = inviteOptions.userToInvite;

// Only add the user to the invites list if it is valid
if (userToInvite) {
newUsersToInviteDict[userToInvite.accountID] = userToInvite;
}
// Only add the user to the invites list if it is valid
if (userToInvite) {
newUsersToInviteDict[userToInvite.accountID] = userToInvite;
}

// Add all personal details to the new dict
_.each(inviteOptions.personalDetails, (details) => {
newPersonalDetailsDict[details.accountID] = details;
});
// Add all personal details to the new dict
_.each(inviteOptions.personalDetails, (details) => {
newPersonalDetailsDict[details.accountID] = details;
});

// Add all selected options to the new dict
_.each(newSelectedOptions, (option) => {
newSelectedOptionsDict[option.accountID] = option;
});
// Add all selected options to the new dict
_.each(newSelectedOptions, (option) => {
newSelectedOptionsDict[option.accountID] = option;
});

// Strip out dictionary keys and update arrays
Expand Down

0 comments on commit 2868f68

Please sign in to comment.