1- import React , { useState , useEffect } from 'react' ;
1+ import React , { useState , useEffect , useContext } from 'react' ;
22import { Navigate , useNavigate , useParams } from 'react-router-dom' ;
33import GridItem from '../../components/Grid/GridItem' ;
44import GridContainer from '../../components/Grid/GridContainer' ;
55import Card from '../../components/Card/Card' ;
66import CardBody from '../../components/Card/CardBody' ;
77import Button from '../../components/CustomButtons/Button' ;
88import FormLabel from '@material-ui/core/FormLabel' ;
9- import { getUser , updateUser , getUserLoggedIn } from '../../services/user' ;
9+ import { getUser , updateUser } from '../../services/user' ;
10+ import { UserContext } from '../../../context' ;
1011
1112import { UserData } from '../../../types/models' ;
1213import { makeStyles } from '@material-ui/core/styles' ;
@@ -32,10 +33,10 @@ export default function UserProfile(): React.ReactElement {
3233 const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ;
3334 const [ isError , setIsError ] = useState < boolean > ( false ) ;
3435 const [ isProfile , setIsProfile ] = useState < boolean > ( false ) ;
35- const [ isAdmin , setIsAdmin ] = useState < boolean > ( false ) ;
3636 const [ gitAccount , setGitAccount ] = useState < string > ( '' ) ;
3737 const navigate = useNavigate ( ) ;
3838 const { id } = useParams < { id ?: string } > ( ) ;
39+ const { user : loggedInUser } = useContext ( UserContext ) ;
3940
4041 useEffect ( ( ) => {
4142 if ( id == null ) {
@@ -53,9 +54,7 @@ export default function UserProfile(): React.ReactElement {
5354 setIsError ,
5455 id ,
5556 ) ;
56- getUserLoggedIn ( setIsLoading , setIsAdmin , setIsError , setAuth ) ;
5757 } else {
58- console . log ( 'getting user data' ) ;
5958 setIsProfile ( true ) ;
6059 getUser (
6160 setIsLoading ,
@@ -169,7 +168,7 @@ export default function UserProfile(): React.ReactElement {
169168 ) }
170169 </ GridItem >
171170 </ GridContainer >
172- { isProfile || isAdmin ? (
171+ { isProfile || loggedInUser . admin ? (
173172 < div style = { { marginTop : '50px' } } >
174173 < hr style = { { opacity : 0.2 } } />
175174 < div style = { { marginTop : '25px' } } >
0 commit comments