diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-08-01 17:35:27 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-08-01 17:35:27 +0530 |
commit | fb04271b5288e8fb5891b7d6326f4806d12b82d5 (patch) | |
tree | e459c3e1f8bb6e168becdddd0d48779135d91a7f /panel/src/pages/Roles.jsx | |
parent | 4bb13ee84f6bb51cba6544ccd0690ab2049512a9 (diff) | |
parent | b3c07fd9f1664dda4f16357aaca74dff8226401d (diff) | |
download | admin-panel-fb04271b5288e8fb5891b7d6326f4806d12b82d5.tar.gz admin-panel-fb04271b5288e8fb5891b7d6326f4806d12b82d5.tar.bz2 admin-panel-fb04271b5288e8fb5891b7d6326f4806d12b82d5.zip |
Merge remote-tracking branch 'project/master'
Diffstat (limited to 'panel/src/pages/Roles.jsx')
-rw-r--r-- | panel/src/pages/Roles.jsx | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/panel/src/pages/Roles.jsx b/panel/src/pages/Roles.jsx new file mode 100644 index 0000000..5b18ace --- /dev/null +++ b/panel/src/pages/Roles.jsx @@ -0,0 +1,57 @@ +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([]); + 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 <p>Loading...</p>; + } + + return ( + <div> + <Navbar /> + <div className="container mt-5"> + <h4>Manage Roles</h4> + <div className="list-group"> + {users.map((user, index) => ( + <div key={index} className="list-group-item d-flex justify-content-between align-items-center"> + <p className="mb-0">{user.email}</p> + <div> + <button onClick={() => handleRoleChange(user.email, 'admin')} className="btn btn-primary btn-sm mr-2">Make Admin</button> + <button onClick={() => handleRoleChange(user.email, 'user')} className="btn btn-secondary btn-sm">Make User</button> + </div> + </div> + ))} + </div> + </div> + </div> + ); +}; + +export default Roles; |