Skip to content

Commit

Permalink
Cleaner search term handling
Browse files Browse the repository at this point in the history
Use `each` instead of `forEach`
  • Loading branch information
Samueljh1 committed Oct 11, 2023
1 parent 8166fe3 commit 268be07
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,26 @@ function WorkspaceInvitePage(props) {
const excludedUsers = useMemo(() => PolicyUtils.getIneligibleInvitees(props.policyMembers, props.personalDetails), [props.policyMembers, props.personalDetails]);

useEffect(() => {
let emails = searchTerm.replace(/\s,\s/g, ',').split(',');
emails = _.filter(
_.map(emails, (word) => word.trim()),
(email) => email !== '',
const emails = _.compact(
searchTerm
.trim()
.replace(/\s*,\s*/g, ',')
.split(','),
);

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

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

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

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

Expand All @@ -113,12 +114,12 @@ function WorkspaceInvitePage(props) {
}

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

// Add all selected options to the new dict
_.forEach(newSelectedOptions, (option) => {
_.each(newSelectedOptions, (option) => {
newSelectedOptionsDict[option.accountID] = option;
});
});
Expand Down Expand Up @@ -156,7 +157,7 @@ function WorkspaceInvitePage(props) {
});
indexOffset += personalDetailsFormatted.length;

_.forEach(usersToInvite, (userToInvite) => {
_.each(usersToInvite, (userToInvite) => {
const hasUnselectedUserToInvite = !_.contains(selectedLogins, userToInvite.login);

if (hasUnselectedUserToInvite) {
Expand Down

0 comments on commit 268be07

Please sign in to comment.