diff --git a/src/components/dashboard/AtendimentosDia.tsx b/src/components/dashboard/AtendimentosDia.tsx index 5b6e94d..68fd956 100644 --- a/src/components/dashboard/AtendimentosDia.tsx +++ b/src/components/dashboard/AtendimentosDia.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import { useAuth } from '../../contexts/AuthContext'; interface Atendimento { id: string; @@ -8,6 +9,7 @@ interface Atendimento { } export const AtendimentosDia: React.FC = () => { + const { token } = useAuth(); const [atendimentos, setAtendimentos] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -17,7 +19,12 @@ export const AtendimentosDia: React.FC = () => { try { setLoading(true); setError(null); - const res = await fetch('/api/atendimentos-dia'); + const res = await fetch('/api/atendimentos-dia', { + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + }); if (!res.ok) throw new Error('Erro ao buscar atendimentos do dia'); const data = await res.json(); setAtendimentos(data); @@ -28,7 +35,7 @@ export const AtendimentosDia: React.FC = () => { } } fetchAtendimentos(); - }, []); + }, [token]); if (loading) return
Carregando atendimentos...
; if (error) return
{error}
; diff --git a/src/components/dashboard/BenchmarkingEscritorio.tsx b/src/components/dashboard/BenchmarkingEscritorio.tsx index 37082dd..3b8679d 100644 --- a/src/components/dashboard/BenchmarkingEscritorio.tsx +++ b/src/components/dashboard/BenchmarkingEscritorio.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import { useAuth } from '../../contexts/AuthContext'; interface Benchmarking { ajuizados15dias: number; @@ -6,6 +7,7 @@ interface Benchmarking { } export const BenchmarkingEscritorio: React.FC = () => { + const { token } = useAuth(); const [benchmarking, setBenchmarking] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -15,7 +17,12 @@ export const BenchmarkingEscritorio: React.FC = () => { try { setLoading(true); setError(null); - const res = await fetch('/api/benchmarking'); + const res = await fetch('/api/benchmarking', { + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + }); if (!res.ok) throw new Error('Erro ao buscar benchmarking'); const data = await res.json(); setBenchmarking(data); @@ -26,7 +33,7 @@ export const BenchmarkingEscritorio: React.FC = () => { } } fetchBenchmarking(); - }, []); + }, [token]); if (loading) return
Carregando benchmarking...
; if (error) return
{error}
; diff --git a/src/components/dashboard/CalendarioAtendimentos.tsx b/src/components/dashboard/CalendarioAtendimentos.tsx index b1b5eb6..96065d3 100644 --- a/src/components/dashboard/CalendarioAtendimentos.tsx +++ b/src/components/dashboard/CalendarioAtendimentos.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import { useAuth } from '../../contexts/AuthContext'; interface Evento { id: string; @@ -8,6 +9,7 @@ interface Evento { } export const CalendarioAtendimentos: React.FC = () => { + const { token } = useAuth(); const [eventos, setEventos] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -17,7 +19,12 @@ export const CalendarioAtendimentos: React.FC = () => { try { setLoading(true); setError(null); - const res = await fetch('/api/eventos'); + const res = await fetch('/api/eventos', { + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + }); if (!res.ok) throw new Error('Erro ao buscar eventos'); const data = await res.json(); setEventos(data); @@ -28,7 +35,7 @@ export const CalendarioAtendimentos: React.FC = () => { } } fetchEventos(); - }, []); + }, [token]); // Simulação de calendário mensal const diasMes = Array.from({ length: 30 }, (_, i) => i + 1);