mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-06 13:11:25 +00:00
fix: Mise à jour des plannings
This commit is contained in:
@ -13,7 +13,7 @@ import { getWeekEvents } from '@/utils/events';
|
||||
import { CalendarDays, ChevronLeft, ChevronRight, Plus } from 'lucide-react';
|
||||
|
||||
const DayView = ({ onDateClick, onEventClick, events, onOpenDrawer }) => {
|
||||
const { currentDate, setCurrentDate, parentView } = usePlanning();
|
||||
const { currentDate, setCurrentDate, parentView, schedules } = usePlanning();
|
||||
const [currentTime, setCurrentTime] = useState(new Date());
|
||||
const scrollRef = useRef(null);
|
||||
|
||||
@ -43,11 +43,28 @@ const DayView = ({ onDateClick, onEventClick, events, onOpenDrawer }) => {
|
||||
return `${(hours + minutes / 60) * 5}rem`;
|
||||
};
|
||||
|
||||
const getScheduleColor = (event) => {
|
||||
const schedule = schedules?.find(
|
||||
(item) => Number(item.id) === Number(event.planning)
|
||||
);
|
||||
return schedule?.color || event.color || '#6B7280';
|
||||
};
|
||||
|
||||
const getScheduleClassLevelLabel = (event) => {
|
||||
const schedule = schedules?.find(
|
||||
(item) => Number(item.id) === Number(event.planning)
|
||||
);
|
||||
const scheduleName = schedule?.name || '';
|
||||
if (!scheduleName) return '';
|
||||
return scheduleName;
|
||||
};
|
||||
|
||||
const calculateEventStyle = (event, allDayEvents) => {
|
||||
const start = new Date(event.start);
|
||||
const end = new Date(event.end);
|
||||
const startMinutes = (start.getMinutes() / 60) * 5;
|
||||
const duration = ((end - start) / (1000 * 60 * 60)) * 5;
|
||||
const scheduleColor = getScheduleColor(event);
|
||||
|
||||
const overlapping = allDayEvents.filter((other) => {
|
||||
if (other.id === event.id) return false;
|
||||
@ -179,8 +196,11 @@ const DayView = ({ onDateClick, onEventClick, events, onOpenDrawer }) => {
|
||||
>
|
||||
{dayEvents
|
||||
.filter((e) => new Date(e.start).getHours() === hour)
|
||||
.map((event) => (
|
||||
<div
|
||||
.map((event) => {
|
||||
const scheduleColor = getScheduleColor(event);
|
||||
const classLevelLabel = getScheduleClassLevelLabel(event);
|
||||
return (
|
||||
<div
|
||||
key={event.id}
|
||||
className="rounded-sm overflow-hidden cursor-pointer hover:shadow-lg"
|
||||
style={calculateEventStyle(event, dayEvents)}
|
||||
@ -192,32 +212,53 @@ const DayView = ({ onDateClick, onEventClick, events, onOpenDrawer }) => {
|
||||
onEventClick(event);
|
||||
}
|
||||
}
|
||||
>
|
||||
<div className="p-1">
|
||||
<div
|
||||
className="font-semibold text-xs truncate"
|
||||
style={{ color: event.color }}
|
||||
>
|
||||
{event.title}
|
||||
</div>
|
||||
<div
|
||||
className="text-xs"
|
||||
style={{ color: event.color, opacity: 0.75 }}
|
||||
>
|
||||
{format(new Date(event.start), 'HH:mm')} –{' '}
|
||||
{format(new Date(event.end), 'HH:mm')}
|
||||
</div>
|
||||
{event.location && (
|
||||
>
|
||||
{classLevelLabel && (
|
||||
<div
|
||||
className="text-xs truncate"
|
||||
style={{ color: event.color, opacity: 0.75 }}
|
||||
className="px-1 py-0.5 border-t-2"
|
||||
style={{
|
||||
borderTopColor: scheduleColor,
|
||||
backgroundColor: `${scheduleColor}22`,
|
||||
}}
|
||||
>
|
||||
{event.location}
|
||||
<span
|
||||
className="text-[10px] font-semibold uppercase tracking-wide truncate block text-center"
|
||||
style={{ color: scheduleColor }}
|
||||
>
|
||||
{classLevelLabel}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="p-1">
|
||||
<div
|
||||
className="font-semibold text-xs truncate flex items-center gap-1"
|
||||
style={{ color: event.color }}
|
||||
>
|
||||
<span
|
||||
className="w-2 h-2 rounded-full shrink-0"
|
||||
style={{ backgroundColor: event.color }}
|
||||
/>
|
||||
<span className="truncate flex-1">{event.title}</span>
|
||||
</div>
|
||||
<div
|
||||
className="text-xs"
|
||||
style={{ color: event.color, opacity: 0.75 }}
|
||||
>
|
||||
{format(new Date(event.start), 'HH:mm')} –{' '}
|
||||
{format(new Date(event.end), 'HH:mm')}
|
||||
</div>
|
||||
{event.location && (
|
||||
<div
|
||||
className="text-xs truncate"
|
||||
style={{ color: event.color, opacity: 0.75 }}
|
||||
>
|
||||
{event.location}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</React.Fragment>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user