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
This commit is contained in:
M-Gabrielly 2025-10-02 01:53:21 -03:00
parent 8d1473a148
commit a1f8a7995c
3 changed files with 8 additions and 8 deletions

View File

@ -177,7 +177,7 @@ export default function PacientesPage() {
<PatientRegistrationForm
inline
mode={editingId ? "edit" : "create"}
patientId={editingId ? Number(editingId) : null}
patientId={editingId}
onSaved={handleSaved}
onClose={() => setShowForm(false)}
/>

View File

@ -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();

View File

@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference path="./.next/types/routes.d.ts" />
// 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.