@@ -4,6 +4,7 @@ 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 { AlertColor } from '@mui/material' ;
78
89export interface EditEventModalProps {
910 open : boolean ;
@@ -14,10 +15,17 @@ export interface EditEventModalProps {
1415
1516const EditEventModal : React . FC < EditEventModalProps > = ( { open, onClose, event, eventTypes } ) => {
1617 const toast = useToast ( ) ;
17- const { isLoading, isError, mutateAsync : editEvent } = useEditEvent ( event . eventId ) ;
18+ const { isLoading, isError, error , mutateAsync : editEvent } = useEditEvent ( event . eventId ) ;
1819 const { mutateAsync : uploadDocuments } = useUploadManyDocuments ( ) ;
1920 const { mutateAsync : editScheduleSlot } = useEditScheduleSlot ( event . eventId , event . scheduleSlotId ) ;
2021
22+ if ( isLoading ) {
23+ //?
24+ }
25+ if ( isError ) {
26+ editEventModalError ( error , toast ) ;
27+ }
28+
2129 const initialValues = convertEventToFormValues ( event ) ;
2230
2331 const handleSubmit = async ( payload : EventPayload ) => {
@@ -59,12 +67,7 @@ const EditEventModal: React.FC<EditEventModalProps> = ({ open, onClose, event, e
5967
6068 toast . success ( 'Event updated successfully!' ) ;
6169 } catch ( e : unknown ) {
62- if ( e instanceof Error ) {
63- toast . error ( e . message , 5000 ) ;
64- } else {
65- toast . error ( 'Failed to update event' , 5000 ) ;
66- }
67- throw e ;
70+ editEventModalError ( e , toast ) ;
6871 }
6972 } ;
7073
@@ -82,3 +85,20 @@ const EditEventModal: React.FC<EditEventModalProps> = ({ open, onClose, event, e
8285} ;
8386
8487export default EditEventModal ;
88+ function editEventModalError (
89+ e : unknown ,
90+ toast : {
91+ fire : ( message : string , options : { type : AlertColor ; autoHideDuration ?: number } ) => void ;
92+ info ( message : string , autoHideDuration ?: number ) : void ;
93+ success ( message : string , autoHideDuration ?: number ) : void ;
94+ warning ( message : string , autoHideDuration ?: number ) : void ;
95+ error ( message : string , autoHideDuration ?: number ) : void ;
96+ }
97+ ) {
98+ if ( e instanceof Error ) {
99+ toast . error ( e . message , 5000 ) ;
100+ } else {
101+ toast . error ( 'Failed to update event' , 5000 ) ;
102+ }
103+ throw e ;
104+ }
0 commit comments