diff --git a/src/components/secretaria/SecretaryAppointmentList.tsx b/src/components/secretaria/SecretaryAppointmentList.tsx index bebc2a694..a2a267385 100644 --- a/src/components/secretaria/SecretaryAppointmentList.tsx +++ b/src/components/secretaria/SecretaryAppointmentList.tsx @@ -123,6 +123,11 @@ export function SecretaryAppointmentList() { // Mapeia o valor selecionado no select para o valor real usado na API/data const mapStatusFilterToValue = (label: string) => { if (label === "Todos") return null; + // Se já é um valor de API, retorna ele mesmo + if (['requested', 'confirmed', 'checked_in', 'in_progress', 'completed', 'cancelled', 'no_show'].includes(label)) { + return label; + } + // Mantém mapeamento legado por compatibilidade const map: Record = { Confirmada: "confirmed", Agendada: "requested", @@ -249,6 +254,50 @@ export function SecretaryAppointmentList() { loadAppointments(); }; + const handleStatusChange = async (appointmentId: string, newStatus: string) => { + try { + console.log(`[SecretaryAppointmentList] Atualizando status da consulta ${appointmentId} para ${newStatus}`); + + await appointmentService.update(appointmentId, { + status: newStatus as any + }); + + toast.success(`Status atualizado para: ${ + newStatus === 'requested' ? 'Solicitada' : + newStatus === 'confirmed' ? 'Confirmada' : + newStatus === 'checked_in' ? 'Check-in' : + newStatus === 'in_progress' ? 'Em Atendimento' : + newStatus === 'completed' ? 'Concluída' : + newStatus === 'cancelled' ? 'Cancelada' : + newStatus === 'no_show' ? 'Não Compareceu' : newStatus + }`); + + loadAppointments(); + } catch (error) { + console.error("Erro ao atualizar status:", error); + toast.error("Erro ao atualizar status da consulta"); + } + }; + + const handleDeleteAppointment = async (appointmentId: string) => { + if (!confirm("Tem certeza que deseja cancelar esta consulta?")) { + return; + } + + try { + await appointmentService.update(appointmentId, { + status: "cancelled", + cancelled_at: new Date().toISOString(), + cancellation_reason: "Cancelado pela secretaria" + }); + toast.success("Consulta cancelada com sucesso!"); + loadAppointments(); + } catch (error) { + console.error("Erro ao cancelar consulta:", error); + toast.error("Erro ao cancelar consulta"); + } + }; + // Reset página quando filtros mudarem useEffect(() => { setCurrentPage(1); @@ -355,10 +404,13 @@ export function SecretaryAppointmentList() { className="px-3 py-1.5 border border-gray-300 dark:border-gray-600 rounded-lg text-sm focus:ring-2 focus:ring-green-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100" > - - - - + + + + + + +
@@ -496,27 +548,58 @@ export function SecretaryAppointmentList() { - {getStatusBadge(appointment.status || "agendada")} +
diff --git a/src/components/secretaria/SecretaryDoctorSchedule.tsx b/src/components/secretaria/SecretaryDoctorSchedule.tsx index f30a7a16c..029a7409a 100644 --- a/src/components/secretaria/SecretaryDoctorSchedule.tsx +++ b/src/components/secretaria/SecretaryDoctorSchedule.tsx @@ -516,24 +516,32 @@ export function SecretaryDoctorSchedule() { {/* Legenda */}
-
+
Solicitada
-
+
Confirmada
-
+
+ Em Atendimento +
+
+
Concluída
-
- Bloqueio +
+ Cancelada
-
- Disponibilidade Extra +
+ Bloqueio +
+
+
+ Disponibilidade Extra
@@ -593,21 +601,55 @@ export function SecretaryDoctorSchedule() { minute: '2-digit', }) : ''; + + // Determina as cores baseado no status + let bgColor = ''; + let textColor = ''; + let borderColor = ''; + + switch (apt.status) { + case 'requested': + bgColor = '!bg-yellow-100'; + textColor = '!text-yellow-800'; + borderColor = 'border-yellow-300'; + break; + case 'confirmed': + bgColor = '!bg-green-100'; + textColor = '!text-green-800'; + borderColor = 'border-green-300'; + break; + case 'completed': + bgColor = '!bg-blue-100'; + textColor = '!text-blue-800'; + borderColor = 'border-blue-300'; + break; + case 'cancelled': + bgColor = '!bg-gray-100'; + textColor = '!text-gray-600'; + borderColor = 'border-gray-300'; + break; + case 'checked_in': + case 'in_progress': + bgColor = '!bg-orange-100'; + textColor = '!text-orange-800'; + borderColor = 'border-orange-300'; + break; + case 'no_show': + bgColor = '!bg-red-100'; + textColor = '!text-red-800'; + borderColor = 'border-red-300'; + break; + default: + bgColor = '!bg-gray-100'; + textColor = '!text-gray-600'; + borderColor = 'border-gray-300'; + } + return (
📅 {time}