diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c136893..a123770 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,13 +1,19 @@ -import React from "react"; -import { QueryClient, QueryClientProvider } from "react-query"; -import { Route, Routes } from "react-router-dom"; -import "./App.css"; -import Coordinator from "./views/coordinator/Coordinator"; -import Groups from "./views/coordinator/Groups"; -import Leaders from "./views/coordinator/Leaders"; -import Students from "./views/coordinator/Students"; +import React from 'react' +import { QueryClient, QueryClientProvider } from 'react-query' +import { Route, Routes } from 'react-router-dom' +import './App.css' +import Coordinator from './views/coordinator/Coordinator' +import Groups from './views/coordinator/Groups' +import Leaders from './views/coordinator/Leaders' +import Students from './views/coordinator/Students' -const queryClient = new QueryClient(); +const queryClient = new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus: false, + }, + }, +}) function App() { return ( @@ -23,7 +29,7 @@ function App() { - ); + ) } -export default App; +export default App diff --git a/frontend/src/api/students.ts b/frontend/src/api/students.ts index 2061cec..f598ee6 100644 --- a/frontend/src/api/students.ts +++ b/frontend/src/api/students.ts @@ -1,10 +1,23 @@ -import axiosInstance from "./axiosInstance"; +import axiosInstance from './axiosInstance' interface StudentResponse { - max_pages: number, - students: {first_name: string, last_name: string, index: number, mode: boolean; group: any}[] + max_pages: number + students: { + first_name: string + last_name: string + index: number + mode: boolean + group: any + }[] } -export const getStudents = () => axiosInstance.get( - "http://127.0.0.1:5000/api/coordinator/students" -) \ No newline at end of file +export const getStudents = () => + axiosInstance.get( + 'http://127.0.0.1:5000/api/coordinator/students', + ) + +export const uploadStudents = (payload: FormData) => + axiosInstance.post( + 'http://127.0.0.1:5000/api/coordinator/students/upload/', + payload, + ) diff --git a/frontend/src/components/TopBar.tsx b/frontend/src/components/TopBar.tsx index 10eefc6..eb6af27 100644 --- a/frontend/src/components/TopBar.tsx +++ b/frontend/src/components/TopBar.tsx @@ -1,8 +1,8 @@ -import { NavLink } from "react-router-dom"; +import { NavLink } from 'react-router-dom' const TopBar = () => { const linkClass = ({ isActive }: { isActive: boolean }) => - isActive ? "underline font-bold" : ""; + isActive ? 'underline font-bold' : '' return (

System PRI

@@ -18,7 +18,7 @@ const TopBar = () => {
- ); -}; + ) +} -export default TopBar; +export default TopBar diff --git a/frontend/src/views/coordinator/Students.tsx b/frontend/src/views/coordinator/Students.tsx index 8dd6ea2..d5c52f2 100644 --- a/frontend/src/views/coordinator/Students.tsx +++ b/frontend/src/views/coordinator/Students.tsx @@ -1,6 +1,6 @@ import React from 'react' -import { useQuery } from 'react-query' -import { getStudents } from '../../api/students' +import { useMutation, useQuery } from 'react-query' +import { getStudents, uploadStudents } from '../../api/students' const TableHeader = (props: { children: React.ReactNode }) => ( @@ -9,17 +9,50 @@ const TableHeader = (props: { children: React.ReactNode }) => ( ) const Students = () => { - const { isLoading, data: students } = useQuery('students', () => - getStudents(), + const { + isLoading: isStudentsLoading, + data: students, + refetch: refetchStudents, + } = useQuery('students', () => getStudents()) + + const { mutate: mutateUpload } = useMutation( + 'uploadStudents', + (payload: FormData) => uploadStudents(payload), + { + onSuccess: () => refetchStudents(), + }, ) - if (isLoading) { + + const handleOnChange = (event: any) => { + const file = event.target.files[0] + const payload = new FormData() + payload.append('file', file, file.name) + mutateUpload(payload) + } + + if (isStudentsLoading) { return
Ɓadowanie
} return (
- + + +
@@ -34,7 +67,7 @@ const Students = () => { {students?.data?.students?.map( ({ first_name, last_name, index, group, mode }) => ( - +
{first_name}