'use client'; import { useState } from 'react'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'; interface CreateIssueFormProps { taskId: string; projectId: string; workspaceId: string; onSuccess: () => void; onCancel: () => void; } export default function CreateIssueForm({ taskId, projectId, workspaceId, onSuccess, onCancel }: CreateIssueFormProps) { const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [formData, setFormData] = useState({ title: '', description: '', }); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const res = await fetch(`${API_BASE}/api/v1/project-management/issues`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ task_id: taskId, project_id: projectId, workspace_id: workspaceId, ...formData, }), }); if (!res.ok) { const data = await res.json(); throw new Error(data.detail || '创建失败'); } onSuccess(); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; return (
{error && (
{error}
)}
setFormData({ ...formData, title: e.target.value })} style={{ width: '100%', padding: '8px 12px', border: '1px solid var(--border)', borderRadius: '4px', fontSize: '14px', }} placeholder="简要描述问题" />