fix statistics;
rewrite availability filters; fix availability filters; ProtectedRoute.IsInRole helper
This commit is contained in:
@@ -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");
|
||||
|
@@ -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;
|
||||
};
|
@@ -114,7 +114,7 @@ function ConfirmationModal({ isOpen, onClose, onConfirm, subscribedPublishers, a
|
||||
checked={selectedGroups.includes('availablePublishers')}
|
||||
onChange={() => handleToggleGroup('availablePublishers')}
|
||||
/>
|
||||
<span className="text-sm font-medium">На разположение:</span>
|
||||
<span className="text-sm font-medium">На разположение :</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap">
|
||||
{availablePublishers.map(pub => (
|
||||
|
Reference in New Issue
Block a user