Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
|
|
import { apiFetch } from '@/lib/api/client';
|
|
|
|
|
import { useDebounce } from '@/hooks/use-debounce';
|
|
|
|
|
|
|
|
|
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
interface SearchResults {
|
|
|
|
|
clients: Array<{ id: string; fullName: string; companyName: string | null }>;
|
|
|
|
|
interests: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
clientName: string;
|
|
|
|
|
berthMooringNumber: string | null;
|
|
|
|
|
pipelineStage: string;
|
|
|
|
|
}>;
|
|
|
|
|
berths: Array<{ id: string; mooringNumber: string; area: string | null; status: string }>;
|
2026-04-24 15:47:54 +02:00
|
|
|
yachts: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
hullNumber: string | null;
|
|
|
|
|
registration: string | null;
|
|
|
|
|
}>;
|
|
|
|
|
companies: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
legalName: string | null;
|
|
|
|
|
taxId: string | null;
|
|
|
|
|
}>;
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Hook ─────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
export function useSearch(query: string) {
|
|
|
|
|
const debouncedQuery = useDebounce(query, 300);
|
|
|
|
|
|
|
|
|
|
const searchQuery = useQuery<SearchResults>({
|
|
|
|
|
queryKey: ['search', debouncedQuery],
|
|
|
|
|
queryFn: () =>
|
|
|
|
|
apiFetch<SearchResults>(`/api/v1/search?q=${encodeURIComponent(debouncedQuery)}`),
|
|
|
|
|
enabled: debouncedQuery.length >= 2,
|
|
|
|
|
staleTime: 30_000,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const recentQuery = useQuery<{ searches: string[] }>({
|
|
|
|
|
queryKey: ['search', 'recent'],
|
|
|
|
|
queryFn: () => apiFetch<{ searches: string[] }>('/api/v1/search/recent'),
|
|
|
|
|
staleTime: 60_000,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
results: searchQuery.data,
|
|
|
|
|
isLoading: searchQuery.isLoading,
|
|
|
|
|
recentSearches: recentQuery.data?.searches ?? [],
|
|
|
|
|
};
|
|
|
|
|
}
|