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;
|
||||
}
|
||||
20
apps/web/feactures/surveys/hooks/use-query-surveys.ts
Normal file
20
apps/web/feactures/surveys/hooks/use-query-surveys.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
'use client'
|
||||
import { useSafeQuery } from "@/hooks/use-safe-query";
|
||||
import { getSurveyByIdAction, getSurveysAction, getSurveysForUserAction } from "../actions/surveys-actions";
|
||||
|
||||
|
||||
// Hook for all survesys
|
||||
export function useSurveysQuery(params = {}) {
|
||||
return useSafeQuery(['surveys',params], () => getSurveysAction(params))
|
||||
}
|
||||
|
||||
export function useSurveysForUserQuery(params = {}) {
|
||||
return useSafeQuery(['surveys',params], () => getSurveysForUserAction(params))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export function useSurveysByIdQuery(id: number) {
|
||||
return useSafeQuery(['surveys',id], () => getSurveyByIdAction(id))
|
||||
}
|
||||
Reference in New Issue
Block a user