From faa00ab353aa594a033370fc23f57ad41cdd4be7 Mon Sep 17 00:00:00 2001 From: adam-skowronek Date: Thu, 24 Nov 2022 20:31:47 +0100 Subject: [PATCH] Add availabilities for coordinator --- frontend/src/App.tsx | 10 +++ frontend/src/api/schedule.ts | 16 ++++ .../coordinator/AvailabilitySchedule.tsx | 79 +++++++++++++++++++ .../src/views/coordinator/Coordinator.tsx | 1 + .../coordinator/SupervisorAvailabilities.tsx | 24 ++++++ .../views/supervisor/SupervisorSchedule.tsx | 4 +- 6 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 frontend/src/views/coordinator/AvailabilitySchedule.tsx create mode 100644 frontend/src/views/coordinator/SupervisorAvailabilities.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 07077de..79d8023 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -21,6 +21,8 @@ import StudentSchedules from './views/student/StudentSchedules' import StudentSchedule from './views/student/StudentSchedule' import SupervisorSchedule from './views/supervisor/SupervisorSchedule' import Home from './views/coordinator/Home' +import SupervisorAvailabilities from './views/coordinator/SupervisorAvailabilities' +import AvailabilitySchedule from './views/coordinator/AvailabilitySchedule' const queryClient = new QueryClient({ defaultOptions: { @@ -46,6 +48,14 @@ function App() { } /> } /> } /> + } + /> + } + /> }> } /> diff --git a/frontend/src/api/schedule.ts b/frontend/src/api/schedule.ts index b083cb9..1b7428a 100644 --- a/frontend/src/api/schedule.ts +++ b/frontend/src/api/schedule.ts @@ -1,4 +1,5 @@ import axiosInstance from './axiosInstance' +import { Leader } from './leaders' import { Student } from './students' interface TermOfDefences { @@ -48,6 +49,17 @@ export const getAvailabilityForSupervisor = (scheduleId: number) => { }>(`project_supervisor/${scheduleId}/temporary-availabilities?id=1`) //fix hardcode id } +export const getAvailabilityForCoordinator = (scheduleId: number) => { + return axiosInstance.get<{ + temporary_availabilities: { + id: number + start_date: string + end_date: string + project_supervisor: Leader + }[] + }>(`coordinator/enrollments/${scheduleId}/temporary-availabilities`) +} + export const getSchedules = (year_group_id: number = 1) => { return axiosInstance.get<{ examination_schedules: { @@ -175,3 +187,7 @@ export const setDateOfExaminationSchedule = ( payload, ) } + +export const generateTermsOfDefence = (scheduleId: number) => { + return axiosInstance.post(`coordinator/enrollments/${scheduleId}/generate`) +} diff --git a/frontend/src/views/coordinator/AvailabilitySchedule.tsx b/frontend/src/views/coordinator/AvailabilitySchedule.tsx new file mode 100644 index 0000000..34ed1a2 --- /dev/null +++ b/frontend/src/views/coordinator/AvailabilitySchedule.tsx @@ -0,0 +1,79 @@ +import { Calendar, luxonLocalizer, Views } from 'react-big-calendar' +import { DateTime, Settings } from 'luxon' +import { useCallback, useState } from 'react' +import { useMutation, useQuery } from 'react-query' +import { useParams } from 'react-router-dom' +import useLocalStorageState from 'use-local-storage-state' +import bigCalendarTranslations from '../../utils/bigCalendarTranslations' +import { + generateTermsOfDefence, + getAvailabilityForCoordinator, +} from '../../api/schedule' + +const SupervisorSchedule = () => { + Settings.defaultZone = DateTime.local().zoneName + Settings.defaultLocale = 'pl' + + const { id } = useParams<{ id: string }>() + const [yearGroupId] = useLocalStorageState('yearGroupId') + const [supervisorId] = useLocalStorageState('supervisorId') + const [events, setEvents] = useState< + { + id: number + title: string + start: Date + end: Date + resource: any + }[] + >([]) + const [view, setView] = useState(Views.MONTH) + const onView = useCallback((newView: any) => setView(newView), [setView]) + + useQuery(['availability'], () => getAvailabilityForCoordinator(Number(id)), { + onSuccess: (data) => { + setEvents([ + ...events, + ...data.data.temporary_availabilities.map( + ({ id, start_date, end_date, project_supervisor }) => { + return { + id, + title: `${project_supervisor.first_name} ${project_supervisor.last_name}`, + start: new Date(start_date), + end: new Date(end_date), + resource: {}, + } + }, + ), + ]) + }, + }) + + const { mutate: mutateGenerate } = useMutation(['generateTerms'], () => + generateTermsOfDefence(Number(id)), + ) + + return ( +
+ + +
+ ) +} + +export default SupervisorSchedule diff --git a/frontend/src/views/coordinator/Coordinator.tsx b/frontend/src/views/coordinator/Coordinator.tsx index 54015c9..e98344d 100644 --- a/frontend/src/views/coordinator/Coordinator.tsx +++ b/frontend/src/views/coordinator/Coordinator.tsx @@ -11,6 +11,7 @@ const Coordinator = () => { { name: 'Studenci', path: '/coordinator/students' }, { name: 'Opiekunowie', path: '/coordinator/leaders' }, { name: 'Harmonogram', path: '/coordinator/schedule' }, + { name: 'Dostępność', path: '/coordinator/supervisors_availability' }, ]} />
diff --git a/frontend/src/views/coordinator/SupervisorAvailabilities.tsx b/frontend/src/views/coordinator/SupervisorAvailabilities.tsx new file mode 100644 index 0000000..dbfe14c --- /dev/null +++ b/frontend/src/views/coordinator/SupervisorAvailabilities.tsx @@ -0,0 +1,24 @@ +import { useQuery } from 'react-query' +import { getSchedules } from '../../api/schedule' +import { Link } from 'react-router-dom' + +const SupervisorAvailabilities = () => { + const { data: schedules } = useQuery(['getSchedules'], () => getSchedules()) + + return ( +
+

Wybierz zapisy:

+ {schedules && + schedules?.data?.examination_schedules.map((schedule) => ( +

+ -{' '} + + {schedule.title} + +

+ ))} +
+ ) +} + +export default SupervisorAvailabilities diff --git a/frontend/src/views/supervisor/SupervisorSchedule.tsx b/frontend/src/views/supervisor/SupervisorSchedule.tsx index 7705d06..4715d1a 100644 --- a/frontend/src/views/supervisor/SupervisorSchedule.tsx +++ b/frontend/src/views/supervisor/SupervisorSchedule.tsx @@ -64,7 +64,7 @@ const SupervisorSchedule = () => { to: string }>({ mode: 'onBlur' }) - const { refetch, isSuccess } = useQuery( + const { refetch, isFetching } = useQuery( ['schedules'], () => getSupervisorTermsOfDefences(Number(id)), { @@ -113,7 +113,7 @@ const SupervisorSchedule = () => { }), ]) }, - enabled: isSuccess, + enabled: !isFetching, }, ) const { mutateAsync: mutateAddAvailability } = useMutation(