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