Files
dataroom/lib/swr/use-visitor-groups.ts
zeekayandMarc Seitz 3951a3a031 feat: add visitor groups API routes and SWR hook
- 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]>
2026-02-12 07:14:48 +00:00

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,
};
}