@@ -23,7 +23,7 @@ import HttpUtils from '@libs/HttpUtils';
2323import { appendCountryCode } from '@libs/LoginUtils' ;
2424import Navigation from '@libs/Navigation/Navigation' ;
2525import 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' ;
2727import type { MemberForList } from '@libs/OptionsListUtils' ;
2828import { addSMSDomainIfPhoneNumber , parsePhoneNumber } from '@libs/PhoneNumber' ;
2929import { 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