@@ -4,6 +4,8 @@ import type { EventInstance, EventType, EventDocumentUploadArgs } from 'shared';
44import { convertEventToFormValues } from '../../../utils/calendar.utils' ;
55import { useEditEvent , useEditScheduleSlot , useUploadManyDocuments } from '../../../hooks/calendar.hooks' ;
66import { useToast } from '../../../hooks/toasts.hooks' ;
7+ import ErrorPage from '../../ErrorPage' ;
8+ import LoadingIndicator from '../../../components/LoadingIndicator' ;
79
810export interface EditEventModalProps {
911 open : boolean ;
@@ -14,9 +16,23 @@ export interface EditEventModalProps {
1416
1517const EditEventModal : React . FC < EditEventModalProps > = ( { open, onClose, event, eventTypes } ) => {
1618 const toast = useToast ( ) ;
17- const { mutateAsync : editEvent } = useEditEvent ( event . eventId ) ;
18- const { mutateAsync : editScheduleSlot } = useEditScheduleSlot ( event . eventId , event . scheduleSlotId ) ;
19+ const {
20+ isLoading : editEventIsLoading ,
21+ isError : editEventIsError ,
22+ error : editEventError ,
23+ mutateAsync : editEvent
24+ } = useEditEvent ( event . eventId ) ;
1925 const { mutateAsync : uploadDocuments } = useUploadManyDocuments ( ) ;
26+ const {
27+ isLoading : editScheduleSlotIsLoading ,
28+ isError : editScheduleSlotIsError ,
29+ error : editScheduleSlotError ,
30+ mutateAsync : editScheduleSlot
31+ } = useEditScheduleSlot ( event . eventId , event . scheduleSlotId ) ;
32+
33+ if ( editEventIsError ) return < ErrorPage message = { editEventError ?. message } /> ;
34+ if ( editScheduleSlotIsError ) return < ErrorPage message = { editScheduleSlotError ?. message } /> ;
35+ if ( editEventIsLoading || editScheduleSlotIsLoading ) return < LoadingIndicator /> ;
2036
2137 const initialValues = convertEventToFormValues ( event ) ;
2238
@@ -34,8 +50,6 @@ const EditEventModal: React.FC<EditEventModalProps> = ({ open, onClose, event, e
3450 } ) )
3551 } ;
3652
37- const editedEvent = await editEvent ( editArgs ) ;
38-
3953 // If there are schedule slot changes, update the schedule slot separately
4054 if ( editScheduleSlotArgs ) {
4155 await editScheduleSlot ( {
@@ -46,6 +60,8 @@ const EditEventModal: React.FC<EditEventModalProps> = ({ open, onClose, event, e
4660 } ) ;
4761 }
4862
63+ const editedEvent = await editEvent ( editArgs ) ;
64+
4965 // Handle document uploads
5066 const filesToUpload = documentFiles
5167 . map ( ( doc : EventDocumentUploadArgs ) => doc . file )
0 commit comments