Merge branch 'fix/patient-page' into feature/perfis-cal3d
This commit is contained in:
commit
b96f9e56bb
@ -2,26 +2,16 @@
|
||||
|
||||
// Imports mantidos
|
||||
import { useEffect, useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Link from "next/link";
|
||||
|
||||
// --- Imports do EventManager (NOVO) - MANTIDOS ---
|
||||
import { EventManager, type Event } from "@/components/features/general/event-manager";
|
||||
import { v4 as uuidv4 } from 'uuid'; // Usado para IDs de fallback
|
||||
|
||||
// Imports mantidos
|
||||
import { Sidebar } from "@/components/layout/sidebar";
|
||||
import { PagesHeader } from "@/components/features/dashboard/header";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { mockWaitingList } from "@/lib/mocks/appointment-mocks";
|
||||
import "./index.css";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { ThreeDWallCalendar, CalendarEvent } from "@/components/ui/three-dwall-calendar"; // Calendário 3D mantido
|
||||
import { PatientRegistrationForm } from "@/components/features/forms/patient-registration-form";
|
||||
|
||||
@ -33,11 +23,24 @@ const ListaEspera = dynamic(
|
||||
export default function AgendamentoPage() {
|
||||
const { user, token } = useAuth();
|
||||
const [appointments, setAppointments] = useState<any[]>([]);
|
||||
const [waitingList, setWaitingList] = useState(mockWaitingList);
|
||||
const [activeTab, setActiveTab] = useState<"calendar" | "espera" | "3d">("calendar");
|
||||
|
||||
const [activeTab, setActiveTab] = useState<"calendar" | "3d">("calendar");
|
||||
const [threeDEvents, setThreeDEvents] = useState<CalendarEvent[]>([]);
|
||||
|
||||
// Padroniza idioma da página para pt-BR (afeta componentes que usam o lang do documento)
|
||||
useEffect(() => {
|
||||
try {
|
||||
// Atributos no <html>
|
||||
document.documentElement.lang = "pt-BR";
|
||||
document.documentElement.setAttribute("xml:lang", "pt-BR");
|
||||
document.documentElement.setAttribute("data-lang", "pt-BR");
|
||||
// Cookie de locale (usado por apps com i18n)
|
||||
const oneYear = 60 * 60 * 24 * 365;
|
||||
document.cookie = `NEXT_LOCALE=pt-BR; Path=/; Max-Age=${oneYear}; SameSite=Lax`;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}, []);
|
||||
|
||||
// --- NOVO ESTADO ---
|
||||
// Estado para alimentar o NOVO EventManager com dados da API
|
||||
const [managerEvents, setManagerEvents] = useState<Event[]>([]);
|
||||
@ -48,15 +51,8 @@ export default function AgendamentoPage() {
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "c") {
|
||||
setActiveTab("calendar");
|
||||
}
|
||||
if (event.key === "f") {
|
||||
setActiveTab("espera");
|
||||
}
|
||||
if (event.key === "3") {
|
||||
setActiveTab("3d");
|
||||
}
|
||||
if (event.key === "c") setActiveTab("calendar");
|
||||
if (event.key === "3") setActiveTab("3d");
|
||||
});
|
||||
}, []);
|
||||
|
||||
@ -92,18 +88,23 @@ export default function AgendamentoPage() {
|
||||
|
||||
const patient = (patientsById[String(obj.patient_id)]?.full_name) || obj.patient_name || obj.patient_full_name || obj.patient || 'Paciente';
|
||||
const title = `${patient}: ${obj.appointment_type ?? obj.type ?? ''}`.trim();
|
||||
|
||||
let color = "gray"; // Cor padrão
|
||||
if (obj.status === 'confirmed') color = 'green';
|
||||
if (obj.status === 'pending') color = 'orange';
|
||||
|
||||
// Mapeamento de cores padronizado:
|
||||
// azul = solicitado; verde = confirmado; laranja = pendente; vermelho = cancelado; azul como fallback
|
||||
const status = String(obj.status || "").toLowerCase();
|
||||
let color: Event["color"] = "blue";
|
||||
if (status === "confirmed" || status === "confirmado") color = "green";
|
||||
else if (status === "pending" || status === "pendente") color = "orange";
|
||||
else if (status === "canceled" || status === "cancelado" || status === "cancelled") color = "red";
|
||||
else if (status === "requested" || status === "solicitado") color = "blue";
|
||||
|
||||
return {
|
||||
id: obj.id || uuidv4(), // Usa ID da API ou gera um
|
||||
title: title,
|
||||
description: `Agendamento para ${patient}. Status: ${obj.status || 'N/A'}.`,
|
||||
id: obj.id || uuidv4(),
|
||||
title,
|
||||
description: `Agendamento para ${patient}. Status: ${obj.status || 'N/A'}.`,
|
||||
startTime: start,
|
||||
endTime: end,
|
||||
color: color,
|
||||
color,
|
||||
};
|
||||
});
|
||||
setManagerEvents(newManagerEvents);
|
||||
@ -152,10 +153,6 @@ export default function AgendamentoPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleNotifyPatient = (patientId: string) => {
|
||||
console.log(`Notificando paciente ${patientId}`);
|
||||
};
|
||||
|
||||
const handleAddEvent = (event: CalendarEvent) => {
|
||||
setThreeDEvents((prev) => [...prev, event]);
|
||||
};
|
||||
@ -178,26 +175,10 @@ export default function AgendamentoPage() {
|
||||
Navegue através dos atalhos: Calendário (C), Fila de espera (F) ou 3D (3).
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex space-x-2">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger className="bg-primary hover:bg-primary/90 px-5 py-1 text-primary-foreground rounded-sm">
|
||||
Opções »
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<Link href={"/agenda"}>
|
||||
<DropdownMenuItem>Agendamento</DropdownMenuItem>
|
||||
</Link>
|
||||
<Link href={"/procedimento"}>
|
||||
<DropdownMenuItem>Procedimento</DropdownMenuItem>
|
||||
</Link>
|
||||
<Link href={"/financeiro"}>
|
||||
<DropdownMenuItem>Financeiro</DropdownMenuItem>
|
||||
</Link>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
<div className="flex space-x-2 items-center">
|
||||
<div className="flex flex-row">
|
||||
<Button
|
||||
type="button"
|
||||
variant={"outline"}
|
||||
className="bg-muted hover:bg-primary! hover:text-white! transition-colors rounded-l-[100px] rounded-r-none"
|
||||
onClick={() => setActiveTab("calendar")}
|
||||
@ -206,20 +187,27 @@ export default function AgendamentoPage() {
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type="button"
|
||||
variant={"outline"}
|
||||
className="bg-muted hover:bg-primary! hover:text-white! transition-colors rounded-none"
|
||||
className="bg-muted hover:bg-primary! hover:text-white! transition-colors rounded-r-[100px] rounded-l-none"
|
||||
onClick={() => setActiveTab("3d")}
|
||||
>
|
||||
3D
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant={"outline"}
|
||||
className="bg-muted hover:bg-primary! hover:text-white! transition-colors rounded-r-[100px] rounded-l-none"
|
||||
onClick={() => setActiveTab("espera")}
|
||||
>
|
||||
Lista de espera
|
||||
</Button>
|
||||
{/* Legenda de status (estilo Google Calendar) */}
|
||||
<div className="rounded-md border bg-card/60 p-2 sm:p-3 -mt-4">
|
||||
<div className="flex flex-wrap items-center gap-6 text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<span aria-hidden className="h-3 w-3 rounded-full bg-blue-500 ring-2 ring-blue-500/30" />
|
||||
<span className="text-foreground">Solicitado</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span aria-hidden className="h-3 w-3 rounded-full bg-green-500 ring-2 ring-green-500/30" />
|
||||
<span className="text-foreground">Confirmado</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -251,14 +239,7 @@ export default function AgendamentoPage() {
|
||||
onOpenAddPatientForm={() => setShowPatientForm(true)}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
// A Lista de Espera foi MANTIDA
|
||||
<ListaEspera
|
||||
patients={waitingList}
|
||||
onNotify={handleNotifyPatient}
|
||||
onAddToWaitlist={() => {}}
|
||||
/>
|
||||
)}
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Formulário de Registro de Paciente */}
|
||||
|
||||
@ -18,7 +18,8 @@ import Link from 'next/link'
|
||||
import ProtectedRoute from '@/components/shared/ProtectedRoute'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { buscarPacientes, buscarPacientePorUserId, getUserInfo, listarAgendamentos, buscarMedicosPorIds, buscarMedicos, atualizarPaciente, buscarPacientePorId, getDoctorById } from '@/lib/api'
|
||||
import { buscarPacientes, buscarPacientePorUserId, getUserInfo, listarAgendamentos, buscarMedicosPorIds, buscarMedicos, atualizarPaciente, buscarPacientePorId, getDoctorById, atualizarAgendamento, deletarAgendamento } from '@/lib/api'
|
||||
import { CalendarRegistrationForm } from '@/components/features/forms/calendar-registration-form'
|
||||
import { buscarRelatorioPorId, listarRelatoriosPorMedico } from '@/lib/reports'
|
||||
import { ENV_CONFIG } from '@/lib/env-config'
|
||||
import { listarRelatoriosPorPaciente } from '@/lib/reports'
|
||||
@ -35,7 +36,6 @@ const strings = {
|
||||
ultimosExames: 'Últimos Exames',
|
||||
mensagensNaoLidas: 'Mensagens Não Lidas',
|
||||
agendar: 'Agendar',
|
||||
reagendar: 'Reagendar',
|
||||
cancelar: 'Cancelar',
|
||||
detalhes: 'Detalhes',
|
||||
adicionarCalendario: 'Adicionar ao calendário',
|
||||
@ -445,11 +445,10 @@ export default function PacientePage() {
|
||||
</span>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Consultas fictícias
|
||||
const [currentDate, setCurrentDate] = useState(new Date())
|
||||
|
||||
// helper: produce a local YYYY-MM-DD key (uses local timezone, not toISOString UTC)
|
||||
@ -519,10 +518,15 @@ export default function PacientePage() {
|
||||
const selectedDate = new Date(currentDate); selectedDate.setHours(0, 0, 0, 0);
|
||||
const isSelectedDateToday = selectedDate.getTime() === today.getTime()
|
||||
|
||||
// Appointments state (loaded when component mounts)
|
||||
const [appointments, setAppointments] = useState<any[] | null>(null)
|
||||
const [loadingAppointments, setLoadingAppointments] = useState(false)
|
||||
const [appointmentsError, setAppointmentsError] = useState<string | null>(null)
|
||||
// Appointments state (loaded when component mounts)
|
||||
const [appointments, setAppointments] = useState<any[] | null>(null)
|
||||
const [doctorsMap, setDoctorsMap] = useState<Record<string, any>>({}) // Store doctor info by ID
|
||||
const [loadingAppointments, setLoadingAppointments] = useState(false)
|
||||
const [appointmentsError, setAppointmentsError] = useState<string | null>(null)
|
||||
// expanded appointment id for inline details (kept for possible fallback)
|
||||
const [expandedId, setExpandedId] = useState<number | null>(null)
|
||||
// selected appointment for modal details
|
||||
const [selectedAppointment, setSelectedAppointment] = useState<any | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true
|
||||
@ -608,6 +612,7 @@ export default function PacientePage() {
|
||||
}
|
||||
})
|
||||
|
||||
setDoctorsMap(doctorsMap)
|
||||
setAppointments(mapped)
|
||||
} catch (err: any) {
|
||||
console.warn('[Consultas] falha ao carregar agendamentos', err)
|
||||
@ -638,6 +643,60 @@ export default function PacientePage() {
|
||||
const _dialogSource = (appointments !== null ? appointments : consultasFicticias)
|
||||
const _todaysAppointments = (_dialogSource || []).filter((c: any) => c.data === todayStr)
|
||||
|
||||
// helper: present a localized label for appointment status
|
||||
const statusLabel = (s: any) => {
|
||||
const raw = (s === null || s === undefined) ? '' : String(s)
|
||||
const key = raw.toLowerCase()
|
||||
const map: Record<string,string> = {
|
||||
'requested': 'Solicitado',
|
||||
'request': 'Solicitado',
|
||||
'confirmed': 'Confirmado',
|
||||
'confirmada': 'Confirmada',
|
||||
'confirmado': 'Confirmado',
|
||||
'completed': 'Concluído',
|
||||
'concluído': 'Concluído',
|
||||
'cancelled': 'Cancelado',
|
||||
'cancelada': 'Cancelada',
|
||||
'cancelado': 'Cancelado',
|
||||
'pending': 'Pendente',
|
||||
'pendente': 'Pendente',
|
||||
'checked_in': 'Registrado',
|
||||
'in_progress': 'Em andamento',
|
||||
'no_show': 'Não compareceu'
|
||||
}
|
||||
return map[key] || raw
|
||||
}
|
||||
|
||||
// map an appointment (row) to the CalendarRegistrationForm's formData shape
|
||||
const mapAppointmentToFormData = (appointment: any) => {
|
||||
// Use the raw appointment with all fields: doctor_id, scheduled_at, appointment_type, etc.
|
||||
const schedIso = appointment.scheduled_at || (appointment.data && appointment.hora ? `${appointment.data}T${appointment.hora}` : null) || null
|
||||
const baseDate = schedIso ? new Date(schedIso) : new Date()
|
||||
const appointmentDate = schedIso ? baseDate.toISOString().split('T')[0] : ''
|
||||
const startTime = schedIso ? baseDate.toLocaleTimeString('pt-BR', { hour: '2-digit', minute: '2-digit' }) : (appointment.hora || '')
|
||||
const duration = appointment.duration_minutes ?? appointment.duration ?? 30
|
||||
|
||||
// Get doctor name from doctorsMap if available
|
||||
const docName = appointment.medico || (appointment.doctor_id ? doctorsMap[String(appointment.doctor_id)]?.full_name : null) || appointment.doctor_name || appointment.professional_name || '---'
|
||||
|
||||
return {
|
||||
id: appointment.id,
|
||||
patientName: docName,
|
||||
patientId: null,
|
||||
doctorId: appointment.doctor_id ?? null,
|
||||
professionalName: docName,
|
||||
appointmentDate,
|
||||
startTime,
|
||||
endTime: '',
|
||||
status: appointment.status || undefined,
|
||||
appointmentType: appointment.appointment_type || appointment.type || (appointment.local ? 'presencial' : 'teleconsulta'),
|
||||
duration_minutes: duration,
|
||||
notes: appointment.notes || '',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Hero Section */}
|
||||
@ -771,7 +830,7 @@ export default function PacientePage() {
|
||||
? 'bg-linear-to-r from-amber-500 to-amber-600 shadow-amber-500/20'
|
||||
: 'bg-linear-to-r from-red-500 to-red-600 shadow-red-500/20'
|
||||
}`}>
|
||||
{consulta.status}
|
||||
{statusLabel(consulta.status)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -781,28 +840,43 @@ export default function PacientePage() {
|
||||
type="button"
|
||||
size="sm"
|
||||
className="border border-primary/30 text-primary bg-primary/5 hover:bg-primary! hover:text-white! hover:border-primary! transition-all duration-200 focus-visible:ring-2 focus-visible:ring-primary/40 active:scale-95 text-xs font-semibold flex-1"
|
||||
onClick={() => setSelectedAppointment(consulta)}
|
||||
>
|
||||
Detalhes
|
||||
</Button>
|
||||
{consulta.status !== 'Cancelada' && (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
className="bg-primary/10 text-primary border border-primary/30 hover:bg-primary! hover:text-white! hover:border-primary! transition-all duration-200 focus-visible:ring-2 focus-visible:ring-primary/40 active:scale-95 text-xs font-semibold flex-1"
|
||||
>
|
||||
Reagendar
|
||||
</Button>
|
||||
)}
|
||||
{/* Reagendar removed by request */}
|
||||
{consulta.status !== 'Cancelada' && (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
className="border border-destructive/30 text-destructive bg-destructive/5 hover:bg-destructive! hover:text-white! hover:border-destructive! transition-all duration-200 focus-visible:ring-2 focus-visible:ring-destructive/40 active:scale-95 text-xs font-semibold flex-1"
|
||||
onClick={async () => {
|
||||
try {
|
||||
const ok = typeof window !== 'undefined' ? window.confirm('Deseja realmente cancelar esta consulta?') : true
|
||||
if (!ok) return
|
||||
// call API to delete
|
||||
await deletarAgendamento(consulta.id)
|
||||
// remove from local list
|
||||
setAppointments((prev) => {
|
||||
if (!prev) return prev
|
||||
return prev.filter((a: any) => String(a.id) !== String(consulta.id))
|
||||
})
|
||||
// if modal open for this appointment, close it
|
||||
if (selectedAppointment && String(selectedAppointment.id) === String(consulta.id)) setSelectedAppointment(null)
|
||||
setToast({ type: 'success', msg: 'Consulta cancelada.' })
|
||||
} catch (err: any) {
|
||||
console.error('[Consultas] falha ao cancelar agendamento', err)
|
||||
try { setToast({ type: 'error', msg: err?.message || 'Falha ao cancelar a consulta.' }) } catch (e) {}
|
||||
}
|
||||
}}
|
||||
>
|
||||
Cancelar
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Inline detalhes removed: modal will show details instead */}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
@ -811,6 +885,45 @@ export default function PacientePage() {
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<Dialog open={!!selectedAppointment} onOpenChange={open => !open && setSelectedAppointment(null)}>
|
||||
<DialogContent className="w-full sm:mx-auto sm:my-8 max-w-3xl md:max-w-4xl lg:max-w-5xl max-h-[90vh] overflow-hidden sm:p-6 p-4">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Detalhes da Consulta</DialogTitle>
|
||||
<DialogDescription className="sr-only">Detalhes da consulta</DialogDescription>
|
||||
<div className="mt-4 grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-3 max-h-[70vh] overflow-y-auto text-sm text-foreground">
|
||||
{selectedAppointment ? (
|
||||
<>
|
||||
<div className="space-y-3">
|
||||
<div><span className="font-medium">Profissional:</span> {selectedAppointment.medico || '-'}</div>
|
||||
<div><span className="font-medium">Especialidade:</span> {selectedAppointment.especialidade || '-'}</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div><span className="font-medium">Data:</span> {(function(d:any,h:any){ try{ const dt = new Date(String(d) + 'T' + String(h||'00:00')); return formatDatePt(dt) }catch(e){ return String(d||'-') } })(selectedAppointment.data, selectedAppointment.hora)}</div>
|
||||
<div><span className="font-medium">Hora:</span> {selectedAppointment.hora || '-'}</div>
|
||||
<div><span className="font-medium">Status:</span> {statusLabel(selectedAppointment.status) || '-'}</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div>Carregando...</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogHeader>
|
||||
<DialogFooter className="flex flex-col sm:flex-row gap-2 sm:justify-end sm:items-center mt-4">
|
||||
<div className="flex w-full sm:w-auto justify-between sm:justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => setSelectedAppointment(null)} className="transition duration-200 hover:bg-primary/10 hover:text-primary min-w-[110px]">
|
||||
Fechar
|
||||
</Button>
|
||||
</div>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Reagendar feature removed */}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -1262,7 +1375,7 @@ export default function PacientePage() {
|
||||
setReportsPage(1)
|
||||
}, [reports])
|
||||
|
||||
return (
|
||||
return (<>
|
||||
<section className="bg-card shadow-md rounded-lg border border-border p-6">
|
||||
<h2 className="text-2xl font-bold mb-6">Laudos</h2>
|
||||
|
||||
@ -1334,10 +1447,13 @@ export default function PacientePage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<Dialog open={!!selectedReport} onOpenChange={open => !open && setSelectedReport(null)}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{selectedReport && (
|
||||
(() => {
|
||||
const looksLikeIdStr = (s: any) => {
|
||||
@ -1422,7 +1538,7 @@ export default function PacientePage() {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</section>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ export default function ResultadosClient() {
|
||||
try {
|
||||
setLoadingMedicos(true)
|
||||
console.log('[ResultadosClient] Initial doctors fetch starting')
|
||||
const list = await buscarMedicos('medico').catch((err) => {
|
||||
const list = await buscarMedicos('').catch((err) => {
|
||||
console.error('[ResultadosClient] Initial fetch error:', err)
|
||||
return []
|
||||
})
|
||||
@ -175,7 +175,7 @@ export default function ResultadosClient() {
|
||||
setAgendaByDoctor({})
|
||||
setAgendasExpandida({})
|
||||
// termo de busca: usar a especialidade escolhida
|
||||
const termo = (especialidadeHero && especialidadeHero !== 'Veja mais') ? especialidadeHero : 'medico'
|
||||
const termo = (especialidadeHero && especialidadeHero !== 'Veja mais') ? especialidadeHero : ''
|
||||
console.log('[ResultadosClient] Fetching doctors with term:', termo)
|
||||
const list = await buscarMedicos(termo).catch((err) => {
|
||||
console.error('[ResultadosClient] buscarMedicos error:', err)
|
||||
@ -219,9 +219,9 @@ export default function ResultadosClient() {
|
||||
}, [searchQuery])
|
||||
|
||||
// 3) Carregar horários disponíveis para um médico (próximos 7 dias) e agrupar por dia
|
||||
async function loadAgenda(doctorId: string) {
|
||||
if (!doctorId) return
|
||||
if (agendaLoading[doctorId]) return
|
||||
async function loadAgenda(doctorId: string): Promise<{ iso: string; label: string } | null> {
|
||||
if (!doctorId) return null
|
||||
if (agendaLoading[doctorId]) return null
|
||||
setAgendaLoading((s) => ({ ...s, [doctorId]: true }))
|
||||
try {
|
||||
// janela de 7 dias
|
||||
@ -271,10 +271,12 @@ export default function ResultadosClient() {
|
||||
nearest = { iso: s.iso, label: s.label }
|
||||
}
|
||||
|
||||
setAgendaByDoctor((prev) => ({ ...prev, [doctorId]: days }))
|
||||
setNearestSlotByDoctor((prev) => ({ ...prev, [doctorId]: nearest }))
|
||||
setAgendaByDoctor((prev) => ({ ...prev, [doctorId]: days }))
|
||||
setNearestSlotByDoctor((prev) => ({ ...prev, [doctorId]: nearest }))
|
||||
return nearest
|
||||
} catch (e: any) {
|
||||
showToast('error', e?.message || 'Falha ao buscar horários')
|
||||
return null
|
||||
} finally {
|
||||
setAgendaLoading((s) => ({ ...s, [doctorId]: false }))
|
||||
}
|
||||
@ -752,19 +754,7 @@ export default function ResultadosClient() {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select value={bairro} onValueChange={setBairro}>
|
||||
<SelectTrigger className="h-10 min-w-40 rounded-full border border-primary/40 bg-primary/10 text-primary transition duration-200 hover:border-primary! focus:ring-2 focus:ring-primary cursor-pointer">
|
||||
<SelectValue placeholder="Bairro" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Todos">Todos os bairros</SelectItem>
|
||||
<SelectItem value="Centro">Centro</SelectItem>
|
||||
<SelectItem value="Jardins">Jardins</SelectItem>
|
||||
<SelectItem value="Farolândia">Farolândia</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{/* Search input para buscar médico por nome */}
|
||||
{/* Search input para buscar médico por nome (movido antes do Select de bairro para ficar ao lado visualmente) */}
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder="Buscar médico por nome"
|
||||
@ -806,6 +796,18 @@ export default function ResultadosClient() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Select value={bairro} onValueChange={setBairro}>
|
||||
<SelectTrigger className="h-10 min-w-40 rounded-full border border-primary/40 bg-primary/10 text-primary transition duration-200 hover:border-primary! focus:ring-2 focus:ring-primary cursor-pointer">
|
||||
<SelectValue placeholder="Bairro" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Todos">Todos os bairros</SelectItem>
|
||||
<SelectItem value="Centro">Centro</SelectItem>
|
||||
<SelectItem value="Jardins">Jardins</SelectItem>
|
||||
<SelectItem value="Farolândia">Farolândia</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="ml-auto rounded-full text-primary hover:bg-primary! hover:text-white! transition-colors"
|
||||
@ -934,7 +936,29 @@ export default function ResultadosClient() {
|
||||
<div className="flex flex-wrap gap-3 pt-2">
|
||||
<Button
|
||||
className="h-11 rounded-full bg-primary text-primary-foreground hover:bg-primary/90"
|
||||
onClick={() => { if (!agendaByDoctor[id]) loadAgenda(id) }}
|
||||
onClick={async () => {
|
||||
// If we don't have the agenda loaded, load it and try to open the nearest slot.
|
||||
if (!agendaByDoctor[id]) {
|
||||
const nearest = await loadAgenda(id)
|
||||
if (nearest) {
|
||||
openConfirmDialog(id, nearest.iso)
|
||||
return
|
||||
}
|
||||
// fallback: open the "more times" modal to let the user pick a date/time
|
||||
setMoreTimesForDoctor(id)
|
||||
void fetchSlotsForDate(id, moreTimesDate)
|
||||
return
|
||||
}
|
||||
|
||||
// If agenda already loaded, try nearest known slot
|
||||
const nearest = nearestSlotByDoctor[id]
|
||||
if (nearest) {
|
||||
openConfirmDialog(id, nearest.iso)
|
||||
} else {
|
||||
setMoreTimesForDoctor(id)
|
||||
void fetchSlotsForDate(id, moreTimesDate)
|
||||
}
|
||||
}}
|
||||
>
|
||||
Agendar consulta
|
||||
</Button>
|
||||
|
||||
1485
susconecta/components/event-manager.tsx
Normal file
1485
susconecta/components/event-manager.tsx
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import React, { useState, useCallback, useMemo } from "react"
|
||||
import React, { useState, useCallback, useMemo, useEffect } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card } from "@/components/ui/card"
|
||||
import { Input } from "@/components/ui/input"
|
||||
@ -16,16 +16,8 @@ import {
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { ChevronLeft, ChevronRight, Plus, Calendar, Clock, Grid3x3, List, Search, Filter, X } from "lucide-react"
|
||||
import { ChevronLeft, ChevronRight, Plus, Calendar, Clock, Grid3x3, List, Search, X } from "lucide-react"
|
||||
import { cn } from "@/lib/utils"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
|
||||
export interface Event {
|
||||
id: string
|
||||
@ -60,6 +52,10 @@ const defaultColors = [
|
||||
{ name: "Red", value: "red", bg: "bg-red-500", text: "text-red-700" },
|
||||
]
|
||||
|
||||
// Locale/timezone padrão BR
|
||||
const LOCALE = "pt-BR"
|
||||
const TIMEZONE = "America/Sao_Paulo"
|
||||
|
||||
export function EventManager({
|
||||
events: initialEvents = [],
|
||||
onEventCreate,
|
||||
@ -87,13 +83,19 @@ export function EventManager({
|
||||
})
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState("")
|
||||
const [selectedColors, setSelectedColors] = useState<string[]>([])
|
||||
const [selectedTags, setSelectedTags] = useState<string[]>([])
|
||||
const [selectedCategories, setSelectedCategories] = useState<string[]>([])
|
||||
|
||||
// Dialog: lista completa de pacientes do dia
|
||||
const [dayDialogEvents, setDayDialogEvents] = useState<Event[] | null>(null)
|
||||
const [isDayDialogOpen, setIsDayDialogOpen] = useState(false)
|
||||
const openDayDialog = useCallback((eventsForDay: Event[]) => {
|
||||
// ordena por horário antes de abrir
|
||||
const ordered = [...eventsForDay].sort((a, b) => a.startTime.getTime() - b.startTime.getTime())
|
||||
setDayDialogEvents(ordered)
|
||||
setIsDayDialogOpen(true)
|
||||
}, [])
|
||||
|
||||
const filteredEvents = useMemo(() => {
|
||||
return events.filter((event) => {
|
||||
// Search filter
|
||||
if (searchQuery) {
|
||||
const query = searchQuery.toLowerCase()
|
||||
const matchesSearch =
|
||||
@ -101,36 +103,15 @@ export function EventManager({
|
||||
event.description?.toLowerCase().includes(query) ||
|
||||
event.category?.toLowerCase().includes(query) ||
|
||||
event.tags?.some((tag) => tag.toLowerCase().includes(query))
|
||||
|
||||
if (!matchesSearch) return false
|
||||
}
|
||||
|
||||
// Color filter
|
||||
if (selectedColors.length > 0 && !selectedColors.includes(event.color)) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Tag filter
|
||||
if (selectedTags.length > 0) {
|
||||
const hasMatchingTag = event.tags?.some((tag) => selectedTags.includes(tag))
|
||||
if (!hasMatchingTag) return false
|
||||
}
|
||||
|
||||
// Category filter
|
||||
if (selectedCategories.length > 0 && event.category && !selectedCategories.includes(event.category)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}, [events, searchQuery, selectedColors, selectedTags, selectedCategories])
|
||||
}, [events, searchQuery])
|
||||
|
||||
const hasActiveFilters = selectedColors.length > 0 || selectedTags.length > 0 || selectedCategories.length > 0
|
||||
const hasActiveFilters = false
|
||||
|
||||
const clearFilters = () => {
|
||||
setSelectedColors([])
|
||||
setSelectedTags([])
|
||||
setSelectedCategories([])
|
||||
setSearchQuery("")
|
||||
}
|
||||
|
||||
@ -238,23 +219,16 @@ export function EventManager({
|
||||
[colors],
|
||||
)
|
||||
|
||||
const toggleTag = (tag: string, isCreating: boolean) => {
|
||||
if (isCreating) {
|
||||
setNewEvent((prev) => ({
|
||||
...prev,
|
||||
tags: prev.tags?.includes(tag) ? prev.tags.filter((t) => t !== tag) : [...(prev.tags || []), tag],
|
||||
}))
|
||||
} else {
|
||||
setSelectedEvent((prev) =>
|
||||
prev
|
||||
? {
|
||||
...prev,
|
||||
tags: prev.tags?.includes(tag) ? prev.tags.filter((t) => t !== tag) : [...(prev.tags || []), tag],
|
||||
}
|
||||
: null,
|
||||
)
|
||||
}
|
||||
}
|
||||
// Força lang/cookie pt-BR no documento (reforço local)
|
||||
useEffect(() => {
|
||||
try {
|
||||
document.documentElement.lang = "pt-BR"
|
||||
document.documentElement.setAttribute("xml:lang", "pt-BR")
|
||||
document.documentElement.setAttribute("data-lang", "pt-BR")
|
||||
const oneYear = 60 * 60 * 24 * 365
|
||||
document.cookie = `NEXT_LOCALE=pt-BR; Path=/; Max-Age=${oneYear}; SameSite=Lax`
|
||||
} catch {}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className={cn("flex flex-col gap-4", className)}>
|
||||
@ -263,21 +237,24 @@ export function EventManager({
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4">
|
||||
<h2 className="text-xl font-semibold sm:text-2xl">
|
||||
{view === "month" &&
|
||||
currentDate.toLocaleDateString("pt-BR", {
|
||||
currentDate.toLocaleDateString(LOCALE, {
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
timeZone: TIMEZONE,
|
||||
})}
|
||||
{view === "week" &&
|
||||
`Semana de ${currentDate.toLocaleDateString("pt-BR", {
|
||||
`Semana de ${currentDate.toLocaleDateString(LOCALE, {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
timeZone: TIMEZONE,
|
||||
})}`}
|
||||
{view === "day" &&
|
||||
currentDate.toLocaleDateString("pt-BR", {
|
||||
currentDate.toLocaleDateString(LOCALE, {
|
||||
weekday: "long",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
timeZone: TIMEZONE,
|
||||
})}
|
||||
{view === "list" && "Todos os eventos"}
|
||||
</h2>
|
||||
@ -285,9 +262,6 @@ export function EventManager({
|
||||
<Button variant="outline" size="icon" onClick={() => navigateDate("prev")} className="h-8 w-8">
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={() => setCurrentDate(new Date())}>
|
||||
Hoje
|
||||
</Button>
|
||||
<Button variant="outline" size="icon" onClick={() => navigateDate("next")} className="h-8 w-8">
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
@ -385,290 +359,46 @@ export function EventManager({
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Buscar eventos..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-9"
|
||||
/>
|
||||
{searchQuery && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2"
|
||||
onClick={() => setSearchQuery("")}
|
||||
<div className="flex items-center">
|
||||
{/* Lupa minimalista à esquerda (somente ícone) */}
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Buscar"
|
||||
className="flex items-center justify-center h-10 w-10 p-0 text-muted-foreground bg-transparent border-0"
|
||||
onClick={() => {
|
||||
const el = document.querySelector<HTMLInputElement>('input[placeholder="Buscar eventos..."]')
|
||||
el?.focus()
|
||||
}}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Search className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
{/* Mobile: Horizontal scroll with full-length buttons */}
|
||||
<div className="sm:hidden -mx-4 px-4">
|
||||
<div className="flex gap-2 overflow-x-auto pb-2 scrollbar-hide">
|
||||
{/* Color Filter */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="gap-2 whitespace-nowrap flex-shrink-0 bg-transparent">
|
||||
<Filter className="h-4 w-4" />
|
||||
Cores
|
||||
{selectedColors.length > 0 && (
|
||||
<Badge variant="secondary" className="ml-1 h-5 px-1.5">
|
||||
{selectedColors.length}
|
||||
</Badge>
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-48">
|
||||
<DropdownMenuLabel>Filtrar por Cor</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{colors.map((color) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={color.value}
|
||||
checked={selectedColors.includes(color.value)}
|
||||
onCheckedChange={(checked) => {
|
||||
setSelectedColors((prev) =>
|
||||
checked ? [...prev, color.value] : prev.filter((c) => c !== color.value),
|
||||
)
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className={cn("h-3 w-3 rounded", color.bg)} />
|
||||
{color.name}
|
||||
</div>
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{/* Input central com altura consistente e foco visível */}
|
||||
<Input
|
||||
placeholder="Buscar eventos..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className={cn(
|
||||
"flex-1 h-10 px-3 border border-border focus:ring-2 focus:ring-primary/20 outline-none",
|
||||
searchQuery ? "rounded-l-md rounded-r-none" : "rounded-md"
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Tag Filter */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="gap-2 whitespace-nowrap flex-shrink-0 bg-transparent">
|
||||
<Filter className="h-4 w-4" />
|
||||
Tags
|
||||
{selectedTags.length > 0 && (
|
||||
<Badge variant="secondary" className="ml-1 h-5 px-1.5">
|
||||
{selectedTags.length}
|
||||
</Badge>
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-48">
|
||||
<DropdownMenuLabel>Filtrar por Tag</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{availableTags.map((tag) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={tag}
|
||||
checked={selectedTags.includes(tag)}
|
||||
onCheckedChange={(checked) => {
|
||||
setSelectedTags((prev) => (checked ? [...prev, tag] : prev.filter((t) => t !== tag)))
|
||||
}}
|
||||
>
|
||||
{tag}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Category Filter */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="gap-2 whitespace-nowrap flex-shrink-0 bg-transparent">
|
||||
<Filter className="h-4 w-4" />
|
||||
Categorias
|
||||
{selectedCategories.length > 0 && (
|
||||
<Badge variant="secondary" className="ml-1 h-5 px-1.5">
|
||||
{selectedCategories.length}
|
||||
</Badge>
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-48">
|
||||
<DropdownMenuLabel>Filtrar por Categoria</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{categories.map((category) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={category}
|
||||
checked={selectedCategories.includes(category)}
|
||||
onCheckedChange={(checked) => {
|
||||
setSelectedCategories((prev) =>
|
||||
checked ? [...prev, category] : prev.filter((c) => c !== category),
|
||||
)
|
||||
}}
|
||||
>
|
||||
{category}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{hasActiveFilters && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={clearFilters}
|
||||
className="gap-2 whitespace-nowrap flex-shrink-0"
|
||||
{/* Botão limpar discreto à direita (aparece somente com query) */}
|
||||
{searchQuery ? (
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Limpar busca"
|
||||
className="flex items-center justify-center h-10 w-10 p-0 text-muted-foreground bg-transparent border-0"
|
||||
onClick={() => setSearchQuery("")}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
Limpar Filtros
|
||||
</Button>
|
||||
)}
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Desktop: Original layout */}
|
||||
<div className="hidden sm:flex items-center gap-2">
|
||||
{/* Color Filter */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="gap-2 bg-transparent">
|
||||
<Filter className="h-4 w-4" />
|
||||
Cores
|
||||
{selectedColors.length > 0 && (
|
||||
<Badge variant="secondary" className="ml-1 h-5 px-1">
|
||||
{selectedColors.length}
|
||||
</Badge>
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
<DropdownMenuLabel>Filtrar por Cor</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{colors.map((color) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={color.value}
|
||||
checked={selectedColors.includes(color.value)}
|
||||
onCheckedChange={(checked) => {
|
||||
setSelectedColors((prev) =>
|
||||
checked ? [...prev, color.value] : prev.filter((c) => c !== color.value),
|
||||
)
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className={cn("h-3 w-3 rounded", color.bg)} />
|
||||
{color.name}
|
||||
</div>
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Tag Filter */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="gap-2 bg-transparent">
|
||||
<Filter className="h-4 w-4" />
|
||||
Tags
|
||||
{selectedTags.length > 0 && (
|
||||
<Badge variant="secondary" className="ml-1 h-5 px-1">
|
||||
{selectedTags.length}
|
||||
</Badge>
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
<DropdownMenuLabel>Filtrar por Tag</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{availableTags.map((tag) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={tag}
|
||||
checked={selectedTags.includes(tag)}
|
||||
onCheckedChange={(checked) => {
|
||||
setSelectedTags((prev) => (checked ? [...prev, tag] : prev.filter((t) => t !== tag)))
|
||||
}}
|
||||
>
|
||||
{tag}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Category Filter */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="gap-2 bg-transparent">
|
||||
<Filter className="h-4 w-4" />
|
||||
Categorias
|
||||
{selectedCategories.length > 0 && (
|
||||
<Badge variant="secondary" className="ml-1 h-5 px-1">
|
||||
{selectedCategories.length}
|
||||
</Badge>
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
<DropdownMenuLabel>Filtrar por Categoria</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{categories.map((category) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={category}
|
||||
checked={selectedCategories.includes(category)}
|
||||
onCheckedChange={(checked) => {
|
||||
setSelectedCategories((prev) =>
|
||||
checked ? [...prev, category] : prev.filter((c) => c !== category),
|
||||
)
|
||||
}}
|
||||
>
|
||||
{category}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{hasActiveFilters && (
|
||||
<Button variant="ghost" size="sm" onClick={clearFilters} className="gap-2">
|
||||
<X className="h-4 w-4" />
|
||||
Limpar
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{hasActiveFilters && (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm text-muted-foreground">Filtros ativos:</span>
|
||||
{selectedColors.map((colorValue) => {
|
||||
const color = getColorClasses(colorValue)
|
||||
return (
|
||||
<Badge key={colorValue} variant="secondary" className="gap-1">
|
||||
<div className={cn("h-2 w-2 rounded-full", color.bg)} />
|
||||
{color.name}
|
||||
<button
|
||||
onClick={() => setSelectedColors((prev) => prev.filter((c) => c !== colorValue))}
|
||||
className="ml-1 hover:text-foreground"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
)
|
||||
})}
|
||||
{selectedTags.map((tag) => (
|
||||
<Badge key={tag} variant="secondary" className="gap-1">
|
||||
{tag}
|
||||
<button
|
||||
onClick={() => setSelectedTags((prev) => prev.filter((t) => t !== tag))}
|
||||
className="ml-1 hover:text-foreground"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
))}
|
||||
{selectedCategories.map((category) => (
|
||||
<Badge key={category} variant="secondary" className="gap-1">
|
||||
{category}
|
||||
<button
|
||||
onClick={() => setSelectedCategories((prev) => prev.filter((c) => c !== category))}
|
||||
className="ml-1 hover:text-foreground"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Calendar Views - Pass filteredEvents instead of events */}
|
||||
{view === "month" && (
|
||||
<MonthView
|
||||
@ -682,9 +412,66 @@ export function EventManager({
|
||||
onDragEnd={() => handleDragEnd()}
|
||||
onDrop={handleDrop}
|
||||
getColorClasses={getColorClasses}
|
||||
openDayDialog={openDayDialog}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Dialog com todos os pacientes do dia */}
|
||||
<Dialog open={isDayDialogOpen} onOpenChange={setIsDayDialogOpen}>
|
||||
<DialogContent className="max-w-lg max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Pacientes do dia</DialogTitle>
|
||||
<DialogDescription>Todos os agendamentos do dia selecionado.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-3 py-2">
|
||||
{dayDialogEvents?.map((ev) => (
|
||||
<div
|
||||
key={ev.id}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => {
|
||||
setSelectedEvent(ev)
|
||||
setIsDialogOpen(true)
|
||||
setIsDayDialogOpen(false)
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
setSelectedEvent(ev)
|
||||
setIsDialogOpen(true)
|
||||
setIsDayDialogOpen(false)
|
||||
}
|
||||
}}
|
||||
className="flex items-start gap-3 p-2 border-b last:border-b-0 rounded-md cursor-pointer hover:bg-accent/40 focus:outline-none focus:ring-2 focus:ring-primary/30"
|
||||
>
|
||||
<div className={cn("mt-1 h-3 w-3 rounded-full", getColorClasses(ev.color).bg)} />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="font-semibold truncate">{ev.title}</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{ev.startTime.toLocaleTimeString(LOCALE,{hour:"2-digit",minute:"2-digit",hour12:false,timeZone:TIMEZONE})}
|
||||
{" - "}
|
||||
{ev.endTime.toLocaleTimeString(LOCALE,{hour:"2-digit",minute:"2-digit",hour12:false,timeZone:TIMEZONE})}
|
||||
</div>
|
||||
</div>
|
||||
{ev.description && (
|
||||
<div className="text-xs text-muted-foreground line-clamp-2">{ev.description}</div>
|
||||
)}
|
||||
<div className="mt-1 flex flex-wrap gap-1">
|
||||
{ev.category && <Badge variant="secondary" className="text-[11px] h-5">{ev.category}</Badge>}
|
||||
{ev.tags?.map((t) => (
|
||||
<Badge key={t} variant="outline" className="text-[11px] h-5">{t}</Badge>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{!dayDialogEvents?.length && (
|
||||
<div className="py-6 text-center text-sm text-muted-foreground">Nenhum evento</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{view === "week" && (
|
||||
<WeekView
|
||||
currentDate={currentDate}
|
||||
@ -728,7 +515,7 @@ export function EventManager({
|
||||
|
||||
{/* Event Dialog */}
|
||||
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
||||
<DialogContent className="max-w-md max-h-[90vh] overflow-y-auto">
|
||||
<DialogContent className="max-w-md max-h[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{isCreating ? "Criar Evento" : "Detalhes do Evento"}</DialogTitle>
|
||||
<DialogDescription>
|
||||
@ -827,75 +614,9 @@ export function EventManager({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="category">Categoria</Label>
|
||||
<Select
|
||||
value={isCreating ? newEvent.category : selectedEvent?.category}
|
||||
onValueChange={(value) =>
|
||||
isCreating
|
||||
? setNewEvent((prev) => ({ ...prev, category: value }))
|
||||
: setSelectedEvent((prev) => (prev ? { ...prev, category: value } : null))
|
||||
}
|
||||
>
|
||||
<SelectTrigger id="category">
|
||||
<SelectValue placeholder="Selecione a categoria" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{categories.map((cat) => (
|
||||
<SelectItem key={cat} value={cat}>
|
||||
{cat}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{/* Campos de Categoria/Cor removidos */}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="color">Cor</Label>
|
||||
<Select
|
||||
value={isCreating ? newEvent.color : selectedEvent?.color}
|
||||
onValueChange={(value) =>
|
||||
isCreating
|
||||
? setNewEvent((prev) => ({ ...prev, color: value }))
|
||||
: setSelectedEvent((prev) => (prev ? { ...prev, color: value } : null))
|
||||
}
|
||||
>
|
||||
<SelectTrigger id="color">
|
||||
<SelectValue placeholder="Selecione a cor" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{colors.map((color) => (
|
||||
<SelectItem key={color.value} value={color.value}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className={cn("h-4 w-4 rounded", color.bg)} />
|
||||
{color.name}
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Tags</Label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{availableTags.map((tag) => {
|
||||
const isSelected = isCreating ? newEvent.tags?.includes(tag) : selectedEvent?.tags?.includes(tag)
|
||||
return (
|
||||
<Badge
|
||||
key={tag}
|
||||
variant={isSelected ? "default" : "outline"}
|
||||
className="cursor-pointer transition-all hover:scale-105"
|
||||
onClick={() => toggleTag(tag, isCreating)}
|
||||
>
|
||||
{tag}
|
||||
</Badge>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
{/* Campo de Tags removido */}
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
@ -944,9 +665,11 @@ function EventCard({
|
||||
const colorClasses = getColorClasses(event.color)
|
||||
|
||||
const formatTime = (date: Date) => {
|
||||
return date.toLocaleTimeString("en-US", {
|
||||
return date.toLocaleTimeString(LOCALE, {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hour12: false,
|
||||
timeZone: TIMEZONE,
|
||||
})
|
||||
}
|
||||
|
||||
@ -1124,6 +847,7 @@ function MonthView({
|
||||
onDragEnd,
|
||||
onDrop,
|
||||
getColorClasses,
|
||||
openDayDialog,
|
||||
}: {
|
||||
currentDate: Date
|
||||
events: Event[]
|
||||
@ -1132,6 +856,7 @@ function MonthView({
|
||||
onDragEnd: () => void
|
||||
onDrop: (date: Date) => void
|
||||
getColorClasses: (color: string) => { bg: string; text: string }
|
||||
openDayDialog: (eventsForDay: Event[]) => void
|
||||
}) {
|
||||
const firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1)
|
||||
const lastDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0)
|
||||
@ -1170,6 +895,15 @@ function MonthView({
|
||||
<div className="grid grid-cols-7">
|
||||
{days.map((day, index) => {
|
||||
const dayEvents = getEventsForDay(day)
|
||||
// dedup por título para evitar repetidos
|
||||
const uniqueMap = new Map<string, Event>()
|
||||
dayEvents.forEach((ev) => {
|
||||
const k = (ev.title || "").trim().toLowerCase()
|
||||
if (!uniqueMap.has(k)) uniqueMap.set(k, ev)
|
||||
})
|
||||
const uniqueEvents = Array.from(uniqueMap.values())
|
||||
const eventsToShow = uniqueEvents.slice(0, 3)
|
||||
const moreCount = Math.max(0, uniqueEvents.length - 3)
|
||||
const isCurrentMonth = day.getMonth() === currentDate.getMonth()
|
||||
const isToday = day.toDateString() === new Date().toDateString()
|
||||
|
||||
@ -1184,16 +918,11 @@ function MonthView({
|
||||
onDragOver={(e) => e.preventDefault()}
|
||||
onDrop={() => onDrop(day)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"mb-1 flex h-5 w-5 items-center justify-center rounded-full text-xs sm:h-6 sm:w-6 sm:text-sm",
|
||||
isToday && "bg-primary text-primary-foreground font-semibold",
|
||||
)}
|
||||
>
|
||||
{day.getDate()}
|
||||
</div>
|
||||
{/* Número do dia padronizado (sem destaque azul no 'hoje') */}
|
||||
<div className="mb-1 text-xs sm:text-sm">{day.getDate()}</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
{dayEvents.slice(0, 3).map((event) => (
|
||||
{eventsToShow.map((event) => (
|
||||
<EventCard
|
||||
key={event.id}
|
||||
event={event}
|
||||
@ -1204,8 +933,16 @@ function MonthView({
|
||||
variant="compact"
|
||||
/>
|
||||
))}
|
||||
{dayEvents.length > 3 && (
|
||||
<div className="text-[10px] text-muted-foreground sm:text-xs">+{dayEvents.length - 3} mais</div>
|
||||
{moreCount > 0 && (
|
||||
<div className="text-[10px] sm:text-xs">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openDayDialog(uniqueEvents)}
|
||||
className="text-primary underline"
|
||||
>
|
||||
+{moreCount} mais
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@ -1267,17 +1004,17 @@ function WeekView({
|
||||
key={day.toISOString()}
|
||||
className="border-r p-2 text-center text-xs font-medium last:border-r-0 sm:text-sm"
|
||||
>
|
||||
<div className="hidden sm:block">{day.toLocaleDateString("pt-BR", { weekday: "short" })}</div>
|
||||
<div className="sm:hidden">{day.toLocaleDateString("pt-BR", { weekday: "narrow" })}</div>
|
||||
<div className="hidden sm:block">{day.toLocaleDateString(LOCALE, { weekday: "short", timeZone: TIMEZONE })}</div>
|
||||
<div className="sm:hidden">{day.toLocaleDateString(LOCALE, { weekday: "narrow", timeZone: TIMEZONE })}</div>
|
||||
<div className="text-[10px] text-muted-foreground sm:text-xs">
|
||||
{day.toLocaleDateString("pt-BR", { month: "short", day: "numeric" })}
|
||||
{day.toLocaleDateString(LOCALE, { month: "short", day: "numeric", timeZone: TIMEZONE })}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid grid-cols-8">
|
||||
{hours.map((hour) => (
|
||||
<>
|
||||
<React.Fragment key={`hour-${hour}`}>
|
||||
<div
|
||||
key={`time-${hour}`}
|
||||
className="border-b border-r p-1 text-[10px] text-muted-foreground sm:p-2 sm:text-xs"
|
||||
@ -1309,7 +1046,7 @@ function WeekView({
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
@ -1401,15 +1138,14 @@ function ListView({
|
||||
|
||||
const groupedEvents = sortedEvents.reduce(
|
||||
(acc, event) => {
|
||||
const dateKey = event.startTime.toLocaleDateString("pt-BR", {
|
||||
const dateKey = event.startTime.toLocaleDateString(LOCALE, {
|
||||
weekday: "long",
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
timeZone: TIMEZONE,
|
||||
})
|
||||
if (!acc[dateKey]) {
|
||||
acc[dateKey] = []
|
||||
}
|
||||
if (!acc[dateKey]) acc[dateKey] = []
|
||||
acc[dateKey].push(event)
|
||||
return acc
|
||||
},
|
||||
@ -1426,11 +1162,7 @@ function ListView({
|
||||
{dateEvents.map((event) => {
|
||||
const colorClasses = getColorClasses(event.color)
|
||||
return (
|
||||
<div
|
||||
key={event.id}
|
||||
onClick={() => onEventClick(event)}
|
||||
className="group cursor-pointer rounded-lg border bg-card p-3 transition-all hover:shadow-md hover:scale-[1.01] animate-in fade-in slide-in-from-bottom-2 duration-300 sm:p-4"
|
||||
>
|
||||
<div key={event.id} onClick={() => onEventClick(event)} className="group cursor-pointer rounded-lg border bg-card p-3 transition-all hover:shadow-md hover:scale-[1.01] animate-in fade-in slide-in-from-bottom-2 duration-300 sm:p-4">
|
||||
<div className="flex items-start gap-2 sm:gap-3">
|
||||
<div className={cn("mt-1 h-2.5 w-2.5 rounded-full sm:h-3 sm:w-3", colorClasses.bg)} />
|
||||
<div className="flex-1 min-w-0">
|
||||
@ -1456,7 +1188,9 @@ function ListView({
|
||||
<div className="mt-2 flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground sm:gap-4 sm:text-xs">
|
||||
<div className="flex items-center gap-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
{event.startTime.toLocaleTimeString("pt-BR", { hour: "2-digit", minute: "2-digit" })} - {event.endTime.toLocaleTimeString("pt-BR", { hour: "2-digit", minute: "2-digit" })}
|
||||
{event.startTime.toLocaleTimeString(LOCALE, { hour: "2-digit", minute: "2-digit", hour12: false, timeZone: TIMEZONE })}
|
||||
{" - "}
|
||||
{event.endTime.toLocaleTimeString(LOCALE, { hour: "2-digit", minute: "2-digit", hour12: false, timeZone: TIMEZONE })}
|
||||
</div>
|
||||
{event.tags && event.tags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user