calendar 24

This commit is contained in:
Alma 2025-04-13 16:01:17 +02:00
parent 995129cdb6
commit cbad105ed8

View File

@ -608,24 +608,39 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
const startDate = new Date(selectInfo.start);
const endDate = new Date(selectInfo.end);
console.log("Date select handler - Current calendars:", calendars);
console.log("Date select handler - Current selectedCalendarId:", selectedCalendarId);
console.log("Date select handler - Current state:", {
calendars: calendars.map(c => ({ id: c.id, name: c.name })),
selectedCalendarId,
availableCalendars: calendars.length
});
// If no calendar is selected, use the first available calendar
if (!selectedCalendarId && calendars.length > 0) {
console.log("No calendar selected, selecting first calendar:", calendars[0]);
setSelectedCalendarId(calendars[0].id);
const firstCalendar = calendars[0];
console.log("No calendar selected, selecting first calendar:", firstCalendar);
setSelectedCalendarId(firstCalendar.id);
setEventForm({
title: "",
description: null,
start: startDate.toISOString(),
end: endDate.toISOString(),
allDay: selectInfo.allDay,
location: null,
calendarId: firstCalendar.id
});
} else {
setEventForm({
title: "",
description: null,
start: startDate.toISOString(),
end: endDate.toISOString(),
allDay: selectInfo.allDay,
location: null,
calendarId: selectedCalendarId
});
}
setEventForm({
title: "",
description: null,
start: startDate.toISOString(),
end: endDate.toISOString(),
allDay: selectInfo.allDay,
location: null,
calendarId: selectedCalendarId || calendars[0]?.id,
});
setIsEventModalOpen(true);
};
@ -649,27 +664,40 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
const handleEventSubmit = async () => {
try {
// Log the current state before validation
console.log("Current state before submission:", {
selectedCalendarId,
eventForm,
calendars
});
if (!eventForm.title || !eventForm.start || !eventForm.end || !selectedCalendarId) {
console.log("Form validation failed:", {
title: eventForm.title,
start: eventForm.start,
end: eventForm.end,
selectedCalendarId
selectedCalendarId,
calendars: calendars.map(c => ({ id: c.id, name: c.name }))
});
setError("Veuillez remplir tous les champs obligatoires");
return;
}
setLoading(true);
// Ensure we're using the selected calendar ID
const eventData = {
...eventForm,
id: selectedEvent?.id,
calendarId: selectedCalendarId,
userId,
isAllDay: eventForm.allDay
title: eventForm.title,
description: eventForm.description,
start: new Date(eventForm.start).toISOString(),
end: new Date(eventForm.end).toISOString(),
allDay: eventForm.allDay,
location: eventForm.location,
calendarId: selectedCalendarId, // Use selectedCalendarId directly
userId
};
console.log("Submitting event with data:", eventData);
console.log("Available calendars:", calendars);
console.log("Available calendars:", calendars.map(c => ({ id: c.id, name: c.name })));
console.log("Selected calendar ID:", selectedCalendarId);
const response = await fetch("/api/events", {
@ -688,8 +716,6 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
throw new Error(responseData.error || "Failed to save event");
}
console.log("Event saved successfully:", responseData);
// Reset form and close modal first
setIsEventModalOpen(false);
setEventForm({