Skip to content
Snippets Groups Projects
Commit bff0fb3c authored by Chif Gergő's avatar Chif Gergő
Browse files

Refactor IProfile type

parent b13566e8
Branches
No related tags found
2 merge requests!19fix type imports,!17Authentication
import Axios, { AxiosRequestConfig } from 'axios'; import Axios, { AxiosRequestConfig } from 'axios';
import { IProfile } from '../types/Profile'; import { IProfile } from '../types/Profile';
type MeQuery = () => Promise<Partial<IProfile>>; type MeQuery = () => Promise<IProfile>;
type RegisterQuery = (data: ProfileData) => Promise<any>; type RegisterQuery = (data: ProfileData) => Promise<any>;
export type ProfileData = { export type ProfileData = {
...@@ -20,8 +20,8 @@ export function auth(config: AxiosRequestConfig): AuthClient { ...@@ -20,8 +20,8 @@ export function auth(config: AxiosRequestConfig): AuthClient {
baseURL: `${config.baseURL}/api/v1/`, baseURL: `${config.baseURL}/api/v1/`,
}); });
const me: MeQuery = async (): Promise<Partial<IProfile>> => { const me: MeQuery = async (): Promise<IProfile> => {
return (await axios.get<Partial<IProfile>>('/users/me')).data; return (await axios.get<IProfile>('/users/me')).data;
}; };
const register: RegisterQuery = async (data: ProfileData): Promise<any> => { const register: RegisterQuery = async (data: ProfileData): Promise<any> => {
......
...@@ -164,19 +164,15 @@ const Header: React.FC<HeaderProps> = ({ customToolbar, menuItems = MENU_ITEMS } ...@@ -164,19 +164,15 @@ const Header: React.FC<HeaderProps> = ({ customToolbar, menuItems = MENU_ITEMS }
{!isNil(profile) ? ( {!isNil(profile) ? (
<> <>
<IconButton size="medium"> <IconButton size="medium">
<Badge <Badge color="error">
badgeContent={profile.notices?.filter((item) => !item.isSeen).length ?? 0}
color="error"
>
<MailOutline style={{ color: 'white' }} /> <MailOutline style={{ color: 'white' }} />
</Badge> </Badge>
</IconButton> </IconButton>
{profile.warnings && profile.warnings.length > 0 && (
<IconButton size="medium" disableRipple> <IconButton size="medium" disableRipple>
<Report color="error" /> <Report color="error" />
</IconButton> </IconButton>
)}
<Typography variant="h6" align="center" className={classes.texts}> <Typography variant="h6" align="center" className={classes.texts}>
{profile.name} {profile.name}
</Typography> </Typography>
......
...@@ -2,8 +2,8 @@ import React, { createContext, useState } from 'react'; ...@@ -2,8 +2,8 @@ import React, { createContext, useState } from 'react';
import { IProfile } from '../types/Profile'; import { IProfile } from '../types/Profile';
export interface UserContextType { export interface UserContextType {
profile: Partial<IProfile> | undefined; profile: IProfile | undefined;
setProfile: (profile: Partial<IProfile> | undefined) => void; setProfile: (profile: IProfile | undefined) => void;
} }
/* // Context /* // Context
...@@ -24,7 +24,7 @@ export const UserContext = createContext({} as UserContextType); ...@@ -24,7 +24,7 @@ export const UserContext = createContext({} as UserContextType);
const { Provider } = UserContext; const { Provider } = UserContext;
export const UserStateProvider: React.FC = ({ children }) => { export const UserStateProvider: React.FC = ({ children }) => {
const [profile, setProfile] = useState<Partial<IProfile> | undefined>(); const [profile, setProfile] = useState<IProfile | undefined>();
return <Provider value={{ profile, setProfile }}>{children}</Provider>; return <Provider value={{ profile, setProfile }}>{children}</Provider>;
}; };
......
...@@ -2,8 +2,8 @@ import { useQuery, UseQueryResult } from 'react-query'; ...@@ -2,8 +2,8 @@ import { useQuery, UseQueryResult } from 'react-query';
import { IProfile } from '../types/Profile'; import { IProfile } from '../types/Profile';
import useClientContext from './useClientContext'; import useClientContext from './useClientContext';
export default function useMe(): UseQueryResult<Partial<IProfile>, Error> { export default function useMe(): UseQueryResult<IProfile, Error> {
const client = useClientContext(); const client = useClientContext();
return useQuery<Partial<IProfile>, Error>('me', async () => client.client.auth.me()); return useQuery<IProfile, Error>('me', async () => client.client.auth.me());
} }
...@@ -19,16 +19,9 @@ export interface IWarning { ...@@ -19,16 +19,9 @@ export interface IWarning {
export interface IProfile { export interface IProfile {
_id: string; _id: string;
externalId: string;
studentCardNumber?: string; studentCardNumber?: string;
roomNumber?: Number; roomNumber?: Number;
newPicture?: string;
acceptedPicture?: string;
role: Role; role: Role;
email: string; email: string;
name: string; name: string;
isStaffMember?: boolean;
staffMemberText?: string;
warnings: IWarning[];
notices: INotice[];
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment