diff --git a/src/components/dashboard/WorkflowTarefas.tsx b/src/components/dashboard/WorkflowTarefas.tsx index 0608737..7641c7d 100644 --- a/src/components/dashboard/WorkflowTarefas.tsx +++ b/src/components/dashboard/WorkflowTarefas.tsx @@ -1,50 +1,37 @@ -import React, { useEffect, useState } from 'react'; - -interface Tarefa { - id: string; - titulo: string; - status: string; -} +import React from 'react'; +import { useAuth } from '../../contexts/AuthContext'; +import { useTarefas } from '../../hooks/useTarefas'; +import { Tarefa } from '../../types/entities'; export const WorkflowTarefas: React.FC = () => { - const [tarefas, setTarefas] = useState([]); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); + const { user } = useAuth(); + const { tarefas, isLoading, deleteTarefa } = useTarefas(); - useEffect(() => { - async function fetchTarefas() { - try { - setLoading(true); - setError(null); - const res = await fetch('/api/tarefas', { - headers: { - 'Content-Type': 'application/json', - }, - }); - if (!res.ok) throw new Error('Erro ao buscar tarefas'); - const data = await res.json(); - setTarefas(data); - } catch (err: any) { - setError(err.message); - } finally { - setLoading(false); - } - } - fetchTarefas(); - }, []); + if (isLoading) { + return ( +
+ Carregando tarefas... +
+ ); + } - if (loading) return
Carregando tarefas...
; - if (error) return
{error}
; + if (!tarefas || tarefas.length === 0) { + return ( +
+ Nenhuma tarefa encontrada. +
+ ); + } return (
- {tarefas.map((tarefa) => ( + {tarefas.map((tarefa: Tarefa) => (
{tarefa.titulo} - {tarefa.status} + {tarefa.status.replace('_', ' ')}
))}