fix and consolidate calendar dates usage and format
This commit is contained in:
@@ -58,7 +58,9 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
|
||||
useEffect(() => {
|
||||
const updatedEvents = events.map(event => ({
|
||||
...event,
|
||||
date: new Date(event.startTime).setHours(0, 0, 0, 0)
|
||||
date: new Date(event.startTime).setHours(0, 0, 0, 0),
|
||||
startTime: new Date(event.startTime),
|
||||
endTime: event.endTime ? new Date(event.endTime) : undefined
|
||||
}));
|
||||
|
||||
setEvents(updatedEvents);
|
||||
@@ -164,12 +166,15 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
|
||||
const totalHours = maxHour - minHour;
|
||||
|
||||
const handleSelect = ({ start, end }) => {
|
||||
const startdate = typeof start === 'string' ? new Date(start) : start;
|
||||
const enddate = typeof end === 'string' ? new Date(end) : end;
|
||||
|
||||
if (!start || !end) return;
|
||||
if (start < new Date() || end < new Date() || start > end) return;
|
||||
if (startdate < new Date() || end < new Date() || startdate > end) return;
|
||||
|
||||
// Check if start and end are on the same day
|
||||
if (start.toDateString() !== end.toDateString()) {
|
||||
end = common.setTimeHHmm(start, "23:59");
|
||||
if (startdate.toDateString() !== enddate.toDateString()) {
|
||||
end = common.setTimeHHmm(startdate, "23:59");
|
||||
}
|
||||
|
||||
const startMinutes = common.getTimeInMinutes(start);
|
||||
@@ -186,7 +191,7 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
|
||||
setDate(start);
|
||||
|
||||
// get exising events for the selected date
|
||||
const existingEvents = evts?.filter(event => (event.publisher?.id || event.publisherId) === publisherId && new Date(event.date).toDateString() === start.toDateString());
|
||||
const existingEvents = evts?.filter(event => (event.publisher?.id || event.publisherId) === publisherId && new Date(event.date).toDateString() === startdate.toDateString());
|
||||
// const existingEvents = evts?.filter(event => {
|
||||
// return event.publisherId === publisherId &&
|
||||
// new Date(event.startTime).getFullYear() === start.getFullYear() &&
|
||||
|
@@ -7,7 +7,7 @@ import axiosInstance from '../../src/axiosSecure';
|
||||
import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../src/helpers/const"
|
||||
import common from "../../src/helpers/common";
|
||||
|
||||
type Assignment = {
|
||||
type Assignments = {
|
||||
items: {
|
||||
[key: string]: any[];
|
||||
};
|
||||
@@ -18,7 +18,7 @@ type Assignment = {
|
||||
};
|
||||
|
||||
type ShiftsListProps = {
|
||||
assignments: Assignment;
|
||||
assignments: Assignments;
|
||||
selectedtab: string;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user