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