feat: fix profile viewing and implement real user login state
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m47s

This commit is contained in:
Cauê Faleiros
2026-02-25 11:04:51 -03:00
parent a175315437
commit 456f13c930
6 changed files with 66 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import { NavLink, useLocation, useNavigate } from 'react-router-dom';
import { LayoutDashboard, Users, UserCircle, Bell, Search, Menu, X, LogOut, Hexagon, Settings, Building2 } from 'lucide-react';
import { USERS } from '../constants';
import { getAttendances, getUsers, getUserById } from '../services/dataService';
import { User } from '../types';
const SidebarItem = ({ to, icon: Icon, label, collapsed }: { to: string, icon: any, label: string, collapsed: boolean }) => (
@@ -24,16 +24,19 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
const location = useLocation();
const navigate = useNavigate();
const [currentUser, setCurrentUser] = useState<User>(USERS[1]); // Default to standard user fallback
const [currentUser, setCurrentUser] = useState<User | null>(null);
useEffect(() => {
const storedUserId = localStorage.getItem('ctms_user_id');
if (storedUserId) {
const user = USERS.find(u => u.id === storedUserId);
if (user) {
setCurrentUser(user);
const fetchCurrentUser = async () => {
const storedUserId = localStorage.getItem('ctms_user_id');
if (storedUserId) {
const user = await getUserById(storedUserId);
if (user) {
setCurrentUser(user);
}
}
}
};
fetchCurrentUser();
}, []);
const handleLogout = () => {
@@ -41,16 +44,9 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
navigate('/login');
};
// Simple title mapping based on route
const getPageTitle = () => {
if (location.pathname === '/') return 'Dashboard';
if (location.pathname.includes('/admin/users')) return 'Gestão de Equipe';
if (location.pathname.includes('/users/')) return 'Histórico do Usuário';
if (location.pathname.includes('/attendances')) return 'Detalhes do Atendimento';
if (location.pathname.includes('/super-admin')) return 'Gestão de Organizações';
if (location.pathname.includes('/profile')) return 'Meu Perfil';
return 'CTMS';
};
if (!currentUser) {
return <div className="flex h-screen items-center justify-center bg-slate-50">Carregando...</div>;
}
const isSuperAdmin = currentUser.role === 'super_admin';