base con autenticacion, registro, modulo encuestas
This commit is contained in:
47
apps/web/feactures/surveys/hooks/use-mutation-surveys.ts
Normal file
47
apps/web/feactures/surveys/hooks/use-mutation-surveys.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Survey, SurveyResponse } from "../schemas/survey";
|
||||
import { deleteSurveyAction, saveSurveysAction, saveSurveyAnswer } from "../actions/surveys-actions";
|
||||
|
||||
// Mutation hook remains the same
|
||||
export function useSurveyMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationFn: (data: Survey) => saveSurveysAction(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['surveys'] });
|
||||
},
|
||||
// onError: (error) => {
|
||||
// console.error('Error:', error);
|
||||
// },
|
||||
});
|
||||
|
||||
return mutation;
|
||||
}
|
||||
|
||||
export function useDeleteSurvey() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => deleteSurveyAction(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['surveys'] });
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error('Error:', error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useSurveyAnswerMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationFn: (data: SurveyResponse) => saveSurveyAnswer(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['surveys'] });
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error('Error:', error);
|
||||
},
|
||||
});
|
||||
|
||||
return mutation;
|
||||
}
|
||||
Reference in New Issue
Block a user