mirror of
https://github.com/hanzoai/dataroom.git
synced 2026-10-30 18:41:07 +00:00
27 lines
656 B
TypeScript
27 lines
656 B
TypeScript
import { useTeam } from "@/context/team-context";
|
|
import { View } from "@prisma/client";
|
|
import useSWR from "swr";
|
|
|
|
import { TStatsData } from "@/lib/swr/use-stats";
|
|
import { fetcher } from "@/lib/utils";
|
|
|
|
export function useDocumentStats(documentId: string | null | undefined) {
|
|
const { currentTeamId: teamId } = useTeam();
|
|
|
|
const { data: stats, error } = useSWR<TStatsData>(
|
|
documentId && teamId
|
|
? `/api/teams/${teamId}/documents/${encodeURIComponent(documentId)}/stats`
|
|
: null,
|
|
fetcher,
|
|
{
|
|
dedupingInterval: 10000,
|
|
},
|
|
);
|
|
|
|
return {
|
|
stats,
|
|
loading: documentId ? !error && !stats : false,
|
|
error,
|
|
};
|
|
}
|