fix(agenda): fix $.map crash and getPacientes type mismatch; restore preloader
AgendaView:
- Fix agendamentos?.filter(...).map(...) crash: optional chain didn't guard .map when agendamentos is null on initial render
- Fix getPacientes fetcher to extract .data array — API now returns {data, total} not Paciente[], causing searchResults.map crash
LoginView:
- Restore 3s preloader splash screen with {APP_VERSION} instead of hardcoded version string
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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<Paciente[]>(fetcher, [debouncedSearchTerm]);
|
||||
|
||||
const { data: agendamentos, refresh: refreshAgendamentos } = useHybridBackend<Agendamento[]>(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) || [];
|
||||
|
||||
Reference in New Issue
Block a user