feat: boards with statuses fetch
This commit is contained in:
29
src/hooks/useBoardsList.ts
Normal file
29
src/hooks/useBoardsList.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { BoardSchema } from "@/client";
|
||||
import { getBoardsOptions } from "@/client/@tanstack/react-query.gen";
|
||||
|
||||
type Props = {
|
||||
projectId?: number;
|
||||
};
|
||||
|
||||
const useBoardsList = ({ projectId }: Props) => {
|
||||
const [boards, setBoards] = useState<BoardSchema[]>([]);
|
||||
|
||||
const { data, refetch, isLoading } = useQuery({
|
||||
...getBoardsOptions({ path: { project_id: projectId! } }),
|
||||
enabled: projectId !== undefined,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId === undefined) {
|
||||
setBoards([]);
|
||||
} else if (data?.boards) {
|
||||
setBoards(data.boards);
|
||||
}
|
||||
}, [data?.boards, projectId]);
|
||||
|
||||
return { boards, setBoards, refetch, isLoading };
|
||||
};
|
||||
|
||||
export default useBoardsList;
|
||||
Reference in New Issue
Block a user