"use client"; import Link from "next/link"; import { useState, useTransition } from "react"; import { moveTaskCard } from "@/app/(app)/actions"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; export type Column = "backlog" | "in_progress" | "review" | "done"; export interface Card { key: string; title: string; status: string; column: Column; goal: string | null; } const COLUMNS: Array<{ id: Column; title: string; hint: string; dot: string }> = [ { id: "backlog", title: "Бэклог", hint: "", dot: "bg-muted-foreground" }, { id: "in_progress", title: "В работе", hint: "сюда — запустить агента", dot: "bg-info" }, { id: "review", title: "Ревью", hint: "", dot: "bg-ok" }, { id: "done", title: "Готово", hint: "", dot: "bg-ok" }, ]; const STATUS: Record = { proposing: { label: "proposal", tone: "primary" }, awaiting_approval: { label: "ждёт PM", tone: "primary" }, blocked: { label: "блок", tone: "danger" }, in_progress: { label: "агент", tone: "info" }, }; const NEXT: Partial> = { backlog: { to: "in_progress", label: "В работу →" }, review: { to: "done", label: "Принять ✓" }, }; /** Task board: drag a card (or use its button) to move it; the server starts/stops agents. */ export function Board({ cards, back }: { cards: Card[]; back: string }) { const [pending, start] = useTransition(); const [over, setOver] = useState(null); const move = (key: string, to: Column) => { const f = new FormData(); f.set("taskKey", key); f.set("to", to); f.set("back", back); start(() => moveTaskCard(f)); }; return (
{COLUMNS.map((c) => { const list = cards.filter((x) => x.column === c.id); return (
{ e.preventDefault(); setOver(c.id); }} onDragLeave={() => setOver(null)} onDrop={(e) => { e.preventDefault(); setOver(null); const key = e.dataTransfer.getData("text/plain"); const card = cards.find((x) => x.key === key); if (card && card.column !== c.id) move(key, c.id); }} >

{c.title} {list.length}

{c.hint &&

{c.hint}

} {list.map((card) => (
e.dataTransfer.setData("text/plain", card.key)} className="flex cursor-grab flex-col gap-2 rounded-md border bg-card p-2.5 text-sm shadow-xs transition-colors hover:border-primary/40 active:cursor-grabbing" > {card.key} {card.title} {(card.goal || STATUS[card.status] || NEXT[c.id]) && (
{card.goal && ◎ {card.goal}} {STATUS[card.status] && {STATUS[card.status]!.label}} {NEXT[c.id] && ( )}
)}
))}
); })}
); }