removing-test-pages
This commit is contained in:
parent
6030263128
commit
e9929e04f7
@ -8,7 +8,6 @@ import Link from "next/link";
|
||||
import ProtectedRoute from "@/components/ProtectedRoute";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { buscarPacientes } from "@/lib/api";
|
||||
import { ApiTest } from "@/components/debug/ApiTest";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
@ -2424,18 +2423,6 @@ function LaudoEditor() {
|
||||
);
|
||||
|
||||
|
||||
const renderDebugSection = () => (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-4">Debug da API</h2>
|
||||
<p className="text-gray-600 mb-6">
|
||||
Use esta seção para testar a conectividade com a API e debugar problemas de busca de pacientes.
|
||||
</p>
|
||||
</div>
|
||||
<ApiTest />
|
||||
</div>
|
||||
);
|
||||
|
||||
const renderActiveSection = () => {
|
||||
switch (activeSection) {
|
||||
case 'calendario':
|
||||
@ -2452,8 +2439,6 @@ function LaudoEditor() {
|
||||
return renderRelatoriosMedicosSection();
|
||||
case 'perfil':
|
||||
return renderPerfilSection();
|
||||
case 'debug':
|
||||
return renderDebugSection();
|
||||
default:
|
||||
return renderCalendarioSection();
|
||||
}
|
||||
@ -2548,14 +2533,6 @@ function LaudoEditor() {
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
Meu Perfil
|
||||
</Button>
|
||||
<Button
|
||||
variant={activeSection === 'debug' ? 'default' : 'ghost'}
|
||||
className="w-full justify-start cursor-pointer hover:bg-primary hover:text-primary-foreground cursor-pointer"
|
||||
onClick={() => setActiveSection('debug')}
|
||||
>
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
Debug API
|
||||
</Button>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
|
||||
@ -1,191 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { buscarPacientePorId, buscarPacientes, listarPacientes } from "@/lib/api";
|
||||
|
||||
export const ApiTest = () => {
|
||||
const [testId, setTestId] = useState("7ddbd1e2-1aee-4f7a-94f9-ee4c735ca276");
|
||||
const [resultado, setResultado] = useState<any>(null);
|
||||
const [erro, setErro] = useState<string | null>(null);
|
||||
const [carregando, setCarregando] = useState(false);
|
||||
|
||||
const testarConexao = async () => {
|
||||
setCarregando(true);
|
||||
setErro(null);
|
||||
setResultado(null);
|
||||
|
||||
try {
|
||||
console.log("Testando conexão com a API...");
|
||||
|
||||
// Primeiro teste básico
|
||||
const pacientes = await listarPacientes({ limit: 5 });
|
||||
console.log("Pacientes encontrados:", pacientes);
|
||||
|
||||
// Teste direto da API para ver estrutura
|
||||
const REST = "https://yuanqfswhberkoevtmfr.supabase.co/rest/v1";
|
||||
const headers: Record<string, string> = {
|
||||
apikey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ",
|
||||
Accept: "application/json",
|
||||
};
|
||||
|
||||
// Token do localStorage se disponível
|
||||
const token = localStorage.getItem("auth_token") || localStorage.getItem("token");
|
||||
if (token) {
|
||||
headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
console.log("Headers sendo usados:", headers);
|
||||
|
||||
const directRes = await fetch(`${REST}/patients?limit=3&select=id,full_name,cpf,email`, {
|
||||
method: "GET",
|
||||
headers
|
||||
});
|
||||
|
||||
console.log("Status da resposta direta:", directRes.status);
|
||||
|
||||
if (directRes.ok) {
|
||||
const directData = await directRes.json();
|
||||
console.log("Dados diretos da API:", directData);
|
||||
|
||||
setResultado({
|
||||
tipo: "Conexão + Estrutura",
|
||||
data: {
|
||||
pacientes: pacientes,
|
||||
estruturaDireta: directData,
|
||||
statusCode: directRes.status,
|
||||
headers: Object.fromEntries(directRes.headers.entries())
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const errorText = await directRes.text();
|
||||
console.error("Erro na resposta direta:", errorText);
|
||||
setErro(`Erro ${directRes.status}: ${errorText}`);
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
console.error("Erro na conexão:", error);
|
||||
setErro(error.message);
|
||||
} finally {
|
||||
setCarregando(false);
|
||||
}
|
||||
};
|
||||
|
||||
const testarBuscaPorId = async () => {
|
||||
if (!testId.trim()) {
|
||||
setErro("Digite um ID para buscar");
|
||||
return;
|
||||
}
|
||||
|
||||
setCarregando(true);
|
||||
setErro(null);
|
||||
setResultado(null);
|
||||
|
||||
try {
|
||||
console.log("Buscando paciente por ID:", testId);
|
||||
const paciente = await buscarPacientePorId(testId);
|
||||
setResultado({ tipo: "Busca por ID", data: paciente });
|
||||
} catch (error: any) {
|
||||
console.error("Erro na busca por ID:", error);
|
||||
setErro(error.message);
|
||||
} finally {
|
||||
setCarregando(false);
|
||||
}
|
||||
};
|
||||
|
||||
const testarBuscaGeral = async () => {
|
||||
if (!testId.trim()) {
|
||||
setErro("Digite um termo para buscar");
|
||||
return;
|
||||
}
|
||||
|
||||
setCarregando(true);
|
||||
setErro(null);
|
||||
setResultado(null);
|
||||
|
||||
try {
|
||||
console.log("Buscando pacientes:", testId);
|
||||
const pacientes = await buscarPacientes(testId);
|
||||
setResultado({ tipo: "Busca geral", data: pacientes });
|
||||
} catch (error: any) {
|
||||
console.error("Erro na busca geral:", error);
|
||||
setErro(error.message);
|
||||
} finally {
|
||||
setCarregando(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Card className="max-w-2xl mx-auto">
|
||||
<CardHeader>
|
||||
<CardTitle>Teste da API - Pacientes</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
placeholder="Digite ID, CPF ou nome para buscar..."
|
||||
value={testId}
|
||||
onChange={(e) => setTestId(e.target.value)}
|
||||
className="flex-1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
<Button
|
||||
onClick={testarConexao}
|
||||
disabled={carregando}
|
||||
variant="outline"
|
||||
>
|
||||
{carregando ? "Testando..." : "Testar Conexão"}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={testarBuscaPorId}
|
||||
disabled={carregando || !testId.trim()}
|
||||
>
|
||||
{carregando ? "Buscando..." : "Buscar por ID"}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={testarBuscaGeral}
|
||||
disabled={carregando || !testId.trim()}
|
||||
variant="secondary"
|
||||
>
|
||||
{carregando ? "Buscando..." : "Busca Geral"}
|
||||
</Button>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
{erro && (
|
||||
<div className="p-3 bg-red-50 border border-red-200 rounded-md">
|
||||
<p className="text-red-700 font-medium">Erro:</p>
|
||||
<p className="text-red-600 text-sm">{erro}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{resultado && (
|
||||
<div className="p-3 bg-green-50 border border-green-200 rounded-md">
|
||||
<p className="text-green-700 font-medium">Resultado ({resultado.tipo}):</p>
|
||||
<pre className="text-sm text-green-600 mt-2 overflow-auto">
|
||||
{JSON.stringify(resultado.data, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-xs text-gray-500 mt-4">
|
||||
<p>• <strong>Testar Conexão:</strong> Lista os primeiros 5 pacientes e verifica a estrutura da API</p>
|
||||
<p>• <strong>Buscar por ID:</strong> Busca um paciente específico por ID, CPF ou nome</p>
|
||||
<p>• <strong>Busca Geral:</strong> Busca avançada em múltiplos campos</p>
|
||||
<p className="mt-2 font-medium">Abra o console do navegador (F12) para ver logs detalhados da investigação.</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
@ -1,56 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { listarPacientes, buscarPacientePorId } from "@/lib/api";
|
||||
|
||||
export const ApiTestSimple = () => {
|
||||
const [resultado, setResultado] = useState<string>("");
|
||||
const [carregando, setCarregando] = useState(false);
|
||||
|
||||
const testarListarPacientes = async () => {
|
||||
setCarregando(true);
|
||||
try {
|
||||
const pacientes = await listarPacientes();
|
||||
setResultado(`✅ Sucesso! Encontrados ${pacientes.length} pacientes:\n${JSON.stringify(pacientes, null, 2)}`);
|
||||
} catch (error: any) {
|
||||
setResultado(`❌ Erro: ${error.message}`);
|
||||
} finally {
|
||||
setCarregando(false);
|
||||
}
|
||||
};
|
||||
|
||||
const testarBuscarPorId = async () => {
|
||||
setCarregando(true);
|
||||
const id = "7ddbd1e2-1aee-4f7a-94f9-ee4c735ca276";
|
||||
try {
|
||||
const paciente = await buscarPacientePorId(id);
|
||||
setResultado(`✅ Paciente encontrado:\n${JSON.stringify(paciente, null, 2)}`);
|
||||
} catch (error: any) {
|
||||
setResultado(`❌ Erro ao buscar ID ${id}: ${error.message}`);
|
||||
} finally {
|
||||
setCarregando(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-4 border rounded-lg max-w-4xl mx-auto">
|
||||
<h3 className="text-lg font-bold mb-4">Teste da API Mock</h3>
|
||||
|
||||
<div className="flex gap-2 mb-4">
|
||||
<Button onClick={testarListarPacientes} disabled={carregando}>
|
||||
{carregando ? "Testando..." : "Listar Pacientes"}
|
||||
</Button>
|
||||
<Button onClick={testarBuscarPorId} disabled={carregando}>
|
||||
{carregando ? "Testando..." : "Buscar ID Específico"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{resultado && (
|
||||
<div className="bg-gray-100 p-4 rounded-lg">
|
||||
<pre className="text-sm overflow-auto">{resultado}</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user