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(
|
||||
(classe) => classe?.school_year === currentSchoolYear
|
||||
);
|
||||
const scheduleSpecialities = specialities.filter(
|
||||
(speciality) => speciality?.school_year === currentSchoolYear
|
||||
);
|
||||
const scheduleTeachers = teachers.filter(
|
||||
(teacher) => teacher?.school_year === currentSchoolYear
|
||||
);
|
||||
const scheduleSpecialities = specialities;
|
||||
const scheduleTeachers = teachers;
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedEstablishmentId) {
|
||||
|
||||
@ -180,7 +180,7 @@ const DayView = ({ onDateClick, onEventClick, events, onOpenDrawer }) => {
|
||||
{`${hour.toString().padStart(2, '0')}:00`}
|
||||
</div>
|
||||
<div
|
||||
className={`h-20 relative border-b border-gray-100 ${
|
||||
className={`h-20 relative ${
|
||||
isCurrentDay ? 'bg-primary/5/30' : 'bg-white'
|
||||
}`}
|
||||
onClick={
|
||||
|
||||
@ -54,6 +54,8 @@ const WeekView = ({ onDateClick, onEventClick, events }) => {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const todayIndex = weekDays.findIndex((day) => isToday(day));
|
||||
|
||||
const isWeekend = (date) => {
|
||||
const day = date.getDay();
|
||||
return day === 0 || day === 6;
|
||||
@ -212,6 +214,16 @@ const WeekView = ({ onDateClick, onEventClick, events }) => {
|
||||
|
||||
{/* Grille horaire */}
|
||||
<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 */}
|
||||
{isCurrentWeek && (
|
||||
<div
|
||||
@ -241,7 +253,7 @@ const WeekView = ({ onDateClick, onEventClick, events }) => {
|
||||
key={`${hour}-${day}`}
|
||||
className={`h-20 relative border-b border-gray-100
|
||||
${isWeekend(day) ? 'bg-gray-50' : 'bg-white'}
|
||||
${isToday(day) ? 'bg-primary/10/50 border-x border-primary' : ''}`}
|
||||
${isToday(day) ? 'bg-primary/10/50' : ''}`}
|
||||
onClick={
|
||||
parentView
|
||||
? undefined
|
||||
|
||||
@ -22,6 +22,66 @@ export default function ScheduleEventModal({
|
||||
usePlanning();
|
||||
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(() => {
|
||||
if (!eventData?.planning && schedules.length > 0) {
|
||||
const defaultSchedule =
|
||||
@ -37,9 +97,35 @@ export default function ScheduleEventModal({
|
||||
}
|
||||
}, [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 selectedSpeciality = specialities.find(
|
||||
(s) => s.id === parseInt(specialityId, 10)
|
||||
const selectedSpeciality = classSpecialities.find(
|
||||
(s) => Number(s.id) === Number(specialityId)
|
||||
);
|
||||
if (selectedSpeciality) {
|
||||
setEventData((prev) => ({
|
||||
@ -52,8 +138,8 @@ export default function ScheduleEventModal({
|
||||
};
|
||||
|
||||
const handleTeacherChange = (teacherId) => {
|
||||
const selectedTeacher = teachers.find(
|
||||
(t) => t.id === parseInt(teacherId, 10)
|
||||
const selectedTeacher = classTeachers.find(
|
||||
(t) => Number(t.id) === Number(teacherId)
|
||||
);
|
||||
if (selectedTeacher) {
|
||||
setEventData((prev) => ({
|
||||
@ -66,7 +152,7 @@ export default function ScheduleEventModal({
|
||||
|
||||
const handlePlanningChange = (planningId) => {
|
||||
const selectedSchedule = schedules.find(
|
||||
(s) => s.id === parseInt(planningId, 10)
|
||||
(s) => Number(s.id) === Number(planningId)
|
||||
);
|
||||
if (selectedSchedule) {
|
||||
setEventData((prev) => ({
|
||||
@ -185,7 +271,7 @@ export default function ScheduleEventModal({
|
||||
<option value="" disabled>
|
||||
Sélectionnez une matière
|
||||
</option>
|
||||
{specialities.map((speciality) => (
|
||||
{classSpecialities.map((speciality) => (
|
||||
<option key={speciality.id} value={speciality.id}>
|
||||
{speciality.name}
|
||||
</option>
|
||||
@ -207,7 +293,7 @@ export default function ScheduleEventModal({
|
||||
<option value="" disabled>
|
||||
Sélectionnez un professeur
|
||||
</option>
|
||||
{teachers.map((teacher) => (
|
||||
{classTeachers.map((teacher) => (
|
||||
<option key={teacher.id} value={teacher.id}>
|
||||
{`${teacher.first_name} ${teacher.last_name}`}
|
||||
</option>
|
||||
|
||||
Reference in New Issue
Block a user