From b3c07fd9f1664dda4f16357aaca74dff8226401d Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 1 Aug 2024 17:21:25 +0530 Subject: updated project --- panel/src/App.jsx | 25 ++++++----- panel/src/components/Navbar.css | 27 ++++++++++++ panel/src/components/Navbar.jsx | 18 ++++++++ panel/src/components/PrivateRoute.jsx | 24 ++++------- panel/src/main.jsx | 5 ++- panel/src/pages/Dashboard.jsx | 39 ++++++++++++----- panel/src/pages/ManageAds.jsx | 80 ++++++++++++++++++----------------- panel/src/pages/Roles.jsx | 26 +++++++----- 8 files changed, 157 insertions(+), 87 deletions(-) create mode 100644 panel/src/components/Navbar.css create mode 100644 panel/src/components/Navbar.jsx (limited to 'panel') diff --git a/panel/src/App.jsx b/panel/src/App.jsx index 906f859..6d88aaf 100644 --- a/panel/src/App.jsx +++ b/panel/src/App.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; +import { Route, Routes, Navigate } from 'react-router-dom'; import LoginPage from './pages/LoginPage'; import RegisterPage from './pages/RegisterPage'; import ResetPage from './pages/ResetPage'; @@ -14,18 +14,17 @@ import './tailwind.css'; function App() { return ( - - - } /> - } /> - } /> - }> - } /> - } /> - } /> - - - + + } /> + } /> + } /> + } /> + }> + } /> + } /> + } /> + + ); } diff --git a/panel/src/components/Navbar.css b/panel/src/components/Navbar.css new file mode 100644 index 0000000..ee38707 --- /dev/null +++ b/panel/src/components/Navbar.css @@ -0,0 +1,27 @@ +.navbar { + background-color: #343a40; + padding: 1rem; + display: flex; + justify-content: center; +} + +.navbar-list { + list-style: none; + padding: 0; + margin: 0; + display: flex; +} + +.navbar-item { + margin: 0 1rem; +} + +.navbar-item a { + color: white; + text-decoration: none; + font-weight: bold; +} + +.navbar-item a:hover { + text-decoration: underline; +} diff --git a/panel/src/components/Navbar.jsx b/panel/src/components/Navbar.jsx new file mode 100644 index 0000000..b287e97 --- /dev/null +++ b/panel/src/components/Navbar.jsx @@ -0,0 +1,18 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import './Navbar.css'; + +const Navbar = () => { + return ( + + ); +}; + +export default Navbar; diff --git a/panel/src/components/PrivateRoute.jsx b/panel/src/components/PrivateRoute.jsx index 2160f74..e2c502d 100644 --- a/panel/src/components/PrivateRoute.jsx +++ b/panel/src/components/PrivateRoute.jsx @@ -1,17 +1,11 @@ -import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; -import LoginPage from '../pages/LoginPage'; -import Dashboard from '../pages/Dashboard'; // Assuming you have a Dashboard component +import React from 'react'; +import { Navigate, Outlet } from 'react-router-dom'; +import { useAuth } from '../contexts/AuthContext'; -function App() { - return ( - - - } /> - } /> - {/* Other routes */} - - - ); -} +const PrivateRoute = () => { + const { currentUser } = useAuth(); -export default App; + return currentUser ? : ; +}; + +export default PrivateRoute; diff --git a/panel/src/main.jsx b/panel/src/main.jsx index 881e61b..f8085d8 100644 --- a/panel/src/main.jsx +++ b/panel/src/main.jsx @@ -1,5 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; +import { BrowserRouter as Router } from 'react-router-dom'; import App from './App'; import './index.css'; import './tailwind.css'; @@ -7,6 +8,8 @@ import 'bootstrap/dist/css/bootstrap.min.css'; ReactDOM.createRoot(document.getElementById('root')).render( - + + + ); diff --git a/panel/src/pages/Dashboard.jsx b/panel/src/pages/Dashboard.jsx index 5aa2b0c..d16204d 100644 --- a/panel/src/pages/Dashboard.jsx +++ b/panel/src/pages/Dashboard.jsx @@ -1,5 +1,9 @@ -import React from 'react'; +import React, { useEffect, useRef } from 'react'; +import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend } from 'chart.js'; import { Bar } from 'react-chartjs-2'; +import Navbar from '../components/Navbar'; + +Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend); const Dashboard = () => { const userStats = { totalUsers: 100, totalAds: 50, totalRevenue: 5000 }; @@ -15,16 +19,31 @@ const Dashboard = () => { ], }; + const chartRef = useRef(null); + + useEffect(() => { + const chartInstance = chartRef.current.chartInstance; + + return () => { + if (chartInstance) { + chartInstance.destroy(); + } + }; + }, []); + return ( -
-

Dashboard

-
-
Total Users: {userStats.totalUsers}
-
Total Ads: {userStats.totalAds}
-
Total Revenue: {userStats.totalRevenue}
-
-
- +
+ +
+

Dashboard

+
+
Total Users: {userStats.totalUsers}
+
Total Ads: {userStats.totalAds}
+
Total Revenue: {userStats.totalRevenue}
+
+
+ +
); diff --git a/panel/src/pages/ManageAds.jsx b/panel/src/pages/ManageAds.jsx index 4ec0b36..70142d2 100644 --- a/panel/src/pages/ManageAds.jsx +++ b/panel/src/pages/ManageAds.jsx @@ -1,6 +1,7 @@ import React, { useState, useEffect } from 'react'; import { db } from '../firebase'; import { collection, addDoc, getDocs } from 'firebase/firestore'; +import Navbar from '../components/Navbar'; const ManageAds = () => { const [ads, setAds] = useState([]); @@ -22,46 +23,49 @@ const ManageAds = () => { }; return ( -
-

Manage Ads

-
-
- - setNewAd({ ...newAd, title: e.target.value })} - className="form-control" - /> -
-
- - setNewAd({ ...newAd, description: e.target.value })} - className="form-control" - /> +
+ +
+

Manage Ads

+
+
+ + setNewAd({ ...newAd, title: e.target.value })} + className="form-control" + /> +
+
+ + setNewAd({ ...newAd, description: e.target.value })} + className="form-control" + /> +
+
+ + setNewAd({ ...newAd, imageUrl: e.target.value })} + className="form-control" + /> +
+
-
- - setNewAd({ ...newAd, imageUrl: e.target.value })} - className="form-control" - /> +
+ {ads.map((ad, index) => ( +
+
{ad.title}
+

{ad.description}

+ {ad.title} +
+ ))}
- -
-
- {ads.map((ad, index) => ( -
-
{ad.title}
-

{ad.description}

- {ad.title} -
- ))}
); diff --git a/panel/src/pages/Roles.jsx b/panel/src/pages/Roles.jsx index 05f73b6..5b18ace 100644 --- a/panel/src/pages/Roles.jsx +++ b/panel/src/pages/Roles.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import { db, auth } from '../firebase'; import { collection, getDocs } from 'firebase/firestore'; import { httpsCallable } from 'firebase/functions'; +import Navbar from '../components/Navbar'; const Roles = () => { const [users, setUsers] = useState([]); @@ -33,16 +34,21 @@ const Roles = () => { } return ( -
-

Manage Roles

-
- {users.map((user, index) => ( -
-

{user.email}

- - -
- ))} +
+ +
+

Manage Roles

+
+ {users.map((user, index) => ( +
+

{user.email}

+
+ + +
+
+ ))} +
); -- cgit v1.2.3-59-g8ed1b