calendar 22

This commit is contained in:
Alma 2025-04-13 15:53:48 +02:00
parent 7bd520de34
commit 593ed2b9e7

View File

@ -587,6 +587,11 @@ 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);
// If no calendar is selected, use the first available calendar
if (!selectedCalendarId && calendars.length > 0) {
setSelectedCalendarId(calendars[0].id);
}
setEventForm({ setEventForm({
title: "", title: "",
description: null, description: null,
@ -594,7 +599,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
end: endDate.toISOString(), end: endDate.toISOString(),
allDay: selectInfo.allDay, allDay: selectInfo.allDay,
location: null, location: null,
calendarId: selectedCalendarId, calendarId: selectedCalendarId || calendars[0]?.id,
}); });
setIsEventModalOpen(true); setIsEventModalOpen(true);
}; };
@ -630,6 +635,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
id: selectedEvent?.id, id: selectedEvent?.id,
calendarId: selectedCalendarId, calendarId: selectedCalendarId,
userId, userId,
isAllDay: eventForm.allDay
}; };
console.log("Submitting event:", eventData); console.log("Submitting event:", eventData);
@ -641,14 +647,14 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
body: JSON.stringify(eventData), body: JSON.stringify(eventData),
}); });
const responseData = await response.json();
if (!response.ok) { if (!response.ok) {
const errorData = await response.json(); console.error("Error response:", responseData);
console.error("Error response:", errorData); throw new Error(responseData.error || "Failed to save event");
throw new Error(errorData.error || "Failed to save event");
} }
const savedEvent = await response.json(); console.log("Event saved successfully:", responseData);
console.log("Event saved successfully:", savedEvent);
// Reset form and close modal first // Reset form and close modal first
setIsEventModalOpen(false); setIsEventModalOpen(false);
@ -662,6 +668,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
calendarId: selectedCalendarId calendarId: selectedCalendarId
}); });
setSelectedEvent(null); setSelectedEvent(null);
setError(null);
// Then refresh the calendar data // Then refresh the calendar data
await fetchCalendars(); await fetchCalendars();