//Refactor ToDo: show the whole month instead of just the current week by showing the shift start time in front of the rows, and show all shifts in the month from the first to the last week in the cell where we show one shift now function PublisherShiftsModal({ publisher, shifts, onClose }) { const monthInfo = common.getMonthDatesInfo(new Date(value)); const monthShifts = shifts.filter(shift => { const shiftDate = new Date(shift.startTime); return shiftDate > monthInfo.firstDay && shiftDate < monthInfo.lastDay; }); const weekShifts = monthShifts.filter(shift => { const shiftDate = new Date(shift.startTime); return common.getStartOfWeek(value) <= shiftDate && shiftDate <= common.getEndOfWeek(value); }); const dayShifts = weekShifts.map(shift => { const isAvailable = publisher.availabilities?.some(avail => avail.startTime <= shift.startTime && avail.endTime >= shift.endTime ); let color = isAvailable ? getColorForShift(shift) : 'bg-gray-300'; if (shift.isFromPreviousMonth) { color += ' border-l-4 border-orange-500 '; } if (shift.isFromPreviousAssignment) { color += ' border-l-4 border-red-500 '; } return { ...shift, isAvailable, color }; }).reduce((acc, shift) => { const dayIndex = new Date(shift.startTime).getDay(); acc[dayIndex] = acc[dayIndex] || []; acc[dayIndex].push(shift); return acc; }, {}); console.log("dayShifts:", dayShifts); const hasAssignment = (shiftId) => { // return publisher.assignments.some(ass => ass.shift.id == shiftId); return publisher.assignments?.some(ass => { //console.log(`Comparing: ${ass.shift.id} to ${shiftId}: ${ass.shift.id === shiftId}`); return ass.shift.id === shiftId; }); }; useEffect(() => { const handleKeyDown = (event) => { if (event.key === 'Escape') { console.log('ESC: closing modal.'); onClose(); // Call the onClose function when ESC key is pressed } }; // Add event listener window.addEventListener('keydown', handleKeyDown); // Remove event listener on cleanup return () => { window.removeEventListener('keydown', handleKeyDown); }; }, [onClose]); // Include onClose in the dependency array return (

График на {publisher.firstName} {publisher.lastName} {publisher.email} тази седмица:

{/* ... Display shifts in a calendar-like UI ... */}
{Object.entries(dayShifts).map(([dayIndex, shiftsForDay]) => (
{/* Day header */}
{new Date(shiftsForDay[0].startTime).getDate()}-ти
{shiftsForDay.map((shift, index) => { const assignmentExists = hasAssignment(shift.id); const availability = publisher.availabilities.find(avail => avail.startTime <= shift.startTime && avail.endTime >= shift.endTime ); const isFromPrevMonth = availability && availability.isFromPreviousMonth; return (
{common.getTimeRange(shift.startTime, shift.endTime)} {shift.id} {!assignmentExists && shift.isAvailable && ( )} {assignmentExists && ( )}
); } )}
))}
{/* Close button in the top right corner */} {/* */} {/* Edit button in the top right corner, next to the close button */}
); }