Skip to content

Commit 00384eb

Browse files
authored
Merge pull request Expensify#71304 from lorretheboy/fix/69671
Web - Members do not stay selected after refreshing and going back from members page
2 parents 833c50a + 60b75ee commit 00384eb

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/pages/workspace/WorkspaceInvitePage.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import HttpUtils from '@libs/HttpUtils';
2323
import {appendCountryCode} from '@libs/LoginUtils';
2424
import Navigation from '@libs/Navigation/Navigation';
2525
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
26-
import {filterAndOrderOptions, formatMemberForList, getHeaderMessage, getMemberInviteOptions, getSearchValueForPhoneOrEmail} from '@libs/OptionsListUtils';
26+
import {filterAndOrderOptions, formatMemberForList, getHeaderMessage, getMemberInviteOptions, getSearchValueForPhoneOrEmail, getUserToInviteOption} from '@libs/OptionsListUtils';
2727
import type {MemberForList} from '@libs/OptionsListUtils';
2828
import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from '@libs/PhoneNumber';
2929
import {getIneligibleInvitees, getMemberAccountIDsForWorkspace, goBackFromInvalidPolicy} from '@libs/PolicyUtils';
@@ -125,11 +125,23 @@ function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) {
125125
if (firstRenderRef.current) {
126126
// We only want to add the saved selected user on first render
127127
firstRenderRef.current = false;
128-
Object.keys(invitedEmailsToAccountIDsDraft ?? {}).forEach((login) => {
129-
if (!(login in detailsMap)) {
130-
return;
128+
Object.entries(invitedEmailsToAccountIDsDraft ?? {}).forEach(([login, accountID]) => {
129+
if (login in detailsMap) {
130+
newSelectedOptions.push({...detailsMap[login], isSelected: true});
131+
} else {
132+
const optimisticOption = getUserToInviteOption({
133+
searchValue: login,
134+
});
135+
if (optimisticOption) {
136+
optimisticOption.accountID = Number(accountID);
137+
const memberOption = formatMemberForList({
138+
...optimisticOption,
139+
accountID: Number(accountID),
140+
isSelected: true,
141+
});
142+
newSelectedOptions.push(memberOption);
143+
}
131144
}
132-
newSelectedOptions.push({...detailsMap[login], isSelected: true});
133145
});
134146
}
135147
selectedOptions.forEach((option) => {

0 commit comments

Comments
 (0)