1- import { useState , useEffect } from 'react' ;
1+ import { useEffect } from 'react' ;
22import {
33 Box ,
44 Button ,
@@ -11,7 +11,7 @@ import {
1111 ListItemButton ,
1212} from '@mui/material' ;
1313import { useLocation } from 'react-router-dom' ;
14- import useAuth from '../../hooks/useAuth ' ;
14+ import { useSearchText } from '../../context/searchContext ' ;
1515import PersonIcon from '@mui/icons-material/Person' ;
1616import '../../sass/UserAdmin.scss' ;
1717
@@ -20,8 +20,7 @@ const Buttonsx = {
2020 py : 0.5 ,
2121} ;
2222
23- const DummyComponent = ( { data, isProjectLead, setUserToEdit } ) => {
24- const { auth } = useAuth ( ) ;
23+ const ListComponent = ( { data, isProjectLead, setUserToEdit } ) => {
2524 return (
2625 < List className = "search-results disablePadding" >
2726 { data . map ( ( u , idx ) => {
@@ -104,14 +103,12 @@ const DummyComponent = ({ data, isProjectLead, setUserToEdit }) => {
104103 ) ;
105104} ;
106105
107- const UserPermissionSearch = ( { admins, projectLeads, setUserToEdit } ) => {
108- const [ userType ] = useState ( 'admin' ) ; // Which results will display
109- const [ searchText , setSearchText ] = useState ( '' ) ; // Search term for the admin/PM search
110- const [ isProjectLead , setIsProjectLead ] = useState ( false ) ;
106+ const UserPermissionSearch = ( { admins, projectManagers, setUserToEdit } ) => {
107+ const { searchText, setSearchText, userType, setUserType, isProjectLead, setIsProjectLead } = useSearchText ( ) ; // React context hook
111108
112109 const location = useLocation ( ) ;
113110
114- const resultData = [ ...admins , ...projectLeads ] ;
111+ const resultData = [ ...admins , ...projectManagers ] ;
115112
116113 useEffect ( ( ) => {
117114 // Edit url by adding '/admin' upon loading
@@ -125,8 +122,15 @@ const UserPermissionSearch = ({ admins, projectLeads, setUserToEdit }) => {
125122 } , [ userType ] ) ;
126123
127124 // Swaps the buttons and displayed panels for the search results, by email or by name
128- const buttonSwap = ( ) =>
129- isProjectLead ? setIsProjectLead ( false ) : setIsProjectLead ( true ) ;
125+ const buttonSwap = ( ) => {
126+ if ( isProjectLead ) {
127+ setIsProjectLead ( false ) ;
128+ setUserType ( 'admin' ) ;
129+ } else {
130+ setIsProjectLead ( true ) ;
131+ setUserType ( 'projectLead' ) ;
132+ }
133+ }
130134
131135 // Handle change on input in search form
132136 const handleChange = ( event ) => {
@@ -323,7 +327,7 @@ const UserPermissionSearch = ({ admins, projectLeads, setUserToEdit }) => {
323327 >
324328 < Box >
325329 { /*Component to render admins and PMs*/ }
326- < DummyComponent
330+ < ListComponent
327331 data = { filteredData }
328332 isProjectLead = { isProjectLead }
329333 setUserToEdit = { setUserToEdit }
0 commit comments