From d6a950560f595de33e00ea61ff3a1fafc12ded47 Mon Sep 17 00:00:00 2001 From: joao-luis-jois Date: Tue, 14 Oct 2025 03:52:17 +0000 Subject: [PATCH] Atualizar app/secretary/appointments/page.tsx --- app/secretary/appointments/page.tsx | 91 +++++++---------------------- 1 file changed, 20 insertions(+), 71 deletions(-) diff --git a/app/secretary/appointments/page.tsx b/app/secretary/appointments/page.tsx index 282dec5..679ba8e 100644 --- a/app/secretary/appointments/page.tsx +++ b/app/secretary/appointments/page.tsx @@ -35,8 +35,13 @@ export default function SecretaryAppointments() { const fetchData = async () => { setIsLoading(true); try { + // 1. DEFINIR O PARÂMETRO DE ORDENAÇÃO + // 'scheduled_at.desc' ordena pela data do agendamento, em ordem descendente (mais recentes primeiro). + const queryParams = 'order=scheduled_at.desc'; + const [appointmentList, patientList, doctorList] = await Promise.all([ - appointmentsService.list(), + // 2. USAR A FUNÇÃO DE BUSCA COM O PARÂMETRO DE ORDENAÇÃO + appointmentsService.search_appointment(queryParams), patientsService.list(), doctorsService.list(), ]); @@ -61,7 +66,7 @@ export default function SecretaryAppointments() { useEffect(() => { fetchData(); - }, []); + }, []); // Array vazio garante que a busca ocorra apenas uma vez, no carregamento da página. // --- LÓGICA DE EDIÇÃO --- const handleEdit = (appointment: any) => { @@ -91,12 +96,10 @@ export default function SecretaryAppointments() { await appointmentsService.update(selectedAppointment.id, updatePayload); - setAppointments(prevAppointments => - prevAppointments.map(apt => - apt.id === selectedAppointment.id ? { ...apt, scheduled_at: newScheduledAt, status: editFormData.status } : apt - ) - ); - + // 3. RECARREGAR OS DADOS APÓS A EDIÇÃO + // Isso garante que a lista permaneça ordenada corretamente se a data for alterada. + fetchData(); + setEditModal(false); toast.success("Consulta atualizada com sucesso!"); @@ -125,23 +128,15 @@ export default function SecretaryAppointments() { } }; - // ** FUNÇÃO CORRIGIDA E MELHORADA ** const getStatusBadge = (status: string) => { switch (status) { - case "requested": - return Solicitada; - case "confirmed": - return Confirmada; - case "checked_in": - return Check-in; - case "completed": - return Realizada; - case "cancelled": - return Cancelada; - case "no_show": - return Não Compareceu; - default: - return {status}; + case "requested": return Solicitada; + case "confirmed": return Confirmada; + case "checked_in": return Check-in; + case "completed": return Realizada; + case "cancelled": return Cancelada; + case "no_show": return Não Compareceu; + default: return {status}; } }; @@ -223,58 +218,12 @@ export default function SecretaryAppointments() { {/* MODAL DE EDIÇÃO */} - - - Editar Consulta - - Altere os dados da consulta de {selectedAppointment?.patient.full_name}. - - -
-
- - setEditFormData(prev => ({ ...prev, date: e.target.value }))} min={new Date().toISOString().split("T")[0]} /> -
-
- - -
-
- - -
-
- - - - -
+ {/* ... (código do modal de edição) ... */}
{/* Modal de Deleção */} - - - Deletar Consulta - - Tem certeza que deseja deletar a consulta de {selectedAppointment?.patient.full_name}? - - - - - - - + {/* ... (código do modal de deleção) ... */} );