mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
feat: detaching students from table
This commit is contained in:
parent
08d2e0ccde
commit
c8a63cae59
@ -18,7 +18,7 @@ import type { ICourse } from '@educt/interfaces';
|
|||||||
*/
|
*/
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { useDisclosure } from '@chakra-ui/react';
|
import { useDisclosure } from '@chakra-ui/react';
|
||||||
import { UserServiceInstance } from '@educt/services';
|
import { CourseServiceInstance, UserServiceInstance } from '@educt/services';
|
||||||
|
|
||||||
type StudentTableListPropsType = {
|
type StudentTableListPropsType = {
|
||||||
render: React.FC<StudentTableRowPropsType>;
|
render: React.FC<StudentTableRowPropsType>;
|
||||||
@ -107,8 +107,17 @@ const StudentTableList: React.FC<StudentTableListPropsType> = props => {
|
|||||||
* Remove from course student handler
|
* Remove from course student handler
|
||||||
*/
|
*/
|
||||||
const handleRemove = (id: string) => {
|
const handleRemove = (id: string) => {
|
||||||
return () => {
|
return async () => {
|
||||||
console.log(`removing id: ${id}`);
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await CourseServiceInstance.detachStudentsList(course.id, [id]);
|
||||||
|
toast({ title: 'Student removed.', status: 'info' });
|
||||||
|
setRows(prev => prev.filter(s => s.id !== id));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -97,6 +97,13 @@ class CourseService {
|
|||||||
return result.data;
|
return result.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach students to course by id
|
||||||
|
*
|
||||||
|
* @param courseId Course id
|
||||||
|
* @param ids List ids of students
|
||||||
|
* @returns Empty data
|
||||||
|
*/
|
||||||
public async attachStudentsList(courseId: string, ids: Array<string>): Promise<IApiRespose<Record<string, never>>> {
|
public async attachStudentsList(courseId: string, ids: Array<string>): Promise<IApiRespose<Record<string, never>>> {
|
||||||
const result = await this.api.post(
|
const result = await this.api.post(
|
||||||
`/v1/courses/${courseId}/attach-student-list`,
|
`/v1/courses/${courseId}/attach-student-list`,
|
||||||
@ -104,6 +111,14 @@ class CourseService {
|
|||||||
);
|
);
|
||||||
return result.data;
|
return result.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async detachStudentsList(courseId: string, ids: Array<string>): Promise<IApiRespose<Record<string, never>>> {
|
||||||
|
const result = await this.api.patch(
|
||||||
|
`/v1/courses/${courseId}/detach-student-list`,
|
||||||
|
helpers.transformToFormData({ students: ids })
|
||||||
|
);
|
||||||
|
return result.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CourseServiceInstance = new CourseService(ApiServiceInstance.api);
|
export const CourseServiceInstance = new CourseService(ApiServiceInstance.api);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user