diff --git a/components/calendar/event-modal.tsx b/components/calendar/event-modal.tsx index a99ec146..795ea232 100644 --- a/components/calendar/event-modal.tsx +++ b/components/calendar/event-modal.tsx @@ -25,7 +25,7 @@ interface EventModalProps { calendars: Calendar[]; defaultDate?: Date; defaultEndDate?: Date; - onSave: (data: Partial, sendSchedulingMessages?: boolean) => void; + onSave: (data: Partial, sendSchedulingMessages?: boolean) => void | Promise; onDelete?: (id: string, sendSchedulingMessages?: boolean) => void; onDuplicate?: (data: Partial) => void; onRsvp?: (eventId: string, participantId: string, status: CalendarParticipant['participationStatus']) => void; @@ -209,6 +209,7 @@ export function EventModal({ return "none"; }); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); + const [isSaving, setIsSaving] = useState(false); const [attendees, setAttendees] = useState<{ name: string; email: string }[]>(() => { if (!event?.participants) return []; @@ -231,9 +232,9 @@ export function EventModal({ setAttendees(prev => prev.filter(a => a.email.toLowerCase() !== email.toLowerCase())); }, []); - const handleSave = useCallback(() => { + const handleSave = useCallback(async () => { const trimmedTitle = title.trim(); - if (!trimmedTitle) return; + if (!trimmedTitle || isSaving) return; if (trimmedTitle.length > 500 || description.trim().length > 10000 || location.trim().length > 500) return; const startStr = allDay @@ -343,8 +344,13 @@ export function EventModal({ } const shouldSendScheduling = attendees.length > 0 && sendInvitations; - onSave(data, shouldSendScheduling); - }, [title, description, location, startDate, startTime, endDate, endTime, allDay, calendarId, recurrence, alert, attendees, sendInvitations, currentUserEmails, existingParticipants, event, onSave]); + setIsSaving(true); + try { + await onSave(data, shouldSendScheduling); + } finally { + setIsSaving(false); + } + }, [title, description, location, startDate, startTime, endDate, endTime, allDay, calendarId, recurrence, alert, attendees, sendInvitations, currentUserEmails, existingParticipants, event, onSave, isSaving]); const handleRsvp = useCallback((status: CalendarParticipant['participationStatus']) => { if (!event || !userParticipantId || !onRsvp) return; @@ -945,7 +951,7 @@ export function EventModal({ - diff --git a/stores/calendar-store.ts b/stores/calendar-store.ts index 9a9ed309..d3a4f3ee 100644 --- a/stores/calendar-store.ts +++ b/stores/calendar-store.ts @@ -142,13 +142,6 @@ export const useCalendarStore = create()( } const created = await client.createCalendarEvent(cleanEvent, sendSchedulingMessages, targetAccountId); set((state) => ({ events: [...state.events, created] })); - if (sendSchedulingMessages && created.participants) { - try { - await client.sendImipInvitation(created); - } catch (e) { - debug.error('Failed to send invitation emails:', e); - } - } return created; } catch (error) { debug.error('Failed to create event:', error); @@ -178,16 +171,6 @@ export const useCalendarStore = create()( set((state) => ({ events: state.events.map(e => e.id === id ? { ...e, ...updates } : e), })); - if (sendSchedulingMessages) { - try { - const updatedEvent = await client.getCalendarEvent(realId, targetAccountId); - if (updatedEvent?.participants) { - await client.sendImipInvitation(updatedEvent); - } - } catch (e) { - debug.error('Failed to send update notification emails:', e); - } - } } catch (error) { debug.error('Failed to update event:', error); set({ error: 'Failed to update event' });