Add api to fetch employee project allocation

This commit is contained in:
Vikas Nale 2025-08-06 17:01:40 +05:30
parent 0e8691f6d0
commit eb735f443d
3 changed files with 91 additions and 33 deletions

View File

@ -1,14 +1,15 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import EmpOverview from "./EmpOverview"; import EmpOverview from "./EmpOverview";
import { useProjectsByEmployee } from "../../hooks/useProjects"; import { useProjectsAllocationByEmployee } from "../../hooks/useProjects";
const EmpDashboard = ({ profile }) => { const EmpDashboard = ({ profile }) => {
const { const {
projectList, projectList,
loading: selectedProjectLoding, loading: selectedProjectLoding,
refetch, refetch,
} = useProjectsByEmployee(profile?.id); } = useProjectsAllocationByEmployee(profile?.id);
console.log(projectList);
return ( return (
<> <>
<div className="row"> <div className="row">
@ -32,16 +33,47 @@ const EmpDashboard = ({ profile }) => {
> >
<div className="avatar flex-shrink-0 me-4"> <div className="avatar flex-shrink-0 me-4">
<span className="avatar-initial rounded bg-label-primary"> <span className="avatar-initial rounded bg-label-primary">
<i className="icon-base bx bx-buildings icon-lg"></i> <i className="icon-base bx bx-buildings icon-lg "></i>
</span> </span>
</div> </div>
<div className="row w-100 align-items-center"> <div className="row w-100 align-items-center">
<div className="col-sm-8 col-lg-12 col-xxl-8 mb-1 mb-sm-0 mb-lg-1 mb-xxl-0 text-start"> <div className="d-flex w-100 flex-wrap align-items-center justify-content-between gap-2">
<h6 className="mb-0">{project.shortName}</h6> <div className="me-2">
<div className="d-flex align-items-center">
<h6 className="mb-0 me-2">
{project.projectShortName}
</h6>
</div>
<small>{project.projectName}</small>
</div>
<div className="user-progress">
<div className="badge bg-label-secondary ">
{project.designation}
</div>
</div>
</div> </div>
<div className="col-sm-4 col-lg-12 col-xxl-4 d-flex justify-content-xxl-end"> <div className="col-sm-4 col-lg-12 col-xxl-4 d-flex justify-content-xxl-end mt-1">
<div className="label-secondary">{project.name}</div> <div className="label-secondary">
Assigned:{" "}
{project.assignedDate ? (
new Date(project.assignedDate).toLocaleDateString()
) : (
<em>NA</em>
)}
</div>
</div> </div>
{project.removedDate && (
<div className="col-sm-4 col-lg-12 col-xxl-4 d-flex justify-content-xxl-end mt-1">
<div className="label-secondary">
Unassigned:{" "}
{project.removedDate ? (
new Date(project.removedDate).toLocaleDateString()
) : (
<em>NA</em>
)}
</div>
</div>
)}
</div> </div>
</li> </li>
))} ))}
@ -49,15 +81,6 @@ const EmpDashboard = ({ profile }) => {
</div> </div>
</div> </div>
</div> </div>
{/* <div className="col col-4 pt-5">
<div className="card">
<div className="card-body">
<small className="card-text text-uppercase text-body-secondary small">
My Expences
</small>{" "}
</div>{" "}
</div>
</div> */}
</div> </div>
</> </>
); );

View File

@ -307,6 +307,36 @@ export const useProjectsByEmployee = (employeeId) => {
return { projectList, loading: isLoading, error, refetch }; return { projectList, loading: isLoading, error, refetch };
}; };
export const useProjectsAllocationByEmployee = (employeeId) => {
const {
data: projectList = [],
isLoading,
error,
refetch,
} = useQuery({
queryKey: ["ProjectsAllocationByEmployee", employeeId],
queryFn: async () => {
const res = await ProjectRepository.getProjectsAllocationByEmployee(
employeeId
);
const sortedProjects = [...res.data].sort((a, b) =>
a.projectName.localeCompare(b.projectName)
);
return sortedProjects || res;
//return res.data || res;
},
enabled: !!employeeId,
onError: (error) => {
showToast(
error.message || "Error while Fetching project Employee",
"error"
);
},
});
return { projectList, loading: isLoading, error, refetch };
};
export const useProjectName = () => { export const useProjectName = () => {
const { const {
data = [], data = [],

View File

@ -6,32 +6,37 @@ const ProjectRepository = {
api.get(`/api/project/details/${projetid}`), api.get(`/api/project/details/${projetid}`),
getProjectAllocation: (projetid) => getProjectAllocation: (projetid) =>
api.get( `api/project/allocation/${ projetid }` ), api.get(`api/project/allocation/${projetid}`),
getEmployeesByProject:(projectId)=>api.get(`/api/Project/employees/get/${projectId}`), getEmployeesByProject: (projectId) =>
api.get(`/api/Project/employees/get/${projectId}`),
manageProject: (data) => api.post("/api/project", data), manageProject: (data) => api.post("/api/project", data),
// updateProject: (data) => api.post("/api/project/update", data), // updateProject: (data) => api.post("/api/project/update", data),
manageProjectAllocation: ( data ) => api.post( "/api/project/allocation", data ), manageProjectAllocation: (data) => api.post("/api/project/allocation", data),
manageProjectInfra: (data) => api.post("/api/project/manage-infra", data), manageProjectInfra: (data) => api.post("/api/project/manage-infra", data),
manageProjectTasks: ( data ) => api.post( "/api/project/task", data ), manageProjectTasks: (data) => api.post("/api/project/task", data),
deleteProjectTask:(id)=> api.delete(`/api/project/task/${id}`), deleteProjectTask: (id) => api.delete(`/api/project/task/${id}`),
updateProject: (id, data) => api.put(`/api/project/update/${id}`, data), updateProject: (id, data) => api.put(`/api/project/update/${id}`, data),
deleteProject: ( id ) => api.delete( `/projects/${ id }` ), deleteProject: (id) => api.delete(`/projects/${id}`),
getProjectsByEmployee: ( id ) => api.get( `/api/project/assigned-projects/${ id }` ), getProjectsByEmployee: (id) =>
updateProjectsByEmployee:(id,data)=>api.post(`/api/project/assign-projects/${id}`,data), api.get(`/api/project/assigned-projects/${id}`),
projectNameList: () => api.get( "/api/project/list/basic" ), getProjectsAllocationByEmployee: (id) =>
api.get(`/api/project/allocation-histery/${id}`),
getProjectDetails:(id)=>api.get(`/api/project/details/${id}`), updateProjectsByEmployee: (id, data) =>
getProjectInfraByproject: ( id ) => api.get( `/api/project/infra-details/${ id }` ), api.post(`/api/project/assign-projects/${id}`, data),
getProjectTasksByWorkArea:(id)=>api.get(`/api/project/tasks/${id}`) projectNameList: () => api.get("/api/project/list/basic"),
getProjectDetails: (id) => api.get(`/api/project/details/${id}`),
getProjectInfraByproject: (id) => api.get(`/api/project/infra-details/${id}`),
getProjectTasksByWorkArea: (id) => api.get(`/api/project/tasks/${id}`),
}; };
export const TasksRepository = { export const TasksRepository = {
assignTask: ( data ) => api.post( "/api/task/assign", data ), assignTask: (data) => api.post("/api/task/assign", data),
// reportTask:(data)=>api.post("/api/task/report",data) // reportTask:(data)=>api.post("/api/task/report",data)
} };
export default ProjectRepository; export default ProjectRepository;