Initial commit: CI Agent competitive-intelligence monitoring app
FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring, source collection, LLM-based change analysis, enrichment, and account security (Turnstile, escalating lockout, email verification).
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
"use client";
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { api } from "@/lib/api-client";
|
||||
import type {
|
||||
CompanyCreatePayload,
|
||||
CompanyResponse,
|
||||
CompanyUpdatePayload,
|
||||
MonitorConfigurationUpdatePayload,
|
||||
} from "@/lib/types";
|
||||
|
||||
export function useCompanies() {
|
||||
return useQuery({ queryKey: ["companies"], queryFn: api.listCompanies });
|
||||
}
|
||||
|
||||
export function useCompany(companyId: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ["companies", companyId],
|
||||
queryFn: () => api.getCompany(companyId as string),
|
||||
enabled: Boolean(companyId),
|
||||
// Enrichment (NinjaPear) runs in the background after company
|
||||
// creation - poll while it's still pending so the Enrichment tab
|
||||
// updates itself once the task finishes, without a manual refresh.
|
||||
refetchInterval: (query) => {
|
||||
const company = query.state.data as CompanyResponse | undefined;
|
||||
return company?.enrichment?.status === "pending" ? 3000 : false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateCompany() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (payload: CompanyCreatePayload) => api.createCompany(payload),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["companies"] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateCompany(companyId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (payload: CompanyUpdatePayload) => api.updateCompany(companyId, payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["companies"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["companies", companyId] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteCompany() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (companyId: string) => api.deleteCompany(companyId),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["companies"] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useSetCompanyPaused() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ companyId, paused }: { companyId: string; paused: boolean }) =>
|
||||
paused ? api.pauseCompany(companyId) : api.resumeCompany(companyId),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["companies"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["companies", variables.companyId] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateMonitorConfiguration(companyId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (payload: MonitorConfigurationUpdatePayload) =>
|
||||
api.updateMonitorConfiguration(companyId, payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["companies"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["companies", companyId] });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user