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
|
// EmployeeList.jsx
|
||||||
export const useEmployeesAllOrByProjectId = (showAllEmployees ,projectId,
|
export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
||||||
showInactive) => {
|
const isAllEmployees = !projectId && projectId !== undefined;
|
||||||
|
|
||||||
|
const queryKey = isAllEmployees
|
||||||
const queryKey = showAllEmployees
|
? ['allEmployees', showInactive]
|
||||||
? ['allEmployees', showInactive]
|
: ['projectEmployees', projectId];
|
||||||
: ['projectEmployees', projectId, showInactive];
|
|
||||||
|
|
||||||
const queryFn = async () => {
|
const queryFn = async () => {
|
||||||
if (showAllEmployees) {
|
if (isAllEmployees) {
|
||||||
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
||||||
return res.data;
|
return res.data;
|
||||||
} else {
|
} else {
|
||||||
if (!projectId) return [];
|
|
||||||
const res = await EmployeeRepository.getEmployeeListByproject(projectId);
|
const res = await EmployeeRepository.getEmployeeListByproject(projectId);
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
@ -139,7 +137,7 @@ const queryKey = showAllEmployees
|
|||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey,
|
queryKey,
|
||||||
queryFn,
|
queryFn,
|
||||||
enabled:typeof showInactive === "boolean" && (showAllEmployees || !!projectId),
|
enabled: isAllEmployees || !!projectId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ const EmployeeList = () => {
|
|||||||
|
|
||||||
const { employees, loading, setLoading, error, recallEmployeeData } =
|
const { employees, loading, setLoading, error, recallEmployeeData } =
|
||||||
useEmployeesAllOrByProjectId(
|
useEmployeesAllOrByProjectId(
|
||||||
showAllEmployees ,selectedProjectId,
|
showAllEmployees ? null : selectedProjectId,
|
||||||
showInactive
|
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 handleAllEmployeesToggle = (e) => {
|
||||||
const isChecked = e.target.checked;
|
const isChecked = e.target.checked;
|
||||||
@ -334,7 +340,7 @@ const EmployeeList = () => {
|
|||||||
role="switch"
|
role="switch"
|
||||||
id="inactiveEmployeesCheckbox"
|
id="inactiveEmployeesCheckbox"
|
||||||
checked={showInactive}
|
checked={showInactive}
|
||||||
onChange={()=> setShowInactive(e.target.checked)}
|
onChange={handleToggle}
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
className="form-check-label ms-0"
|
className="form-check-label ms-0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user