28 lines
975 B
TypeScript
28 lines
975 B
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { projectsApi } from '@/lib/api/projects';
|
|
import type { KanbanBoard } from '@/types/kanban';
|
|
import { api } from '@/lib/api/client';
|
|
|
|
export function useKanbanBoard(projectId: string) {
|
|
return useQuery<KanbanBoard>({
|
|
queryKey: ['projects', projectId, 'kanban'],
|
|
queryFn: () => projectsApi.getKanban(projectId),
|
|
enabled: !!projectId,
|
|
staleTime: 2 * 60 * 1000, // 2 minutes
|
|
});
|
|
}
|
|
|
|
export function useUpdateTaskStatus() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ taskId, newStatus }: { taskId: string; newStatus: string }) =>
|
|
api.patch(`/tasks/${taskId}/status`, { status: newStatus }),
|
|
onSuccess: (_, { taskId }) => {
|
|
// Invalidate kanban board queries to refetch
|
|
queryClient.invalidateQueries({ queryKey: ['kanban'] });
|
|
queryClient.invalidateQueries({ queryKey: ['tasks', taskId] });
|
|
},
|
|
});
|
|
}
|