fixed togger for active and inactive employee
This commit is contained in:
parent
c254b98405
commit
00902fff9f
@ -143,7 +143,8 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
|||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
const fetchData = async (showInactive) => {
|
const fetchData = async (showInactive) => {
|
||||||
if (projectId) {
|
if ( projectId )
|
||||||
|
{
|
||||||
const Employees_cache = getCachedData("employeeListByProject");
|
const Employees_cache = getCachedData("employeeListByProject");
|
||||||
if (!Employees_cache || Employees_cache.projectId !== projectId) {
|
if (!Employees_cache || Employees_cache.projectId !== projectId) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -166,18 +167,11 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
|||||||
setEmployees(Employees_cache.data);
|
setEmployees(Employees_cache.data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
const cacheKey = showInactive
|
const cacheKey = showInactive
|
||||||
? "allInactiveEmployeeList"
|
? "allInactiveEmployeeList"
|
||||||
: "allEmployeeList";
|
: "allEmployeeList";
|
||||||
const employeesCache = getCachedData(cacheKey);
|
|
||||||
|
|
||||||
if (employeesCache) {
|
|
||||||
setEmployees(employeesCache.data);
|
|
||||||
setLoading(false);
|
|
||||||
} else {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await EmployeeRepository.getAllEmployeeList(
|
const response = await EmployeeRepository.getAllEmployeeList(
|
||||||
@ -190,7 +184,7 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
|||||||
setError("Failed to fetch data.");
|
setError("Failed to fetch data.");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import { useEmployeesAllOrByProjectId } from "../../hooks/useEmployees";
|
|||||||
import { useProjects } from "../../hooks/useProjects";
|
import { useProjects } from "../../hooks/useProjects";
|
||||||
import { useProfile } from "../../hooks/useProfile";
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
import { hasUserPermission } from "../../utils/authUtils";
|
import { hasUserPermission } from "../../utils/authUtils";
|
||||||
import { MANAGE_EMPLOYEES } from "../../utils/constants";
|
import { ITEMS_PER_PAGE, MANAGE_EMPLOYEES } from "../../utils/constants";
|
||||||
import { clearCacheKey } from "../../slices/apiDataManager";
|
import { clearCacheKey } from "../../slices/apiDataManager";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import SuspendEmp from "../../components/Employee/SuspendEmp";
|
import SuspendEmp from "../../components/Employee/SuspendEmp";
|
||||||
@ -29,10 +29,9 @@ const EmployeeList = () => {
|
|||||||
const [selectedProject, setSelectedProject] = useState(() => selectedProjectId || "");
|
const [selectedProject, setSelectedProject] = useState(() => selectedProjectId || "");
|
||||||
const { projects, loading: projectLoading } = useProjects();
|
const { projects, loading: projectLoading } = useProjects();
|
||||||
const [showInactive, setShowInactive] = useState(false);
|
const [showInactive, setShowInactive] = useState(false);
|
||||||
const [showAllEmployees, setShowAllEmployees] = useState(false); // New state for "All Employee"
|
const [showAllEmployees, setShowAllEmployees] = useState(false);
|
||||||
const Manage_Employee = useHasUserPermission(MANAGE_EMPLOYEES);
|
const Manage_Employee = useHasUserPermission(MANAGE_EMPLOYEES);
|
||||||
|
|
||||||
// Modify the hook to conditionally pass selectedProject or null based on showAllEmployees
|
|
||||||
const { employees, loading, setLoading, error, recallEmployeeData } =
|
const { employees, loading, setLoading, error, recallEmployeeData } =
|
||||||
useEmployeesAllOrByProjectId(showAllEmployees ? null : selectedProject, showInactive);
|
useEmployeesAllOrByProjectId(showAllEmployees ? null : selectedProject, showInactive);
|
||||||
const [projectsList, setProjectsList] = useState(projects || []);
|
const [projectsList, setProjectsList] = useState(projects || []);
|
||||||
@ -40,7 +39,7 @@ const EmployeeList = () => {
|
|||||||
const [employeeList, setEmployeeList] = useState([]);
|
const [employeeList, setEmployeeList] = useState([]);
|
||||||
const [modelConfig, setModelConfig] = useState();
|
const [modelConfig, setModelConfig] = useState();
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [itemsPerPage] = useState(20);
|
const [itemsPerPage] = useState(ITEMS_PER_PAGE);
|
||||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
const [isEmployeeModalOpen, setIsEmployeeModalOpen] = useState(false);
|
const [isEmployeeModalOpen, setIsEmployeeModalOpen] = useState(false);
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
@ -189,10 +188,11 @@ const EmployeeList = () => {
|
|||||||
recallEmployeeData(e.target.checked);
|
recallEmployeeData(e.target.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
// New handler for "All Employee" toggle
|
|
||||||
const handleAllEmployeesToggle = (e) => {
|
const handleAllEmployeesToggle = (e) => {
|
||||||
const isChecked = e.target.checked;
|
const isChecked = e.target.checked;
|
||||||
setShowAllEmployees(isChecked);
|
setShowInactive(false)
|
||||||
|
setShowAllEmployees( isChecked );
|
||||||
|
|
||||||
recallEmployeeData(showInactive, isChecked ? null : selectedProject);
|
recallEmployeeData(showInactive, isChecked ? null : selectedProject);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ const EmployeeList = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Show Inactive Employees Switch */}
|
{/* Show Inactive Employees Switch */}
|
||||||
{!showAllEmployees && (
|
{showAllEmployees && (
|
||||||
<div className="form-check form-switch text-start">
|
<div className="form-check form-switch text-start">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user