Compare commits

..

3 Commits

Author SHA1 Message Date
9a663d88ec routes1 2025-10-09 10:40:57 -03:00
2893975e82 routes 2025-10-09 10:29:11 -03:00
14445b4e18 dropdownroutes 2025-10-09 09:46:57 -03:00
2 changed files with 109 additions and 69 deletions

View File

@ -1,82 +1,60 @@
import {React, useState, useEffect} from 'react' import React, { useState, useEffect } from "react";
import { useNavigate, useLocation } from 'react-router-dom' import { useNavigate, useLocation } from "react-router-dom";
import { UserInfos } from './utils/Functions-Endpoints/General'; import { UserInfos } from "./utils/Functions-Endpoints/General";
import { useAuth } from './utils/AuthProvider'; import { useAuth } from "./utils/AuthProvider";
import './Estilo/TrocardePerfis.css' import "./Estilo/TrocardePerfis.css";
const TrocardePerfis = () => { const TrocardePerfis = () => {
const location = useLocation(); const location = useLocation();
const [selectedProfile, setSelectedProfile] = useState('');
const { getAuthorizationHeader } = useAuth();
const [showProfiles, setShowProfiles] = useState([]);
const navigate = useNavigate(); const navigate = useNavigate();
const { getAuthorizationHeader } = useAuth();
let authHeader = getAuthorizationHeader(); const [selectedProfile, setSelectedProfile] = useState("");
console.log('AUTH HEADER', authHeader) const [showProfiles, setShowProfiles] = useState([]);
const handleProfileClick = (route) => {
navigate(route);
};
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
setSelectedProfile(location.pathname); const authHeader = getAuthorizationHeader();
setSelectedProfile(location.pathname || "");
const userInfo = await UserInfos(authHeader); const userInfo = await UserInfos(authHeader);
setShowProfiles(userInfo?.roles || []); setShowProfiles(userInfo?.roles || []);
}; };
fetchData(); fetchData();
}, []); }, [location.pathname, getAuthorizationHeader]);
const handleSelectChange = (e) => {
const route = e.target.value;
setSelectedProfile(route);
if (route) navigate(route);
};
const options = [
{ key: "secretaria", label: "Secretaria", route: "/secretaria" },
{ key: "medico", label: "Médico", route: "/medico" },
{ key: "financeiro", label: "Financeiro", route: "/financeiro" },
{ key: "admin", label: "Administração", route: "/admin" },
].filter(
(opt) =>
showProfiles?.includes(opt.key) || showProfiles?.includes("admin")
);
return ( return (
<div className="container-perfis">
<div className='container-perfis'> <p className="acesso-text">Acesso aos módulos:</p>
<select
<p>Acesso aos modulos:</p> className="perfil-select"
<div id='primeiro-conjunto-botoes'> value={selectedProfile}
{(showProfiles?.includes('secretaria') || showProfiles?.includes('admin')) && ( onChange={handleSelectChange}
<button
className={`perfil-button${selectedProfile === '/secretaria' ? ' selecionado' : ''}`}
onClick={() => handleProfileClick('/secretaria')}
> >
Secretaria <option value="">Selecionar perfil</option>
</button> {options.map((opt) => (
)} <option key={opt.key} value={opt.route}>
{(showProfiles?.includes('medico') || showProfiles?.includes('admin')) && ( {opt.label}
<button </option>
className={`perfil-button${selectedProfile === '/medico' ? ' selecionado' : ''}`} ))}
onClick={() => handleProfileClick('/medico')} </select>
>
Médicos
</button>
)}
</div> </div>
);
};
<div id='segundo-conjunto-botoes'> export default TrocardePerfis;
{(showProfiles?.includes('financeiro') || showProfiles?.includes('admin')) && (
<button
className={`perfil-button${selectedProfile === '/financeiro' ? ' selecionado' : ''}`}
onClick={() => handleProfileClick('/financeiro')}
>
Financeiro
</button>
)}
{showProfiles?.includes('admin') && (
<button
className={`perfil-button${selectedProfile === '/admin' ? ' selecionado' : ''}`}
onClick={() => handleProfileClick('/admin')}
>
Administração
</button>
)}
</div>
</div>
)
}
export default TrocardePerfis

View File

@ -0,0 +1,62 @@
.container-perfis {
position: absolute;
top: 80px;
left: 30px;
width: calc(100% - 60px);
display: flex;
flex-direction: column;
align-items: flex-start;
z-index: 60;
}
.acesso-text {
font-size: 15px;
font-weight: 600;
color: #1e2b57;
margin-bottom: 6px;
}
/* estilo visual refinado do select */
.perfil-select {
width: 100%;
padding: 10px 14px;
border-radius: 10px;
border: 1.8px solid #d0d5dd;
background-color: #f9fafc;
color: #1e2b57;
font-weight: 600;
font-size: 14px;
outline: none;
cursor: pointer;
transition: all 0.2s ease;
box-shadow: 0 1px 3px rgba(30, 43, 87, 0.08);
}
.perfil-select:hover {
border-color: #7a85ff;
background-color: #ffffff;
box-shadow: 0 2px 6px rgba(30, 43, 87, 0.1);
}
.perfil-select:focus {
border-color: #5a46ff;
box-shadow: 0 0 0 3px rgba(90, 70, 255, 0.2);
}
.perfil-select option[value=""] {
color: #777;
font-weight: 500;
}
/* responsivo */
@media (max-width: 780px) {
.container-perfis {
top: 60px;
left: 20px;
width: calc(100% - 40px);
}
.perfil-select {
font-size: 13px;
padding: 8px 12px;
}
}