AvForm is now stable and working as expected

This commit is contained in:
Dobromir Popov
2024-03-03 04:06:45 +02:00
parent 193dd91605
commit d9625f624f
2 changed files with 68 additions and 51 deletions

View File

@ -56,7 +56,12 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
// Update internal state when `events` prop changes
useEffect(() => {
setEvents(events);
const updatedEvents = events.map(event => ({
...event,
date: new Date(event.startTime).setHours(0, 0, 0, 0)
}));
setEvents(updatedEvents);
// Call any function here to process and set displayedEvents
// based on the new events, if necessary
}, [events]);
@ -181,8 +186,13 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
setDate(start);
// get exising events for the selected date
const existingEvents = evts?.filter(event => event.publisherId === publisherId && event.startTime === start.toDateString());
const existingEvents = evts?.filter(event => (event.publisher?.id || event.publisherId) === publisherId && new Date(event.date).toDateString() === start.toDateString());
// const existingEvents = evts?.filter(event => {
// return event.publisherId === publisherId &&
// new Date(event.startTime).getFullYear() === start.getFullYear() &&
// new Date(event.startTime).getMonth() === start.getMonth() &&
// new Date(event.startTime).getDate() === start.getDate();
// });
console.log("handleSelect: " + existingEvents);
setSelectedEvents(existingEvents);
@ -203,23 +213,24 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
const handleEventClick = (event) => {
if (event.type === "assignment") return;
handleSelect({ start: event.startTime, end: event.endTime });
// Handle event click
const eventForEditing = {
...event,
startTime: new Date(event.startTime),
endTime: new Date(event.endTime),
publisherId: event.publisherId || event.publisher?.connect?.id,
repeatWeekly: event.repeatWeekly || false,
};
//strip title, start, end and allDay properties
delete eventForEditing.title;
delete eventForEditing.start;
delete eventForEditing.end;
delete eventForEditing.type;
delete eventForEditing.publisher
console.log("handleEventClick: " + eventForEditing);
setSelectedEvents([eventForEditing]);
setIsModalOpen(true);
// const eventForEditing = {
// ...event,
// startTime: new Date(event.startTime),
// endTime: new Date(event.endTime),
// publisherId: event.publisherId || event.publisher?.connect?.id,
// repeatWeekly: event.repeatWeekly || false,
// };
// //strip title, start, end and allDay properties
// delete eventForEditing.title;
// delete eventForEditing.start;
// delete eventForEditing.end;
// delete eventForEditing.type;
// delete eventForEditing.publisher
// console.log("handleEventClick: " + eventForEditing);
// setSelectedEvents([eventForEditing]);
// setIsModalOpen(true);
};