evcalendar - use dates for timeslots insead of integers

This commit is contained in:
Dobromir Popov
2024-04-07 20:48:51 +03:00
parent 3f7255bf96
commit 39597890bc
2 changed files with 21 additions and 19 deletions

View File

@ -198,7 +198,13 @@ add assignment in calendar planner
fix database
--
emails
emails: new shifts, replacements, announcements
mobile apps
apple login
разрешителни - upload
wpa: android? apple? pc?
push notifications
store replacement
test email

View File

@ -64,9 +64,14 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
// Define the minimum and maximum times
const minTime = new Date();
minTime.setHours(8, 0, 0, 0); // 8:00 AM
minTime.setHours(9, 0, 0, 0); // 8:00 AM
const maxTime = new Date();
maxTime.setHours(20, 0, 0, 0); // 8:00 PM
maxTime.setHours(19, 30, 0, 0); // 8:00 PM
useEffect(() => {
setTimeSlots(generateTimeSlots(minTime, maxTime, 90, availabilities));
}, []);
const fetchItemFromDB = async () => {
const id = parseInt(router.query.id);
@ -330,12 +335,9 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
const generateTimeSlots = (start, end, increment, items) => {
const slots = [];
// Initialize baseDate at the start of the day
const baseDate = new Date(items?.startTime || day);
baseDate.setHours(start, 0, 0, 0);
let currentTime = baseDate.getTime();
let currentTime = start.getTime();
const endTime = new Date(baseDate).setHours(end, 0, 0, 0);
const endTime = end.getTime();
while (currentTime < endTime) {
let slotStart = new Date(currentTime);
@ -343,11 +345,10 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
const isChecked = items.some(item =>
item.startTime && item.endTime &&
(slotStart.getHours() * 60 + slotStart.getMinutes()) < (item.endTime.getHours() * 60 + item.endTime.getMinutes()) &&
(slotEnd.getHours() * 60 + slotEnd.getMinutes()) > (item.startTime.getHours() * 60 + item.startTime.getMinutes())
(slotStart.getTime() < item.endTime.getTime()) &&
(slotEnd.getTime() > item.startTime.getTime())
);
slots.push({
startTime: slotStart,
endTime: slotEnd,
@ -358,17 +359,16 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
}
// Optional: Add isFirst, isLast, and isWithTransport properties
if (slots.length > 0) {
if (slots.length > 0 && items?.length > 0) {
slots[0].isFirst = true;
slots[slots.length - 1].isLast = true;
slots[0].isWithTransport = items[0].isWithTransportIn;
slots[slots.length - 1].isWithTransport = items[items.length - 1].isWithTransportOut;
slots[0].isWithTransport = items[0]?.isWithTransportIn;
slots[slots.length - 1].isWithTransport = items[items.length - 1]?.isWithTransportOut;
}
return slots;
};
const TimeSlotCheckboxes = ({ slots, setSlots, items: [] }) => {
const [allDay, setAllDay] = useState(slots.every(slot => slot.isChecked));
const handleAllDayChange = (e) => {
@ -462,10 +462,6 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
);
};
useEffect(() => {
setTimeSlots(generateTimeSlots(9, 18, 90, availabilities));
}, []);
return (
<div className="w-full">
<ToastContainer></ToastContainer>