@@ -2,9 +2,9 @@ import React, {useEffect, useMemo, useState} from 'react';
22import type { OnyxEntry } from 'react-native-onyx' ;
33import * as Expensicons from '@components/Icon/Expensicons' ;
44import InteractiveStepWrapper from '@components/InteractiveStepWrapper' ;
5- import SelectionList from '@components/SelectionListWithSections ' ;
6- import type { ListItem } from '@components/SelectionListWithSections/types ' ;
7- import UserListItem from '@components/SelectionListWithSections/UserListItem ' ;
5+ import SelectionList from '@components/SelectionList ' ;
6+ import UserListItem from '@components/SelectionList/ListItem/UserListItem ' ;
7+ import type { ListItem } from '@components/SelectionList/types ' ;
88import Text from '@components/Text' ;
99import useCurrencyForExpensifyCard from '@hooks/useCurrencyForExpensifyCard' ;
1010import useLocalize from '@hooks/useLocalize' ;
@@ -150,74 +150,32 @@ function AssigneeStep({policy, stepNames, startStepIndex, route}: AssigneeStepPr
150150 return membersList ;
151151 } , [ policy ?. employeeList , localeCompare , isOffline , issueNewCard ?. data ?. assigneeEmail , formatPhoneNumber ] ) ;
152152
153- const sections = useMemo ( ( ) => {
153+ const assignees = useMemo ( ( ) => {
154154 if ( ! debouncedSearchTerm ) {
155- return [
156- {
157- data : membersDetails ,
158- shouldShow : true ,
159- } ,
160- ] ;
155+ return membersDetails ;
161156 }
162157
163- const sectionsArr = [ ] ;
164-
165158 if ( ! areOptionsInitialized ) {
166159 return [ ] ;
167160 }
168161
169162 const searchValueForOptions = getSearchValueForPhoneOrEmail ( debouncedSearchTerm , countryCode ) . toLowerCase ( ) ;
170- const filteredOptions = tokenizedSearch ( membersDetails , searchValueForOptions , ( option ) => [ option . text ?? '' , option . alternateText ?? '' ] ) ;
171-
172- sectionsArr . push ( {
173- title : undefined ,
174- data : filteredOptions ,
175- shouldShow : true ,
176- } ) ;
177-
178- // Selected options section
179- if ( selectedOptionsForDisplay . length > 0 ) {
180- sectionsArr . push ( {
181- title : undefined ,
182- data : selectedOptionsForDisplay ,
183- } ) ;
184- }
185-
186- // Recent reports section
187- if ( availableOptions . recentReports . length > 0 ) {
188- sectionsArr . push ( {
189- title : undefined ,
190- data : availableOptions . recentReports ,
191- } ) ;
192- }
193163
194- // Contacts section
195- if ( availableOptions . personalDetails . length > 0 ) {
196- sectionsArr . push ( {
197- title : undefined ,
198- data : availableOptions . personalDetails ,
199- } ) ;
200- }
164+ const filteredMembers = tokenizedSearch ( membersDetails , searchValueForOptions , ( option ) => [ option . text ?? '' , option . alternateText ?? '' ] ) ;
201165
202- // User to invite section
203- if ( availableOptions . userToInvite ) {
204- sectionsArr . push ( {
205- title : undefined ,
206- data : [ availableOptions . userToInvite ] ,
207- } ) ;
208- }
166+ const options = [
167+ ... filteredMembers ,
168+ ... selectedOptionsForDisplay ,
169+ ... availableOptions . recentReports ,
170+ ... availableOptions . personalDetails ,
171+ ... ( availableOptions . userToInvite ? [ availableOptions . userToInvite ] : [ ] ) ,
172+ ] ;
209173
210- return sectionsArr ;
211- } , [
212- debouncedSearchTerm ,
213- areOptionsInitialized ,
214- countryCode ,
215- membersDetails ,
216- selectedOptionsForDisplay ,
217- availableOptions . recentReports ,
218- availableOptions . personalDetails ,
219- availableOptions . userToInvite ,
220- ] ) ;
174+ return options . map ( ( option ) => ( {
175+ ...option ,
176+ keyForList : option . keyForList ?? option . login ?? '' ,
177+ } ) ) ;
178+ } , [ debouncedSearchTerm , areOptionsInitialized , countryCode , membersDetails , selectedOptionsForDisplay , availableOptions ] ) ;
221179
222180 useEffect ( ( ) => {
223181 searchInServer ( searchTerm ) ;
@@ -228,14 +186,18 @@ function AssigneeStep({policy, stepNames, startStepIndex, route}: AssigneeStepPr
228186 if ( ! availableOptions . userToInvite && CONST . EXPENSIFY_EMAILS_OBJECT [ searchValue ] ) {
229187 return translate ( 'messages.errorMessageInvalidEmail' ) ;
230188 }
231- return getHeaderMessage (
232- sections . some ( ( section ) => section . data . length > 0 ) ,
233- ! ! availableOptions . userToInvite ,
234- searchValue ,
235- countryCode ,
236- false ,
237- ) ;
238- } , [ searchTerm , availableOptions . userToInvite , sections , countryCode , translate ] ) ;
189+ return getHeaderMessage ( assignees . length > 0 , ! ! availableOptions . userToInvite , searchValue , countryCode , false ) ;
190+ } , [ searchTerm , availableOptions . userToInvite , assignees , countryCode , translate ] ) ;
191+
192+ const textInputOptions = useMemo (
193+ ( ) => ( {
194+ label : translate ( 'selectionList.nameEmailOrPhoneNumber' ) ,
195+ value : searchTerm ,
196+ onChangeText : setSearchTerm ,
197+ headerMessage,
198+ } ) ,
199+ [ headerMessage , searchTerm , setSearchTerm , translate ] ,
200+ ) ;
239201
240202 return (
241203 < InteractiveStepWrapper
@@ -251,17 +213,15 @@ function AssigneeStep({policy, stepNames, startStepIndex, route}: AssigneeStepPr
251213 >
252214 < Text style = { [ styles . textHeadlineLineHeightXXL , styles . ph5 , styles . mv3 ] } > { translate ( 'workspace.card.issueNewCard.whoNeedsCard' ) } </ Text >
253215 < SelectionList
254- textInputLabel = { translate ( 'selectionList.nameEmailOrPhoneNumber' ) }
255- textInputValue = { searchTerm }
256- onChangeText = { setSearchTerm }
257- sections = { sections }
258- headerMessage = { headerMessage }
216+ data = { assignees }
217+ onSelectRow = { submit }
259218 ListItem = { UserListItem }
219+ textInputOptions = { textInputOptions }
220+ isLoadingNewOptions = { ! ! isSearchingForReports }
221+ initiallyFocusedItemKey = { issueNewCard ?. data ?. assigneeEmail }
222+ disableMaintainingScrollPosition
260223 shouldUpdateFocusedIndex
261- initiallyFocusedOptionKey = { issueNewCard ?. data ?. assigneeEmail }
262- onSelectRow = { submit }
263224 addBottomSafeAreaPadding
264- isLoadingNewOptions = { ! ! isSearchingForReports }
265225 />
266226 </ InteractiveStepWrapper >
267227 ) ;
0 commit comments