ajuste do filtro de paciente
This commit is contained in:
parent
6c5b0604c2
commit
63fc99c151
@ -3,10 +3,30 @@
|
||||
import { useState, useEffect, useRef, useCallback } from "react";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Plus, Edit, Trash2, Eye, Calendar, Filter } from "lucide-react";
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import SecretaryLayout from "@/components/secretary-layout";
|
||||
import { patientsService } from "@/services/patientsApi.mjs";
|
||||
|
||||
@ -58,7 +78,9 @@ export default function PacientesPage() {
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
@ -100,7 +122,9 @@ export default function PacientesPage() {
|
||||
alert(`${res.error} ${res.message}`);
|
||||
}
|
||||
|
||||
setPatients((prev) => prev.filter((p) => String(p.id) !== String(patientId)));
|
||||
setPatients((prev) =>
|
||||
prev.filter((p) => String(p.id) !== String(patientId))
|
||||
);
|
||||
} catch (e: any) {
|
||||
setError(e?.message || "Erro ao deletar paciente");
|
||||
}
|
||||
@ -114,9 +138,15 @@ export default function PacientesPage() {
|
||||
};
|
||||
|
||||
const filteredPatients = patients.filter((patient) => {
|
||||
const matchesSearch = patient.nome?.toLowerCase().includes(searchTerm.toLowerCase()) || patient.telefone?.includes(searchTerm);
|
||||
const matchesConvenio = convenioFilter === "all" || (patient.convenio ?? "") === convenioFilter;
|
||||
const matchesVip = vipFilter === "all" || (vipFilter === "vip" && patient.vip) || (vipFilter === "regular" && !patient.vip);
|
||||
const matchesSearch =
|
||||
patient.nome?.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
patient.telefone?.includes(searchTerm);
|
||||
const matchesConvenio =
|
||||
convenioFilter === "all" || (patient.convenio ?? "") === convenioFilter;
|
||||
const matchesVip =
|
||||
vipFilter === "all" ||
|
||||
(vipFilter === "vip" && patient.vip) ||
|
||||
(vipFilter === "regular" && !patient.vip);
|
||||
|
||||
return matchesSearch && matchesConvenio && matchesVip;
|
||||
});
|
||||
@ -126,8 +156,12 @@ 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">
|
||||
@ -142,7 +176,9 @@ export default function PacientesPage() {
|
||||
<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" />
|
||||
@ -170,7 +206,9 @@ 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" />
|
||||
@ -183,34 +221,6 @@ export default function PacientesPage() {
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm font-medium text-foreground">VIP</span>
|
||||
<Select value={vipFilter} onValueChange={setVipFilter}>
|
||||
<SelectTrigger className="w-32">
|
||||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">Todos</SelectItem>
|
||||
<SelectItem value="vip">VIP</SelectItem>
|
||||
<SelectItem value="regular">Regular</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm font-medium text-foreground">Aniversariantes</span>
|
||||
<Select>
|
||||
<SelectTrigger className="w-32">
|
||||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="today">Hoje</SelectItem>
|
||||
<SelectItem value="week">Esta semana</SelectItem>
|
||||
<SelectItem value="month">Este mês</SelectItem>
|
||||
</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
|
||||
@ -225,50 +235,85 @@ export default function PacientesPage() {
|
||||
<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>
|
||||
<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"}
|
||||
{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">
|
||||
<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>
|
||||
<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>
|
||||
<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.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 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))}>
|
||||
<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`}>
|
||||
<Link
|
||||
href={`/secretary/pacientes/${patient.id}/editar`}
|
||||
>
|
||||
<Edit className="w-4 h-4 mr-2" />
|
||||
Editar
|
||||
</Link>
|
||||
@ -277,7 +322,12 @@ export default function PacientesPage() {
|
||||
<Calendar className="w-4 h-4 mr-2" />
|
||||
Marcar consulta
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="text-red-600" onClick={() => openDeleteDialog(String(patient.id))}>
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onClick={() =>
|
||||
openDeleteDialog(String(patient.id))
|
||||
}
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
Excluir
|
||||
</DropdownMenuItem>
|
||||
@ -291,7 +341,11 @@ export default function PacientesPage() {
|
||||
</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>
|
||||
|
||||
@ -299,11 +353,19 @@ 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>
|
||||
@ -311,7 +373,10 @@ export default function PacientesPage() {
|
||||
</AlertDialog>
|
||||
|
||||
{/* Modal de detalhes do paciente */}
|
||||
<AlertDialog open={detailsDialogOpen} onOpenChange={setDetailsDialogOpen}>
|
||||
<AlertDialog
|
||||
open={detailsDialogOpen}
|
||||
onOpenChange={setDetailsDialogOpen}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Detalhes do Paciente</AlertDialogTitle>
|
||||
@ -332,16 +397,22 @@ export default function PacientesPage() {
|
||||
<strong>Email:</strong> {patientDetails.email}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Telefone:</strong> {patientDetails.phone_mobile ?? patientDetails.phone1 ?? patientDetails.phone2 ?? "-"}
|
||||
<strong>Telefone:</strong>{" "}
|
||||
{patientDetails.phone_mobile ??
|
||||
patientDetails.phone1 ??
|
||||
patientDetails.phone2 ??
|
||||
"-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Nome social:</strong> {patientDetails.social_name ?? "-"}
|
||||
<strong>Nome social:</strong>{" "}
|
||||
{patientDetails.social_name ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Sexo:</strong> {patientDetails.sex ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Tipo sanguíneo:</strong> {patientDetails.blood_type ?? "-"}
|
||||
<strong>Tipo sanguíneo:</strong>{" "}
|
||||
{patientDetails.blood_type ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Peso:</strong> {patientDetails.weight_kg ?? "-"}
|
||||
@ -358,7 +429,8 @@ export default function PacientesPage() {
|
||||
<strong>Endereço:</strong> {patientDetails.street ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Bairro:</strong> {patientDetails.neighborhood ?? "-"}
|
||||
<strong>Bairro:</strong>{" "}
|
||||
{patientDetails.neighborhood ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Cidade:</strong> {patientDetails.city ?? "-"}
|
||||
@ -370,10 +442,12 @@ export default function PacientesPage() {
|
||||
<strong>CEP:</strong> {patientDetails.cep ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Criado em:</strong> {patientDetails.created_at ?? "-"}
|
||||
<strong>Criado em:</strong>{" "}
|
||||
{patientDetails.created_at ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Atualizado em:</strong> {patientDetails.updated_at ?? "-"}
|
||||
<strong>Atualizado em:</strong>{" "}
|
||||
{patientDetails.updated_at ?? "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Id:</strong> {patientDetails.id ?? "-"}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user