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 */} - + navigate(`/admin/users/${user.id}`)} variant="outline" @@ -259,6 +285,41 @@ const AdminStaff = () => { Manage + + {hasPermission('users.status') && ( + handleToggleStatus(user.id, user.status)} + variant="outline" + className={`border-2 rounded-full px-4 py-2 ${ + user.status === 'active' + ? 'border-orange-500 text-orange-600 hover:bg-orange-50' + : 'border-green-500 text-green-600 hover:bg-green-50' + }`} + > + {user.status === 'active' ? ( + <> + + Deactivate + > + ) : ( + <> + + Activate + > + )} + + )} + + {hasPermission('users.delete') && ( + handleDeleteUser(user.id, `${user.first_name} ${user.last_name}`)} + variant="outline" + className="border-2 border-red-500 text-red-600 hover:bg-red-50 rounded-full px-4 py-2" + > + + Delete + + )}