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 fix database
-- --
emails emails: new shifts, replacements, announcements
mobile apps mobile apps
apple login apple login
разрешителни - upload разрешителни - 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 // Define the minimum and maximum times
const minTime = new Date(); 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(); 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 fetchItemFromDB = async () => {
const id = parseInt(router.query.id); 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 generateTimeSlots = (start, end, increment, items) => {
const slots = []; const slots = [];
// Initialize baseDate at the start of the day let currentTime = start.getTime();
const baseDate = new Date(items?.startTime || day);
baseDate.setHours(start, 0, 0, 0);
let currentTime = baseDate.getTime();
const endTime = new Date(baseDate).setHours(end, 0, 0, 0); const endTime = end.getTime();
while (currentTime < endTime) { while (currentTime < endTime) {
let slotStart = new Date(currentTime); let slotStart = new Date(currentTime);
@ -343,11 +345,10 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
const isChecked = items.some(item => const isChecked = items.some(item =>
item.startTime && item.endTime && item.startTime && item.endTime &&
(slotStart.getHours() * 60 + slotStart.getMinutes()) < (item.endTime.getHours() * 60 + item.endTime.getMinutes()) && (slotStart.getTime() < item.endTime.getTime()) &&
(slotEnd.getHours() * 60 + slotEnd.getMinutes()) > (item.startTime.getHours() * 60 + item.startTime.getMinutes()) (slotEnd.getTime() > item.startTime.getTime())
); );
slots.push({ slots.push({
startTime: slotStart, startTime: slotStart,
endTime: slotEnd, endTime: slotEnd,
@ -358,17 +359,16 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
} }
// Optional: Add isFirst, isLast, and isWithTransport properties // Optional: Add isFirst, isLast, and isWithTransport properties
if (slots.length > 0) { if (slots.length > 0 && items?.length > 0) {
slots[0].isFirst = true; slots[0].isFirst = true;
slots[slots.length - 1].isLast = true; slots[slots.length - 1].isLast = true;
slots[0].isWithTransport = items[0].isWithTransportIn; slots[0].isWithTransport = items[0]?.isWithTransportIn;
slots[slots.length - 1].isWithTransport = items[items.length - 1].isWithTransportOut; slots[slots.length - 1].isWithTransport = items[items.length - 1]?.isWithTransportOut;
} }
return slots; return slots;
}; };
const TimeSlotCheckboxes = ({ slots, setSlots, items: [] }) => { const TimeSlotCheckboxes = ({ slots, setSlots, items: [] }) => {
const [allDay, setAllDay] = useState(slots.every(slot => slot.isChecked)); const [allDay, setAllDay] = useState(slots.every(slot => slot.isChecked));
const handleAllDayChange = (e) => { const handleAllDayChange = (e) => {
@ -462,10 +462,6 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
); );
}; };
useEffect(() => {
setTimeSlots(generateTimeSlots(9, 18, 90, availabilities));
}, []);
return ( return (
<div className="w-full"> <div className="w-full">
<ToastContainer></ToastContainer> <ToastContainer></ToastContainer>