fix(doctor-form): load existing doctor data on edit mode

- Fix doctorId 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
- Improve error handling in useEffect for doctor and attachments loading
- Ensure form fields are properly populated with doctor data when editing
This commit is contained in:
M-Gabrielly 2025-10-02 02:14:39 -03:00
parent a1f8a7995c
commit 389aa8adfb
2 changed files with 48 additions and 41 deletions

View File

@ -298,7 +298,7 @@ export default function DoutoresPage() {
<DoctorRegistrationForm
inline
mode={editingId ? "edit" : "create"}
doctorId={editingId ? Number(editingId) : null}
doctorId={editingId}
onSaved={handleSaved}
onClose={() => setShowForm(false)}
/>

View File

@ -51,7 +51,7 @@ type Mode = "create" | "edit";
export interface DoctorRegistrationFormProps {
open?: boolean;
onOpenChange?: (open: boolean) => void;
doctorId?: number | null;
doctorId?: string | number | null;
inline?: boolean;
mode?: Mode;
onSaved?: (medico: Medico) => void;
@ -155,7 +155,10 @@ export function DoctorRegistrationForm({
let alive = true;
async function load() {
if (mode === "edit" && doctorId) {
try {
console.log("[DoctorForm] Carregando médico ID:", doctorId);
const medico = await buscarMedicoPorId(String(doctorId));
console.log("[DoctorForm] Dados recebidos:", medico);
if (!alive) return;
setForm({
photo: null,
@ -190,11 +193,15 @@ export function DoctorRegistrationForm({
valor_consulta: medico.valor_consulta ? String(medico.valor_consulta) : "",
});
try {
const list = await listarAnexosMedico(doctorId);
const list = await listarAnexosMedico(String(doctorId));
setServerAnexos(list ?? []);
} catch {}
} catch (err) {
console.error("[DoctorForm] Erro ao carregar anexos:", err);
}
} catch (err) {
console.error("[DoctorForm] Erro ao carregar médico:", err);
}
}
}
load();