Skip to content

Commit cb98da3

Browse files
committed
chore: remove unnecessary load - user already in the context
1 parent fdd808d commit cb98da3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/ui/views/User/User.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useEffect, useContext } from 'react';
22
import { Navigate, useNavigate, useParams } from 'react-router-dom';
33
import GridItem from '../../components/Grid/GridItem';
44
import GridContainer from '../../components/Grid/GridContainer';
55
import Card from '../../components/Card/Card';
66
import CardBody from '../../components/Card/CardBody';
77
import Button from '../../components/CustomButtons/Button';
88
import 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

1112
import { UserData } from '../../../types/models';
1213
import { 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

Comments
 (0)