import { useState, useEffect } from "react"; import { Plus, Building2, MapPin, Calendar, Users, Settings, Trash2, Eye, Edit3 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; import { Badge } from "@/components/ui/badge"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { useToast } from "@/hooks/use-toast"; import { offlineStorage } from "@/lib/offlineStorage"; import { projectSchema } from "@/lib/validationSchemas"; import { errorHandler, withErrorHandling } from "@/lib/errorHandler"; export default function ProjectManager() { const [selectedProject, setSelectedProject] = useState(null); const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); const [projects, setProjects] = useState([]); const [isLoading, setIsLoading] = useState(true); const [isCreating, setIsCreating] = useState(false); const { toast } = useToast(); const form = useForm({ resolver: zodResolver(projectSchema), defaultValues: { name: "", description: "", type: "", location: "", status: "active" as const, }, }); // Load projects on component mount useEffect(() => { loadProjects(); }, []); const loadProjects = async () => { const result = await withErrorHandling.async( () => offlineStorage.getProjects(), 'ProjectManager', 'loading projects' ); if (result.success) { setProjects(result.data || []); } else { toast({ title: "Error loading projects", description: "Could not load projects from storage", variant: "destructive" }); } setIsLoading(false); }; const onSubmit = async (data: any) => { setIsCreating(true); const result = await withErrorHandling.async( () => offlineStorage.createProject(data), 'ProjectManager', 'creating project' ); if (result.success) { setProjects(prev => [...prev, result.data]); setIsCreateDialogOpen(false); form.reset(); toast({ title: "Project created successfully" }); } else { const errorLog = errorHandler.getRecentErrors(1)[0]; toast({ title: "Error creating project", description: errorLog?.recoveryAction || "Please try again", variant: "destructive" }); } setIsCreating(false); }; const getProjectTypeIcon = (type: string) => { switch (type) { case "university": return ; case "residential": return ; case "commercial": return ; case "infrastructure": return ; default: return ; } }; const getStatusColor = (status: string) => { switch (status) { case "active": return "bg-green-100 text-green-800"; case "completed": return "bg-blue-100 text-blue-800"; case "archived": return "bg-gray-100 text-gray-800"; default: return "bg-gray-100 text-gray-800"; } }; if (isLoading) { return (

Loading projects...

); } return (
{/* Header */}

परियोजना प्रबंधक

Integrated Project Management Dashboard

Create projects and link engineering modules for comprehensive analysis

Create New Project Start a new engineering project to organize your calculations and reports
( Project Name )} /> ( Project Type )} /> ( Location )} /> ( Description