mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-05 12:41:27 +00:00
fix: sélection enseignants dans les plannings
This commit is contained in:
@ -60,12 +60,8 @@ export default function Page() {
|
|||||||
const scheduleClasses = classes.filter(
|
const scheduleClasses = classes.filter(
|
||||||
(classe) => classe?.school_year === currentSchoolYear
|
(classe) => classe?.school_year === currentSchoolYear
|
||||||
);
|
);
|
||||||
const scheduleSpecialities = specialities.filter(
|
const scheduleSpecialities = specialities;
|
||||||
(speciality) => speciality?.school_year === currentSchoolYear
|
const scheduleTeachers = teachers;
|
||||||
);
|
|
||||||
const scheduleTeachers = teachers.filter(
|
|
||||||
(teacher) => teacher?.school_year === currentSchoolYear
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEstablishmentId) {
|
if (selectedEstablishmentId) {
|
||||||
|
|||||||
@ -180,7 +180,7 @@ const DayView = ({ onDateClick, onEventClick, events, onOpenDrawer }) => {
|
|||||||
{`${hour.toString().padStart(2, '0')}:00`}
|
{`${hour.toString().padStart(2, '0')}:00`}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`h-20 relative border-b border-gray-100 ${
|
className={`h-20 relative ${
|
||||||
isCurrentDay ? 'bg-primary/5/30' : 'bg-white'
|
isCurrentDay ? 'bg-primary/5/30' : 'bg-white'
|
||||||
}`}
|
}`}
|
||||||
onClick={
|
onClick={
|
||||||
|
|||||||
@ -54,6 +54,8 @@ const WeekView = ({ onDateClick, onEventClick, events }) => {
|
|||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
|
const todayIndex = weekDays.findIndex((day) => isToday(day));
|
||||||
|
|
||||||
const isWeekend = (date) => {
|
const isWeekend = (date) => {
|
||||||
const day = date.getDay();
|
const day = date.getDay();
|
||||||
return day === 0 || day === 6;
|
return day === 0 || day === 6;
|
||||||
@ -212,6 +214,16 @@ const WeekView = ({ onDateClick, onEventClick, events }) => {
|
|||||||
|
|
||||||
{/* Grille horaire */}
|
{/* Grille horaire */}
|
||||||
<div ref={scrollContainerRef} className="flex-1 relative">
|
<div ref={scrollContainerRef} className="flex-1 relative">
|
||||||
|
{isCurrentWeek && todayIndex >= 0 && (
|
||||||
|
<div
|
||||||
|
className="absolute top-0 bottom-0 z-[5] border-x border-primary pointer-events-none"
|
||||||
|
style={{
|
||||||
|
left: `calc(2.5rem + ((100% - 2.5rem) / 7) * ${todayIndex})`,
|
||||||
|
width: 'calc((100% - 2.5rem) / 7)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Ligne de temps actuelle */}
|
{/* Ligne de temps actuelle */}
|
||||||
{isCurrentWeek && (
|
{isCurrentWeek && (
|
||||||
<div
|
<div
|
||||||
@ -241,7 +253,7 @@ const WeekView = ({ onDateClick, onEventClick, events }) => {
|
|||||||
key={`${hour}-${day}`}
|
key={`${hour}-${day}`}
|
||||||
className={`h-20 relative border-b border-gray-100
|
className={`h-20 relative border-b border-gray-100
|
||||||
${isWeekend(day) ? 'bg-gray-50' : 'bg-white'}
|
${isWeekend(day) ? 'bg-gray-50' : 'bg-white'}
|
||||||
${isToday(day) ? 'bg-primary/10/50 border-x border-primary' : ''}`}
|
${isToday(day) ? 'bg-primary/10/50' : ''}`}
|
||||||
onClick={
|
onClick={
|
||||||
parentView
|
parentView
|
||||||
? undefined
|
? undefined
|
||||||
|
|||||||
@ -22,6 +22,66 @@ export default function ScheduleEventModal({
|
|||||||
usePlanning();
|
usePlanning();
|
||||||
const { showNotification } = useNotification();
|
const { showNotification } = useNotification();
|
||||||
|
|
||||||
|
const selectedPlanning = React.useMemo(() => {
|
||||||
|
return schedules.find(
|
||||||
|
(schedule) => Number(schedule.id) === Number(eventData?.planning)
|
||||||
|
);
|
||||||
|
}, [schedules, eventData?.planning]);
|
||||||
|
|
||||||
|
const selectedClass = React.useMemo(() => {
|
||||||
|
if (!selectedPlanning?.school_class) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return classes.find(
|
||||||
|
(schoolClass) =>
|
||||||
|
Number(schoolClass.id) === Number(selectedPlanning.school_class)
|
||||||
|
);
|
||||||
|
}, [classes, selectedPlanning]);
|
||||||
|
|
||||||
|
const classTeachers = React.useMemo(() => {
|
||||||
|
if (!selectedClass) {
|
||||||
|
return teachers;
|
||||||
|
}
|
||||||
|
|
||||||
|
const classTeacherIds = [
|
||||||
|
...(Array.isArray(selectedClass.teachers) ? selectedClass.teachers : []),
|
||||||
|
...((selectedClass.teachers_details || []).map((teacher) => teacher.id) || []),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (classTeacherIds.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const classTeacherIdSet = new Set(classTeacherIds.map((id) => Number(id)));
|
||||||
|
return teachers.filter((teacher) => classTeacherIdSet.has(Number(teacher.id)));
|
||||||
|
}, [teachers, selectedClass]);
|
||||||
|
|
||||||
|
const classSpecialities = React.useMemo(() => {
|
||||||
|
const specialityMap = new Map();
|
||||||
|
|
||||||
|
classTeachers.forEach((teacher) => {
|
||||||
|
(teacher.specialities_details || []).forEach((speciality) => {
|
||||||
|
specialityMap.set(Number(speciality.id), speciality);
|
||||||
|
});
|
||||||
|
|
||||||
|
(teacher.specialities || []).forEach((specialityId) => {
|
||||||
|
if (specialityMap.has(Number(specialityId))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const speciality = specialities.find(
|
||||||
|
(item) => Number(item.id) === Number(specialityId)
|
||||||
|
);
|
||||||
|
if (speciality) {
|
||||||
|
specialityMap.set(Number(speciality.id), speciality);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return Array.from(specialityMap.values());
|
||||||
|
}, [classTeachers, specialities]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!eventData?.planning && schedules.length > 0) {
|
if (!eventData?.planning && schedules.length > 0) {
|
||||||
const defaultSchedule =
|
const defaultSchedule =
|
||||||
@ -37,9 +97,35 @@ export default function ScheduleEventModal({
|
|||||||
}
|
}
|
||||||
}, [schedules, selectedSchedule, eventData?.planning]);
|
}, [schedules, selectedSchedule, eventData?.planning]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (
|
||||||
|
eventData?.teacher &&
|
||||||
|
!classTeachers.some(
|
||||||
|
(teacher) => Number(teacher.id) === Number(eventData.teacher)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
setEventData((prev) => ({
|
||||||
|
...prev,
|
||||||
|
teacher: '',
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
eventData?.speciality &&
|
||||||
|
!classSpecialities.some(
|
||||||
|
(speciality) => Number(speciality.id) === Number(eventData.speciality)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
setEventData((prev) => ({
|
||||||
|
...prev,
|
||||||
|
speciality: '',
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [classTeachers, classSpecialities, eventData?.teacher, eventData?.speciality]);
|
||||||
|
|
||||||
const handleSpecialityChange = (specialityId) => {
|
const handleSpecialityChange = (specialityId) => {
|
||||||
const selectedSpeciality = specialities.find(
|
const selectedSpeciality = classSpecialities.find(
|
||||||
(s) => s.id === parseInt(specialityId, 10)
|
(s) => Number(s.id) === Number(specialityId)
|
||||||
);
|
);
|
||||||
if (selectedSpeciality) {
|
if (selectedSpeciality) {
|
||||||
setEventData((prev) => ({
|
setEventData((prev) => ({
|
||||||
@ -52,8 +138,8 @@ export default function ScheduleEventModal({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleTeacherChange = (teacherId) => {
|
const handleTeacherChange = (teacherId) => {
|
||||||
const selectedTeacher = teachers.find(
|
const selectedTeacher = classTeachers.find(
|
||||||
(t) => t.id === parseInt(teacherId, 10)
|
(t) => Number(t.id) === Number(teacherId)
|
||||||
);
|
);
|
||||||
if (selectedTeacher) {
|
if (selectedTeacher) {
|
||||||
setEventData((prev) => ({
|
setEventData((prev) => ({
|
||||||
@ -66,7 +152,7 @@ export default function ScheduleEventModal({
|
|||||||
|
|
||||||
const handlePlanningChange = (planningId) => {
|
const handlePlanningChange = (planningId) => {
|
||||||
const selectedSchedule = schedules.find(
|
const selectedSchedule = schedules.find(
|
||||||
(s) => s.id === parseInt(planningId, 10)
|
(s) => Number(s.id) === Number(planningId)
|
||||||
);
|
);
|
||||||
if (selectedSchedule) {
|
if (selectedSchedule) {
|
||||||
setEventData((prev) => ({
|
setEventData((prev) => ({
|
||||||
@ -185,7 +271,7 @@ export default function ScheduleEventModal({
|
|||||||
<option value="" disabled>
|
<option value="" disabled>
|
||||||
Sélectionnez une matière
|
Sélectionnez une matière
|
||||||
</option>
|
</option>
|
||||||
{specialities.map((speciality) => (
|
{classSpecialities.map((speciality) => (
|
||||||
<option key={speciality.id} value={speciality.id}>
|
<option key={speciality.id} value={speciality.id}>
|
||||||
{speciality.name}
|
{speciality.name}
|
||||||
</option>
|
</option>
|
||||||
@ -207,7 +293,7 @@ export default function ScheduleEventModal({
|
|||||||
<option value="" disabled>
|
<option value="" disabled>
|
||||||
Sélectionnez un professeur
|
Sélectionnez un professeur
|
||||||
</option>
|
</option>
|
||||||
{teachers.map((teacher) => (
|
{classTeachers.map((teacher) => (
|
||||||
<option key={teacher.id} value={teacher.id}>
|
<option key={teacher.id} value={teacher.id}>
|
||||||
{`${teacher.first_name} ${teacher.last_name}`}
|
{`${teacher.first_name} ${teacher.last_name}`}
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user