forked from RiseUP/riseup-squad20
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:
parent
8d1473a148
commit
a1f8a7995c
@ -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)}
|
||||
/>
|
||||
|
||||
@ -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();
|
||||
|
||||
3
susconecta/next-env.d.ts
vendored
3
susconecta/next-env.d.ts
vendored
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user