import { useState, useEffect, useCallback } from 'react'; import { motion } from 'framer-motion'; import { HiSearch } from 'react-icons/hi'; import { HiArrowPath } from 'react-icons/hi2'; import api from '../../../services/api'; import { formatDate } from '../../../utils/helpers'; import { useAuth } from '../../../contexts/AuthContext'; import toast from 'react-hot-toast'; const ROLES = [ { value: 'citizen', label: 'Citizen', color: '#6B7280' }, { value: 'volunteer_coordinator',label: 'Vol. Coordinator', color: '#3B82F6' }, { value: 'content_manager', label: 'Content Manager', color: '#8B5CF6' }, { value: 'manager', label: 'Manager', color: '#D97706' }, { value: 'admin', label: 'Admin', color: '#EF4444' }, ]; const ROLE_STYLE = Object.fromEntries(ROLES.map(r => [r.value, r])); function RoleChangeModal({ user, onClose, onSave }) { const [newRole, setNewRole] = useState(user.role); const [saving, setSaving] = useState(false); const handle = async () => { if (newRole === user.role) { onClose(); return; } if (!window.confirm(`Change ${user.displayName || user.email}'s role to "${newRole}"?`)) return; setSaving(true); try { await api.put('/auth/role', { userId: user.uid, role: newRole }); toast.success(`Role updated to ${newRole}`); onSave(); onClose(); } catch (e) { toast.error(e.message || 'Update failed.'); } finally { setSaving(false); } }; return (
{user.displayName || user.email}
View all users and manage their roles and permissions.
No users found.
| User | Role | Status | Joined | {isRole('admin') &&Actions | }
{u.profileImage ? (
{initials}
)}
{u.displayName || '—'} {isSelf && (you)}
|
{u.email} | {roleSty.label} | {u.status || 'active'} | {u.createdAt ? formatDate(u.createdAt) : '—'} | {isRole('admin') && ({!isSelf && ( )} | )}
|---|