@@ -67,72 +67,72 @@ const FeedbackExternalRecipientSelector = ({ changeQuery, fromQuery, forQuery, a
6767 const hasRenewedFromURL = useRef ( false ) ;
6868 const [ searchText , setSearchText ] = useState ( '' ) ;
6969 const [ externalRecipients , setExternalRecipients ] = useState ( [ ] ) ;
70- const normalizedMembers = selectNormalizedMembers ( state , searchText ) ;
7170
72- useEffect ( ( ) => {
73- if (
74- ! searchTextUpdated . current &&
75- searchText . length !== 0 &&
76- searchText !== '' &&
77- searchText
78- ) {
79- if ( fromQuery !== undefined ) {
80- let selectedMembers = externalRecipients . filter ( profile =>
81- fromQuery . includes ( profile . id )
82- ) ;
83- let filteredNormalizedMembers = normalizedMembers . filter ( member => {
84- return ! selectedMembers . some ( selectedMember => {
85- return selectedMember . id === member . id ;
86- } ) ;
87- } ) ;
88- setExternalRecipients ( filteredNormalizedMembers ) ;
89- } else {
90- setExternalRecipients ( normalizedMembers ) ;
91- }
92- searchTextUpdated . current = true ;
93- }
94- } , [ searchText , externalRecipients , fromQuery , state , userProfile , normalizedMembers ] )
95- ;
9671
97- useEffect ( ( ) => {
98- function bindFromURL ( ) {
99- if (
72+ useEffect ( ( ) => {
73+
74+ if ( ! searchTextUpdated . current && searchText . length !== 0 && searchText !== '' && searchText ) {
75+ if ( fromQuery !== undefined ) {
76+ let selectedRecipients = externalRecipients . filter ( externalRecipient =>
77+ fromQuery . includes ( externalRecipient . id )
78+ ) ;
79+ const normalizedRecipients = [ ...externalRecipients ] ;
80+ const filteredNormalizedMembers = normalizedRecipients . filter ( member => {
81+ const searchTextLower = searchText . toLowerCase ( ) ;
82+ const matchesSearchText = [ 'firstName' , 'lastName' , 'email' , 'companyName' ] . some ( key =>
83+ member [ key ] && member [ key ] . toLowerCase ( ) . includes ( searchTextLower )
84+ ) ;
85+ const isInFromQuery = fromQuery . includes ( member . id ) ;
86+ return matchesSearchText || isInFromQuery ;
87+ } ) ;
88+ setExternalRecipients ( filteredNormalizedMembers ) ;
89+ } else {
90+ setExternalRecipients ( normalizedRecipients ) ;
91+ }
92+ searchTextUpdated . current = true ;
93+ }
94+ } , [ searchText , externalRecipients , fromQuery , state , userProfile ] )
95+ ;
96+
97+ useEffect ( ( ) => {
98+ function bindFromURL ( ) {
99+ if (
100100 ! hasRenewedFromURL . current &&
101101 fromQuery !== null &&
102102 fromQuery !== undefined
103- ) {
103+ ) {
104104 let profileCopy = externalRecipients ;
105105 if ( typeof fromQuery === 'string' ) {
106106 let newProfile = { id : fromQuery } ;
107- if ( externalRecipients . filter ( member => member . id === newProfile . id ) . length === 0 ) {
107+ if ( externalRecipients . filter ( externalRecipient => externalRecipient . id === newProfile . id ) . length === 0 ) {
108108 profileCopy . push ( newProfile ) ;
109109 }
110110 } else if ( Array . isArray ( fromQuery ) ) {
111111 for ( let i = 0 ; i < fromQuery . length ; ++ i ) {
112112 let newProfile = { id : fromQuery [ i ] } ;
113- if ( externalRecipients . filter ( member => member . id === newProfile . id ) . length === 0 ) {
113+ if ( externalRecipients . filter ( externalRecipient => externalRecipient . id === newProfile . id ) . length === 0 ) {
114114 profileCopy . push ( newProfile ) ;
115115 }
116116 }
117117 }
118118 setExternalRecipients ( profileCopy ) ;
119119 hasRenewedFromURL . current = true ;
120- }
121- }
120+ }
121+ }
122122
123- async function getExternalRecipientsForSelector ( ) {
124- if ( forQuery === undefined || forQuery === null ) {
123+ async function getExternalRecipientsForSelector ( ) {
124+ if ( forQuery === undefined || forQuery === null ) {
125125 return ;
126- }
127- let res = await getExternalRecipients ( csrf ) ;
128- if ( res && res . payload ) {
126+ }
127+ let res = await getExternalRecipients ( csrf ) ;
128+ if ( res && res . payload ) {
129129 return res . payload . data && ! res . error ? res . payload . data : undefined ;
130- }
131- return null ;
132- }
130+ }
131+ return null ;
132+ }
133133
134- if ( csrf && ( searchText === '' || searchText . length === 0 ) ) {
135- getExternalRecipientsForSelector ( ) . then ( res => {
134+ if ( csrf && ( searchText === '' || searchText . length === 0 ) ) {
135+ getExternalRecipientsForSelector ( ) . then ( res => {
136136 bindFromURL ( ) ;
137137 if ( res !== undefined && res !== null ) {
138138 let filteredProfileCopy = externalRecipients . filter ( member => {
@@ -143,10 +143,10 @@ const FeedbackExternalRecipientSelector = ({ changeQuery, fromQuery, forQuery, a
143143 let newProfiles = filteredProfileCopy . concat ( res ) ;
144144 setExternalRecipients ( newProfiles ) ;
145145 }
146- } ) ;
147- } // eslint-disable-next-line react-hooks/exhaustive-deps
148- } , [ id , csrf , searchText ] )
149- ;
146+ } ) ;
147+ } // eslint-disable-next-line react-hooks/exhaustive-deps
148+ } , [ id , csrf , searchText ] )
149+ ;
150150
151151 const cardClickHandler = id => {
152152 if ( ! Array . isArray ( fromQuery ) ) {
@@ -194,7 +194,7 @@ const FeedbackExternalRecipientSelector = ({ changeQuery, fromQuery, forQuery, a
194194 }
195195 }
196196
197- const getSelectedCards = ( ) => {
197+ const getSelectedCards = ( ) => {
198198 if ( fromQuery ) {
199199 const title = (
200200 < Typography
0 commit comments