// app/manager/usuario/[id]/editar/page.tsx "use client"; import React, { useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; import { usuariosApi } from "@/services/usuariosApi"; import { perfisApi } from "@/services/perfisApi"; interface Profile { id?: number | string; full_name?: string; email?: string; [k: string]: any; } export default function ManagerUsuarioEditPage() { const params = useParams(); const id = params?.id; const router = useRouter(); const [profile, setProfile] = useState(null); const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); const [error, setError] = useState(null); useEffect(() => { let mounted = true; const load = async () => { setIsLoading(true); setError(null); try { if (!id) throw new Error("ID ausente"); const full = await usuariosApi.getFullData(String(id)); // getFullData pode retornar objeto com profile const prof = (full && full.profile) ? full.profile : full; if (mounted) setProfile(prof ?? null); } catch (err: any) { console.error("Erro ao buscar usuário:", err); if (mounted) setError(err?.message ?? "Erro ao buscar usuário"); } finally { if (mounted) setIsLoading(false); } }; load(); return () => { mounted = false; }; }, [id]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!id || !profile) return; setIsSaving(true); setError(null); try { await perfisApi.update(String(id), profile); router.push("/manager/usuario"); } catch (err: any) { console.error("Erro ao atualizar perfil:", err); setError(err?.message ?? "Erro ao salvar"); } finally { setIsSaving(false); } }; if (isLoading) return
Carregando...
; if (error) return
Erro: {error}
; if (!profile) return
Usuário não encontrado.
; return (

Editar Usuário

setProfile({ ...profile, full_name: e.target.value })} required className="w-full" />
); }