Spaces:
Running
Running
| import { create } from 'zustand'; | |
| import { getProjects } from '../api/client'; | |
| export interface Project { | |
| id: string; | |
| title: string; | |
| description?: string; | |
| program_name?: string; | |
| estimated_value?: number; | |
| status: string; | |
| created_at: string; | |
| updated_at: string; | |
| clerk_user_id: string; | |
| sections?: { id: string; is_approved: boolean; section_type: string }[]; | |
| } | |
| interface ProjectState { | |
| projects: Project[]; | |
| fetchProjects: () => Promise<void>; | |
| addProject: (project: Project) => void; | |
| deleteProject: (id: string) => void; | |
| } | |
| export const useProjectStore = create<ProjectState>((set) => ({ | |
| projects: [], | |
| fetchProjects: async () => { | |
| try { | |
| const data = await getProjects(); | |
| set({ projects: data }); | |
| } catch (error) { | |
| console.error("Failed to fetch projects", error); | |
| } | |
| }, | |
| addProject: (p) => set((state) => ({ projects: [p, ...state.projects] })), | |
| deleteProject: (id) => set((state) => ({ projects: state.projects.filter(p => p.id !== id) })), | |
| })); | |