diff --git a/components/publisher/PublisherShiftsModal.js b/components/publisher/PublisherShiftsModal.js index 55d31d6..9b61cff 100644 --- a/components/publisher/PublisherShiftsModal.js +++ b/components/publisher/PublisherShiftsModal.js @@ -1,16 +1,22 @@ -//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)); +import React, { useEffect } from 'react'; +import Link from 'next/link'; +import common from 'src/helpers/common'; + +const PublisherShiftsModal = ({ publisher, shifts, onClose, date }) => { + + //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 + + const monthInfo = common.getMonthDatesInfo(new Date(date)); 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); + return common.getStartOfWeek(date) <= shiftDate && shiftDate <= common.getEndOfWeek(date); }); const dayShifts = weekShifts.map(shift => { - const isAvailable = publisher.availabilities?.some(avail => + const isAvailable = publisher?.availabilities?.some(avail => avail.startTime <= shift.startTime && avail.endTime >= shift.endTime ); let color = isAvailable ? getColorForShift(shift) : 'bg-gray-300'; @@ -113,12 +119,12 @@ function PublisherShiftsModal({ publisher, shifts, onClose }) { × - {/* */} {/* Edit button in the top right corner, next to the close button */} - + @@ -126,3 +132,17 @@ function PublisherShiftsModal({ publisher, shifts, onClose }) { ); } + +function getColorForShift(shift) { + const assignedCount = shift.assignedCount || 0; // Assuming each shift has an assignedCount property + switch (assignedCount) { + case 0: return 'bg-blue-300'; + case 1: return 'bg-green-300'; + case 2: return 'bg-yellow-300'; + case 3: return 'bg-orange-300'; + case 4: return 'bg-red-200'; + default: return 'bg-gray-300'; + } +} + +export default PublisherShiftsModal; \ No newline at end of file diff --git a/pages/api/schedule.ts b/pages/api/schedule.ts index b723095..51d5c50 100644 --- a/pages/api/schedule.ts +++ b/pages/api/schedule.ts @@ -93,7 +93,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const shifts = await prisma.shift.findMany({ where: { isActive: true, - isPublished: true, + OR: [ + { isPublished: true }, + { user: { role: 'admin' } } // Todo: example. fix this + ], startTime: { gte: fromDate, //lt: toDate, diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx index 5f0f117..38b2948 100644 --- a/pages/cart/calendar/index.tsx +++ b/pages/cart/calendar/index.tsx @@ -821,8 +821,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { className={`flex justify-between items-center p-4 sm:py-2 rounded-lg shadow-sm mb-2 ${bgAndBorderColorClass} ${selectedBorderClass} ${activeOpacityClass} ${pub.currentMonthAssignments === pub.desiredShiftsPerMonth ? 'text-gray-400' : pub.currentMonthAssignments > pub.desiredShiftsPerMonth ? 'text-orange-300' : 'text-gray-800'}`} - onDoubleClick={(handlePublisherModalOpen.bind(this, pub))} - onClick={handleSelectedPublisher.bind(this, pub)} + onDoubleClick={() => handlePublisherModalOpen(pub)} > {pub.firstName} {pub.lastName} @@ -838,11 +837,10 @@ export default function CalendarPage({ initialEvents, initialShifts }) { - ); @@ -881,24 +879,21 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
{/* */}
- {isModalOpen && setIsModalOpen(false)} />} + {isModalOpen && ( + setIsModalOpen(false)} + date={value} + /> + )} ); - function getColorForShift(shift) { - const assignedCount = shift.assignedCount || 0; // Assuming each shift has an assignedCount property - switch (assignedCount) { - case 0: return 'bg-blue-300'; - case 1: return 'bg-green-300'; - case 2: return 'bg-yellow-300'; - case 3: return 'bg-orange-300'; - case 4: return 'bg-red-200'; - default: return 'bg-gray-300'; - } - } + } import axiosServer from '../../../src/axiosServer';