"use client"; import { completeTaskRecord, createTaskRecord, deleteTaskRecord, updateTaskRecord, } from "@/app/(dashboard)/tasks/actions"; import { Badge, Button, Card, CardContent, Input, Label, Textarea } from "poyraz-ui/atoms"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "poyraz-ui/molecules"; import { CalendarDays, CheckCircle2, KanbanSquare, LayoutList, Pencil, Plus, Trash2, } from "lucide-react"; import { useState } from "react"; export type TaskRelationOption = { id: string; name: string; client_id?: string | null; }; export type TaskListItem = { id: string; title: string; description: string | null; status: "todo" | "in_progress" | "done"; priority: "low" | "medium" | "high" | "urgent"; due_at: string | null; estimated_minutes: number | null; actual_minutes: number | null; client_id: string | null; clientName: string | null; project_id: string | null; projectName: string | null; created_at: string; }; const statusLabels = { todo: "Yapılacak", in_progress: "Devam ediyor", done: "Tamamlandı", }; const priorityLabels = { low: "Düşük", medium: "Orta", high: "Yüksek", urgent: "Acil", }; const priorityClasses = { low: "border-zinc-200 bg-zinc-50 text-zinc-700", medium: "border-blue-200 bg-blue-50 text-blue-700", high: "border-amber-200 bg-amber-50 text-amber-700", urgent: "border-rose-200 bg-rose-50 text-rose-700", }; type TasksClientProps = { tasks: TaskListItem[]; clients: TaskRelationOption[]; projects: TaskRelationOption[]; }; export function TasksClient({ tasks, clients, projects }: TasksClientProps) { const [query, setQuery] = useState(""); const [view, setView] = useState<"list" | "kanban">("list"); const normalizedQuery = query.trim().toLowerCase(); const filteredTasks = normalizedQuery ? tasks.filter((task) => [task.title, task.description, task.clientName, task.projectName] .filter(Boolean) .some((value) => value!.toLowerCase().includes(normalizedQuery)), ) : tasks; const doneCount = tasks.filter((task) => task.status === "done").length; const overdueCount = tasks.filter((task) => isOverdue(task)).length; const urgentCount = tasks.filter((task) => task.priority === "urgent").length; return (
Günlük operasyon

Görevler

Proje ve müşteri bağlantılı işleri liste veya basit kanban ile takip et.

Görev listesi

{filteredTasks.length} kayıt görüntüleniyor.

setQuery(event.target.value)} placeholder="Görev, proje veya müşteri ara" className="sm:w-80" />
{filteredTasks.length > 0 ? ( view === "list" ? ( ) : ( ) ) : ( )}
); } function TaskList({ tasks, clients, projects, }: { tasks: TaskListItem[]; clients: TaskRelationOption[]; projects: TaskRelationOption[]; }) { return (
Görev Bağlantı Öncelik Son tarih İşlem
{tasks.map((task) => ( ))}
); } function TaskRow({ task, clients, projects, }: { task: TaskListItem; clients: TaskRelationOption[]; projects: TaskRelationOption[]; }) { return (
{task.title}
{statusLabels[task.status]}
{task.projectName || "Proje yok"}
{task.clientName || "Müşteri yok"}
{priorityLabels[task.priority]}
{task.due_at ? formatDateTime(task.due_at) : "Yok"}
); } function TaskKanban({ tasks, clients, projects, }: { tasks: TaskListItem[]; clients: TaskRelationOption[]; projects: TaskRelationOption[]; }) { const columns = ["todo", "in_progress", "done"] as const; return (
{columns.map((status) => { const columnTasks = tasks.filter((task) => task.status === status); return (

{statusLabels[status]}

{columnTasks.length}
{columnTasks.map((task) => (
{task.title}
{task.projectName || task.clientName || "Bağlantı yok"}
{priorityLabels[task.priority]}
))}
); })}
); } function TaskActions({ task, clients, projects, compact = false, }: { task: TaskListItem; clients: TaskRelationOption[]; projects: TaskRelationOption[]; compact?: boolean; }) { return (
{task.status !== "done" ? (
) : null}
); } function TaskDialog({ mode, task, clients, projects, }: { mode: "create" | "edit"; task?: TaskListItem; clients: TaskRelationOption[]; projects: TaskRelationOption[]; }) { const [open, setOpen] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const action = mode === "create" ? createTaskRecord : updateTaskRecord; async function handleSubmit(formData: FormData) { setIsSubmitting(true); try { await action(formData); setOpen(false); } finally { setIsSubmitting(false); } } return (
{task ? : null} {mode === "create" ? "Yeni görev" : "Görevi düzenle"} Görevi proje, müşteri, öncelik ve son tarih bilgileriyle kaydet.
); } function TaskFormFields({ task, clients, projects, }: { task?: TaskListItem; clients: TaskRelationOption[]; projects: TaskRelationOption[]; }) { return (