From 7cdbd53dc0f8994f4bae691d7c34e2b61ce49a57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chif.gergo@cloud.bme.hu>
Date: Wed, 21 Oct 2020 22:36:11 +0200
Subject: [PATCH] Move News type into core/types

---
 .eslintrc.js                     |  1 +
 src/core/context/UserContext.tsx | 37 +++-----------------------------
 src/core/types.ts                |  6 ++++++
 src/hooks/types.ts               |  6 ------
 src/hooks/useAddNews.ts          |  6 +++---
 src/hooks/useGetNewsList.ts      |  8 +++----
 6 files changed, 17 insertions(+), 47 deletions(-)

diff --git a/.eslintrc.js b/.eslintrc.js
index 4c0c2c7..518fe41 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -14,5 +14,6 @@ module.exports = {
 
   rules: {
     'implicit-arrow-linebreak': 0,
+    'react/prop-types': 0,
   },
 };
diff --git a/src/core/context/UserContext.tsx b/src/core/context/UserContext.tsx
index 34f1be7..0c87308 100644
--- a/src/core/context/UserContext.tsx
+++ b/src/core/context/UserContext.tsx
@@ -1,36 +1,5 @@
-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 }) => {
diff --git a/src/core/types.ts b/src/core/types.ts
index 60db482..23e1422 100644
--- a/src/core/types.ts
+++ b/src/core/types.ts
@@ -23,3 +23,9 @@ export interface Warnings {
     name: string;
   };
 }
+
+export interface News {
+  title: string;
+  text: string;
+  publishedAt: string;
+}
diff --git a/src/hooks/types.ts b/src/hooks/types.ts
index d639a34..ab423a8 100644
--- a/src/hooks/types.ts
+++ b/src/hooks/types.ts
@@ -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;
-}
diff --git a/src/hooks/useAddNews.ts b/src/hooks/useAddNews.ts
index bbc5b5b..51d2eb1 100644
--- a/src/hooks/useAddNews.ts
+++ b/src/hooks/useAddNews.ts
@@ -1,12 +1,12 @@
-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;
diff --git a/src/hooks/useGetNewsList.ts b/src/hooks/useGetNewsList.ts
index 2b36ca7..8505723 100644
--- a/src/hooks/useGetNewsList.ts
+++ b/src/hooks/useGetNewsList.ts
@@ -1,12 +1,12 @@
-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;
-- 
GitLab