pramod_Task-#444 : Add "Assign Project" Feature in Employee Action Menu #191
@ -4,6 +4,7 @@ import ProjectRepository from "../repositories/ProjectRepository";
|
|||||||
import { useProfile } from "./useProfile";
|
import { useProfile } from "./useProfile";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { setProjectId } from "../slices/localVariablesSlice";
|
import { setProjectId } from "../slices/localVariablesSlice";
|
||||||
|
import EmployeeList from "../components/Directory/EmployeeList";
|
||||||
|
|
||||||
export const useProjects = () => {
|
export const useProjects = () => {
|
||||||
|
|
||||||
@ -130,3 +131,47 @@ export const useProjectDetails = (projectId) => {
|
|||||||
|
|
||||||
return { projects_Details, loading, error, refetch: fetchData }
|
return { projects_Details, loading, error, refetch: fetchData }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const useProjectsByEmployee = ( employeeId ) =>
|
||||||
|
{
|
||||||
|
const [projectList, setProjectList] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
|
const fetchProjects = async (id) => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
setError(''); // clear previous error
|
||||||
|
const res = await ProjectRepository.getProjectsByEmployee(id);
|
||||||
|
setProjectList(res.data);
|
||||||
|
cacheData('ProjectsByEmployee', { data: res.data, employeeId: id });
|
||||||
|
} catch (err) {
|
||||||
|
setError(err?.message || 'Failed to fetch projects');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!employeeId) return;
|
||||||
|
|
||||||
|
const cache_project = getCachedData('ProjectsByEmployee');
|
||||||
|
|
||||||
|
if (
|
||||||
|
!cache_project?.data ||
|
||||||
|
cache_project?.employeeId !== employeeId
|
||||||
|
) {
|
||||||
|
fetchProjects(employeeId);
|
||||||
|
} else {
|
||||||
|
setProjectList(cache_project.data);
|
||||||
|
}
|
||||||
|
}, [employeeId]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
projectList,
|
||||||
|
loading,
|
||||||
|
error
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user