fix statistics;

rewrite availability filters;
fix availability filters;
ProtectedRoute.IsInRole helper
This commit is contained in:
Dobromir Popov
2024-04-27 15:31:28 +03:00
parent 029a9af390
commit 58ac046ee5
12 changed files with 267 additions and 138 deletions

View File

@ -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");