Skip to content

Commit 4414875

Browse files
PranshuLakhotiaPranshuLakhotia
authored andcommitted
Added Login and Profile Page
1 parent 280cd6b commit 4414875

File tree

6 files changed

+508
-39
lines changed

6 files changed

+508
-39
lines changed

frontend/package-lock.json

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"react": "^18.3.1",
1616
"react-dom": "^18.3.1",
1717
"react-hot-toast": "^2.5.2",
18+
"react-router-dom": "^7.5.0",
1819
"recharts": "^2.15.1",
1920
"tailwind-merge": "^3.0.2"
2021
},

frontend/src/App.tsx

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,104 @@
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';
23
import { AnimatePresence } from 'framer-motion';
3-
44
import Sidebar from './components/layout/Sidebar';
55
import Dashboard from './components/dashboard/Dashboard';
6-
import BotIntegrationPage from './components/integration/BotIntegrationPage';
6+
import BotIntegrationPage from './components/integration/BotIntegrationPage';
77
import ContributorsPage from './components/contributors/ContributorsPage';
88
import PullRequestsPage from './components/pages/PullRequestsPage';
99
import Settings from './components/pages/SettingsPage';
10-
import AnalyticsPage from './components/pages/AnalyticsPage'
10+
import AnalyticsPage from './components/pages/AnalyticsPage';
1111
import SupportPage from './components/pages/SupportPage';
12-
12+
import LoginPage from './components/pages/LoginPage';
13+
import ProfilePage from './components/pages/ProfilePage';
1314

1415
function 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;

frontend/src/components/layout/Sidebar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
GitPullRequest,
1010
MessageCircleQuestion,
1111
Menu,
12-
Settings
12+
Settings,
13+
User
1314
} from 'lucide-react';
1415

1516
interface SidebarProps {
@@ -37,6 +38,7 @@ const Sidebar: React.FC<SidebarProps> = ({ isOpen, setIsOpen, activePage, setAct
3738
{ icon: <GitPullRequest size={20} />, label: 'Pull Requests', id: 'prs' },
3839
{ icon: <MessageCircleQuestion size={20} />, label: 'Support', id: 'support' },
3940
{ icon: <Settings size={20} />, label: 'Settings', id: 'settings' },
41+
{ icon: <User size={20} />, label: 'Profile', id: 'profile' },
4042
].map((item) => (
4143
<button
4244
key={item.id}

0 commit comments

Comments
 (0)