import { AnimatePresence, motion } from 'framer-motion' import { AlertCircle, Calendar, CheckCircle2, Clock, Filter, Layers, Plus, RefreshCw, Search, Tag, XCircle, } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' import { Link } from 'react-router-dom' import { taskService } from '../services/taskService' import { cn } from '../lib/utils' import { TASK_STATUS_LABELS } from '../types/task' import type { TaskResponse } from '../types/task' function getStatusConfig(status: TaskResponse['status']) { switch (status) { case 'COMPLETED': return { tone: 'bg-success-soft text-success border-success/20', icon: CheckCircle2, label: 'Concluído', } case 'IN_PROGRESS': return { tone: 'bg-warning-soft text-warning border-warning/20', icon: Clock, label: 'Em Andamento', } case 'CANCELED': return { tone: 'bg-danger-soft text-danger border-danger/20', icon: XCircle, label: 'Cancelado', } default: return { tone: 'bg-surface-muted text-text-muted border-border-soft', icon: AlertCircle, label: 'Pendente', } } } import { TaskTimer } from '../components/TaskTimer' export function TaskListPage() { const [tasks, setTasks] = useState([]) const [isLoading, setIsLoading] = useState(true) const [errorMessage, setErrorMessage] = useState(null) const [searchQuery, setSearchQuery] = useState('') const [statusFilter, setStatusFilter] = useState('ALL') const loadTasks = async (silent = false) => { if (!silent) setIsLoading(true) setErrorMessage(null) try { const response = await taskService.getTasks() setTasks(response) } catch (error) { setErrorMessage( error instanceof Error ? error.message : 'Não foi possível carregar as tarefas.', ) } finally { setIsLoading(false) } } useEffect(() => { void loadTasks() }, []) const filteredTasks = useMemo(() => { return tasks.filter((task) => { const matchesSearch = task.title.toLowerCase().includes(searchQuery.toLowerCase()) || task.description?.toLowerCase().includes(searchQuery.toLowerCase()) || task.project?.toLowerCase().includes(searchQuery.toLowerCase()) const matchesStatus = statusFilter === 'ALL' || task.status === statusFilter return matchesSearch && matchesStatus }) }, [tasks, searchQuery, statusFilter]) return (
{/* Header & Action */}

Gerenciamento de Tarefas

Visualize e organize suas atividades em tempo real.

Criar Tarefa
{/* Toolbar */}
setSearchQuery(e.target.value)} className="h-11 w-full rounded-xl border border-border-soft bg-app-bg pl-10 pr-4 text-sm outline-none transition-all focus:border-brand focus:ring-2 focus:ring-brand/10" />
{['ALL', 'NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', 'CANCELED'].map( (status) => ( ), )}
{/* Task List */}
{filteredTasks.map((task, i) => { const config = getStatusConfig(task.status) const StatusIcon = config.icon return (
{config.label}
#{task.id}

{task.title}

{task.description || 'Sem descrição informada.'}

loadTasks(true)} />
{task.project || 'Geral'}
{task.history?.length ?? 0} registros
) })}
{/* Empty States */} {!isLoading && filteredTasks.length === 0 && (

Nenhuma tarefa encontrada

Tente ajustar seus filtros ou busque por outro termo para encontrar o que procura.

)} {/* Loading State */} {isLoading && tasks.length === 0 && (
{Array.from({ length: 6 }).map((_, i) => (
))}
)}
) }