diff --git a/_doc/ToDo.md b/_doc/ToDo.md
index 123edcb..6b98df9 100644
--- a/_doc/ToDo.md
+++ b/_doc/ToDo.md
@@ -226,7 +226,7 @@ in schedule admin - if a publisher is always pair & family is not in the shift -
last login. pubs.
otchet - za denq
-делете цонфирм
+OK - делете цонфирм
статистика - фкс (янка) + posledno vlizane
заместник, предпочитание в миналото - да не може.
diff --git a/components/calendar/avcalendar.tsx b/components/calendar/avcalendar.tsx
index 258463c..647ce69 100644
--- a/components/calendar/avcalendar.tsx
+++ b/components/calendar/avcalendar.tsx
@@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react';
import { Calendar, momentLocalizer, dateFnsLocalizer } from 'react-big-calendar';
import 'react-big-calendar/lib/css/react-big-calendar.css';
import AvailabilityForm from '../availability/AvailabilityForm';
+import ProtectedRoute from '../protectedRoute';
+import { UserRole } from "@prisma/client";
import common from '../../src/helpers/common';
import { toast } from 'react-toastify';
@@ -16,6 +18,7 @@ import { MdToday } from 'react-icons/md';
import { useSwipeable } from 'react-swipeable';
import axiosInstance from '../../src/axiosSecure';
+
// import { set, format, addDays } from 'date-fns';
// import { isEqual, isSameDay, getHours, getMinutes } from 'date-fns';
import { filter } from 'jszip';
@@ -45,6 +48,8 @@ const messages = {
const AvCalendar = ({ publisherId, events, selectedDate }) => {
+ const isAdmin = ProtectedRoute.IsInRole(UserRole.ADMIN);
+
const [date, setDate] = useState(new Date());
//ToDo: see if we can optimize this
const [evts, setEvents] = useState(events); // Existing events
@@ -211,8 +216,9 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
if (!start || !end) return;
//readonly for past dates (ToDo: if not admin)
- if (startdate < new Date() || end < new Date() || startdate > end) return;
-
+ if (!isAdmin) {
+ if (startdate < new Date() || end < new Date() || startdate > end) return;
+ }
// Check if start and end are on the same day
if (startdate.toDateString() !== enddate.toDateString()) {
end = common.setTimeHHmm(startdate, "23:59");
diff --git a/components/protectedRoute.tsx b/components/protectedRoute.tsx
index 9a9b88a..4c2adc9 100644
--- a/components/protectedRoute.tsx
+++ b/components/protectedRoute.tsx
@@ -68,3 +68,8 @@ export async function serverSideAuth({ req, allowedRoles }) {
// Return the session if the user is authenticated and has the required role
return { session };
}
+// Static method to check if the user has a specific role
+ProtectedRoute.IsInRole = async (roleName) => {
+ const session = await getSession();
+ return session && session.user && session.user.role === roleName;
+};
\ No newline at end of file
diff --git a/components/publisher/SearchReplacement.js b/components/publisher/SearchReplacement.js
index 527cbc0..5d69bf1 100644
--- a/components/publisher/SearchReplacement.js
+++ b/components/publisher/SearchReplacement.js
@@ -114,7 +114,7 @@ function ConfirmationModal({ isOpen, onClose, onConfirm, subscribedPublishers, a
checked={selectedGroups.includes('availablePublishers')}
onChange={() => handleToggleGroup('availablePublishers')}
/>
- На разположение:
+ На разположение :
{availablePublishers.map(pub => (
diff --git a/pages/api/email.ts b/pages/api/email.ts
index facba07..ac5c980 100644
--- a/pages/api/email.ts
+++ b/pages/api/email.ts
@@ -272,7 +272,8 @@ export default async function handler(req, res) {
if (toAvailable) {
- availablePublishers = await data.filterPublishersNew("id,firstName,lastName,email", new Date(assignment.shift.startTime), true, false);
+ availablePublishers = await data.filterPublishersNew("id,firstName,lastName,email", new Date(assignment.shift.startTime),
+ true, false);
}
//concat and remove duplicate emails
diff --git a/pages/api/index.ts b/pages/api/index.ts
index 1f7b7b3..6669608 100644
--- a/pages/api/index.ts
+++ b/pages/api/index.ts
@@ -4,6 +4,7 @@ import { DayOfWeek, AvailabilityType } from '@prisma/client';
const common = require('../../src/helpers/common');
const data = require('../../src/helpers/data');
const subq = require('../../prisma/bl/subqueries');
+import { addMinutes } from 'date-fns';
import fs from 'fs';
import path from 'path';
@@ -350,7 +351,7 @@ export default async function handler(req, res) {
break;
case "getPossibleShiftPublisherEmails":
- const subscribedPublishers = await prisma.publisher.findMany({
+ let subscribedPublishers = await prisma.publisher.findMany({
where: {
isSubscribedToCoverMe: true
},
@@ -373,10 +374,37 @@ export default async function handler(req, res) {
let shift = await prisma.shift.findUnique({
where: {
id: parseInt(req.query.shiftId)
+ },
+ include: {
+ assignments: {
+ include: {
+ publisher: {
+ select: {
+ id: true,
+ firstName: true,
+ lastName: true,
+ email: true
+ }
+ }
+ }
+ }
}
});
- let availablePublishers = await filterPublishersNew_Available("id,firstName,lastName,email", new Date(shift.startTime), true, false);
+ let availableIn = new Date(addMinutes(shift.startTime, 0))
+ let availablePublishers = await filterPublishersNew_Available("id,firstName,lastName,email", availableIn,
+ true, false, false);
+
+ //filter out publishers that are already assigned to the shift
+ availablePublishers = availablePublishers.filter(pub => {
+ return shift.assignments.findIndex(assignment => assignment.publisher.id == pub.id) == -1;
+ });
+ //subscribed list includes only publishers that are not already assigned to the shift
+ subscribedPublishers = subscribedPublishers.filter(pub => {
+ return availablePublishers.findIndex(availablePub => availablePub.id == pub.id) == -1
+ && shift.assignments.findIndex(assignment => assignment.publisher.id == pub.id) == -1;
+ });
//return names and email info only
+
availablePublishers = availablePublishers.map(pub => {
return {
id: pub.id,
diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx
index 5bbb9ae..0ab474b 100644
--- a/pages/cart/calendar/index.tsx
+++ b/pages/cart/calendar/index.tsx
@@ -603,7 +603,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
message="Това ще изпрати имейли до всички участници за смените им през избрания месец. Сигурни ли сте?"
/>