- Implemented `stage-resolver.ts` to unify old and new pipeline stage definitions. - Created `org-scope.ts` for organization access verification and scoping queries. - Added role-based permissions management in `permissions.ts` and `rbac-service.ts`. - Introduced invitation management in `invitation-service.ts` with validation schemas. - Developed custom field and notification rule services with respective validators. - Established pipeline template CRUD operations in `pipeline-template-service.ts`. - Added Zustand store for managing pipeline builder state in `pipeline-builder-store.ts`.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
async function fetchJson<T>(url: string, init?: RequestInit): Promise<T> {
|
|
const res = await fetch(url, init);
|
|
if (!res.ok) {
|
|
const body = await res.json().catch(() => ({}));
|
|
throw new Error(body.error || `Request failed: ${res.status}`);
|
|
}
|
|
return res.json();
|
|
}
|
|
|
|
export function useInvitations() {
|
|
return useQuery({
|
|
queryKey: ["invitations"],
|
|
queryFn: () => fetchJson("/api/org/invitations"),
|
|
});
|
|
}
|
|
|
|
export function useCreateInvitation() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (data: { email: string; role?: string }) =>
|
|
fetchJson("/api/org/invitations", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
}),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ["invitations"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useRevokeInvitation() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (id: string) =>
|
|
fetchJson(`/api/org/invitations/${id}`, { method: "DELETE" }),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ["invitations"] });
|
|
},
|
|
});
|
|
}
|