Melhorias nos botões de troca de perfil
This commit is contained in:
parent
c060fd7a4f
commit
db212835bf
@ -1,10 +1,10 @@
|
||||
.perfil-button, .selecionado{
|
||||
margin: 8px;
|
||||
margin-left:0px;
|
||||
padding: 10px 12px;
|
||||
padding: 10px 19px;
|
||||
font-size: 15px;
|
||||
|
||||
width:68%;
|
||||
width:70%;
|
||||
border: 2px solid #25396f;
|
||||
border-radius: 20px;
|
||||
cursor: pointer;
|
||||
@ -22,6 +22,7 @@
|
||||
margin: 20px;
|
||||
justify-content: flex-end;
|
||||
margin-left: 0px;
|
||||
margin-left: 18px;
|
||||
}
|
||||
|
||||
#primeiro-conjunto-botoes, #segundo-conjunto-botoes{
|
||||
|
||||
@ -15,61 +15,63 @@ const TrocardePerfis = () => {
|
||||
let authHeader = getAuthorizationHeader();
|
||||
console.log('AUTH HEADER', authHeader)
|
||||
|
||||
const handleUserInfo = async () => {
|
||||
const userInfo = await UserInfos(authHeader);
|
||||
setShowProfiles(userInfo.roles)
|
||||
|
||||
};
|
||||
|
||||
const handleProfileClick = (profile, route) => {
|
||||
setSelectedProfile(profile);
|
||||
const handleProfileClick = (route) => {
|
||||
|
||||
navigate(route);
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedProfile(location.pathname)
|
||||
const fetchData = async () => {
|
||||
setSelectedProfile(location.pathname);
|
||||
const userInfo = await UserInfos(authHeader);
|
||||
setShowProfiles(userInfo?.roles || []);
|
||||
};
|
||||
|
||||
handleUserInfo();
|
||||
},[])
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
<div className='container-perfis'>
|
||||
|
||||
<p>Acesso aos modulos:</p>
|
||||
<div id='primeiro-conjunto-botoes'>
|
||||
{(showProfiles.includes('secretaria') || showProfiles.includes('admin')) && (
|
||||
{(showProfiles?.includes('secretaria') || showProfiles?.includes('admin')) && (
|
||||
<button
|
||||
className={`perfil-button${selectedProfile === 'secretaria' ? 'selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('secretaria', '/secretaria')}
|
||||
className={`perfil-button${selectedProfile === '/secretaria' ? ' selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('/secretaria')}
|
||||
>
|
||||
Secretaria
|
||||
</button>
|
||||
)}
|
||||
{(showProfiles.includes('medico') || showProfiles.includes('admin')) && (
|
||||
{(showProfiles?.includes('medico') || showProfiles?.includes('admin')) && (
|
||||
<button
|
||||
className={`perfil-button${selectedProfile === 'medico' ? 'selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('medico', '/medico')}
|
||||
className={`perfil-button${selectedProfile === '/medico' ? ' selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('/medico')}
|
||||
>
|
||||
Médico(a)
|
||||
Médicos
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div id='segundo-conjunto-botoes'>
|
||||
{(showProfiles.includes('financeiro') || showProfiles.includes('admin')) && (
|
||||
{(showProfiles?.includes('financeiro') || showProfiles?.includes('admin')) && (
|
||||
<button
|
||||
className={`perfil-button${selectedProfile === 'financeiro' ? 'selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('financeiro', '/financeiro')}
|
||||
className={`perfil-button${selectedProfile === '/financeiro' ? ' selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('/financeiro')}
|
||||
>
|
||||
Financeiro
|
||||
</button>
|
||||
)}
|
||||
{showProfiles.includes('admin') && (
|
||||
{showProfiles?.includes('admin') && (
|
||||
<button
|
||||
className={`perfil-button${selectedProfile === 'admin' ? 'selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('admin', '/admin')}
|
||||
|
||||
className={`perfil-button${selectedProfile === '/admin' ? ' selecionado' : ''}`}
|
||||
onClick={() => handleProfileClick('/admin')}
|
||||
>
|
||||
Administrador(a)
|
||||
Administração
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@ -117,7 +117,15 @@ function Login({ onEnterSystem }) {
|
||||
const UserData = await UserInfos(`bearer ${data.access_token}`);
|
||||
console.log(UserData, 'Dados do usuário');
|
||||
|
||||
if(UserData?.roles?.includes('admin')){
|
||||
navigate(`/admin/`);
|
||||
} else if(UserData?.roles?.includes('secretaria')){
|
||||
navigate(`/secretaria/`);
|
||||
} else if(UserData?.roles?.includes('medico')){
|
||||
navigate(`/medico/`);
|
||||
} else if(UserData?.roles?.includes('financeiro')){
|
||||
navigate(`/financeiro/`);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user