diff --git a/frontend/views/AgendaView.tsx b/frontend/views/AgendaView.tsx index ae10bbd..8b4046c 100644 --- a/frontend/views/AgendaView.tsx +++ b/frontend/views/AgendaView.tsx @@ -44,7 +44,7 @@ const AppointmentModal: React.FC<{ const debouncedSearchTerm = useDebounce(searchTerm, 400); - const fetcher = useCallback(() => HybridBackend.getPacientes(debouncedSearchTerm), [debouncedSearchTerm]); + const fetcher = useCallback(() => HybridBackend.getPacientes(debouncedSearchTerm).then(r => Array.isArray(r.data) ? r.data : []), [debouncedSearchTerm]); const { data: searchResults, isLoading: isSearching } = useHybridBackend(fetcher, [debouncedSearchTerm]); const { data: agendamentos, refresh: refreshAgendamentos } = useHybridBackend(HybridBackend.getAgendamentos); @@ -93,14 +93,14 @@ const AppointmentModal: React.FC<{ const slots: string[] = []; if (!selectedDentistId || !selectedDate) return slots; - const existingAppointments = agendamentos?.filter(ag => + const existingAppointments = (agendamentos ?? []).filter(ag => ag.dentistaId === selectedDentistId && new Date(ag.start).toISOString().split('T')[0] === selectedDate && ag.id !== initialAppointment?.id ).map(ag => ({ start: new Date(ag.start).getHours() * 60 + new Date(ag.start).getMinutes(), end: new Date(ag.end).getHours() * 60 + new Date(ag.end).getMinutes(), - })) || []; + })); const dayOfWeek = new Date(selectedDate).getUTCDay(); const dayHorarios = allHorarios?.filter(h => h.dia_semana === dayOfWeek && h.ativo) || []; diff --git a/frontend/views/LoginView.tsx b/frontend/views/LoginView.tsx index f4cacfc..e0c392a 100644 --- a/frontend/views/LoginView.tsx +++ b/frontend/views/LoginView.tsx @@ -1,5 +1,5 @@ -import React, { useState } from 'react'; -import { Database, Lock, User, ArrowRight, ShieldCheck } from 'lucide-react'; +import React, { useState, useEffect } from 'react'; +import { Database, Lock, User, ArrowRight, ShieldCheck, Loader2 } from 'lucide-react'; import { HybridBackend } from '../services/backend.ts'; import { APP_VERSION } from '../constants.ts'; @@ -12,6 +12,22 @@ export const LoginView: React.FC = ({ onLoginSuccess }) => { const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); + const [isInitializing, setIsInitializing] = useState(true); + + useEffect(() => { + const timer = setTimeout(() => setIsInitializing(false), 3000); + return () => clearTimeout(timer); + }, []); + + if (isInitializing) { + return ( +
+ +

Inicializando Sistema...

+ {APP_VERSION} +
+ ); + } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault();