calendar 22
This commit is contained in:
parent
7bd520de34
commit
593ed2b9e7
@ -587,6 +587,11 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
const startDate = new Date(selectInfo.start);
|
||||
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({
|
||||
title: "",
|
||||
description: null,
|
||||
@ -594,7 +599,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
end: endDate.toISOString(),
|
||||
allDay: selectInfo.allDay,
|
||||
location: null,
|
||||
calendarId: selectedCalendarId,
|
||||
calendarId: selectedCalendarId || calendars[0]?.id,
|
||||
});
|
||||
setIsEventModalOpen(true);
|
||||
};
|
||||
@ -630,6 +635,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
id: selectedEvent?.id,
|
||||
calendarId: selectedCalendarId,
|
||||
userId,
|
||||
isAllDay: eventForm.allDay
|
||||
};
|
||||
console.log("Submitting event:", eventData);
|
||||
|
||||
@ -641,14 +647,14 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
body: JSON.stringify(eventData),
|
||||
});
|
||||
|
||||
const responseData = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
console.error("Error response:", errorData);
|
||||
throw new Error(errorData.error || "Failed to save event");
|
||||
console.error("Error response:", responseData);
|
||||
throw new Error(responseData.error || "Failed to save event");
|
||||
}
|
||||
|
||||
const savedEvent = await response.json();
|
||||
console.log("Event saved successfully:", savedEvent);
|
||||
console.log("Event saved successfully:", responseData);
|
||||
|
||||
// Reset form and close modal first
|
||||
setIsEventModalOpen(false);
|
||||
@ -662,6 +668,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
calendarId: selectedCalendarId
|
||||
});
|
||||
setSelectedEvent(null);
|
||||
setError(null);
|
||||
|
||||
// Then refresh the calendar data
|
||||
await fetchCalendars();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user