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

Move News type into core/types

parent 84f070d4
No related branches found
No related tags found
2 merge requests!7update master to dev,!5Add api data types
......@@ -14,5 +14,6 @@ module.exports = {
rules: {
'implicit-arrow-linebreak': 0,
'react/prop-types': 0,
},
};
import React, { createContext, ReactNode, useState } from 'react';
import { Profile } from '../types';
// Interface definitions
interface IWarnings extends Document {
text: string;
date: Date;
given_by: {
_id: string;
name: string;
};
}
enum Role {
Admin,
Staff,
User,
}
export interface IProfile {
external_id: string;
studentCardNumber?: string;
roomNumber?: string;
picture?: string;
role: Role.Admin | Role.Staff | Role.User;
email: string;
name: string;
warnings: [IWarnings] | [];
}
type Props = {
children: ReactNode;
};
import React, { createContext, useState } from 'react';
import { Profile, Role } from '../types';
interface ContextProps {
profile: Profile;
......@@ -48,7 +17,7 @@ const initialState: Profile = {
name: 'Nagy Gizike',
warnings: [],
};
export const userContext = createContext({} as IContextProps);
export const userContext = createContext({} as ContextProps);
const { Provider } = userContext;
export const UserStateProvider: React.FC = ({ children }) => {
......
......@@ -23,3 +23,9 @@ export interface Warnings {
name: string;
};
}
export interface News {
title: string;
text: string;
publishedAt: string;
}
......@@ -21,9 +21,3 @@ export interface RequestParams {
export type ApiRequest<T> = (params: RequestParams) => AxiosPromise<T>;
export type Refetch = (params?: RequestParams) => void;
export interface INews {
title: string;
text: string;
publishedAt: string;
}
import { INews } from './types';
import { News } from '../core/types';
import useRequest from './useRequest';
import useRestQueries from './useRestQueries';
const useAddNews = () => {
const { post } = useRestQueries();
const request = post<INews>('/api/v1/news');
const request = post<News>('/api/v1/news');
return useRequest<INews>({ request });
return useRequest<News>({ request });
};
export default useAddNews;
import { INews } from './types';
import { News } from '../core/types';
import useRequest from './useRequest';
import useRestQueries from './useRestQueries';
const useGetNewsList = (data?: INews[]) => {
const useGetNewsList = (data?: News[]) => {
const { get } = useRestQueries();
const request = get<INews[]>('/api/v1/news');
const request = get<News[]>('/api/v1/news');
return useRequest<INews[]>({ request, initialData: data });
return useRequest<News[]>({ request, initialData: data });
};
export default useGetNewsList;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment