diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 9204c4e1db399a9581a68a1f0eaf53131dc6380c..9b209902c47bc788f04bb787d4c9a45b0cb99c11 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -119,17 +119,20 @@ const Header: React.FC<HeaderProps> = ({ customToolbar, menuItems = MENU_ITEMS } }} TabIndicatorProps={{ className: classes.indicator }} > - {menuItems.map((item) => ( - <Tab - key={item.id} - className={classes.tab} - label={item.title} - onClick={(): void => { - history.push(item.redirectTo); - }} - /> - ))} - {!isNil(profile) && ( + {menuItems.map( + (item) => + (isNil(profile) || !profile.isLoggedIn || profile.profile) && ( + <Tab + key={item.id} + className={classes.tab} + label={item.title} + onClick={(): void => { + history.push(item.redirectTo); + }} + /> + ), + )} + {!isNil(profile) && profile.profile && ( <> {USER_MENU_ITEMS.map((item) => ( <Tab @@ -161,21 +164,26 @@ const Header: React.FC<HeaderProps> = ({ customToolbar, menuItems = MENU_ITEMS } </Tabs> </Grid> - {!isNil(profile) && profile.profile ? ( + {!isNil(profile) && profile.isLoggedIn ? ( <> - <IconButton size="medium"> - <Badge color="error"> - <MailOutline style={{ color: 'white' }} /> - </Badge> - </IconButton> + {profile.profile && ( + <> + <IconButton size="medium"> + <Badge color="error"> + <MailOutline style={{ color: 'white' }} /> + </Badge> + </IconButton> - <IconButton size="medium" disableRipple> - <Report color="error" /> - </IconButton> + <IconButton size="medium" disableRipple> + <Report color="error" /> + </IconButton> + + <Typography variant="h6" align="center" className={classes.texts}> + {profile.profile && profile.profile.name} + </Typography> + </> + )} - <Typography variant="h6" align="center" className={classes.texts}> - {profile.profile && profile.profile.name} - </Typography> <a href="/api/v1/logout"> <Box color="secondary.main"> <IconButton color="inherit" size="medium"> diff --git a/src/components/ProfileForm.tsx b/src/components/ProfileForm.tsx index 2ca4948e0d65ca37077612fc4c37bdaad21d657c..c7f56b71b7b1e6b421e9d802135cb654b6243a40 100644 --- a/src/components/ProfileForm.tsx +++ b/src/components/ProfileForm.tsx @@ -23,7 +23,7 @@ const ProfileForm: React.FC = () => { client.invalidateQueries('me'); setRedirect(true); } - }, [data, isError]); + }, [data, isError, client]); return ( <Container style={{ diff --git a/src/context/UserContext.tsx b/src/context/UserContext.tsx index cac0b3611410621645bee86a42312661d7190ff0..44aba2af531e113830e92d328b22661211ea6447 100644 --- a/src/context/UserContext.tsx +++ b/src/context/UserContext.tsx @@ -11,19 +11,6 @@ export interface UserContextType { setProfile: (profile: ProfileWithStatus | undefined) => void; } -/* // Context -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const initialState: IProfile = { - externalId: 'abcd', - studentCardNumber: '1234', - roomNumber: 104, - role: Role.Admin, - email: 'alma@gmail.com', - name: 'Nagy Gizike', - warnings: [], - notices: [{ _id: '123', text: 'Asd', isSeen: false }], -}; */ - export const UserContext = createContext({} as UserContextType); const { Provider } = UserContext;