diff --git a/src/components/fechamento/UnidadeGate.tsx b/src/components/fechamento/UnidadeGate.tsx index 7098500..31bb150 100644 --- a/src/components/fechamento/UnidadeGate.tsx +++ b/src/components/fechamento/UnidadeGate.tsx @@ -52,7 +52,7 @@ export function UnidadeGate({ children }: UnidadeGateProps) { return; } - if (papel !== "admin" && me?.unidadeId && me.unidadeId !== row.id) { + if (papel !== "admin" && papel !== "supervisor" && me?.unidadeId && me.unidadeId !== row.id) { setPhase("usuario_outra_unidade"); return; } @@ -71,6 +71,7 @@ export function UnidadeGate({ children }: UnidadeGateProps) { }, [me?.unidadeId, location.pathname, papel]); const isAdmin = papel === "admin"; + const isStaff = papel === "admin" || papel === "supervisor"; const onConfiguracoes = isConfiguracoesPath(location.pathname); if (phase === "loading") { @@ -88,7 +89,7 @@ export function UnidadeGate({ children }: UnidadeGateProps) { return <>{children}; } - if (phase === "unidade_nao_cadastrada" && isAdmin && onConfiguracoes) { + if (phase === "unidade_nao_cadastrada" && isStaff && onConfiguracoes) { return <>{children}; } diff --git a/src/modules/fechamento-hgtx/App.tsx b/src/modules/fechamento-hgtx/App.tsx index 3614a79..bc89892 100644 --- a/src/modules/fechamento-hgtx/App.tsx +++ b/src/modules/fechamento-hgtx/App.tsx @@ -1,5 +1,6 @@ import { Navigate, Route, Routes, useLocation } from "react-router-dom"; import { MainLayout } from "@/modules/fechamento-hgtx/components/layout/MainLayout"; +import DashboardPontos from "@/modules/fechamento-hgtx/pages/DashboardPontos"; import Fechamentos from "@/modules/fechamento-hgtx/pages/Fechamentos"; import CompetenciaFechamentos from "@/modules/fechamento-hgtx/pages/CompetenciaFechamentos"; import FechamentoDetalhes from "@/modules/fechamento-hgtx/pages/FechamentoDetalhes"; @@ -16,10 +17,10 @@ import { AuthAccessProvider, useAuthAccess } from "@/contexts/AuthAccessContext" import { AuthGate } from "@/components/auth/AuthGate"; import { UnidadeGate } from "@/components/fechamento/UnidadeGate"; -function RequireAdminRoute({ children }: { children: JSX.Element }) { +function RequireStaffRoute({ children }: { children: JSX.Element }) { const { papel } = useAuthAccess(); - if (papel === "admin") { + if (papel === "admin" || papel === "supervisor") { return children; } @@ -31,7 +32,7 @@ function RequireFechamentoDetalheRoute({ children }: { children: JSX.Element }) const location = useLocation(); const readonlyView = Boolean((location.state as { readonlyView?: boolean } | null)?.readonlyView); - if (papel === "admin") { + if (papel === "admin" || papel === "supervisor") { return children; } @@ -49,20 +50,29 @@ const FechamentoHgtxApp = () => { + } /> + + + + } + /> + - + } /> + - + } /> { + - + } /> + - + } /> } /> @@ -95,25 +105,25 @@ const FechamentoHgtxApp = () => { + - + } /> + - + } /> + - + } /> } /> diff --git a/src/modules/fechamento-hgtx/components/layout/AppSidebar.tsx b/src/modules/fechamento-hgtx/components/layout/AppSidebar.tsx index 596c6e8..fe5569a 100644 --- a/src/modules/fechamento-hgtx/components/layout/AppSidebar.tsx +++ b/src/modules/fechamento-hgtx/components/layout/AppSidebar.tsx @@ -6,6 +6,7 @@ import { ChevronRight, ClipboardList, Landmark, + LayoutDashboard, Menu, ReceiptText, Settings, @@ -18,67 +19,86 @@ import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { GlobalFunctions } from "@/GlobalFunctions"; import { useAuthAccess } from "@/contexts/AuthAccessContext"; +import type { Capabilities, PapelUsuario } from "@/services/fechamento/authMe"; + +function canSeeNavItem(path: string, caps: Capabilities | undefined, papel: PapelUsuario | null): boolean { + if (!caps || !papel) return false; + if (path === "meu-fechamento" || path === "meu-perfil") { + return papel === "admin" || papel === "parceiro" || papel === "supervisor"; + } + if (path === "configuracoes") { + return papel === "admin" || papel === "supervisor"; + } + if (path === "dashboard") { + return (papel === "admin" || papel === "supervisor") && caps.competencias.listar; + } + if (path === "gerenciar-fechamentos") return caps.competencias.listar; + if (path === "banco-pontos") return caps.bancoPontos.acessoAdmin; + if (path === "parceiros") return caps.parceiros.listar; + if (path === "usuarios") return caps.usuarios.listar; + return false; +} const navItems = [ { - section: "Fechamento", - title: "Gerenciar Fechamentos", - path: "", - icon: ClipboardList, - roles: ["admin"] as const, + section: "Fechamento" as const, + title: "Dashboard", + path: "dashboard", + icon: LayoutDashboard, }, { - section: "Fechamento", + section: "Fechamento" as const, + title: "Gerenciar Fechamentos", + path: "gerenciar-fechamentos", + icon: ClipboardList, + }, + { + section: "Fechamento" as const, title: "Banco de Pontos", path: "banco-pontos", icon: Landmark, - roles: ["admin"] as const, }, { - section: "Fechamento", + section: "Fechamento" as const, title: "Meu Fechamento", path: "meu-fechamento", icon: ReceiptText, - roles: ["admin", "parceiro"] as const, }, { - section: "Configurações", + section: "Configurações" as const, title: "Parceiros", path: "parceiros", icon: Wallet, - roles: ["admin"] as const, }, { - section: "Configurações", + section: "Configurações" as const, title: "Usuários", path: "usuarios", icon: Users, - roles: ["admin"] as const, }, { - section: "Configurações", + section: "Configurações" as const, title: "Configurações", path: "configuracoes", icon: Settings, - roles: ["admin"] as const, }, { - section: "Configurações", + section: "Configurações" as const, title: "Meu Perfil", path: "meu-perfil", icon: UserCircle2, - roles: ["admin", "parceiro"] as const, }, ]; export function AppSidebar() { - const { papel } = useAuthAccess(); + const { papel, me } = useAuthAccess(); const [collapsed, setCollapsed] = useState(false); const [mobileOpen, setMobileOpen] = useState(false); - const isAdmin = papel === "admin"; - const role = papel ?? "parceiro"; - const allowedNavItems = navItems.filter((item) => item.roles.includes(role)); + const caps = me?.capabilities; + const allowedNavItems = navItems.filter((item) => canSeeNavItem(item.path, caps, papel)); const sections = ["Fechamento", "Configurações"] as const; + const painelLabel = + papel === "supervisor" ? "Painel Supervisor" : papel === "admin" ? "Painel Admin" : "Painel Parceiro"; const SidebarContent = () => ( <> @@ -98,7 +118,7 @@ export function AppSidebar() {

HGTX Intelligence Score

-

{isAdmin ? "Painel Admin" : "Painel Parceiro"}

+

{painelLabel}

@@ -263,33 +335,39 @@ export default function CompetenciaFechamentos() {

{fechamentos.length} fechamento(s)

{competenciaStatus === "concluido" ? ( - - ) : temFechamentos ? ( - <> - + podeReabrirCompetencia ? ( + ) : null + ) : temFechamentos ? ( + <> + {podeImportarAsana ? ( + + ) : null} + {podeConcluirCompetencia ? ( + + ) : null} ) : null}
@@ -309,11 +387,15 @@ export default function CompetenciaFechamentos() {
{importKind === "sheet" ? ( - ) : ( + ) : podeImportarAsana ? ( + ) : ( +

+ Não há permissão para importar do Asana neste perfil. Peça a um administrador. +

)}
@@ -374,17 +456,44 @@ export default function CompetenciaFechamentos() { -
+
+ + {podeExcluirFechamento ? ( + + ) : null}
@@ -656,6 +780,67 @@ export default function CompetenciaFechamentos() { + + { + if (!open) { + setFechamentoExcluir(null); + setMotivoExclusaoFechamento(""); + } + }} + > + + + Excluir fechamento + + {fechamentoExcluir ? ( + <> + Parceiro: {getDisplayNome(fechamentoExcluir)}. + {fechamentoExcluir.status === "fechado" ? ( + <> + {" "} + Será aplicado estorno no banco de pontos (como na reabertura). Se a competência estiver + concluída, reabra a competência antes de excluir este fechamento. + + ) : null} + + ) : null} + + +
+ +