diff --git a/components/calendar/calendar-client.tsx b/components/calendar/calendar-client.tsx index 8e951cf8..615502d2 100644 --- a/components/calendar/calendar-client.tsx +++ b/components/calendar/calendar-client.tsx @@ -619,6 +619,11 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend const handleEventSubmit = async () => { try { + if (!eventForm.title || !eventForm.start || !eventForm.end || !selectedCalendarId) { + setError("Veuillez remplir tous les champs obligatoires"); + return; + } + setLoading(true); const eventData = { ...eventForm, @@ -645,10 +650,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend const savedEvent = await response.json(); console.log("Event saved successfully:", savedEvent); - // Refresh calendars and update the view - await fetchCalendars(); - - // Reset form and close modal + // Reset form and close modal first setIsEventModalOpen(false); setEventForm({ title: "", @@ -660,6 +662,9 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend calendarId: selectedCalendarId }); setSelectedEvent(null); + + // Then refresh the calendar data + await fetchCalendars(); // Force calendar refresh if (calendarRef.current) { @@ -905,7 +910,22 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend /> {/* Event dialog */} - !open && setIsEventModalOpen(false)}> + { + if (!open) { + setIsEventModalOpen(false); + setEventForm({ + title: "", + description: null, + start: "", + end: "", + allDay: false, + location: null, + calendarId: selectedCalendarId + }); + setSelectedEvent(null); + setError(null); + } + }}> @@ -913,6 +933,12 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend + {error && ( +
+ {error} +
+ )} +
@@ -927,17 +953,26 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
- +