diff --git a/frontend/src/api/students.ts b/frontend/src/api/students.ts index 5a59bd8..d84b36e 100644 --- a/frontend/src/api/students.ts +++ b/frontend/src/api/students.ts @@ -40,7 +40,15 @@ export const uploadStudents = (payload: FormData) => payload, ) -export const deleteStudent = (payload: Number) => +export const deleteStudent = (index: number) => axiosInstance.delete( - 'http://127.0.0.1:5000/api/coordinator/students/'+payload.toString()+'/', + `http://127.0.0.1:5000/api/coordinator/students/${index}/`, + ) + +export const downloadStudents = () => + axiosInstance.post( + 'http://127.0.0.1:5000/api/coordinator/students/download/', + { + responseType: 'blob', + }, ) diff --git a/frontend/src/views/coordinator/Students.tsx b/frontend/src/views/coordinator/Students.tsx index 851f9ca..fd6b9ed 100644 --- a/frontend/src/views/coordinator/Students.tsx +++ b/frontend/src/views/coordinator/Students.tsx @@ -1,7 +1,12 @@ import React, { useEffect, useState } from 'react' import { useMutation, useQuery } from 'react-query' import { useNavigate } from 'react-router-dom' -import { getStudents, uploadStudents, deleteStudent } from '../../api/students' +import { + getStudents, + uploadStudents, + deleteStudent, + downloadStudents, +} from '../../api/students' import classNames from 'classnames' const Students = () => { @@ -38,6 +43,21 @@ const Students = () => { getStudents({ page, per_page: perPage, mode }), ) + const { mutate: mutateDownload } = useMutation( + 'downloadStudents', + () => downloadStudents(), + { + onSuccess: (res) => { + const url = window.URL.createObjectURL(new Blob([res.data])) + const link = document.createElement('a') + link.href = url + link.setAttribute('download', 'students_list.csv') + document.body.appendChild(link) + link.click() + }, + }, + ) + const { mutate: mutateUpload } = useMutation( 'uploadStudents', (payload: FormData) => uploadStudents(payload), @@ -46,6 +66,14 @@ const Students = () => { }, ) + const { mutate: mutateDelete } = useMutation( + 'deleteStudent', + (index: number) => deleteStudent(index), + { + onSuccess: () => refetchStudents(), + }, + ) + const handleOnChange = (event: any) => { const file = event.target.files[0] const payload = new FormData() @@ -60,7 +88,7 @@ const Students = () => { return (
-
+