import { useApp } from '../context/AppContext.js'; import { buildExportHtml } from '../App.jsx'; import { adminDeleteUser, adminDeleteProject, adminGetProject, adminResetPassword, } from '../syncService.js'; export default function AdminPage() { const { authUser, authStatus, goHome, adminTab, setAdminTab, adminUsers, adminProjects, adminLoading, adminError, adminViewProject, setAdminViewProject, adminResetResult, setAdminResetResult, loadAdminData, } = useApp(); const handleDeleteUserAdmin = async (id, email) => { if (!window.confirm(`Delete account "${email}"? Their projects are kept, not deleted, but become inaccessible until reassigned.`)) return; const result = await adminDeleteUser(id); if (result.ok) loadAdminData(); else alert(result.error ?? 'Failed to delete user.'); }; const handleDeleteProjectAdmin = async (id, title) => { if (!window.confirm(`Permanently delete project "${title}"? This cannot be undone.`)) return; const result = await adminDeleteProject(id); if (result.ok) loadAdminData(); else alert(result.error ?? 'Failed to delete project.'); }; const handleViewProjectAdmin = async (id) => { const result = await adminGetProject(id); if (result.ok) setAdminViewProject(result.data); else alert(result.error ?? 'Failed to load project.'); }; const handleResetPasswordAdmin = async (id, email) => { if (!window.confirm(`Reset the password for "${email}"? They'll be signed out everywhere and need the new temporary password to log back in.`)) return; const result = await adminResetPassword(id); if (result.ok) setAdminResetResult({ email, temporaryPassword: result.data.temporaryPassword }); else alert(result.error ?? 'Failed to reset password.'); }; return (

Bible Study Project

πŸ›‘ Admin

{authStatus}
{adminLoading &&

Loading…

} {adminError &&

{adminError}

} {!adminLoading && !adminError && adminTab === 'users' && (
{adminUsers.map((u) => ( ))}
Email Joined 2FA Projects
{u.email}{u.id === authUser.id && (you)} {new Date(u.createdAt).toLocaleDateString()} {u.totpEnabled ? 'βœ“' : 'β€”'} {u.projectCount} {u.id !== authUser.id && (
)}
)} {!adminLoading && !adminError && adminTab === 'projects' && (
{adminProjects.map((p) => ( ))}
Title Owner Passage Last edited Shared
{p.title} {p.ownerEmail ?? orphaned} {p.chapterSummary} {new Date(p.lastEdited).toLocaleDateString()} {p.shareToken ? 'πŸ”—' : 'β€”'}
)}
{adminViewProject && (
setAdminViewProject(null)}>
e.stopPropagation()}>

{adminViewProject.title}