Initial commit
This commit is contained in:
27
lib/hooks/use-kanban.ts
Normal file
27
lib/hooks/use-kanban.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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] });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user