mirror of
https://github.com/hanzoai/dataroom.git
synced 2026-10-30 18:41:07 +00:00
- GET/POST /api/teams/:teamId/visitor-groups - list & create - GET/PUT/DELETE /api/teams/:teamId/visitor-groups/:groupId - CRUD - Deletion protection: prevents deletion if group is used by active links - SWR hook for consuming visitor groups data in UI Co-authored-by: Marc Seitz <[email protected]>
34 lines
684 B
TypeScript
34 lines
684 B
TypeScript
import { useTeam } from "@/context/team-context";
|
|
import { VisitorGroup } from "@prisma/client";
|
|
import useSWR from "swr";
|
|
|
|
import { fetcher } from "@/lib/utils";
|
|
|
|
export type VisitorGroupWithCount = VisitorGroup & {
|
|
_count: {
|
|
links: number;
|
|
};
|
|
};
|
|
|
|
export default function useVisitorGroups() {
|
|
const teamInfo = useTeam();
|
|
const teamId = teamInfo?.currentTeam?.id;
|
|
|
|
const {
|
|
data: visitorGroups,
|
|
error,
|
|
mutate,
|
|
} = useSWR<VisitorGroupWithCount[]>(
|
|
teamId ? `/api/teams/${teamId}/visitor-groups` : null,
|
|
fetcher,
|
|
{ dedupingInterval: 30000 },
|
|
);
|
|
|
|
return {
|
|
visitorGroups,
|
|
loading: !visitorGroups && !error,
|
|
error,
|
|
mutate,
|
|
};
|
|
}
|