diff --git a/src/constants/routes.ts b/src/constants/routes.ts index 9e47287..63ad893 100644 --- a/src/constants/routes.ts +++ b/src/constants/routes.ts @@ -21,6 +21,8 @@ export const ROUTES = { TASK_RESULTS: "/office/task-results", MY_GROUPS: "/office/my-groups", GROUP_STUDENTS: (groupId: number) => `/office/my-groups/${groupId}/students`, + STUDENT_TASK_ANSWERS: (studentId: number) => + `/office/students/${studentId}/task-answers`, METHODOLOGIES: "/office/methodologies", METHODOLOGY: "/office/methodology", PRESENTATIONS: "/office/presentations", diff --git a/src/interfaces/task.ts b/src/interfaces/task.ts index 105f289..66abbe6 100644 --- a/src/interfaces/task.ts +++ b/src/interfaces/task.ts @@ -29,7 +29,7 @@ export interface ITaskCreate { export interface ITaskUserAnswer { id: number; text: string; - answer: IAnswer; + answer?: IAnswer; user: IUser; task: ITask; createdAt: string; diff --git a/src/pages/my-groups/StudentTaskAnswersPage.tsx b/src/pages/my-groups/StudentTaskAnswersPage.tsx new file mode 100644 index 0000000..70430f6 --- /dev/null +++ b/src/pages/my-groups/StudentTaskAnswersPage.tsx @@ -0,0 +1,65 @@ +import { useTaskUserAnswers } from "@/queries/tasks"; +import { useParams } from "react-router-dom"; +import cn from "classnames"; + +export default function StudentTaskAnswersPage() { + const { id } = useParams(); + + const { userAnswers, isUserAnswersLoading } = useTaskUserAnswers(+id!); + + return ( +
+

Результаты студента

+ + {!isUserAnswersLoading && userAnswers && ( +
+ {!userAnswers.length && ( +
+ Результаты не найдены. +
+ )} + {userAnswers.map((answer) => ( +
+

{answer.task.topic.title}

+
+ +
+

Ответ студента:

+ + {answer.answer ? ( +
+
{answer.answer.text}
+
+ ) : ( +
+
+
+ )} +
+
+ ))} +
+ )} +
+ ); +} diff --git a/src/pages/my-groups/StudentTaskAnswersTable.tsx b/src/pages/my-groups/StudentTaskAnswersTable.tsx new file mode 100644 index 0000000..3105297 --- /dev/null +++ b/src/pages/my-groups/StudentTaskAnswersTable.tsx @@ -0,0 +1 @@ +const columns = [{ key: "id", label: "ID" }]; diff --git a/src/pages/my-groups/StudentsTable.tsx b/src/pages/my-groups/StudentsTable.tsx index f544cf8..129e032 100644 --- a/src/pages/my-groups/StudentsTable.tsx +++ b/src/pages/my-groups/StudentsTable.tsx @@ -11,8 +11,9 @@ import { import { IUser } from "@/interfaces/user"; import StudentProgressModal from "./StudentProgressModal"; import { Key, useState } from "react"; -import { useTaskUserAnswers } from "@/queries/tasks"; import { Icons } from "@/components/shared/Icons"; +import { useNavigate } from "react-router-dom"; +import { ROUTES } from "@/constants/routes"; interface Props { students: IUser[]; @@ -29,18 +30,19 @@ const columns = [ export default function StudentsTable({ students }: Props) { const { isOpen, onOpenChange, onOpen } = useDisclosure(); - const [selectedStudent, setSelectedStudent] = useState(); + const navigate = useNavigate(); - const { userAnswers, isUserAnswersLoading } = useTaskUserAnswers( - selectedStudent?.id, - !!selectedStudent - ); + const [selectedStudent, setSelectedStudent] = useState(); const handleShowProgress = (student: IUser) => { setSelectedStudent(student); onOpen(); }; + const handleStudentTaskAnswers = (student: IUser) => { + navigate(ROUTES.STUDENT_TASK_ANSWERS(student.id)); + }; + return ( <> @@ -58,6 +60,7 @@ export default function StudentsTable({ students }: Props) { user={student} columnKey={columnKey} onShowProgress={() => handleShowProgress(student)} + onShowStudentTasks={() => handleStudentTaskAnswers(student)} /> )} @@ -81,10 +84,12 @@ function StudentRow({ user, columnKey, onShowProgress, + onShowStudentTasks, }: { user: IUser; columnKey: Key; onShowProgress: () => void; + onShowStudentTasks: () => void; }) { const cellValue = user[columnKey as keyof IUser]; @@ -103,7 +108,10 @@ function StudentRow({ - + diff --git a/src/routes/RootRouter.tsx b/src/routes/RootRouter.tsx index 251f50c..474673d 100644 --- a/src/routes/RootRouter.tsx +++ b/src/routes/RootRouter.tsx @@ -25,6 +25,7 @@ import MethodologiesPage from "@/pages/methodologies/MethodologiesPage"; import MethodologyDetails from "@/pages/methodologies/MethodologyDetails"; import PresentationsPage from "@/pages/presentations/PresentationsPage"; import PresentationDetails from "@/pages/presentations/PresentationDetails"; +import StudentTaskAnswersPage from "@/pages/my-groups/StudentTaskAnswersPage"; function RootRouter({ children }) { return ( @@ -63,6 +64,10 @@ function RootRouter({ children }) { path="my-groups/:id/students" element={} /> + } + /> } /> } /> } />