mirror of
https://github.com/hanzoai/dataroom.git
synced 2026-10-30 18:41:07 +00:00
31 lines
654 B
TypeScript
31 lines
654 B
TypeScript
import { useTeam } from "@/context/team-context";
|
|
import { Agreement } from "@prisma/client";
|
|
import useSWR from "swr";
|
|
|
|
import { fetcher } from "@/lib/utils";
|
|
|
|
export interface AgreementWithLinksCount extends Agreement {
|
|
_count: {
|
|
links: number;
|
|
};
|
|
}
|
|
|
|
export function useAgreements() {
|
|
const teamInfo = useTeam();
|
|
const teamId = teamInfo?.currentTeam?.id;
|
|
|
|
const { data: agreements, error } = useSWR<AgreementWithLinksCount[]>(
|
|
teamId && `/api/teams/${teamId}/agreements`,
|
|
fetcher,
|
|
{
|
|
dedupingInterval: 60000,
|
|
},
|
|
);
|
|
|
|
return {
|
|
agreements: agreements || [],
|
|
loading: !agreements && !error,
|
|
error,
|
|
};
|
|
}
|