Suppression de trains et défis
This commit is contained in:
@ -47,3 +47,30 @@ export const useAddTrainMutation = ({ auth, onPostSuccess, onError }: TrainProps
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteTrainMutation = ({ auth, onPostSuccess, onError }: TrainProps) => {
|
||||
return useMutation({
|
||||
mutationFn: async (trainId: string) => {
|
||||
return fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/trains/${trainId}/`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
},
|
||||
onSuccess: async (resp) => {
|
||||
if (resp.status >= 400) {
|
||||
if (onError)
|
||||
onError({ response: await resp.json() })
|
||||
return
|
||||
}
|
||||
if (onPostSuccess)
|
||||
onPostSuccess()
|
||||
},
|
||||
onError: async (error: Error) => {
|
||||
if (onError)
|
||||
onError({ error: error })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user