24 lines
629 B
TypeScript
24 lines
629 B
TypeScript
import { useMutation, useQueryClient } from 'react-query';
|
|
import api from '../services/api';
|
|
import { SubTarefa } from '../types/entities';
|
|
|
|
export const useSubtarefas = (tarefaId: string) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
const toggleSubtarefa = useMutation(
|
|
async ({ id, concluida }: { id: string; concluida: boolean }) => {
|
|
const response = await api.patch(`/tarefas/${tarefaId}/subtarefas/${id}`, { concluida });
|
|
return response.data;
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries(['tarefas', tarefaId]);
|
|
}
|
|
}
|
|
);
|
|
|
|
return {
|
|
toggleSubtarefa
|
|
};
|
|
};
|