1- import React , { useState } from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
2+ import { BrowserRouter as Router , Routes , Route , Navigate } from 'react-router-dom' ;
23import { AnimatePresence } from 'framer-motion' ;
3-
44import Sidebar from './components/layout/Sidebar' ;
55import Dashboard from './components/dashboard/Dashboard' ;
6- import BotIntegrationPage from './components/integration/BotIntegrationPage' ;
6+ import BotIntegrationPage from './components/integration/BotIntegrationPage' ;
77import ContributorsPage from './components/contributors/ContributorsPage' ;
88import PullRequestsPage from './components/pages/PullRequestsPage' ;
99import Settings from './components/pages/SettingsPage' ;
10- import AnalyticsPage from './components/pages/AnalyticsPage'
10+ import AnalyticsPage from './components/pages/AnalyticsPage' ;
1111import SupportPage from './components/pages/SupportPage' ;
12-
12+ import LoginPage from './components/pages/LoginPage' ;
13+ import ProfilePage from './components/pages/ProfilePage' ;
1314
1415function App ( ) {
1516 const [ isSidebarOpen , setIsSidebarOpen ] = useState ( true ) ;
1617 const [ activePage , setActivePage ] = useState ( 'dashboard' ) ;
18+ const [ isAuthenticated , setIsAuthenticated ] = useState < boolean > ( false ) ;
19+
20+ useEffect ( ( ) => {
21+ const auth = localStorage . getItem ( 'isAuthenticated' ) ;
22+ setIsAuthenticated ( auth === 'true' ) ;
23+ } , [ ] ) ;
24+
25+ const handleLogin = ( ) => {
26+ setIsAuthenticated ( true ) ;
27+ localStorage . setItem ( 'isAuthenticated' , 'true' ) ;
28+ } ;
29+
30+ const handleLogout = ( ) => {
31+ setIsAuthenticated ( false ) ;
32+ localStorage . removeItem ( 'isAuthenticated' ) ;
33+ } ;
1734
1835 const renderPage = ( ) => {
1936 switch ( activePage ) {
20- case 'dashboard' :
21- return < Dashboard /> ;
22- case 'integration' :
23- return < BotIntegrationPage /> ;
24- case 'contributors' :
25- return < ContributorsPage /> ;
26- case 'analytics' :
27- return < AnalyticsPage />
28- case 'prs' :
29- return < PullRequestsPage /> ;
30- case 'support' :
31- return < SupportPage />
32- case 'settings' :
33- return < Settings /> ;
34- default :
35- return < Dashboard /> ;
37+ case 'dashboard' :
38+ return < Dashboard /> ;
39+ case 'integration' :
40+ return < BotIntegrationPage /> ;
41+ case 'contributors' :
42+ return < ContributorsPage /> ;
43+ case 'analytics' :
44+ return < AnalyticsPage /> ;
45+ case 'prs' :
46+ return < PullRequestsPage /> ;
47+ case 'support' :
48+ return < SupportPage /> ;
49+ case 'settings' :
50+ return < Settings /> ;
51+ case 'profile' :
52+ return < ProfilePage /> ;
53+ default :
54+ return < Dashboard /> ;
3655 }
3756 } ;
3857
3958 return (
40- < div className = "min-h-screen bg-gray-950 text-white" >
41- < Sidebar
42- isOpen = { isSidebarOpen }
43- setIsOpen = { setIsSidebarOpen }
44- activePage = { activePage }
45- setActivePage = { setActivePage }
46- />
47-
48- < main className = { `transition-all duration-300 ${ isSidebarOpen ? 'ml-64' : 'ml-20' } ` } >
49- < div className = "p-8" >
50- < AnimatePresence mode = "wait" >
51- { renderPage ( ) }
52- </ AnimatePresence >
53- </ div >
54- </ main >
55- </ div >
59+ < Router >
60+ < div className = "min-h-screen bg-gray-950 text-white" >
61+ < Routes >
62+ < Route
63+ path = "/login"
64+ element = {
65+ isAuthenticated ? (
66+ < Navigate to = "/" replace />
67+ ) : (
68+ < LoginPage onLogin = { handleLogin } />
69+ )
70+ }
71+ />
72+ < Route
73+ path = "/*"
74+ element = {
75+ isAuthenticated ? (
76+ < div className = "flex" >
77+ < Sidebar
78+ isOpen = { isSidebarOpen }
79+ setIsOpen = { setIsSidebarOpen }
80+ activePage = { activePage }
81+ setActivePage = { setActivePage }
82+ />
83+ < main
84+ className = { `transition-all duration-300 flex-1 ${
85+ isSidebarOpen ? 'ml-64' : 'ml-20'
86+ } `}
87+ >
88+ < div className = "p-8" >
89+ < AnimatePresence mode = "wait" > { renderPage ( ) } </ AnimatePresence >
90+ </ div >
91+ </ main >
92+ </ div >
93+ ) : (
94+ < Navigate to = "/login" replace />
95+ )
96+ }
97+ />
98+ </ Routes >
99+ </ div >
100+ </ Router >
56101 ) ;
57102}
58103
59- export default App ;
104+ export default App ;
0 commit comments