From 7dfbe0f363a434cfda5f9be996d194f03c36879c Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Wed, 31 Jul 2024 12:16:49 +0530 Subject: new project --- panel/src/pages/Dashboard.jsx | 33 +++++++++++++++++++ panel/src/pages/LoginPage.jsx | 52 +++++++++++++++++++++++++++++ panel/src/pages/ManageAds.jsx | 70 ++++++++++++++++++++++++++++++++++++++++ panel/src/pages/RegisterPage.jsx | 47 +++++++++++++++++++++++++++ panel/src/pages/ResetPage.jsx | 41 +++++++++++++++++++++++ panel/src/pages/Roles.jsx | 51 +++++++++++++++++++++++++++++ 6 files changed, 294 insertions(+) create mode 100644 panel/src/pages/Dashboard.jsx create mode 100644 panel/src/pages/LoginPage.jsx create mode 100644 panel/src/pages/ManageAds.jsx create mode 100644 panel/src/pages/RegisterPage.jsx create mode 100644 panel/src/pages/ResetPage.jsx create mode 100644 panel/src/pages/Roles.jsx (limited to 'panel/src/pages') diff --git a/panel/src/pages/Dashboard.jsx b/panel/src/pages/Dashboard.jsx new file mode 100644 index 0000000..5aa2b0c --- /dev/null +++ b/panel/src/pages/Dashboard.jsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { Bar } from 'react-chartjs-2'; + +const Dashboard = () => { + const userStats = { totalUsers: 100, totalAds: 50, totalRevenue: 5000 }; + + const chartData = { + labels: ['Users', 'Revenue'], + datasets: [ + { + label: 'Statistics', + data: [userStats.totalUsers, userStats.totalRevenue], + backgroundColor: ['rgba(75,192,192,0.6)', 'rgba(153,102,255,0.6)'], + }, + ], + }; + + return ( +
+

Dashboard

+
+
Total Users: {userStats.totalUsers}
+
Total Ads: {userStats.totalAds}
+
Total Revenue: {userStats.totalRevenue}
+
+
+ +
+
+ ); +}; + +export default Dashboard; diff --git a/panel/src/pages/LoginPage.jsx b/panel/src/pages/LoginPage.jsx new file mode 100644 index 0000000..37ce32f --- /dev/null +++ b/panel/src/pages/LoginPage.jsx @@ -0,0 +1,52 @@ +import React, { useState } from 'react'; +import { signInWithEmailAndPassword } from 'firebase/auth'; +import { auth } from '../firebase'; + +const LoginPage = () => { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); + + const handleLogin = async () => { + if (password.length < 8) { + setError('The password should be minimum 8 digits'); + return; + } + + try { + await signInWithEmailAndPassword(auth, email, password); + } catch (error) { + setError(error.message); + } + }; + + return ( +
+
+

Login

+
+ + setEmail(e.target.value)} + className="form-control" + /> +
+
+ + setPassword(e.target.value)} + className="form-control" + /> +
+ {error &&

{error}

} + +
+
+ ); +}; + +export default LoginPage; diff --git a/panel/src/pages/ManageAds.jsx b/panel/src/pages/ManageAds.jsx new file mode 100644 index 0000000..4ec0b36 --- /dev/null +++ b/panel/src/pages/ManageAds.jsx @@ -0,0 +1,70 @@ +import React, { useState, useEffect } from 'react'; +import { db } from '../firebase'; +import { collection, addDoc, getDocs } from 'firebase/firestore'; + +const ManageAds = () => { + const [ads, setAds] = useState([]); + const [newAd, setNewAd] = useState({ title: '', description: '', imageUrl: '' }); + + useEffect(() => { + fetchAds(); + }, []); + + const fetchAds = async () => { + const querySnapshot = await getDocs(collection(db, 'ads')); + const adsData = querySnapshot.docs.map(doc => doc.data()); + setAds(adsData); + }; + + const handleAddAd = async () => { + await addDoc(collection(db, 'ads'), newAd); + fetchAds(); + }; + + return ( +
+

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" + /> +
+ +
+
+ {ads.map((ad, index) => ( +
+
{ad.title}
+

{ad.description}

+ {ad.title} +
+ ))} +
+
+ ); +}; + +export default ManageAds; diff --git a/panel/src/pages/RegisterPage.jsx b/panel/src/pages/RegisterPage.jsx new file mode 100644 index 0000000..f0b2bba --- /dev/null +++ b/panel/src/pages/RegisterPage.jsx @@ -0,0 +1,47 @@ +import React, { useState } from 'react'; +import { TextField, Button, Container, Typography } from '@mui/material'; +import { createUserWithEmailAndPassword } from 'firebase/auth'; +import { auth } from '../firebase'; + +const RegisterPage = () => { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); + + const handleRegister = async () => { + if (password.length < 8) { + setError('The password should be minimum 8 digits'); + return; + } + + try { + await createUserWithEmailAndPassword(auth, email, password); + } catch (error) { + setError(error.message); + } + }; + + return ( + + Register + setEmail(e.target.value)} + fullWidth + /> + setPassword(e.target.value)} + fullWidth + /> + {error && {error}} + + + ); +}; + +export default RegisterPage; diff --git a/panel/src/pages/ResetPage.jsx b/panel/src/pages/ResetPage.jsx new file mode 100644 index 0000000..c1750dc --- /dev/null +++ b/panel/src/pages/ResetPage.jsx @@ -0,0 +1,41 @@ + +import React, { useState } from 'react'; +import { sendPasswordResetEmail } from 'firebase/auth'; +import { auth } from '../firebase'; + +const ResetPage = () => { + const [email, setEmail] = useState(''); + const [message, setMessage] = useState(''); + const [error, setError] = useState(''); + + const handleReset = async () => { + try { + await sendPasswordResetEmail(auth, email); + setMessage('Reset link sent to your email'); + } catch (error) { + setError(error.message); + } + }; + + return ( +
+
+

Reset Password

+
+ + setEmail(e.target.value)} + className="form-control" + /> +
+ {error &&

{error}

} + {message &&

{message}

} + +
+
+ ); +}; + +export default ResetPage; diff --git a/panel/src/pages/Roles.jsx b/panel/src/pages/Roles.jsx new file mode 100644 index 0000000..05f73b6 --- /dev/null +++ b/panel/src/pages/Roles.jsx @@ -0,0 +1,51 @@ +import React, { useState, useEffect } from 'react'; +import { db, auth } from '../firebase'; +import { collection, getDocs } from 'firebase/firestore'; +import { httpsCallable } from 'firebase/functions'; + +const Roles = () => { + const [users, setUsers] = useState([]); + const [loading, setLoading] = useState(true); + + const fetchUsers = async () => { + const querySnapshot = await getDocs(collection(db, 'users')); + const usersData = querySnapshot.docs.map(doc => ({ id: doc.id, ...doc.data() })); + setUsers(usersData); + setLoading(false); + }; + + const handleRoleChange = async (email, newRole) => { + const addUserRole = httpsCallable(auth, 'addUserRole'); + try { + await addUserRole({ email: email, role: newRole }); + fetchUsers(); + } catch (error) { + console.error('Error updating role:', error); + } + }; + + useEffect(() => { + fetchUsers(); + }, []); + + if (loading) { + return

Loading...

; + } + + return ( +
+

Manage Roles

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

{user.email}

+ + +
+ ))} +
+
+ ); +}; + +export default Roles; -- cgit v1.2.3-59-g8ed1b