fix(agenda): atender paciente busca via API antes de navegar para GTO

Substitui o match de nome no frontend por uma busca real no backend.
handleAtender agora chama getPacientes(pacienteNome), seta o paciente
diretamente no store e navega — LancarGTO abre com o card já preenchido.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
VPS 4 Builder
2026-05-14 22:53:19 +02:00
parent 6dcfb27ca8
commit d0f7914c58
+11 -1
View File
@@ -376,9 +376,19 @@ export const AgendaView: React.FC<{ onNavigate?: (view: string) => void }> = ({
const currentUserEmail = HybridBackend.getCurrentUser();
const gtoStore = useGTOStore();
const handleAtender = () => {
const handleAtender = async () => {
if (!selectedAppointment || !onNavigate) return;
try {
const result = await HybridBackend.getPacientes(selectedAppointment.pacienteNome);
const list = Array.isArray(result) ? result : (result?.data ?? []);
if (list.length > 0) {
gtoStore.setPaciente(list[0]);
} else {
gtoStore.setPendingSearch(selectedAppointment.pacienteNome);
}
} catch {
gtoStore.setPendingSearch(selectedAppointment.pacienteNome);
}
setShowDetails(false);
onNavigate('lancar-gto');
};