import React from "react"; import PageLayout from "../../../PageLayout"; import GlobalAnimatedBackground from "../../../../background/GlobalAnimatedBackground"; import useAdminUserProfile from "../hooks/useAdminUserProfile"; import AdminUserProfileCard from "../components/AdminUserProfileCard"; import AdminUserMediaSection from "../components/AdminUserMediaSection"; import AdminUserPermissionsSection from "../components/AdminUserPermissionsSection"; import EnlargeMediaModal from "../components/EnlargeMediaModal"; import AdminUserActionsSection from "../components/AdminUserActionsSection"; import { useTranslation } from "react-i18next"; import PermissionModal from "../components/PermissionModal"; function AdminUserProfilePage() { const { loading, error, user, profile, permissions, documents, enlargeDoc, setEnlargeDoc, enlargeDocNavigation, } = useAdminUserProfile(); const { t } = useTranslation("user_management"); // Log backend data for debugging React.useEffect(() => { if (user) { console.log("AdminUserProfilePage: user data", user); } if (profile) { console.log("AdminUserProfilePage: profile data", profile); } }, [user, profile]); const [permissionModalOpen, setPermissionModalOpen] = React.useState(false); // initialize empty and sync below so async-loaded permissions update the UI const [permissionsState, setPermissionsState] = React.useState(() => permissions || []); // Keep local permissionsState in sync with fetched permissions prop React.useEffect(() => { setPermissionsState(permissions || []); }, [permissions]); // Refresh permissions after modal update const refreshPermissions = async () => { try { // Replace with your actual API endpoint and authentication as needed const res = await fetch(`/api/users/${user.id}/permissions`); const updated = await res.json(); setPermissionsState(updated); } catch { // Optionally handle error } }; if (loading) { return (
{t("headings.profileViewLoading")}
); } if (error || !user) { return (
{error || t("headings.userNotFound")}
); } // Replace these alert handlers with real implementations if you want requests sent const handleEditPermissions = () => { setPermissionModalOpen(true); }; const handleShowStatistics = () => alert("Show statistics (not implemented)"); const handleExportUserData = () => alert("Export user data (not implemented)"); const handleShowLogs = () => alert("Show logs (not implemented)"); return ( {enlargeDoc && ( setEnlargeDoc(null)} navigation={enlargeDocNavigation} /> )} {/* Permission Modal */} setPermissionModalOpen(false)} onSuccess={() => { refreshPermissions(); setPermissionModalOpen(false); }} currentPermissions={permissionsState} />
{/* Header (removed upper gray back button) */}

{t('headings.main', 'User Management')} / {user.email}

{/* Single column order: Profile -> Media -> Permissions -> Actions */}
{/* Media moved under profile info */}
); } export default AdminUserProfilePage;