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>
This commit is contained in:
45
src/hooks/use-search.ts
Normal file
45
src/hooks/use-search.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
'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 }>;
|
||||
}
|
||||
|
||||
// ─── 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 ?? [],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user