diff --git a/pages/UserProfile.tsx b/pages/UserProfile.tsx index ae073ff..8be6941 100644 --- a/pages/UserProfile.tsx +++ b/pages/UserProfile.tsx @@ -1,10 +1,11 @@ import React, { useState, useEffect } from 'react'; import { Camera, Save, Mail, User as UserIcon, Building, Shield, Loader2, CheckCircle2 } from 'lucide-react'; -import { getUserById } from '../services/dataService'; -import { User } from '../types'; +import { getUserById, getTenants } from '../services/dataService'; +import { User, Tenant } from '../types'; export const UserProfile: React.FC = () => { const [user, setUser] = useState(null); + const [tenant, setTenant] = useState(null); const [isLoading, setIsLoading] = useState(false); const [isSuccess, setIsSuccess] = useState(false); @@ -12,22 +13,29 @@ export const UserProfile: React.FC = () => { const [bio, setBio] = useState(''); useEffect(() => { - const fetchUser = async () => { - const storedId = localStorage.getItem('ctms_user_id'); - if (storedId) { + const fetchUserAndTenant = async () => { + const storedUserId = localStorage.getItem('ctms_user_id'); + if (storedUserId) { try { - const fetchedUser = await getUserById(storedId); + const fetchedUser = await getUserById(storedUserId); if (fetchedUser) { setUser(fetchedUser); setName(fetchedUser.name); setBio(fetchedUser.bio || ''); + + // Fetch tenant info + const tenants = await getTenants(); + const userTenant = tenants.find(t => t.id === fetchedUser.tenant_id); + if (userTenant) { + setTenant(userTenant); + } } } catch (err) { - console.error("Error fetching profile:", err); + console.error("Error fetching profile data:", err); } } }; - fetchUser(); + fetchUserAndTenant(); }, []); const handleSubmit = (e: React.FormEvent) => { @@ -59,7 +67,7 @@ export const UserProfile: React.FC = () => {
- {user.name} + {user.name}
@@ -76,21 +84,23 @@ export const UserProfile: React.FC = () => { {user.role} - - {user.team_id === 'sales_1' ? 'Vendas Alpha' : 'Vendas Beta'} - + {user.team_id && ( + + {user.team_id === 'sales_1' ? 'Vendas Alpha' : user.team_id === 'sales_2' ? 'Vendas Beta' : user.team_id} + + )}

Status da Conta

-
- Ativo +
+ {user.status === 'active' ? 'Ativo' : 'Inativo'}
- Fasto Corp (Organização) + {tenant?.name || 'Organização'}