import { ProjectRequirement } from "@vtit-agent-coding/shared"; import { useEffect, useState } from "react"; import { RequirementDetailView } from "./RequirementDetailView"; import { Button } from "./ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "./ui/dialog"; import { Input } from "./ui/input"; import { Label } from "./ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"; import { Textarea } from "./ui/textarea"; export function ProjectRequirementsTab({ projectId }: { projectId: string }) { const [requirements, setRequirements] = useState([]); const [agents, setAgents] = useState<{ id: string; name: string }[]>([]); const [isLoading, setIsLoading] = useState(true); const [selectedReqId, setSelectedReqId] = useState(null); // Form state const [open, setOpen] = useState(false); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [pmModel, setPmModel] = useState(""); const [saModel, setSaModel] = useState(""); const [baModel, setBaModel] = useState(""); useEffect(() => { loadData(); }, [projectId]); async function loadData() { setIsLoading(true); try { const [reqRes, agentsRes] = await Promise.all([fetch(`/api/projects/${projectId}/requirements`), fetch(`/api/agents`)]); if (reqRes.ok) { const data = await reqRes.json(); setRequirements(Array.isArray(data) ? data : []); } if (agentsRes.ok) { const data = await agentsRes.json(); setAgents(Array.isArray(data) ? data : []); } } catch (err) { console.error(err); } finally { setIsLoading(false); } } async function handleCreate(e: React.FormEvent) { e.preventDefault(); if (!title) return; try { const res = await fetch(`/api/projects/${projectId}/requirements`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title, description, pm_model: pmModel, sa_model: saModel, ba_model: baModel, }), }); if (res.ok) { setOpen(false); setTitle(""); setDescription(""); setPmModel(""); setSaModel(""); setBaModel(""); loadData(); } } catch (err) { console.error(err); } } if (selectedReqId) { return ( { setSelectedReqId(null); loadData(); }} /> ); } return (

Danh sách Yêu Cầu

Tạo Yêu Cầu Mới
setTitle(e.target.value)} required />