Compare commits
No commits in common. "a9322039b8e872dffffa49bb6348e33af24cd670" and "6b893bbc9443909ee1059b93a52b114ff4fb9ce1" have entirely different histories.
a9322039b8
...
6b893bbc94
@ -112,20 +112,18 @@ export const useEmployeesByProject = (projectId) => {
|
||||
};
|
||||
|
||||
// EmployeeList.jsx
|
||||
export const useEmployeesAllOrByProjectId = (showAllEmployees ,projectId,
|
||||
showInactive) => {
|
||||
export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
||||
const isAllEmployees = !projectId && projectId !== undefined;
|
||||
|
||||
|
||||
const queryKey = showAllEmployees
|
||||
? ['allEmployees', showInactive]
|
||||
: ['projectEmployees', projectId, showInactive];
|
||||
const queryKey = isAllEmployees
|
||||
? ['allEmployees', showInactive]
|
||||
: ['projectEmployees', projectId];
|
||||
|
||||
const queryFn = async () => {
|
||||
if (showAllEmployees) {
|
||||
if (isAllEmployees) {
|
||||
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
||||
return res.data;
|
||||
} else {
|
||||
if (!projectId) return [];
|
||||
const res = await EmployeeRepository.getEmployeeListByproject(projectId);
|
||||
return res.data;
|
||||
}
|
||||
@ -139,7 +137,7 @@ const queryKey = showAllEmployees
|
||||
} = useQuery({
|
||||
queryKey,
|
||||
queryFn,
|
||||
enabled:typeof showInactive === "boolean" && (showAllEmployees || !!projectId),
|
||||
enabled: isAllEmployees || !!projectId,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@ -51,7 +51,7 @@ const EmployeeList = () => {
|
||||
|
||||
const { employees, loading, setLoading, error, recallEmployeeData } =
|
||||
useEmployeesAllOrByProjectId(
|
||||
showAllEmployees ,selectedProjectId,
|
||||
showAllEmployees ? null : selectedProjectId,
|
||||
showInactive
|
||||
);
|
||||
|
||||
@ -153,7 +153,13 @@ const EmployeeList = () => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleToggle = (e) => {
|
||||
setShowInactive(e.target.checked);
|
||||
recallEmployeeData(
|
||||
e.target.checked,
|
||||
showAllEmployees ? null : selectedProjectId
|
||||
); // Use selectedProjectId here
|
||||
};
|
||||
|
||||
const handleAllEmployeesToggle = (e) => {
|
||||
const isChecked = e.target.checked;
|
||||
@ -334,7 +340,7 @@ const EmployeeList = () => {
|
||||
role="switch"
|
||||
id="inactiveEmployeesCheckbox"
|
||||
checked={showInactive}
|
||||
onChange={()=> setShowInactive(e.target.checked)}
|
||||
onChange={handleToggle}
|
||||
/>
|
||||
<label
|
||||
className="form-check-label ms-0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user