cre-sync/lib/hooks/usePipelines.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

64 lines
1.6 KiB
TypeScript

'use client';
import { useState, useCallback } from 'react';
import { api } from '@/lib/api/client';
interface PipelineStage {
id: string;
name: string;
position: number;
}
interface Pipeline {
id: string;
name: string;
stages: PipelineStage[];
}
export function usePipelines() {
const [pipelines, setPipelines] = useState<Pipeline[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const fetchPipelines = useCallback(async () => {
setLoading(true);
setError(null);
try {
const result = await api.pipelines.getAll();
setPipelines(result.pipelines || []);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch pipelines');
} finally {
setLoading(false);
}
}, []);
const getPipeline = async (id: string) => {
const pipeline = await api.pipelines.getById(id);
return pipeline;
};
const createPipeline = async (data: { name: string; stages: { name: string }[] }) => {
const pipeline = await api.pipelines.create(data);
setPipelines(prev => [...prev, pipeline as Pipeline]);
return pipeline;
};
const addStage = async (pipelineId: string, name: string) => {
const result = await api.pipelines.addStage(pipelineId, name);
// Refresh the specific pipeline to get updated stages
const updated = await api.pipelines.getById(pipelineId);
setPipelines(prev => prev.map(p => p.id === pipelineId ? (updated as Pipeline) : p));
return result;
};
return {
pipelines,
loading,
error,
fetchPipelines,
getPipeline,
createPipeline,
addStage,
};
}