diff --git a/src/app/dashboard/intelligence/companies/page.tsx b/src/app/dashboard/intelligence/companies/page.tsx new file mode 100644 index 0000000..40ed7aa --- /dev/null +++ b/src/app/dashboard/intelligence/companies/page.tsx @@ -0,0 +1,140 @@ +'use client'; + +import { useState } from 'react'; +import { useQuery } from '@tanstack/react-query'; +import { apiFetch } from '../../../../lib/api'; +import { useSession } from '../../../../components/session-provider'; + +interface CompanyResult { + cui?: string; companyId?: string; name?: string; companyName?: string; + industry?: string; county?: string; city?: string; country?: string; + employees?: number; revenue?: number; registrationDate?: string; + isActive?: boolean; caenCode?: string; caenLabel?: string; +} + +export default function CompaniesIntelligencePage() { + const { activeTenant } = useSession(); + const tenantId = activeTenant?.tenantId ?? ''; + + const [q, setQ] = useState(''); + const [submitted, setSubmitted] = useState(''); + + const { data, isLoading, error } = useQuery({ + queryKey: ['intel-companies', tenantId, submitted], + queryFn: () => apiFetch<{ results?: CompanyResult[]; total?: number } | CompanyResult[]>( + `/v1/intelligence/companies/search?q=${encodeURIComponent(submitted)}&limit=20`, + { tenantId } + ), + enabled: Boolean(tenantId) && submitted.length >= 2, + staleTime: 300_000, + }); + + const results: CompanyResult[] = Array.isArray(data) ? data : (data as any)?.results ?? []; + + return ( +
+ Caută companii din registrul de business — nume, CUI, domeniu de activitate. +
+Eroare la căutare. Verifică conexiunea la baza de date.
+🔍
+Niciun rezultat pentru "{submitted}"
+{results.length} rezultate pentru "{submitted}"
+{name}
+ {(company.cui || company.companyId) && ( ++ CUI: {company.cui ?? company.companyId} +
+ )} +Cum funcționează
+{s}
)} +