diff --git a/apps/web/app/components/CreateTaskForm.tsx b/apps/web/app/components/CreateTaskForm.tsx new file mode 100644 index 000000000..d130f9800 --- /dev/null +++ b/apps/web/app/components/CreateTaskForm.tsx @@ -0,0 +1,200 @@ +'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 ( +
+

新增任务

+ + {error && ( +
+ {error} +
+ )} + +
+ + setFormData({ ...formData, name: e.target.value })} + style={{ + width: '100%', + padding: '8px 12px', + border: '1px solid var(--border)', + borderRadius: '4px', + fontSize: '14px', + }} + placeholder="输入任务名称" + /> +
+ +
+ +