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

Loading...

; } return (

Manage Roles

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

{user.email}

))}
); }; export default Roles;