From 8c351773ba3dd76ffc41fad0481ba00170ec353c Mon Sep 17 00:00:00 2001 From: Koncept Kit <63216427+konceptkit@users.noreply.github.com> Date: Mon, 5 Jan 2026 00:11:30 +0700 Subject: [PATCH] Fix staff invitation acceptance & add delete/deactivate buttons --- src/App.js | 2 ++ src/pages/admin/AdminStaff.js | 65 +++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 30ffde2..e348d88 100644 --- a/src/App.js +++ b/src/App.js @@ -50,6 +50,7 @@ import Resources from './pages/Resources'; import ContactUs from './pages/ContactUs'; import TermsOfService from './pages/TermsOfService'; import PrivacyPolicy from './pages/PrivacyPolicy'; +import AcceptInvitation from './pages/AcceptInvitation'; const PrivateRoute = ({ children, adminOnly = false }) => { const { user, loading } = useAuth(); @@ -82,6 +83,7 @@ function App() { } /> } /> } /> + } /> } /> } /> { const navigate = useNavigate(); @@ -71,6 +71,32 @@ const AdminStaff = () => { setFilteredUsers(filtered); }; + const handleToggleStatus = async (userId, currentStatus) => { + const newStatus = currentStatus === 'active' ? 'inactive' : 'active'; + + try { + await api.put(`/admin/users/${userId}/status`, { status: newStatus }); + toast.success(`User ${newStatus === 'active' ? 'activated' : 'deactivated'} successfully`); + fetchStaff(); // Refresh list + } catch (error) { + toast.error(error.response?.data?.detail || 'Failed to update user status'); + } + }; + + const handleDeleteUser = async (userId, userName) => { + if (!window.confirm(`Are you sure you want to delete ${userName}? This action cannot be undone.`)) { + return; + } + + try { + await api.delete(`/admin/users/${userId}`); + toast.success('User deleted successfully'); + fetchStaff(); // Refresh list + } catch (error) { + toast.error(error.response?.data?.detail || 'Failed to delete user'); + } + }; + const getRoleBadge = (role) => { const config = { superadmin: { label: 'Superadmin', className: 'bg-[#664fa3] text-white' }, @@ -250,7 +276,7 @@ const AdminStaff = () => { {/* Actions */} -
+
+ + {hasPermission('users.status') && ( + + )} + + {hasPermission('users.delete') && ( + + )}