Merge pull request #5 from m1guelmcf/alteraçoes-esteticas

ajustes(btn acoes gest de medicos, filtro tabela medico, rfzr data do…
This commit is contained in:
DaniloSts 2025-11-05 20:30:22 -03:00 committed by GitHub
commit 2f12067e9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 568 additions and 640 deletions

View File

@ -1,6 +1,7 @@
"use client";
import React, { useEffect, useState, useCallback } from "react"
// -> ADICIONADO: useMemo para otimizar a criação da lista de especialidades
import React, { useEffect, useState, useCallback, useMemo } from "react"
import ManagerLayout from "@/components/manager-layout";
import Link from "next/link"
import { useRouter } from "next/navigation";
@ -23,14 +24,15 @@ import { doctorsService } from "services/doctorsApi.mjs";
interface Doctor {
id: number;
full_name: string;
specialty: string;
crm: string;
phone_mobile: string | null;
city: string | null;
state: string | null;
id: number;
full_name: string;
specialty: string;
crm: string;
phone_mobile: string | null;
city: string | null;
state: string | null;
// -> ADICIONADO: Campo 'status' para que o filtro funcione. Sua API precisa retornar este dado.
status?: string;
}
@ -38,7 +40,6 @@ interface DoctorDetails {
nome: string;
crm: string;
especialidade: string;
contato: {
celular?: string;
telefone1?: string;
@ -58,7 +59,6 @@ interface DoctorDetails {
export default function DoctorsPage() {
const router = useRouter();
const [doctors, setDoctors] = useState<Doctor[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@ -67,16 +67,22 @@ export default function DoctorsPage() {
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [doctorToDeleteId, setDoctorToDeleteId] = useState<number | null>(null);
// -> PASSO 1: Criar estados para os filtros
const [specialtyFilter, setSpecialtyFilter] = useState("all");
const [statusFilter, setStatusFilter] = useState("all");
const fetchDoctors = useCallback(async () => {
setLoading(true);
setError(null);
try {
const data: Doctor[] = await doctorsService.list();
setDoctors(data || []);
// Exemplo: Adicionando um status fake para o filtro funcionar. O ideal é que isso venha da API.
const dataWithStatus = data.map((doc, index) => ({
...doc,
status: index % 3 === 0 ? "Inativo" : index % 2 === 0 ? "Férias" : "Ativo"
}));
setDoctors(dataWithStatus || []);
} catch (e: any) {
console.error("Erro ao carregar lista de médicos:", e);
setError("Não foi possível carregar a lista de médicos. Verifique a conexão com a API.");
@ -94,44 +100,31 @@ export default function DoctorsPage() {
const openDetailsDialog = async (doctor: Doctor) => {
setDetailsDialogOpen(true);
setDoctorDetails({
nome: doctor.full_name,
crm: doctor.crm,
especialidade: doctor.specialty,
contato: {
celular: doctor.phone_mobile ?? undefined,
telefone1: undefined
},
endereco: {
cidade: doctor.city ?? undefined,
estado: doctor.state ?? undefined,
},
convenio: "Particular",
vip: false,
status: "Ativo",
ultimo_atendimento: "N/A",
proximo_atendimento: "N/A",
nome: doctor.full_name,
crm: doctor.crm,
especialidade: doctor.specialty,
contato: { celular: doctor.phone_mobile ?? undefined },
endereco: { cidade: doctor.city ?? undefined, estado: doctor.state ?? undefined },
status: doctor.status || "Ativo", // Usa o status do médico
convenio: "Particular",
vip: false,
ultimo_atendimento: "N/A",
proximo_atendimento: "N/A",
});
};
const handleDelete = async () => {
if (doctorToDeleteId === null) return;
setLoading(true);
try {
await doctorsService.delete(doctorToDeleteId);
console.log(`Médico com ID ${doctorToDeleteId} excluído com sucesso!`);
setDeleteDialogOpen(false);
setDoctorToDeleteId(null);
await fetchDoctors();
} catch (e) {
console.error("Erro ao excluir:", e);
alert("Erro ao excluir médico.");
} finally {
setLoading(false);
@ -145,10 +138,22 @@ export default function DoctorsPage() {
const handleEdit = (doctorId: number) => {
router.push(`/manager/home/${doctorId}/editar`);
};
// -> MELHORIA: Gera a lista de especialidades dinamicamente
const uniqueSpecialties = useMemo(() => {
const specialties = doctors.map(doctor => doctor.specialty).filter(Boolean);
return [...new Set(specialties)];
}, [doctors]);
// -> PASSO 3: Aplicar a lógica de filtragem
const filteredDoctors = doctors.filter(doctor => {
const specialtyMatch = specialtyFilter === "all" || doctor.specialty === specialtyFilter;
const statusMatch = statusFilter === "all" || doctor.status === statusFilter;
return specialtyMatch && statusMatch;
});
return (
<ManagerLayout>
@ -161,167 +166,173 @@ export default function DoctorsPage() {
</div>
<div className="flex items-center space-x-4 bg-white p-4 rounded-lg border border-gray-200">
<Filter className="w-5 h-5 text-gray-400" />
<Select>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Especialidade" />
</SelectTrigger>
<SelectContent>
<SelectItem value="cardiologia">Cardiologia</SelectItem>
<SelectItem value="dermatologia">Dermatologia</SelectItem>
<SelectItem value="pediatria">Pediatria</SelectItem>
</SelectContent>
</Select>
<Select>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Status" />
</SelectTrigger>
<SelectContent>
<SelectItem value="ativo">Ativo</SelectItem>
<SelectItem value="ferias">Férias</SelectItem>
<SelectItem value="inativo">Inativo</SelectItem>
</SelectContent>
</Select>
</div>
{/* -> PASSO 2: Conectar os estados aos componentes Select <- */}
<div className="flex items-center space-x-4 bg-white p-4 rounded-lg border border-gray-200">
<span className="text-sm font-medium text-foreground">Especialidades</span>
<Select value={specialtyFilter} onValueChange={setSpecialtyFilter}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Especialidade" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">Todas</SelectItem>
{uniqueSpecialties.map(specialty => (
<SelectItem key={specialty} value={specialty}>{specialty}</SelectItem>
))}
</SelectContent>
</Select>
<span className="text-sm font-medium text-foreground">Status</span>
<Select value={statusFilter} onValueChange={setStatusFilter}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Status" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">Todos</SelectItem>
<SelectItem value="Ativo">Ativo</SelectItem>
<SelectItem value="Férias">Férias</SelectItem>
<SelectItem value="Inativo">Inativo</SelectItem>
</SelectContent>
</Select>
<Button variant="outline" className="ml-auto w-full md:w-auto">
<Filter className="w-4 h-4 mr-2" />
Filtro avançado
</Button>
</div>
<div className="bg-white rounded-lg border border-gray-200 shadow-md overflow-hidden">
{loading ? (
<div className="bg-white rounded-lg border border-gray-200 shadow-md overflow-hidden">
{loading ? (
<div className="p-8 text-center text-gray-500">
<Loader2 className="w-8 h-8 animate-spin mx-auto mb-3 text-green-600" />
Carregando médicos...
<Loader2 className="w-8 h-8 animate-spin mx-auto mb-3 text-green-600" />
Carregando médicos...
</div>
) : error ? (
) : error ? (
<div className="p-8 text-center text-red-600">
{error}
{error}
</div>
) : doctors.length === 0 ? (
// -> Atualizado para usar a lista filtrada
) : filteredDoctors.length === 0 ? (
<div className="p-8 text-center text-gray-500">
Nenhum médico cadastrado. <Link href="/manager/home/novo" className="text-green-600 hover:underline">Adicione um novo</Link>.
{doctors.length === 0
? <>Nenhum médico cadastrado. <Link href="/manager/home/novo" className="text-green-600 hover:underline">Adicione um novo</Link>.</>
: "Nenhum médico encontrado com os filtros aplicados."
}
</div>
) : (
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nome</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">CRM</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Especialidade</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Celular</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cidade/Estado</th>
<th scope="col" className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{doctors.map((doctor) => (
<tr key={doctor.id} className="hover:bg-gray-50">
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{doctor.full_name}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{doctor.crm}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{doctor.specialty}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{doctor.phone_mobile || "N/A"}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{(doctor.city || doctor.state) ? `${doctor.city || ''}${doctor.city && doctor.state ? '/' : ''}${doctor.state || ''}` : "N/A"}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<div className="flex justify-end space-x-1">
<Button variant="outline" size="icon" onClick={() => openDetailsDialog(doctor)} title="Visualizar Detalhes">
<Eye className="h-4 w-4" />
</Button>
<Button variant="outline" size="icon" onClick={() => handleEdit(doctor.id)} title="Editar">
<Edit className="h-4 w-4 text-blue-600" />
</Button>
<Button variant="outline" size="icon" onClick={() => openDeleteDialog(doctor.id)} title="Excluir">
<Trash2 className="h-4 w-4 text-red-600" />
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0" title="Mais Ações">
<span className="sr-only">Mais Ações</span>
<MoreVertical className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem>
<Calendar className="mr-2 h-4 w-4" />
Agendar Consulta
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</td>
) : (
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nome</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">CRM</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Especialidade</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Celular</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cidade/Estado</th>
<th scope="col" className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{/* -> ATUALIZADO para mapear a lista filtrada */}
{filteredDoctors.map((doctor) => (
<tr key={doctor.id} className="hover:bg-gray-50">
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{doctor.full_name}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{doctor.crm}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{doctor.specialty}</td>
{/* Coluna de Status adicionada para visualização */}
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{doctor.status}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{doctor.phone_mobile || "N/A"}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{(doctor.city || doctor.state) ? `${doctor.city || ''}${doctor.city && doctor.state ? '/' : ''}${doctor.state || ''}` : "N/A"}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<div className="text-blue-600">Ações</div>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => openDetailsDialog(doctor)}>
<Eye className="w-4 h-4 mr-2" />
Ver detalhes
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleEdit(doctor.id)}>
<Edit className="w-4 h-4 mr-2" />
Editar
</DropdownMenuItem>
<DropdownMenuItem
className="text-red-600 focus:text-red-700"
onClick={() => openDeleteDialog(doctor.id)}
>
<Trash2 className="w-4 h-4 mr-2" />
Excluir
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
<AlertDialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Confirma a exclusão?</AlertDialogTitle>
<AlertDialogDescription>
Esta ação é irreversível e excluirá permanentemente o registro deste médico.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={loading}>Cancelar</AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} className="bg-red-600 hover:bg-red-700" disabled={loading}>
{loading ? (
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
) : null}
{/* ... O resto do seu código (AlertDialogs) permanece o mesmo ... */}
<AlertDialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Confirma a exclusão?</AlertDialogTitle>
<AlertDialogDescription>
Esta ação é irreversível e excluirá permanentemente o registro deste médico.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={loading}>Cancelar</AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} className="bg-red-600 hover:bg-red-700" disabled={loading}>
{loading ? <Loader2 className="w-4 h-4 mr-2 animate-spin" /> : null}
Excluir
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<AlertDialog open={detailsDialogOpen} onOpenChange={setDetailsDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle className="text-2xl">{doctorDetails?.nome}</AlertDialogTitle>
<AlertDialogDescription className="text-left text-gray-700">
{doctorDetails && (
<div className="space-y-3 text-left">
<h3 className="font-semibold mt-2">Informações Principais</h3>
<div className="grid grid-cols-2 gap-y-1 gap-x-4 text-sm">
<AlertDialog open={detailsDialogOpen} onOpenChange={setDetailsDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle className="text-2xl">{doctorDetails?.nome}</AlertDialogTitle>
<AlertDialogDescription className="text-left text-gray-700">
{doctorDetails && (
<div className="space-y-3 text-left">
<h3 className="font-semibold mt-2">Informações Principais</h3>
<div className="grid grid-cols-2 gap-y-1 gap-x-4 text-sm">
<div><strong>CRM:</strong> {doctorDetails.crm}</div>
<div><strong>Especialidade:</strong> {doctorDetails.especialidade}</div>
<div><strong>Celular:</strong> {doctorDetails.contato.celular || 'N/A'}</div>
<div><strong>Localização:</strong> {`${doctorDetails.endereco.cidade || 'N/A'}/${doctorDetails.endereco.estado || 'N/A'}`}</div>
</div>
</div>
<h3 className="font-semibold mt-4">Atendimento e Convênio</h3>
<div className="grid grid-cols-2 gap-y-1 gap-x-4 text-sm">
<h3 className="font-semibold mt-4">Atendimento e Convênio</h3>
<div className="grid grid-cols-2 gap-y-1 gap-x-4 text-sm">
<div><strong>Convênio:</strong> {doctorDetails.convenio || 'N/A'}</div>
<div><strong>VIP:</strong> {doctorDetails.vip ? "Sim" : "Não"}</div>
<div><strong>Status:</strong> {doctorDetails.status || 'N/A'}</div>
<div><strong>Último atendimento:</strong> {doctorDetails.ultimo_atendimento || 'N/A'}</div>
<div><strong>Próximo atendimento:</strong> {doctorDetails.proximo_atendimento || 'N/A'}</div>
</div>
</div>
</div>
)}
{doctorDetails === null && !loading && (
<div className="text-red-600">Detalhes não disponíveis.</div>
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Fechar</AlertDialogCancel>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)}
{doctorDetails === null && !loading && (
<div className="text-red-600">Detalhes não disponíveis.</div>
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Fechar</AlertDialogCancel>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</ManagerLayout>
);
}

View File

@ -30,6 +30,36 @@ import {
import ManagerLayout from "@/components/manager-layout";
import { patientsService } from "@/services/patientsApi.mjs";
// --- INÍCIO DA MODIFICAÇÃO ---
// PASSO 1: Criar uma função para formatar a data
const formatDate = (dateString: string | null | undefined): string => {
// Se a data não existir, retorna um texto padrão
if (!dateString) {
return "N/A";
}
try {
const date = new Date(dateString);
// Verifica se a data é válida após a conversão
if (isNaN(date.getTime())) {
return "Data inválida";
}
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0'); // Mês é base 0, então +1
const year = date.getFullYear();
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${day}/${month}/${year} ${hours}:${minutes}`;
} catch (error) {
// Se houver qualquer erro na conversão, retorna um texto de erro
return "Data inválida";
}
};
// --- FIM DA MODIFICAÇÃO ---
export default function PacientesPage() {
const [searchTerm, setSearchTerm] = useState("");
const [convenioFilter, setConvenioFilter] = useState("all");
@ -227,127 +257,86 @@ export default function PacientesPage() {
</Button>
</div>
<div className="bg-white rounded-lg border border-gray-200">
<div className="overflow-x-auto">
{error ? (
<div className="p-6 text-red-600">{`Erro ao carregar pacientes: ${error}`}</div>
) : (
<table className="w-full min-w-[600px]">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Nome
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Telefone
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Cidade
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Estado
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Último atendimento
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Próximo atendimento
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Ações
</th>
</tr>
</thead>
<tbody>
{filteredPatients.length === 0 ? (
<tr>
<td colSpan={7} className="p-8 text-center text-gray-500">
{patients.length === 0
? "Nenhum paciente cadastrado"
: "Nenhum paciente encontrado com os filtros aplicados"}
</td>
</tr>
) : (
filteredPatients.map((patient) => (
<tr
key={patient.id}
className="border-b border-gray-100 hover:bg-gray-50"
>
<td className="p-4">
<div className="flex items-center gap-3">
<div className="w-8 h-8 bg-gray-100 rounded-full flex items-center justify-center">
<span className="text-gray-600 font-medium text-sm">
{patient.nome?.charAt(0) || "?"}
</span>
</div>
<span className="font-medium text-gray-900">
{patient.nome}
</span>
</div>
</td>
<td className="p-4 text-gray-600">
{patient.telefone}
</td>
<td className="p-4 text-gray-600">{patient.cidade}</td>
<td className="p-4 text-gray-600">{patient.estado}</td>
<td className="p-4 text-gray-600">
{patient.ultimoAtendimento}
</td>
<td className="p-4 text-gray-600">
{patient.proximoAtendimento}
</td>
<td className="p-4">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<div className="text-blue-600">Ações</div>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
onClick={() =>
openDetailsDialog(String(patient.id))
}
>
<Eye className="w-4 h-4 mr-2" />
Ver detalhes
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link
href={`/manager/pacientes/${patient.id}/editar`}
>
<Edit className="w-4 h-4 mr-2" />
Editar
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Calendar className="w-4 h-4 mr-2" />
Marcar consulta
</DropdownMenuItem>
<DropdownMenuItem
className="text-red-600"
onClick={() =>
openDeleteDialog(String(patient.id))
}
>
<Trash2 className="w-4 h-4 mr-2" />
Excluir
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</td>
</tr>
))
)}
</tbody>
</table>
)}
<div ref={observerRef} style={{ height: 1 }} />
{isFetching && (
<div className="p-4 text-center text-gray-500">
Carregando mais pacientes...
</div>
)}
</div>
</div>
<div className="bg-white rounded-lg border border-gray-200">
<div className="overflow-x-auto">
{error ? (
<div className="p-6 text-red-600">{`Erro ao carregar pacientes: ${error}`}</div>
) : (
<table className="w-full min-w-[600px]">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Nome</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Telefone</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Cidade</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Estado</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Último atendimento</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Próximo atendimento</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Ações</th>
</tr>
</thead>
<tbody>
{filteredPatients.length === 0 ? (
<tr>
<td colSpan={7} className="p-8 text-center text-gray-500">
{patients.length === 0 ? "Nenhum paciente cadastrado" : "Nenhum paciente encontrado com os filtros aplicados"}
</td>
</tr>
) : (
filteredPatients.map((patient) => (
<tr key={patient.id} className="border-b border-gray-100 hover:bg-gray-50">
<td className="p-4">
<div className="flex items-center gap-3">
<div className="w-8 h-8 bg-gray-100 rounded-full flex items-center justify-center">
<span className="text-gray-600 font-medium text-sm">{patient.nome?.charAt(0) || "?"}</span>
</div>
<span className="font-medium text-gray-900">{patient.nome}</span>
</div>
</td>
<td className="p-4 text-gray-600">{patient.telefone}</td>
<td className="p-4 text-gray-600">{patient.cidade}</td>
<td className="p-4 text-gray-600">{patient.estado}</td>
{/* --- INÍCIO DA MODIFICAÇÃO --- */}
{/* PASSO 2: Aplicar a formatação de data na tabela */}
<td className="p-4 text-gray-600">{formatDate(patient.ultimoAtendimento)}</td>
<td className="p-4 text-gray-600">{formatDate(patient.proximoAtendimento)}</td>
{/* --- FIM DA MODIFICAÇÃO --- */}
<td className="p-4">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<div className="text-blue-600 cursor-pointer">Ações</div>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => openDetailsDialog(String(patient.id))}>
<Eye className="w-4 h-4 mr-2" />
Ver detalhes
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link href={`/manager/pacientes/${patient.id}/editar`}>
<Edit className="w-4 h-4 mr-2" />
Editar
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Calendar className="w-4 h-4 mr-2" />
Marcar consulta
</DropdownMenuItem>
<DropdownMenuItem className="text-red-600" onClick={() => openDeleteDialog(String(patient.id))}>
<Trash2 className="w-4 h-4 mr-2" />
Excluir
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</td>
</tr>
))
)}
</tbody>
</table>
)}
<div ref={observerRef} style={{ height: 1 }} />
{isFetching && <div className="p-4 text-center text-gray-500">Carregando mais pacientes...</div>}
</div>
</div>
<AlertDialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
<AlertDialogContent>
@ -372,96 +361,87 @@ export default function PacientesPage() {
</AlertDialogContent>
</AlertDialog>
{/* Modal de detalhes do paciente */}
<AlertDialog
open={detailsDialogOpen}
onOpenChange={setDetailsDialogOpen}
>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Detalhes do Paciente</AlertDialogTitle>
<AlertDialogDescription>
{patientDetails === null ? (
<div className="text-gray-500">Carregando...</div>
) : patientDetails?.error ? (
<div className="text-red-600">{patientDetails.error}</div>
) : (
<div className="space-y-2 text-left">
<p>
<strong>Nome:</strong> {patientDetails.full_name}
</p>
<p>
<strong>CPF:</strong> {patientDetails.cpf}
</p>
<p>
<strong>Email:</strong> {patientDetails.email}
</p>
<p>
<strong>Telefone:</strong>{" "}
{patientDetails.phone_mobile ??
patientDetails.phone1 ??
patientDetails.phone2 ??
"-"}
</p>
<p>
<strong>Nome social:</strong>{" "}
{patientDetails.social_name ?? "-"}
</p>
<p>
<strong>Sexo:</strong> {patientDetails.sex ?? "-"}
</p>
<p>
<strong>Tipo sanguíneo:</strong>{" "}
{patientDetails.blood_type ?? "-"}
</p>
<p>
<strong>Peso:</strong> {patientDetails.weight_kg ?? "-"}
{patientDetails.weight_kg ? "kg" : ""}
</p>
<p>
<strong>Altura:</strong> {patientDetails.height_m ?? "-"}
{patientDetails.height_m ? "m" : ""}
</p>
<p>
<strong>IMC:</strong> {patientDetails.bmi ?? "-"}
</p>
<p>
<strong>Endereço:</strong> {patientDetails.street ?? "-"}
</p>
<p>
<strong>Bairro:</strong>{" "}
{patientDetails.neighborhood ?? "-"}
</p>
<p>
<strong>Cidade:</strong> {patientDetails.city ?? "-"}
</p>
<p>
<strong>Estado:</strong> {patientDetails.state ?? "-"}
</p>
<p>
<strong>CEP:</strong> {patientDetails.cep ?? "-"}
</p>
<p>
<strong>Criado em:</strong>{" "}
{patientDetails.created_at ?? "-"}
</p>
<p>
<strong>Atualizado em:</strong>{" "}
{patientDetails.updated_at ?? "-"}
</p>
<p>
<strong>Id:</strong> {patientDetails.id ?? "-"}
</p>
</div>
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Fechar</AlertDialogCancel>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</ManagerLayout>
);
{/* Modal de detalhes do paciente */}
<AlertDialog open={detailsDialogOpen} onOpenChange={setDetailsDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Detalhes do Paciente</AlertDialogTitle>
<AlertDialogDescription>
{patientDetails === null ? (
<div className="text-gray-500">Carregando...</div>
) : patientDetails?.error ? (
<div className="text-red-600">{patientDetails.error}</div>
) : (
<div className="space-y-2 text-left">
<p>
<strong>Nome:</strong> {patientDetails.full_name}
</p>
<p>
<strong>CPF:</strong> {patientDetails.cpf}
</p>
<p>
<strong>Email:</strong> {patientDetails.email}
</p>
<p>
<strong>Telefone:</strong> {patientDetails.phone_mobile ?? patientDetails.phone1 ?? patientDetails.phone2 ?? "-"}
</p>
<p>
<strong>Nome social:</strong> {patientDetails.social_name ?? "-"}
</p>
<p>
<strong>Sexo:</strong> {patientDetails.sex ?? "-"}
</p>
<p>
<strong>Tipo sanguíneo:</strong> {patientDetails.blood_type ?? "-"}
</p>
<p>
<strong>Peso:</strong> {patientDetails.weight_kg ?? "-"}
{patientDetails.weight_kg ? "kg" : ""}
</p>
<p>
<strong>Altura:</strong> {patientDetails.height_m ?? "-"}
{patientDetails.height_m ? "m" : ""}
</p>
<p>
<strong>IMC:</strong> {patientDetails.bmi ?? "-"}
</p>
<p>
<strong>Endereço:</strong> {patientDetails.street ?? "-"}
</p>
<p>
<strong>Bairro:</strong> {patientDetails.neighborhood ?? "-"}
</p>
<p>
<strong>Cidade:</strong> {patientDetails.city ?? "-"}
</p>
<p>
<strong>Estado:</strong> {patientDetails.state ?? "-"}
</p>
<p>
<strong>CEP:</strong> {patientDetails.cep ?? "-"}
</p>
{/* --- INÍCIO DA MODIFICAÇÃO --- */}
{/* PASSO 3: Aplicar a formatação de data no modal */}
<p>
<strong>Criado em:</strong> {formatDate(patientDetails.created_at)}
</p>
<p>
<strong>Atualizado em:</strong> {formatDate(patientDetails.updated_at)}
</p>
{/* --- FIM DA MODIFICAÇÃO --- */}
<p>
<strong>Id:</strong> {patientDetails.id ?? "-"}
</p>
</div>
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Fechar</AlertDialogCancel>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</ManagerLayout>
);
}

View File

@ -30,11 +30,67 @@ import {
import SecretaryLayout from "@/components/secretary-layout";
import { patientsService } from "@/services/patientsApi.mjs";
// --- INÍCIO DA CORREÇÃO ---
interface Patient {
id: string;
nome: string;
telefone: string;
cidade: string;
estado: string;
ultimoAtendimento: string;
proximoAtendimento: string;
vip: boolean;
convenio: string;
status?: string;
// Propriedades detalhadas para o modal
full_name?: string;
cpf?: string;
email?: string;
phone_mobile?: string;
phone1?: string;
phone2?: string;
social_name?: string;
sex?: string;
blood_type?: string;
weight_kg?: number;
height_m?: number;
bmi?: number;
street?: string;
neighborhood?: string;
city?: string; // <-- Adicionado
state?: string; // <-- Adicionado
cep?: string;
created_at?: string;
updated_at?: string;
}
// --- FIM DA CORREÇÃO ---
// Função para formatar a data
const formatDate = (dateString: string | null | undefined): string => {
if (!dateString) {
return "N/A";
}
try {
const date = new Date(dateString);
if (isNaN(date.getTime())) {
return "Data inválida";
}
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${day}/${month}/${year} ${hours}:${minutes}`;
} catch (error) {
return "Data inválida";
}
};
export default function PacientesPage() {
const [searchTerm, setSearchTerm] = useState("");
const [convenioFilter, setConvenioFilter] = useState("all");
const [vipFilter, setVipFilter] = useState("all");
const [patients, setPatients] = useState<any[]>([]);
const [patients, setPatients] = useState<Patient[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [page, setPage] = useState(1);
@ -44,7 +100,8 @@ export default function PacientesPage() {
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [patientToDelete, setPatientToDelete] = useState<string | null>(null);
const [detailsDialogOpen, setDetailsDialogOpen] = useState(false);
const [patientDetails, setPatientDetails] = useState<any | null>(null);
const [patientDetails, setPatientDetails] = useState<Patient | { error: string } | null>(null);
const openDetailsDialog = async (patientId: string) => {
setDetailsDialogOpen(true);
setPatientDetails(null);
@ -63,7 +120,7 @@ export default function PacientesPage() {
setError(null);
try {
const res = await patientsService.list();
const mapped = res.map((p: any) => ({
const mapped: Patient[] = res.map((p: any) => ({
id: String(p.id ?? ""),
nome: p.full_name ?? "",
telefone: p.phone_mobile ?? p.phone1 ?? "",
@ -72,20 +129,22 @@ export default function PacientesPage() {
ultimoAtendimento: p.last_visit_at ?? "",
proximoAtendimento: p.next_appointment_at ?? "",
vip: Boolean(p.vip ?? false),
convenio: p.convenio ?? "", // se não existir, fica vazio
convenio: p.convenio ?? "",
status: p.status ?? undefined,
}));
setPatients((prev) => {
const all = [...prev, ...mapped];
const unique = Array.from(
new Map(all.map((p) => [p.id, p])).values()
);
const unique = Array.from(new Map(all.map((p) => [p.id, p])).values());
return unique;
});
if (!mapped.id) setHasNext(false); // parar carregamento
else setPage((prev) => prev + 1);
if (mapped.length === 0) {
setHasNext(false);
} else {
setPage((prev) => prev + 1);
}
} catch (e: any) {
setError(e?.message || "Erro ao buscar pacientes");
} finally {
@ -96,7 +155,7 @@ export default function PacientesPage() {
);
useEffect(() => {
fetchPacientes(page);
fetchPacientes(1);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@ -109,24 +168,19 @@ export default function PacientesPage() {
});
observer.observe(observerRef.current);
return () => {
if (observerRef.current) observer.unobserve(observerRef.current);
if (observerRef.current) {
observer.unobserve(observerRef.current);
}
};
}, [fetchPacientes, page, hasNext, isFetching]);
const handleDeletePatient = async (patientId: string) => {
// Remove from current list (client-side deletion)
try {
const res = await patientsService.delete(patientId);
if (res) {
alert(`${res.error} ${res.message}`);
}
setPatients((prev) =>
prev.filter((p) => String(p.id) !== String(patientId))
);
await patientsService.delete(patientId);
setPatients((prev) => prev.filter((p) => p.id !== patientId));
} catch (e: any) {
setError(e?.message || "Erro ao deletar paciente");
alert("Erro ao deletar paciente.");
}
setDeleteDialogOpen(false);
setPatientToDelete(null);
@ -156,12 +210,8 @@ export default function PacientesPage() {
<div className="space-y-6">
<div className="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<h1 className="text-xl md:text-2xl font-bold text-foreground">
Pacientes
</h1>
<p className="text-muted-foreground text-sm md:text-base">
Gerencie as informações de seus pacientes
</p>
<h1 className="text-xl md:text-2xl font-bold text-foreground">Pacientes</h1>
<p className="text-muted-foreground text-sm md:text-base">Gerencie as informações de seus pacientes</p>
</div>
<div className="flex gap-2">
<Link href="/secretary/pacientes/novo">
@ -174,11 +224,8 @@ export default function PacientesPage() {
</div>
<div className="flex flex-col md:flex-row flex-wrap gap-4 bg-card p-4 rounded-lg border border-border">
{/* Convênio */}
<div className="flex items-center gap-2 w-full md:w-auto">
<span className="text-sm font-medium text-foreground">
Convênio
</span>
<span className="text-sm font-medium text-foreground">Convênio</span>
<Select value={convenioFilter} onValueChange={setConvenioFilter}>
<SelectTrigger className="w-full md:w-40">
<SelectValue placeholder="Selecione o Convênio" />
@ -191,7 +238,6 @@ export default function PacientesPage() {
</SelectContent>
</Select>
</div>
<div className="flex items-center gap-2 w-full md:w-auto">
<span className="text-sm font-medium text-foreground">VIP</span>
<Select value={vipFilter} onValueChange={setVipFilter}>
@ -206,9 +252,7 @@ export default function PacientesPage() {
</Select>
</div>
<div className="flex items-center gap-2 w-full md:w-auto">
<span className="text-sm font-medium text-foreground">
Aniversariantes
</span>
<span className="text-sm font-medium text-foreground">Aniversariantes</span>
<Select>
<SelectTrigger className="w-full md:w-32">
<SelectValue placeholder="Selecione" />
@ -220,7 +264,6 @@ export default function PacientesPage() {
</SelectContent>
</Select>
</div>
<Button variant="outline" className="ml-auto w-full md:w-auto">
<Filter className="w-4 h-4 mr-2" />
Filtro avançado
@ -229,123 +272,76 @@ export default function PacientesPage() {
<div className="bg-white rounded-lg border border-gray-200">
<div className="overflow-x-auto">
{error ? (
<div className="p-6 text-red-600">{`Erro ao carregar pacientes: ${error}`}</div>
) : (
<table className="w-full min-w-[600px]">
<thead className="bg-gray-50 border-b border-gray-200">
{error && <div className="p-6 text-red-600">{`Erro ao carregar pacientes: ${error}`}</div>}
<table className="w-full min-w-[600px]">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Nome</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Telefone</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Cidade</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Estado</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Último atendimento</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Próximo atendimento</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">Ações</th>
</tr>
</thead>
<tbody>
{filteredPatients.length === 0 && !isFetching ? (
<tr>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Nome
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Telefone
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Cidade
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Estado
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Último atendimento
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Próximo atendimento
</th>
<th className="text-left p-2 md:p-4 font-medium text-gray-700">
Ações
</th>
<td colSpan={7} className="p-8 text-center text-gray-500">
{patients.length === 0 ? "Nenhum paciente cadastrado" : "Nenhum paciente encontrado com os filtros aplicados"}
</td>
</tr>
</thead>
<tbody>
{filteredPatients.length === 0 ? (
<tr>
<td colSpan={7} className="p-8 text-center text-gray-500">
{patients.length === 0
? "Nenhum paciente cadastrado"
: "Nenhum paciente encontrado com os filtros aplicados"}
) : (
filteredPatients.map((patient) => (
<tr key={patient.id} className="border-b border-gray-100 hover:bg-gray-50">
<td className="p-4">
<div className="flex items-center gap-3">
<div className="w-8 h-8 bg-gray-100 rounded-full flex items-center justify-center">
<span className="text-gray-600 font-medium text-sm">{patient.nome?.charAt(0) || "?"}</span>
</div>
<span className="font-medium text-gray-900">{patient.nome}</span>
</div>
</td>
<td className="p-4 text-gray-600">{patient.telefone}</td>
<td className="p-4 text-gray-600">{patient.cidade}</td>
<td className="p-4 text-gray-600">{patient.estado}</td>
<td className="p-4 text-gray-600">{formatDate(patient.ultimoAtendimento)}</td>
<td className="p-4 text-gray-600">{formatDate(patient.proximoAtendimento)}</td>
<td className="p-4">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="text-blue-600 hover:bg-blue-50 hover:text-blue-700 h-8 px-2">Ações</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => openDetailsDialog(patient.id)}>
<Eye className="w-4 h-4 mr-2" />
Ver detalhes
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link href={`/secretary/pacientes/${patient.id}/editar`}>
<Edit className="w-4 h-4 mr-2" />
Editar
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Calendar className="w-4 h-4 mr-2" />
Marcar consulta
</DropdownMenuItem>
<DropdownMenuItem className="text-red-600 focus:text-red-600" onClick={() => openDeleteDialog(patient.id)}>
<Trash2 className="w-4 h-4 mr-2" />
Excluir
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</td>
</tr>
) : (
filteredPatients.map((patient) => (
<tr
key={patient.id}
className="border-b border-gray-100 hover:bg-gray-50"
>
<td className="p-4">
<div className="flex items-center gap-3">
<div className="w-8 h-8 bg-gray-100 rounded-full flex items-center justify-center">
<span className="text-gray-600 font-medium text-sm">
{patient.nome?.charAt(0) || "?"}
</span>
</div>
<span className="font-medium text-gray-900">
{patient.nome}
</span>
</div>
</td>
<td className="p-4 text-gray-600">
{patient.telefone}
</td>
<td className="p-4 text-gray-600">{patient.cidade}</td>
<td className="p-4 text-gray-600">{patient.estado}</td>
<td className="p-4 text-gray-600">
{patient.ultimoAtendimento}
</td>
<td className="p-4 text-gray-600">
{patient.proximoAtendimento}
</td>
<td className="p-4">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<div className="text-blue-600">Ações</div>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
onClick={() =>
openDetailsDialog(String(patient.id))
}
>
<Eye className="w-4 h-4 mr-2" />
Ver detalhes
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link
href={`/secretary/pacientes/${patient.id}/editar`}
>
<Edit className="w-4 h-4 mr-2" />
Editar
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Calendar className="w-4 h-4 mr-2" />
Marcar consulta
</DropdownMenuItem>
<DropdownMenuItem
className="text-red-600"
onClick={() =>
openDeleteDialog(String(patient.id))
}
>
<Trash2 className="w-4 h-4 mr-2" />
Excluir
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</td>
</tr>
))
)}
</tbody>
</table>
)}
))
)}
</tbody>
</table>
<div ref={observerRef} style={{ height: 1 }} />
{isFetching && (
<div className="p-4 text-center text-gray-500">
Carregando mais pacientes...
</div>
)}
{isFetching && <div className="p-4 text-center text-gray-500">Carregando mais pacientes...</div>}
</div>
</div>
@ -353,108 +349,49 @@ export default function PacientesPage() {
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Confirmar exclusão</AlertDialogTitle>
<AlertDialogDescription>
Tem certeza que deseja excluir este paciente? Esta ação não pode
ser desfeita.
</AlertDialogDescription>
<AlertDialogDescription>Tem certeza que deseja excluir este paciente? Esta ação não pode ser desfeita.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancelar</AlertDialogCancel>
<AlertDialogAction
onClick={() =>
patientToDelete && handleDeletePatient(patientToDelete)
}
className="bg-red-600 hover:bg-red-700"
>
<AlertDialogAction onClick={() => patientToDelete && handleDeletePatient(patientToDelete)} className="bg-red-600 hover:bg-red-700">
Excluir
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
{/* Modal de detalhes do paciente */}
<AlertDialog
open={detailsDialogOpen}
onOpenChange={setDetailsDialogOpen}
>
<AlertDialog open={detailsDialogOpen} onOpenChange={setDetailsDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Detalhes do Paciente</AlertDialogTitle>
<AlertDialogDescription>
{patientDetails === null ? (
<div className="text-gray-500">Carregando...</div>
) : patientDetails?.error ? (
<div className="text-red-600">{patientDetails.error}</div>
) : (
<div className="space-y-2 text-left">
<p>
<strong>Nome:</strong> {patientDetails.full_name}
</p>
<p>
<strong>CPF:</strong> {patientDetails.cpf}
</p>
<p>
<strong>Email:</strong> {patientDetails.email}
</p>
<p>
<strong>Telefone:</strong>{" "}
{patientDetails.phone_mobile ??
patientDetails.phone1 ??
patientDetails.phone2 ??
"-"}
</p>
<p>
<strong>Nome social:</strong>{" "}
{patientDetails.social_name ?? "-"}
</p>
<p>
<strong>Sexo:</strong> {patientDetails.sex ?? "-"}
</p>
<p>
<strong>Tipo sanguíneo:</strong>{" "}
{patientDetails.blood_type ?? "-"}
</p>
<p>
<strong>Peso:</strong> {patientDetails.weight_kg ?? "-"}
{patientDetails.weight_kg ? "kg" : ""}
</p>
<p>
<strong>Altura:</strong> {patientDetails.height_m ?? "-"}
{patientDetails.height_m ? "m" : ""}
</p>
<p>
<strong>IMC:</strong> {patientDetails.bmi ?? "-"}
</p>
<p>
<strong>Endereço:</strong> {patientDetails.street ?? "-"}
</p>
<p>
<strong>Bairro:</strong>{" "}
{patientDetails.neighborhood ?? "-"}
</p>
<p>
<strong>Cidade:</strong> {patientDetails.city ?? "-"}
</p>
<p>
<strong>Estado:</strong> {patientDetails.state ?? "-"}
</p>
<p>
<strong>CEP:</strong> {patientDetails.cep ?? "-"}
</p>
<p>
<strong>Criado em:</strong>{" "}
{patientDetails.created_at ?? "-"}
</p>
<p>
<strong>Atualizado em:</strong>{" "}
{patientDetails.updated_at ?? "-"}
</p>
<p>
<strong>Id:</strong> {patientDetails.id ?? "-"}
</p>
{patientDetails === null ? (
<div className="text-gray-500 text-center py-4">Carregando...</div>
) : 'error' in patientDetails ? (
<div className="text-red-600 text-center py-4">{patientDetails.error}</div>
) : (
<AlertDialogDescription asChild>
<div className="space-y-2 text-left max-h-[60vh] overflow-y-auto pr-2">
<p><strong>Nome:</strong> {patientDetails.full_name}</p>
<p><strong>CPF:</strong> {patientDetails.cpf || "-"}</p>
<p><strong>Email:</strong> {patientDetails.email || "-"}</p>
<p><strong>Telefone:</strong> {patientDetails.phone_mobile ?? patientDetails.phone1 ?? patientDetails.phone2 ?? "-"}</p>
<p><strong>Nome social:</strong> {patientDetails.social_name ?? "-"}</p>
<p><strong>Sexo:</strong> {patientDetails.sex ?? "-"}</p>
<p><strong>Tipo sanguíneo:</strong> {patientDetails.blood_type ?? "-"}</p>
<p><strong>Peso:</strong> {patientDetails.weight_kg ? `${patientDetails.weight_kg}kg` : "-"}</p>
<p><strong>Altura:</strong> {patientDetails.height_m ? `${patientDetails.height_m}m` : "-"}</p>
<p><strong>IMC:</strong> {patientDetails.bmi ?? "-"}</p>
<p><strong>Endereço:</strong> {patientDetails.street ?? "-"}</p>
<p><strong>Bairro:</strong> {patientDetails.neighborhood ?? "-"}</p>
<p><strong>Cidade:</strong> {patientDetails.city ?? "-"}</p>
<p><strong>Estado:</strong> {patientDetails.state ?? "-"}</p>
<p><strong>CEP:</strong> {patientDetails.cep ?? "-"}</p>
<p><strong>Criado em:</strong> {formatDate(patientDetails.created_at)}</p>
<p><strong>Atualizado em:</strong> {formatDate(patientDetails.updated_at)}</p>
<p><strong>Id:</strong> {patientDetails.id ?? "-"}</p>
</div>
)}
</AlertDialogDescription>
</AlertDialogDescription>
)}
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Fechar</AlertDialogCancel>