cre-sync/lib/hooks/useContacts.ts
BusyBee3333 4e6467ffb0 Add CRESync CRM application with Setup page
- Build complete Next.js CRM for commercial real estate
- Add authentication with JWT sessions and role-based access
- Add GoHighLevel API integration for contacts, conversations, opportunities
- Add AI-powered Control Center with tool calling
- Add Setup page with onboarding checklist (/setup)
- Add sidebar navigation with Setup menu item
- Fix type errors in onboarding API, GHL services, and control center tools
- Add Prisma schema with SQLite for local development
- Add UI components with clay morphism design system

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 17:30:55 -05:00

42 lines
1.3 KiB
TypeScript

'use client';
import { useState, useCallback } from 'react';
import { api } from '@/lib/api/client';
export function useContacts() {
const [contacts, setContacts] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const fetchContacts = useCallback(async (params?: { query?: string; limit?: number }) => {
setLoading(true);
setError(null);
try {
const result = await api.contacts.getAll(params);
setContacts(result.data || []);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch contacts');
} finally {
setLoading(false);
}
}, []);
const createContact = async (data: any) => {
const contact = await api.contacts.create(data);
setContacts(prev => [contact, ...prev]);
return contact;
};
const updateContact = async (id: string, data: any) => {
const updated = await api.contacts.update(id, data);
setContacts(prev => prev.map(c => c.id === id ? updated : c));
return updated;
};
const deleteContact = async (id: string) => {
await api.contacts.delete(id);
setContacts(prev => prev.filter(c => c.id !== id));
};
return { contacts, loading, error, fetchContacts, createContact, updateContact, deleteContact };
}