bug fixed
This commit is contained in:
parent
d3d9167de2
commit
ccda98a6a5
@ -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 = () => {
|
||||
<img
|
||||
src={isActive ? surveyIconActiveSrc : surveyIconInactiveSrc}
|
||||
alt="Survey"
|
||||
className={`h-[18px] w-[18px] ${(window.location.pathname === '/dashboard' || window.location.pathname === '/overview') ? 'opacity-50' : ''}`}
|
||||
className={`h-[18px] w-[18px] ${(window.location.pathname === '/dashboard' ||
|
||||
window.location.pathname === '/overview' ||
|
||||
window.location.pathname.startsWith('/edit-profile')) ? 'opacity-50' : ''}`}
|
||||
/>
|
||||
<span>Survey</span>
|
||||
</>
|
||||
|
||||
@ -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 (
|
||||
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/10">
|
||||
<div className="bg-white rounded-lg w-[480px] shadow-lg p-6 relative">
|
||||
@ -17,7 +38,7 @@ const EditUserModal = ({ formData, setFormData, onClose, onUpdate }) => {
|
||||
|
||||
{/* Form */}
|
||||
<form
|
||||
onSubmit={onUpdate}
|
||||
onSubmit={handleUpdate}
|
||||
className="flex flex-col gap-4"
|
||||
>
|
||||
{/* Name & Email in one row */}
|
||||
|
||||
@ -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
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -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.';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user