import { PencilIcon, CheckIcon, XMarkIcon, ExclamationTriangleIcon, TrashIcon, } from "@heroicons/react/24/outline"; import { format } from "date-fns"; import { ptBR } from "date-fns/locale"; import React from "react"; import { useAuth } from "../../contexts/AuthContext"; import { useTarefas } from "../../hooks/useTarefas"; import { Tarefa } from "../../types/entities"; interface TarefaCardProps { tarefa: Tarefa; onEdit: (tarefa: Tarefa) => void; onStatusChange: (id: string, status: string, progresso?: number) => void; } export const TarefaCard: React.FC = ({ tarefa, onEdit, onStatusChange, }) => { const { user } = useAuth(); const { deleteTarefa } = useTarefas(); const canDelete = user && ["ADVOGADO_ADMIN", "ADVOGADO"].includes(user.perfil); const handleDelete = async (e: React.MouseEvent) => { e.stopPropagation(); if (!window.confirm("Tem certeza que deseja excluir esta tarefa?")) return; try { await deleteTarefa.mutateAsync(tarefa.id); } catch (error) { console.error("Erro ao excluir tarefa:", error); alert("Erro ao excluir tarefa"); } }; const getPrioridadeColor = () => { switch (tarefa.prioridade) { case "BAIXA": return "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200"; case "MEDIA": return "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200"; case "ALTA": return "bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200"; case "URGENTE": return "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"; } }; return (

{tarefa.titulo}

{tarefa.prioridade}

{tarefa.descricao}

{tarefa.subtarefas.map((subtarefa, index) => (
{subtarefa.concluida ? ( ) : ( index + 1 )}
))}
{format(new Date(tarefa.dataVencimento), "dd/MM/yyyy", { locale: ptBR, })}
{tarefa.status !== "CONCLUIDA" && tarefa.status !== "CANCELADA" && ( <> )} {canDelete && ( )}
); };