feat: deals fetch

This commit is contained in:
2025-08-03 16:55:36 +04:00
parent 5435750fb5
commit 315e7db3db
14 changed files with 148 additions and 71 deletions

29
src/hooks/useDealsList.ts Normal file
View File

@ -0,0 +1,29 @@
import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { DealSchema } from "@/client";
import { getDealsOptions } from "@/client/@tanstack/react-query.gen";
type Props = {
boardId?: number;
};
const useDealsList = ({ boardId }: Props) => {
const [deals, setDeals] = useState<DealSchema[]>([]);
const { data, refetch, isLoading } = useQuery({
...getDealsOptions({ path: { board_id: boardId! } }),
enabled: boardId !== undefined,
});
useEffect(() => {
if (boardId === undefined) {
setDeals([]);
} else if (data?.deals) {
setDeals(data.deals);
}
}, [data?.deals, boardId]);
return { deals, setDeals, refetch, isLoading };
};
export default useDealsList;