diff --git a/saveinmed-frontend/src/app/meu-perfil/page.tsx b/saveinmed-frontend/src/app/meu-perfil/page.tsx new file mode 100644 index 0000000..5192cbf --- /dev/null +++ b/saveinmed-frontend/src/app/meu-perfil/page.tsx @@ -0,0 +1,96 @@ +'use client'; + +import { useEffect, useState } from 'react'; +import Header from '@/components/Header'; +import ProfileForm from '@/components/profile/ProfileForm'; + +interface UserData { + id: string; + identificador: string; + ativo: boolean; + superadmin: boolean; + "auth-id-appwrite": string; + nome: string; + email: string; + nivel: string; + "registro-completo": boolean; + enderecos: string[]; + empresasDados: string[]; + "nome-social": string; + cpf: string; + createdAt: string; + updatedAt: string; +} + +export default function MeuPerfilPage() { + const [usuarioData, setUsuarioData] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchUser = async () => { + try { + const token = localStorage.getItem('access_token'); + + if (!token) { + setError('Token de acesso não encontrado'); + setLoading(false); + return; + } + + const response = await fetch(`${process.env.NEXT_PUBLIC_BFF_API_URL}/auth/me`, { + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + }); + + if (!response.ok) { + throw new Error(`Erro HTTP: ${response.status}`); + } + + const userData = await response.json(); + setUsuarioData(userData); + } catch (error) { + console.error('Erro ao carregar usuário:', error); + setError('Erro ao carregar dados do usuário'); + } finally { + setLoading(false); + } + }; + fetchUser(); + }, []); + + if (loading) { + return ( +
+
+
+

Carregando...

+
+
+ ); + } + + if (error) { + return ( +
+
+
⚠️ Erro
+

{error}

+
+
+ ); + } + + return ( +
+
+ +
+ ); +} diff --git a/saveinmed-frontend/src/components/Header.tsx b/saveinmed-frontend/src/components/Header.tsx index 0f428f3..ea61c52 100644 --- a/saveinmed-frontend/src/components/Header.tsx +++ b/saveinmed-frontend/src/components/Header.tsx @@ -247,7 +247,7 @@ const Header = ({
  • @@ -256,7 +256,7 @@ const Header = ({
  • diff --git a/saveinmed-frontend/src/types/auth.ts b/saveinmed-frontend/src/types/auth.ts index be4ff19..5c6a2a5 100644 --- a/saveinmed-frontend/src/types/auth.ts +++ b/saveinmed-frontend/src/types/auth.ts @@ -119,7 +119,7 @@ export const ROLE_ROUTES = { "/pagamentos", "/relatorios", "/laboratorios", - "/perfil", + "/meu-perfil", "/gestao-usuarios", ], [UserRole.ADMIN]: [ @@ -130,7 +130,7 @@ export const ROLE_ROUTES = { "/pagamentos", "/relatorios", "/laboratorios", - "/perfil", + "/meu-perfil", "/gestao-usuarios", ], [UserRole.COLABORADOR]: [ @@ -138,7 +138,7 @@ export const ROLE_ROUTES = { "/entregas", "/produtos", "/pedidos", - "/perfil", + "/meu-perfil", ], - [UserRole.ENTREGADOR]: ["/entregas", "/pedidos", "/perfil"], + [UserRole.ENTREGADOR]: ["/entregas", "/pedidos", "/meu-perfil"], } as const;