diff --git a/frontend/App.tsx b/frontend/App.tsx index 99e9e8f..c7c7401 100644 --- a/frontend/App.tsx +++ b/frontend/App.tsx @@ -1,4 +1,5 @@ -import React, { useState, useEffect } from "react"; +import React from "react"; +import { BrowserRouter, Routes, Route, Navigate, useNavigate, useLocation } from "react-router-dom"; import { Navbar } from "./components/Navbar"; import { Home } from "./pages/Home"; import { Dashboard } from "./pages/Dashboard"; @@ -14,253 +15,437 @@ import { TermsOfUse } from "./pages/TermsOfUse"; import { LGPD } from "./pages/LGPD"; import { AuthProvider, useAuth } from "./contexts/AuthContext"; import { DataProvider } from "./contexts/DataContext"; -import { Construction } from "lucide-react"; +import { UserRole } from "./types"; +import { ShieldAlert } from "lucide-react"; -const AppContent: React.FC = () => { +// Componente de acesso negado +const AccessDenied: React.FC = () => { + const navigate = useNavigate(); + + return ( +
+
+ +

Acesso Negado

+

+ Você não tem permissão para acessar esta página. +

+ +
+
+ ); +}; + +// Componente de rota protegida +interface ProtectedRouteProps { + children: React.ReactNode; + allowedRoles?: UserRole[]; +} + +const ProtectedRoute: React.FC = ({ children, allowedRoles }) => { const { user } = useAuth(); - const [currentPage, setCurrentPage] = useState("home"); - useEffect(() => { - if (user && currentPage === "login") { - setCurrentPage("dashboard"); - } - }, [user, currentPage]); + if (!user) { + return ; + } - const renderPage = () => { - if (currentPage === "home") - return ( - setCurrentPage(user ? "dashboard" : "login")} /> - ); - if (currentPage === "login") - return user ? : ; - if (currentPage === "register") - return user ? : ; - if (currentPage === "privacy") - return ; - if (currentPage === "terms") - return ; - if (currentPage === "lgpd") return ; + if (allowedRoles && allowedRoles.length > 0 && !allowedRoles.includes(user.role)) { + return ; + } - if (!user) return ; + return <>{children}; +}; - switch (currentPage) { - case "dashboard": - case "events": - return ; +// Wrapper para páginas que usam o sistema antigo de navegação +const PageWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => { + const navigate = useNavigate(); + const location = useLocation(); + + const handleNavigate = (page: string) => { + navigate(`/${page}`); + }; - case "request-event": - return ; - - case "inspiration": - return ; - - case "team": - return ; - - case "finance": - return ; - - case "settings": - return ; - - case "courses": - return ; - - default: - return ; - } + const getCurrentPage = () => { + const path = location.pathname.substring(1) || "home"; + return path; }; return (
- -
{renderPage()}
+ +
{children}
+
+ ); +}; - {currentPage === "home" && ( - + ); +}; + +const AppContent: React.FC = () => { + const location = useLocation(); + const showFooter = location.pathname === "/"; + + return ( + <> + + {/* Rotas Públicas */} + } /> + } /> + } /> + + window.location.href = `/${page}`} /> + + } + /> + + window.location.href = `/${page}`} /> + + } + /> + + window.location.href = `/${page}`} /> + + } + /> + + {/* Rotas Protegidas - Todos os usuários autenticados */} + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + {/* Rota de solicitação de evento - Clientes e Administradores */} + + + + + + } + /> + + {/* Rotas Administrativas - Apenas gestão */} + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + {/* Rota padrão - redireciona para home */} + } /> + + ); }; function App() { return ( - - - - - + + + + + + + ); } diff --git a/frontend/components/Navbar.tsx b/frontend/components/Navbar.tsx index 4a5206e..adb5c39 100644 --- a/frontend/components/Navbar.tsx +++ b/frontend/components/Navbar.tsx @@ -60,18 +60,18 @@ export const Navbar: React.FC = ({ onNavigate, currentPage }) => { case UserRole.SUPERADMIN: case UserRole.BUSINESS_OWNER: return [ - { name: "Gestão de Eventos", path: "dashboard" }, - { name: "Equipe", path: "team" }, - { name: "Gestão de Cursos", path: "courses" }, - { name: "Financeiro", path: "finance" }, + { name: "Gestão de Eventos", path: "painel" }, + { name: "Equipe", path: "equipe" }, + { name: "Gestão de Cursos", path: "cursos" }, + { name: "Financeiro", path: "financeiro" }, ]; case UserRole.EVENT_OWNER: return [ - { name: "Meus Eventos", path: "dashboard" }, - { name: "Solicitar Evento", path: "request-event" }, + { name: "Meus Eventos", path: "painel" }, + { name: "Solicitar Evento", path: "solicitar-evento" }, ]; case UserRole.PHOTOGRAPHER: - return [{ name: "Eventos Designados", path: "dashboard" }]; + return [{ name: "Eventos Designados", path: "painel" }]; default: return []; } @@ -287,7 +287,7 @@ export const Navbar: React.FC = ({ onNavigate, currentPage }) => {