diff --git a/frontend/frontend/src/components/CourseCard.tsx b/frontend/frontend/src/components/CourseCard.tsx index 0359ee2c..71f38fae 100644 --- a/frontend/frontend/src/components/CourseCard.tsx +++ b/frontend/frontend/src/components/CourseCard.tsx @@ -19,6 +19,9 @@ import { Course, project } from '../pages/mainPage/MainPage.tsx' import dayjs from 'dayjs' import { CourseCardSkeleton } from './CourseCardSkeleton.tsx' +import { Submission } from '../pages/submissionPage/SubmissionPage.tsx' +import { Group } from '../pages/groupsPage/GroupsPage.tsx' +import axios from 'axios' /* * CourseCard component displays a card with course information and a list of assignments * @param courseId: string, the id of the course @@ -29,6 +32,7 @@ import { CourseCardSkeleton } from './CourseCardSkeleton.tsx' //TODO: fix archived with state so that the card moves to ArchivedView when archived interface CourseCardProps { + userid: number courseId: string archived: boolean isStudent: boolean @@ -38,6 +42,7 @@ interface CourseCardProps { } export function CourseCard({ + userid, courseId, archived, isStudent, @@ -49,11 +54,15 @@ export function CourseCard({ const [course, setCourse] = useState({ vak_id: 0, naam: '', + jaartal: 0, studenten: [], lesgevers: [], gearchiveerd: false, }) const [assignments, setAssignments] = useState([]) + const [groupsWithSubmissions, setGroupsWithSubmissions] = useState( + [] + ) const [teachers, setTeachers] = useState< { first_name: string; last_name: string }[] >([]) @@ -77,6 +86,32 @@ export function CourseCard({ setCourse(courseResponse.data) setAssignments(assignmentsResponse.data) + //fetch submissions as well if user is student + if (isStudent) { + const groups: Group[] = await instance + .get(`/groepen/?student=${userid}`) + .then((response) => response.data) + const submissionPromises = groups.map(async (group) => { + const response = await instance.get( + `/indieningen/?project=${group.project}` + ) + return response.data + }) + const submissions = await axios.all(submissionPromises) + + console.log(groups) + const validGroups = groups.filter((group) => + submissions + .flat(Infinity) + .some( + (submission) => + submission.groep === group.groep_id + ) + ) + + setGroupsWithSubmissions(validGroups) + } + if (courseResponse.data && courseResponse.data.lesgevers) { const lesgevers = [] for (const teacherId of courseResponse.data.lesgevers) { @@ -198,10 +233,6 @@ export function CourseCard({ {/* Number of students enrolled */} - - {t('students') + ': '} - {course.studenten.length || 0} - + + {t('students') + ': '} + {course.studenten.length || 0} + @@ -340,16 +375,19 @@ export function CourseCard({ assignment.titel } dueDate={ - dayjs( - assignment.deadline - ).format( - 'DD/MM/YYYY HH:mm' - ) || undefined + assignment.deadline + ? dayjs( + assignment.deadline + ).format( + 'DD/MM/YYYY HH:mm' + ) + : undefined } - status={ - assignment.project_id === - 1 - } //TODO dit moet nog aangepast worden + status={groupsWithSubmissions.some( + (group) => + group.project === + assignment.project_id + )} isStudent={isStudent} /> ))} @@ -378,16 +416,22 @@ export function CourseCard({ assignment.titel } dueDate={ - dayjs( - assignment.deadline - ).format( - 'DD/MM/YYYY HH:mm' - ) || - undefined + assignment.deadline + ? dayjs( + assignment.deadline + ).format( + 'DD/MM/YYYY HH:mm' + ) + : undefined } status={ - assignment.project_id === - 1 + groupsWithSubmissions.some( + ( + group + ) => + group.project === + assignment.project_id + ) //TODO: status has to check if there is already a submission } isStudent={ @@ -429,10 +473,11 @@ export function CourseCard({ ) || undefined } - status={ - assignment.project_id === - 1 - } + status={groupsWithSubmissions.some( + (group) => + group.project === + assignment.project_id + )} isStudent={ isStudent } diff --git a/frontend/frontend/src/components/DeadlineCalendar.tsx b/frontend/frontend/src/components/DeadlineCalendar.tsx index 51c041a8..9835c497 100644 --- a/frontend/frontend/src/components/DeadlineCalendar.tsx +++ b/frontend/frontend/src/components/DeadlineCalendar.tsx @@ -7,13 +7,13 @@ import { import dayjs, { Dayjs } from 'dayjs' import { Badge, - SxProps, - Stack, - Typography, List, ListItem, ListItemButton, ListItemText, + Stack, + SxProps, + Typography, } from '@mui/material' import { useEffect, useRef, useState } from 'react' import AssignmentIcon from '@mui/icons-material/Assignment' @@ -125,7 +125,14 @@ function DeadlineMenu({ assignments, selectedDay }: DeadlineMenuProps) { handleProjectClick( @@ -134,8 +141,14 @@ function DeadlineMenu({ assignments, selectedDay }: DeadlineMenuProps) { ) } > - - + + + {assignment.titel} + + ))} @@ -202,6 +215,12 @@ export function DeadlineCalendar({ fetchHighlightedDays(date) } + const handleYearChange = (date: Dayjs) => { + setIsLoading(true) + setHighlightedDays([]) + fetchHighlightedDays(date) + } + return ( <> @@ -211,6 +230,7 @@ export function DeadlineCalendar({ value={value} onChange={(newValue) => setValue(newValue)} onMonthChange={(newValue) => handleMonthChange(newValue)} + onYearChange={(newValue) => handleYearChange(newValue)} renderLoading={() => } loading={isLoading} sx={dateStyle} diff --git a/frontend/frontend/src/components/Header.tsx b/frontend/frontend/src/components/Header.tsx index 0a21c2b3..f8a83cd3 100644 --- a/frontend/frontend/src/components/Header.tsx +++ b/frontend/frontend/src/components/Header.tsx @@ -147,7 +147,7 @@ export const Header = ({ variant, title }: Props) => { > {variant === 'main' && ( {/* Main actions section */} {buttons} - - - {t('must_pass') + ':'} - - setMustPass(!mustPass)} - /> - {t('choose_existing') + ':'} diff --git a/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx b/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx index a5da5ff8..ffa4f0cd 100644 --- a/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx +++ b/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx @@ -32,6 +32,7 @@ import WarningPopup from '../../components/WarningPopup.tsx' import { User } from '../subjectsPage/AddChangeSubjectPage.tsx' import StudentPopUp from '../subjectsPage/StudentPopUp.tsx' import axios, { AxiosResponse } from 'axios' +import { GroupAccessComponent } from '../../components/GroupAccessComponent.tsx' // group interface export interface Group { @@ -186,15 +187,18 @@ export function AssignmentPage() { const groupResponse = await instance.get( `groepen/?student=${user.user}&project=${assignmentId}` ) - const group: Group = groupResponse.data[0] - const studentPromises: Promise>[] = - group.studenten.map((id: number) => - instance.get('/gebruikers/' + id) - ) + if (groupResponse.data.length > 0) { + const group: Group = groupResponse.data[0] + + const studentPromises: Promise>[] = + group.studenten.map((id: number) => + instance.get('/gebruikers/' + id) + ) - const temp_students = await axios.all(studentPromises) - setStudents(temp_students.map((res) => res.data)) + const temp_students = await axios.all(studentPromises) + setStudents(temp_students.map((res) => res.data)) + } setStudentsLoading(false) } @@ -406,26 +410,20 @@ export function AssignmentPage() { height={50} /> ) : ( - <> - {assignment !== undefined && - assignment.deadline !== - null && ( - - {assignment - ? dayjs( - assignment.deadline - ).format( - 'DD/MM/YYYY-HH:MM' - ) - : 'no deadline'} - - )} - + + {assignment && assignment.deadline + ? dayjs( + assignment.deadline + ).format( + 'DD/MM/YYYY HH:mm' + ) + : t('no_deadline')} + )} {loading ? ( @@ -440,60 +438,59 @@ export function AssignmentPage() { /> ) : ( <> - <> - {assignment?.student_groep ? ( - - ) : ( - - {assignment?.max_groep_grootte === - 1 ? ( - - {user.first_name + - ' ' + - user.last_name} - - ) : ( - <> - - - )} - - )} - + {(assignment?.max_groep_grootte + ? assignment.max_groep_grootte + : 1) > 1 && ( + + )} )} + {/*extra deadline*/} + {assignment?.extra_deadline && ( + + + Extra Deadline: + + {loading ? ( + + ) : ( + + {assignment + ? dayjs( + assignment.extra_deadline + ).format( + 'DD/MM/YYYY HH:mm' + ) + : 'no deadline'} + + )} + + )} {/* Assignment description */} @@ -758,26 +755,20 @@ export function AssignmentPage() { height={50} /> ) : ( - <> - {assignment !== undefined && - assignment.deadline !== - null && ( - - {assignment - ? dayjs( - assignment.deadline - ).format( - 'DD/MM/YYYY-HH:MM' - ) - : 'no deadline'} - - )} - + + {assignment && assignment.deadline + ? dayjs( + assignment.deadline + ).format( + 'DD/MM/YYYY HH:mm' + ) + : t('no_deadline')} + )} @@ -837,6 +828,7 @@ export function AssignmentPage() { : students } text="group_members" + noGroup={students.length == 0} /> )} @@ -877,7 +869,7 @@ export function AssignmentPage() { ? dayjs( assignment.extra_deadline ).format( - 'DD/MM/YYYY-HH:MM' + 'DD/MM/YYYY HH:mm' ) : 'no deadline'} @@ -1058,16 +1050,8 @@ export function AssignmentPage() { - submission.indiening_id - ) - ) + - 1 + submissions.length - + index ).toString()} timestamp={dayjs( submission.tijdstip diff --git a/frontend/frontend/src/pages/loginPage/LoginPage.tsx b/frontend/frontend/src/pages/loginPage/LoginPage.tsx index ff1e209a..28b4cb29 100644 --- a/frontend/frontend/src/pages/loginPage/LoginPage.tsx +++ b/frontend/frontend/src/pages/loginPage/LoginPage.tsx @@ -81,7 +81,7 @@ export function LoginPage() { alignSelf={'center'} >