'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'; interface CreateTaskFormProps { projectId: string; workspaceId: string; onSuccess?: () => void; onCancel?: () => void; } export default function CreateTaskForm({ projectId, workspaceId, onSuccess, onCancel }: CreateTaskFormProps) { const router = useRouter(); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [formData, setFormData] = useState({ name: '', description: '', priority: 'medium', assignee_user_id: '', parent_task_id: '', }); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const res = await fetch(`${API_BASE}/api/v1/project-management/tasks`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ project_id: projectId, workspace_id: workspaceId, ...formData, }), }); if (!res.ok) { const data = await res.json(); throw new Error(data.detail || '创建失败'); } if (onSuccess) { onSuccess(); } else { router.push('/projects'); } } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; return (
); }