@@ -22,6 +22,8 @@ import { boxStyle, boxStyleDark } from '~/styles';
2222import ToggleSwitch from '~/components/UserProfile/UserProfileEdit/ToggleSwitch' ;
2323import Loading from '~/components/common/Loading' ;
2424import { getProjectDetail } from '~/actions/project' ;
25+ import axios from 'axios' ;
26+ import { ENDPOINTS } from '~/utils/URL' ;
2527
2628const Members = props => {
2729 const darkMode = props . state . theme . darkMode ;
@@ -34,6 +36,37 @@ const Members = props => {
3436
3537 const [ isLoading , setIsLoading ] = useState ( true ) ;
3638
39+ const [ allProfiles , setAllProfiles ] = useState ( [ ] ) ;
40+
41+ useEffect ( ( ) => {
42+ axios . get ( ENDPOINTS . USER_PROFILES )
43+ . then ( response => {
44+ setAllProfiles ( response . data || [ ] ) ;
45+ } )
46+ . catch ( ( ) => {
47+ setAllProfiles ( [ ] ) ;
48+ } ) ;
49+ } , [ ] ) ;
50+
51+ const filteredUsers = searchText . trim ( )
52+ ? allProfiles
53+ . filter ( user => {
54+ const search = searchText . trim ( ) . toLowerCase ( ) ;
55+ return (
56+ ( user . firstName && user . firstName . toLowerCase ( ) . includes ( search ) ) ||
57+ ( user . lastName && user . lastName . toLowerCase ( ) . includes ( search ) ) ||
58+ ( user . email && user . email . toLowerCase ( ) . includes ( search ) )
59+ ) ;
60+ } )
61+ . map ( user => ( {
62+ fullName : `${ user . firstName || '' } ${ user . lastName || '' } ` . trim ( ) ,
63+ email : user . email ,
64+ assigned : false ,
65+ _id : user . _id ,
66+ } ) )
67+ . filter ( user => ! ! user . email )
68+ : [ ] ;
69+
3770 const canAssignProjectToUsers = props . hasPermission ( 'assignProjectToUsers' ) ;
3871 const canUnassignUserInProject = props . hasPermission ( 'unassignUserInProject' ) ;
3972
@@ -232,13 +265,11 @@ const Members = props => {
232265
233266
234267
235- { showFindUserList && props . state . projectMembers . foundUsers . length > 0 ? (
268+ { showFindUserList && filteredUsers . length > 0 && (
236269 < table className = { `table table-bordered table-responsive-sm ${ darkMode ? 'text-light' : '' } ` } >
237270 < thead >
238271 < tr className = { darkMode ? 'bg-space-cadet' : '' } >
239- < th scope = "col" id = "foundUsers__order" >
240- #
241- </ th >
272+ < th scope = "col" id = "foundUsers__order" > #</ th >
242273 < th scope = "col" > Name</ th >
243274 < th scope = "col" > Email</ th >
244275 { canAssignProjectToUsers ? (
@@ -257,22 +288,21 @@ const Members = props => {
257288 </ tr >
258289 </ thead >
259290 < tbody >
260- { props . state . projectMembers . foundUsers . map ( ( user , i ) => (
291+ { filteredUsers . map ( ( user , i ) => (
261292 < FoundUser
262293 index = { i }
263294 key = { user . _id }
264295 projectId = { projectId }
265296 uid = { user . _id }
297+ fullName = { user . fullName }
266298 email = { user . email }
267- firstName = { user . firstName }
268- lastName = { user . lastName }
269299 assigned = { user . assigned }
270300 darkMode = { darkMode }
271301 />
272302 ) ) }
273303 </ tbody >
274304 </ table >
275- ) : null }
305+ ) }
276306
277307 < ToggleSwitch
278308 switchType = "active_members"
0 commit comments