diff --git a/ipi-survey-platform/src/components/layout/HeaderBar.jsx b/ipi-survey-platform/src/components/layout/HeaderBar.jsx index 0fb5a3a..3c01e31 100644 --- a/ipi-survey-platform/src/components/layout/HeaderBar.jsx +++ b/ipi-survey-platform/src/components/layout/HeaderBar.jsx @@ -100,12 +100,16 @@ const HeaderBar = () => { className={({ isActive, isPending }) => `inline-flex items-center gap-2 pb-1 border-b-2 ${ isActive ? 'text-[#92722A] font-medium border-[#92722A]' - : (window.location.pathname === '/dashboard' || window.location.pathname === '/overview') + : (window.location.pathname === '/dashboard' || + window.location.pathname === '/overview' || + window.location.pathname.startsWith('/edit-profile')) ? 'text-gray-400 cursor-not-allowed' : 'text-[#232528] hover:text-gray-900 border-transparent' }`} onClick={(e) => { - if (window.location.pathname === '/dashboard' || window.location.pathname === '/overview') { + if (window.location.pathname === '/dashboard' || + window.location.pathname === '/overview' || + window.location.pathname.startsWith('/edit-profile')) { e.preventDefault(); } }} @@ -115,7 +119,9 @@ const HeaderBar = () => { Survey Survey diff --git a/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/EditUserModal.jsx b/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/EditUserModal.jsx index 91c36bf..cddd23b 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/EditUserModal.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/EditUserModal.jsx @@ -1,6 +1,27 @@ import React from "react"; -const EditUserModal = ({ formData, setFormData, onClose, onUpdate }) => { +const EditUserModal = ({ formData, setFormData, onClose, onUpdate, showToast }) => { + const handleUpdate = (e) => { + e.preventDefault(); + + // Check if the deactivated user is the currently logged-in user + const currentUser = JSON.parse(sessionStorage.getItem('user_profile') || '{}'); + const currentUserEmail = currentUser?.email?.toLowerCase()?.trim(); + const updatedUserEmail = formData.email?.toLowerCase()?.trim(); + const shouldLogout = currentUserEmail === updatedUserEmail && formData.status === "Inactive"; + // Call the original onUpdate with an additional parameter + onUpdate(e, shouldLogout); + + // If it's the current user being deactivated, show a warning and log out + if (shouldLogout) { + showToast('This account has been deactivated. You will be logged out.', 'warning'); + setTimeout(() => { + sessionStorage.clear(); + window.location.href = '/login'; + }, 1500); + } + }; + return (
@@ -17,7 +38,7 @@ const EditUserModal = ({ formData, setFormData, onClose, onUpdate }) => { {/* Form */}
{/* Name & Email in one row */} diff --git a/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/ListAdminUsers.jsx b/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/ListAdminUsers.jsx index 5c81e64..34c9b01 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/ListAdminUsers.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/AdminUsers/ListAdminUsers.jsx @@ -755,6 +755,7 @@ onClick={() => handleEdit(user.raw || user)} setErrors({}); }} onUpdate={handleEditSubmit} + showToast={showToast} key={currentUser.id} // Add key to force re-render when user changes /> )} diff --git a/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx b/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx index 5fdccf6..2cd6530 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx @@ -1540,7 +1540,7 @@ const CompanyProfile = () => { ) ); - showToast('success', `Establishment ${newStatus ? 'activated' : 'deactivated'} successfully`); + showToast(newStatus ? 'success' : 'error', `Establishment ${newStatus ? 'activated' : 'deactivated'} successfully`); } catch (error) { console.error('Error updating status:', error); const message = error?.response?.data?.message || error?.message || 'Failed to update status. Please try again.';