Interaction avec les boutons de fin de défi
This commit is contained in:
@ -43,3 +43,33 @@ export const useDrawRandomChallengeMutation = ({ auth, onPostSuccess, onError }:
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const useEndChallenge = ({ auth, onPostSuccess, onError }: ChallengeActionProps) => {
|
||||
return useMutation({
|
||||
mutationFn: async ({ success }: { success: boolean }) => {
|
||||
return fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/challenge-actions/end-current/`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: success,
|
||||
})
|
||||
}).then(resp => resp.json())
|
||||
},
|
||||
onSuccess: async (data) => {
|
||||
if (data.statusCode) {
|
||||
if (onError)
|
||||
onError({ response: data })
|
||||
return
|
||||
}
|
||||
if (onPostSuccess)
|
||||
onPostSuccess()
|
||||
},
|
||||
onError: async (error: Error) => {
|
||||
if (onError)
|
||||
onError({ error: error })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user