@@ -77,15 +77,17 @@ export function useCreateRepoSchedule(repoId: number | undefined) {
7777 const queryClient = useQueryClient ( )
7878
7979 return useMutation ( {
80- mutationFn : async ( data : CreateScheduleJobRequest ) => {
81- const response = await createRepoSchedule ( repoId ! , data )
80+ mutationFn : async ( { repoId : callRepoId , data } : { repoId ?: number ; data : CreateScheduleJobRequest } ) => {
81+ const resolvedRepoId = callRepoId ?? repoId
82+ const response = await createRepoSchedule ( resolvedRepoId ! , data )
8283 return response . job
8384 } ,
84- onSuccess : ( ) => {
85- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , repoId ] } )
85+ onSuccess : ( __variables ) => {
86+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , __variables . repoId ?? repoId ] } )
87+ queryClient . invalidateQueries ( { queryKey : [ 'all-schedules' ] } )
8688 showToast . success ( 'Schedule created' )
8789 } ,
88- onError : ( error ) => {
90+ onError : ( error : unknown ) => {
8991 showToast . error ( `Failed to create schedule: ${ error instanceof Error ? error . message : String ( error ) } ` )
9092 } ,
9193 } )
@@ -95,16 +97,18 @@ export function useUpdateRepoSchedule(repoId: number | undefined) {
9597 const queryClient = useQueryClient ( )
9698
9799 return useMutation ( {
98- mutationFn : async ( { jobId, data } : { jobId : number ; data : UpdateScheduleJobRequest } ) => {
99- const response = await updateRepoSchedule ( repoId ! , jobId , data )
100+ mutationFn : async ( { repoId : callRepoId , jobId, data } : { repoId ?: number ; jobId : number ; data : UpdateScheduleJobRequest } ) => {
101+ const resolvedRepoId = callRepoId ?? repoId
102+ const response = await updateRepoSchedule ( resolvedRepoId ! , jobId , data )
100103 return response . job
101104 } ,
102- onSuccess : ( _ , variables ) => {
103- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , repoId ] } )
104- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule' , repoId , variables . jobId ] } )
105+ onSuccess : ( __variables ) => {
106+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , __variables . repoId ?? repoId ] } )
107+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule' , __variables . repoId ?? repoId , __variables . jobId ] } )
108+ queryClient . invalidateQueries ( { queryKey : [ 'all-schedules' ] } )
105109 showToast . success ( 'Schedule updated' )
106110 } ,
107- onError : ( error ) => {
111+ onError : ( error : unknown ) => {
108112 showToast . error ( `Failed to update schedule: ${ error instanceof Error ? error . message : String ( error ) } ` )
109113 } ,
110114 } )
@@ -114,12 +118,16 @@ export function useDeleteRepoSchedule(repoId: number | undefined) {
114118 const queryClient = useQueryClient ( )
115119
116120 return useMutation ( {
117- mutationFn : ( jobId : number ) => deleteRepoSchedule ( repoId ! , jobId ) ,
118- onSuccess : ( ) => {
119- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , repoId ] } )
121+ mutationFn : ( { repoId : callRepoId , jobId } : { repoId ?: number ; jobId : number } ) => {
122+ const resolvedRepoId = callRepoId ?? repoId
123+ return deleteRepoSchedule ( resolvedRepoId ! , jobId )
124+ } ,
125+ onSuccess : ( __variables ) => {
126+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , __variables . repoId ?? repoId ] } )
127+ queryClient . invalidateQueries ( { queryKey : [ 'all-schedules' ] } )
120128 showToast . success ( 'Schedule deleted' )
121129 } ,
122- onError : ( error ) => {
130+ onError : ( error : unknown ) => {
123131 showToast . error ( `Failed to delete schedule: ${ error instanceof Error ? error . message : String ( error ) } ` )
124132 } ,
125133 } )
@@ -129,18 +137,20 @@ export function useRunRepoSchedule(repoId: number | undefined) {
129137 const queryClient = useQueryClient ( )
130138
131139 return useMutation ( {
132- mutationFn : async ( jobId : number ) => {
133- const response = await runRepoSchedule ( repoId ! , jobId )
140+ mutationFn : async ( { repoId : callRepoId , jobId } : { repoId ?: number ; jobId : number } ) => {
141+ const resolvedRepoId = callRepoId ?? repoId
142+ const response = await runRepoSchedule ( resolvedRepoId ! , jobId )
134143 return response . run
135144 } ,
136- onSuccess : ( run ) => {
137- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , repoId ] } )
138- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule-runs' , repoId , run . jobId ] } )
139- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule' , repoId , run . jobId ] } )
140- queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule-run' , repoId , run . jobId , run . id ] } )
145+ onSuccess : ( run , variables ) => {
146+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedules' , variables . repoId ?? repoId ] } )
147+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule-runs' , variables . repoId ?? repoId , run . jobId ] } )
148+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule' , variables . repoId ?? repoId , run . jobId ] } )
149+ queryClient . invalidateQueries ( { queryKey : [ 'repo-schedule-run' , variables . repoId ?? repoId , run . jobId , run . id ] } )
150+ queryClient . invalidateQueries ( { queryKey : [ 'all-schedules' ] } )
141151 showToast . success ( run . status === 'running' ? 'Schedule started' : 'Schedule run completed' )
142152 } ,
143- onError : ( error ) => {
153+ onError : ( error : unknown ) => {
144154 showToast . error ( `Failed to run schedule: ${ error instanceof Error ? error . message : String ( error ) } ` )
145155 } ,
146156 } )
0 commit comments