import { useState, useEffect } from "react"; import type { Task, Member, Label } from "@/lib/api"; import { createTask, getMembers, getLabels } from "@/lib/api"; const STATUSES = [ { key: "backlog", label: "Backlog", color: "#737373" }, { key: "todo", label: "TODO", color: "#3b82f6" }, { key: "in_progress", label: "In Progress", color: "#f59e0b" }, { key: "in_review", label: "Review", color: "#a855f7" }, { key: "done", label: "Done", color: "#22c55e" }, ]; const PRIORITIES = [ { key: "low", label: "Low", color: "#737373" }, { key: "medium", label: "Medium", color: "#3b82f6" }, { key: "high", label: "High", color: "#f59e0b" }, { key: "critical", label: "Critical", color: "#ef4444" }, ]; const TYPES = [ { key: "task", label: "Задача" }, { key: "bug", label: "Баг" }, { key: "feature", label: "Фича" }, ]; interface Props { projectId: string; initialStatus: string; parentId?: string; parentKey?: string; onClose: () => void; onCreated: (task: Task) => void; } export default function CreateTaskModal({ projectId, initialStatus, parentId, parentKey, onClose, onCreated }: Props) { const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [status, setStatus] = useState(initialStatus || "backlog"); const [priority, setPriority] = useState("medium"); const [type, setType] = useState("task"); const [assigneeId, setAssigneeId] = useState(""); const [reviewerId, setReviewerId] = useState(""); const [selectedLabels, setSelectedLabels] = useState([]); const [saving, setSaving] = useState(false); const [error, setError] = useState(""); const [members, setMembers] = useState([]); const [labels, setLabels] = useState([]); useEffect(() => { getMembers().then(setMembers).catch(() => {}); getLabels().then(setLabels).catch(() => {}); }, []); const handleSubmit = async () => { if (!title.trim()) return; setSaving(true); setError(""); try { const task = await createTask(projectId, { title: title.trim(), description: description.trim() || undefined, status, priority, type, parent_id: parentId, assignee_id: assigneeId || undefined, reviewer_id: reviewerId || undefined, labels: selectedLabels, }); onCreated(task); onClose(); } catch (e: any) { setError(e.message || "Ошибка"); } finally { setSaving(false); } }; return (
e.stopPropagation()} >

{parentKey ? `Подзадача для ${parentKey}` : "Новая задача"}

{/* Title */}
setTitle(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleSubmit()} placeholder="Название задачи..." className="w-full bg-[var(--bg)] border border-[var(--border)] rounded-lg px-3 py-2 text-sm outline-none focus:border-[var(--accent)]" />
{/* Description */}