refactor: sorted hooks

This commit is contained in:
2025-08-23 19:01:21 +04:00
parent 6ad813ea1d
commit 10f50ac254
27 changed files with 28 additions and 28 deletions

View File

@ -0,0 +1,31 @@
import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { DealSchema } from "@/lib/client";
import { getDealsOptions } from "@/lib/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: { boardId: boardId! } }),
enabled: boardId !== undefined,
});
useEffect(() => {
if (boardId === undefined) {
setDeals([]);
return;
}
if (data?.deals) {
setDeals(data.deals);
}
}, [data?.deals, boardId]);
return { deals, setDeals, refetch, isLoading };
};
export default useDealsList;