Move admin state into AdminPage
Build and Push Docker Image / build-and-push (push) Failing after 21s

All admin state (tab, users, projects, loading/error, preview, reset
result) and the data loader were only used by AdminPage, so they now live
there as local state instead of in App's context. The page loads its data
when it opens (still gated on authUser.isAdmin; the server enforces it too).

Add tests: admin sees users and projects, deleting a user reloads the
list, and non-admins get no Admin button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Opus 5.5 committed 2026-09-22 14:46:35 -04:00
1 parent 49ffefed54
commit 8c55765ae6
3 files changed
+88 -50

No files matched your search

+30 -13
View File
@@ -1,6 +1,9 @@
import { useEffect, useState } from 'react';
import { useApp } from '../context/AppContext.js';
import { buildExportHtml } from '../utils/bibleUtils.jsx';
import {
adminListUsers,
adminListProjects,
adminDeleteUser,
adminDeleteProject,
adminGetProject,
@@ -8,19 +11,33 @@ import {
} from '../syncService.js';
export default function AdminPage() {
const {
authUser,
authStatus,
goHome,
adminTab, setAdminTab,
adminUsers,
adminProjects,
adminLoading,
adminError,
adminViewProject, setAdminViewProject,
adminResetResult, setAdminResetResult,
loadAdminData,
} = useApp();
const { authUser, authStatus, goHome } = useApp();
const [adminTab, setAdminTab] = useState('users'); // 'users' | 'projects'
const [adminUsers, setAdminUsers] = useState([]);
const [adminProjects, setAdminProjects] = useState([]);
const [adminLoading, setAdminLoading] = useState(false);
const [adminError, setAdminError] = useState('');
const [adminViewProject, setAdminViewProject] = useState(null); // full project data being previewed
const [adminResetResult, setAdminResetResult] = useState(null); // { email, temporaryPassword } shown once
const loadAdminData = () => {
setAdminLoading(true);
setAdminError('');
Promise.all([adminListUsers(), adminListProjects()]).then(([usersResult, projectsResult]) => {
setAdminLoading(false);
if (!usersResult.ok || !projectsResult.ok) {
setAdminError(usersResult.error ?? projectsResult.error ?? 'Failed to load admin data.');
return;
}
setAdminUsers(usersResult.data);
setAdminProjects(projectsResult.data);
});
};
useEffect(() => {
if (authUser?.isAdmin) loadAdminData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [authUser?.isAdmin]);
const handleDeleteUserAdmin = async (id, email) => {
if (!window.confirm(`Delete account "${email}"? Their projects are kept, not deleted, but become inaccessible until reassigned.`)) return;