From a1f8a7995cbe8baa6bbe11f368846e1630a2466e Mon Sep 17 00:00:00 2001 From: M-Gabrielly Date: Thu, 2 Oct 2025 01:53:21 -0300 Subject: [PATCH] fix(patient-form): load existing patient data on edit mode - Fix patientId type to accept string | number | null to handle UUID values - Remove Number() conversion that was causing NaN errors on edit - Add debug console logs to track data loading process - Remove reference to non-existent photo_url field from Paciente type - Ensure form fields are properly populated with patient data when editing --- susconecta/app/(main-routes)/pacientes/page.tsx | 2 +- .../components/forms/patient-registration-form.tsx | 11 +++++------ susconecta/next-env.d.ts | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/susconecta/app/(main-routes)/pacientes/page.tsx b/susconecta/app/(main-routes)/pacientes/page.tsx index 0d8182e..c9bffb7 100644 --- a/susconecta/app/(main-routes)/pacientes/page.tsx +++ b/susconecta/app/(main-routes)/pacientes/page.tsx @@ -177,7 +177,7 @@ export default function PacientesPage() { setShowForm(false)} /> diff --git a/susconecta/components/forms/patient-registration-form.tsx b/susconecta/components/forms/patient-registration-form.tsx index b82ca85..f2a68b1 100644 --- a/susconecta/components/forms/patient-registration-form.tsx +++ b/susconecta/components/forms/patient-registration-form.tsx @@ -37,7 +37,7 @@ type Mode = "create" | "edit"; export interface PatientRegistrationFormProps { open?: boolean; onOpenChange?: (open: boolean) => void; - patientId?: number | null; + patientId?: string | number | null; inline?: boolean; mode?: Mode; onSaved?: (paciente: Paciente) => void; @@ -112,7 +112,9 @@ export function PatientRegistrationForm({ async function load() { if (mode !== "edit" || patientId == null) return; try { + console.log("[PatientForm] Carregando paciente ID:", patientId); const p = await buscarPacientePorId(String(patientId)); + console.log("[PatientForm] Dados recebidos:", p); setForm((s) => ({ ...s, nome: p.full_name || "", // 👈 trocar nome → full_name @@ -133,13 +135,10 @@ export function PatientRegistrationForm({ observacoes: p.notes || "", })); - - - const ax = await listarAnexos(String(patientId)).catch(() => []); setServerAnexos(Array.isArray(ax) ? ax : []); - } catch { - + } catch (err) { + console.error("[PatientForm] Erro ao carregar paciente:", err); } } load(); diff --git a/susconecta/next-env.d.ts b/susconecta/next-env.d.ts index 40c3d68..830fb59 100644 --- a/susconecta/next-env.d.ts +++ b/susconecta/next-env.d.ts @@ -1,5 +1,6 @@ /// /// +/// // NOTE: This file should not be edited -// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.