Skip to content

Commit

Permalink
Merge pull request #38867 from bernhardoj/fix/36350-unselected-user-b…
Browse files Browse the repository at this point in the history
…ecomes-reselected

Fix unchecked user becomes checked again when searching
  • Loading branch information
AndrewGable authored Apr 19, 2024
2 parents 4654d6e + 9cdce1f commit 09ad468
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {SectionListData} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -60,6 +60,8 @@ function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, poli
const [personalDetails, setPersonalDetails] = useState<OptionData[]>([]);
const [usersToInvite, setUsersToInvite] = useState<OptionData[]>([]);
const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false);
const firstRenderRef = useRef(true);

const openWorkspaceInvitePage = () => {
const policyMemberEmailsToAccountIDs = PolicyUtils.getMemberAccountIDsForWorkspace(policy?.employeeList);
Policy.openWorkspaceInvitePage(route.params.policyID, Object.keys(policyMemberEmailsToAccountIDs));
Expand Down Expand Up @@ -102,12 +104,16 @@ function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, poli
});

const newSelectedOptions: MemberForList[] = [];
Object.keys(invitedEmailsToAccountIDsDraft ?? {}).forEach((login) => {
if (!(login in detailsMap)) {
return;
}
newSelectedOptions.push({...detailsMap[login], isSelected: true});
});
if (firstRenderRef.current) {
// We only want to add the saved selected user on first render
firstRenderRef.current = false;
Object.keys(invitedEmailsToAccountIDsDraft ?? {}).forEach((login) => {
if (!(login in detailsMap)) {
return;
}
newSelectedOptions.push({...detailsMap[login], isSelected: true});
});
}
selectedOptions.forEach((option) => {
newSelectedOptions.push(option.login && option.login in detailsMap ? {...detailsMap[option.login], isSelected: true} : option);
});
Expand Down

0 comments on commit 09ad468

Please sign in to comment.