Merge pull request 'fixed : (employee-list display active or inactive and projectwise correctly' (#258) from Bug#751 into Issues_Jun_3W
Reviewed-on: #258 merged
This commit is contained in:
commit
a9322039b8
@ -112,18 +112,20 @@ export const useEmployeesByProject = (projectId) => {
|
||||
};
|
||||
|
||||
// EmployeeList.jsx
|
||||
export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
||||
const isAllEmployees = !projectId && projectId !== undefined;
|
||||
export const useEmployeesAllOrByProjectId = (showAllEmployees ,projectId,
|
||||
showInactive) => {
|
||||
|
||||
const queryKey = isAllEmployees
|
||||
? ['allEmployees', showInactive]
|
||||
: ['projectEmployees', projectId];
|
||||
|
||||
const queryKey = showAllEmployees
|
||||
? ['allEmployees', showInactive]
|
||||
: ['projectEmployees', projectId, showInactive];
|
||||
|
||||
const queryFn = async () => {
|
||||
if (isAllEmployees) {
|
||||
if (showAllEmployees) {
|
||||
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
||||
return res.data;
|
||||
} else {
|
||||
if (!projectId) return [];
|
||||
const res = await EmployeeRepository.getEmployeeListByproject(projectId);
|
||||
return res.data;
|
||||
}
|
||||
@ -137,7 +139,7 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
||||
} = useQuery({
|
||||
queryKey,
|
||||
queryFn,
|
||||
enabled: isAllEmployees || !!projectId,
|
||||
enabled:typeof showInactive === "boolean" && (showAllEmployees || !!projectId),
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -51,7 +51,7 @@ const EmployeeList = () => {
|
||||
|
||||
const { employees, loading, setLoading, error, recallEmployeeData } =
|
||||
useEmployeesAllOrByProjectId(
|
||||
showAllEmployees ? null : selectedProjectId,
|
||||
showAllEmployees ,selectedProjectId,
|
||||
showInactive
|
||||
);
|
||||
|
||||
@ -153,13 +153,7 @@ 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;
|
||||
@ -340,7 +334,7 @@ const EmployeeList = () => {
|
||||
role="switch"
|
||||
id="inactiveEmployeesCheckbox"
|
||||
checked={showInactive}
|
||||
onChange={handleToggle}
|
||||
onChange={()=> setShowInactive(e.target.checked)}
|
||||
/>
|
||||
<label
|
||||
className="form-check-label ms-0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user