Update schedule components

This commit is contained in:
adam-skowronek 2022-11-24 20:00:09 +01:00
parent dd116962e6
commit ee8563fedb
7 changed files with 91 additions and 32 deletions

View File

@ -1,4 +1,5 @@
import axiosInstance from './axiosInstance'
import { Student } from './students'
interface TermOfDefences {
id: number
@ -8,7 +9,7 @@ interface TermOfDefences {
members_of_committee: {
members: { first_name: string; last_name: string }[]
}
group: { name: string }
group: { name: string; students: Student[] }
}
export const getTermsOfDefences = (scheduleId: number) => {
@ -16,6 +17,13 @@ export const getTermsOfDefences = (scheduleId: number) => {
term_of_defences: TermOfDefences[]
}>(`coordinator/enrollments/${scheduleId}/term-of-defences/`)
}
export const getTermsOfDefencesWithGroups = (scheduleId: number) => {
return axiosInstance.get<{
term_of_defences: TermOfDefences[]
}>(
`coordinator/enrollments/${scheduleId}/assigned-group-to-term-of-defences/`,
)
}
export const getStudentsTermsOfDefences = (
scheduleId: number,

View File

@ -89,7 +89,19 @@ const EditSchedule = ({
))}
</ul>
{eventData.resource.group && (
<>
<p className="mt-4">Grupa: {eventData.resource.group.name}</p>
<ul className="list-disc">
{eventData.resource.group.students?.map((member: any) => (
<li
key={`${member.first_name} ${member.last_name}`}
className="ml-4"
>
{member.first_name} {member.last_name}
</li>
))}
</ul>
</>
)}
</>
) : (

View File

@ -6,6 +6,7 @@ import {
createEvent,
downloadSchedule,
getTermsOfDefences,
getTermsOfDefencesWithGroups,
setDateOfExaminationSchedule,
} from '../../api/schedule'
import { useParams } from 'react-router-dom'
@ -92,11 +93,12 @@ const Schedule = () => {
},
)
const { refetch } = useQuery(
const { refetch, isFetching } = useQuery(
['schedules'],
() => getTermsOfDefences(Number(id)),
{
onSuccess: (data) => {
onSettled: (data) => {
if (data) {
setEvents(
data.data.term_of_defences.map(
({
@ -114,14 +116,41 @@ const Schedule = () => {
end: new Date(end_date),
resource: {
members_of_committee,
group,
},
}
},
),
)
}
},
},
)
const { refetch: refetchWithGroups } = useQuery(
['schedules_groups'],
() => getTermsOfDefencesWithGroups(Number(id)),
{
onSettled: (data) => {
data?.data.term_of_defences.forEach((term) => {
const index = events.findIndex((event) => event.id === term.id)
if (index !== -1) {
const eventsCopy = [...events]
eventsCopy[index] = {
...eventsCopy[index],
resource: {
...eventsCopy[index].resource,
group: term.group,
},
}
setEvents(eventsCopy)
}
})
},
enabled: !isFetching,
},
)
const { mutateAsync: mutateCreateEvent } = useMutation(
['createEvent'],
(data: {
@ -197,6 +226,7 @@ const Schedule = () => {
project_supervisors: data?.project_supervisors,
})
refetch()
refetchWithGroups()
reset()
closeModal()
}

View File

@ -132,7 +132,7 @@ const Students = () => {
</option>
))}
</select>
<label className="label justify-start gap-2">
{/* <label className="label justify-start gap-2">
<input
type="radio"
className="radio radio-xs md:radio-md"
@ -149,7 +149,7 @@ const Students = () => {
checked={!mode}
/>
<span className="text-xs md:text-base">Niestacjonarni</span>
</label>
</label> */}
<label className="label">
<input
type="checkbox"
@ -172,7 +172,6 @@ const Students = () => {
<th>Nazwisko</th>
<th>Indeks</th>
<th>Zapisany</th>
<th>Tryb</th>
<th></th>
</tr>
</thead>
@ -185,7 +184,6 @@ const Students = () => {
<td>{last_name}</td>
<td>{index}</td>
<td>{group === null ? 'Nie' : 'Tak'}</td>
<td>{mode ? 'Stacjonarny' : 'Niestacjonarny'}</td>
<td>
<button onClick={() => mutateDelete(index)}>
<IconRemove />

View File

@ -8,6 +8,7 @@ import { assignGroup } from '../../api/schedule'
const ScheduleAddGroup = ({
eventData,
scheduleId,
closeModal,
}: {
eventData: {
start: Date
@ -17,6 +18,7 @@ const ScheduleAddGroup = ({
resource: any
}
scheduleId: string
closeModal: () => void
}) => {
const { register, handleSubmit, reset, control } = useForm<{
student_index: number
@ -30,6 +32,11 @@ const ScheduleAddGroup = ({
enrollmentId: number
studentIndex: number
}) => assignGroup(data),
{
onSuccess: () => {
closeModal()
},
},
)
const onSubmit = (data: any) => {

View File

@ -187,7 +187,11 @@ const StudentSchedule = () => {
style={customStyles}
>
{selectedDate && id ? (
<ScheduleAddGroup eventData={selectedDate} scheduleId={id} />
<ScheduleAddGroup
eventData={selectedDate}
scheduleId={id}
closeModal={() => setIsEditModalOpen(false)}
/>
) : null}
</Modal>
</div>

View File

@ -239,7 +239,7 @@ const SupervisorSchedule = () => {
<button className="btn btn-success mt-4">Dodaj dostępność</button>
</form>
</Modal>
<Modal
{/* <Modal
isOpen={isEditModalOpen}
onRequestClose={() => setIsEditModalOpen(false)}
contentLabel="modal"
@ -248,7 +248,7 @@ const SupervisorSchedule = () => {
{selectedDate && id ? (
<EditSchedule eventData={selectedDate} scheduleId={id} />
) : null}
</Modal>
</Modal> */}
</div>
)
}