Integrate the API for Work Area and fetch data filtered by serviceId. #419
@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import WorkArea from "./WorkArea";
|
import WorkArea from "./WorkArea";
|
||||||
const Floor = ({ floor, workAreas, forBuilding }) => {
|
const Floor = ({ floor, workAreas, forBuilding,serviceId }) => {
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={floor.id}>
|
<React.Fragment key={floor.id}>
|
||||||
{workAreas && workAreas.length > 0 ? (
|
{workAreas && workAreas.length > 0 ? (
|
||||||
@ -10,6 +10,7 @@ const Floor = ({ floor, workAreas, forBuilding }) => {
|
|||||||
key={workArea.id}
|
key={workArea.id}
|
||||||
workArea={workArea}
|
workArea={workArea}
|
||||||
floor={floor}
|
floor={floor}
|
||||||
|
serviceId={serviceId}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
getCachedData,
|
getCachedData,
|
||||||
} from "../../../slices/apiDataManager";
|
} from "../../../slices/apiDataManager";
|
||||||
|
|
||||||
const InfraTable = ({ buildings, projectId}) => {
|
const InfraTable = ({ buildings, projectId, serviceId }) => {
|
||||||
const [projectBuilding, setProjectBuilding] = useState([]);
|
const [projectBuilding, setProjectBuilding] = useState([]);
|
||||||
const [expandedBuildings, setExpandedBuildings] = useState([]);
|
const [expandedBuildings, setExpandedBuildings] = useState([]);
|
||||||
const [showFloorModal, setShowFloorModal] = useState(false);
|
const [showFloorModal, setShowFloorModal] = useState(false);
|
||||||
@ -90,6 +90,7 @@ const InfraTable = ({ buildings, projectId}) => {
|
|||||||
forBuilding={building}
|
forBuilding={building}
|
||||||
floor={floor}
|
floor={floor}
|
||||||
workAreas={floor.workAreas}
|
workAreas={floor.workAreas}
|
||||||
|
serviceId={serviceId}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
@ -100,7 +101,7 @@ const InfraTable = ({ buildings, projectId}) => {
|
|||||||
No floors have been added yet. Start by adding floors to manage
|
No floors have been added yet. Start by adding floors to manage
|
||||||
this building.
|
this building.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -16,18 +16,17 @@ import { useParams } from "react-router-dom";
|
|||||||
import ProgressBar from "../../common/ProgressBar";
|
import ProgressBar from "../../common/ProgressBar";
|
||||||
import {formatNumber} from "../../../utils/dateUtils";
|
import {formatNumber} from "../../../utils/dateUtils";
|
||||||
|
|
||||||
const WorkArea = ({ workArea, floor, forBuilding }) => {
|
const WorkArea = ({ workArea, floor, forBuilding,serviceId = null }) => {
|
||||||
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
const { projects_Details, loading } = useProjectDetails(selectedProject);
|
const { projects_Details, loading } = useProjectDetails(selectedProject);
|
||||||
const [IsExpandedArea, setIsExpandedArea] = useState(false);
|
const [IsExpandedArea, setIsExpandedArea] = useState(false);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [Project, setProject] = useState();
|
const [Project, setProject] = useState();
|
||||||
// const { projectId } = useParams();
|
|
||||||
|
|
||||||
const ManageInfra = useHasUserPermission(MANAGE_PROJECT_INFRA);
|
const ManageInfra = useHasUserPermission(MANAGE_PROJECT_INFRA);
|
||||||
const ManageAndAssignTak = useHasUserPermission(ASSIGN_REPORT_TASK);
|
const ManageAndAssignTak = useHasUserPermission(ASSIGN_REPORT_TASK);
|
||||||
|
|
||||||
const { ProjectTaskList, isLoading } = useProjectTasks(workArea.id, IsExpandedArea);
|
const { ProjectTaskList, isLoading } = useProjectTasks(workArea.id,serviceId, IsExpandedArea);
|
||||||
|
|
||||||
const [workAreaStatus, setWorkAreaStatus] = useState({
|
const [workAreaStatus, setWorkAreaStatus] = useState({
|
||||||
completed: 0,
|
completed: 0,
|
||||||
|
@ -25,7 +25,6 @@ import { useParams } from "react-router-dom";
|
|||||||
import GlobalModel from "../common/GlobalModel";
|
import GlobalModel from "../common/GlobalModel";
|
||||||
|
|
||||||
const ProjectInfra = ({ data, onDataChange, eachSiteEngineer }) => {
|
const ProjectInfra = ({ data, onDataChange, eachSiteEngineer }) => {
|
||||||
// const projectId = useSelector((store)=>store.localVariables.projectId)
|
|
||||||
const projectId = useSelectedProject();
|
const projectId = useSelectedProject();
|
||||||
const reloadedData = useSelector((store) => store.localVariables.reload);
|
const reloadedData = useSelector((store) => store.localVariables.reload);
|
||||||
const [expandedBuildings, setExpandedBuildings] = useState([]);
|
const [expandedBuildings, setExpandedBuildings] = useState([]);
|
||||||
@ -89,37 +88,31 @@ const ProjectInfra = ({ data, onDataChange, eachSiteEngineer }) => {
|
|||||||
className="dataTables_length text-start py-2 px-6 col-md-4 col-12"
|
className="dataTables_length text-start py-2 px-6 col-md-4 col-12"
|
||||||
id="DataTables_Table_0_length"
|
id="DataTables_Table_0_length"
|
||||||
>
|
>
|
||||||
{servicesLoading ? (
|
{!servicesLoading && assignedServices?.length > 0 && (
|
||||||
<span></span>
|
assignedServices.length > 1 ? (
|
||||||
) : assignedServices?.length > 1 ? (
|
<label>
|
||||||
<label>
|
<select
|
||||||
<select
|
name="DataTables_Table_0_length"
|
||||||
name="DataTables_Table_0_length"
|
aria-controls="DataTables_Table_0"
|
||||||
aria-controls="DataTables_Table_0"
|
className="form-select form-select-sm"
|
||||||
className="form-select form-select-sm"
|
aria-label="Select Service"
|
||||||
aria-label="Select Service"
|
value={selectedService}
|
||||||
value={selectedService}
|
onChange={handleServiceChange}
|
||||||
onChange={handleServiceChange}
|
>
|
||||||
>
|
<option value="">All Services</option>
|
||||||
{assignedServices.map((service) => (
|
{assignedServices.map((service) => (
|
||||||
<option key={service.id} value={service.id}>
|
<option key={service.id} value={service.id}>
|
||||||
{service.name}
|
{service.name}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<h5>{assignedServices[0].name}</h5>
|
||||||
style={{
|
)
|
||||||
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{assignedServices?.length === 1
|
|
||||||
? <h5>{ assignedServices[0].name}</h5>
|
|
||||||
: "No service available"}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Buttons Section (aligned to right) */}
|
{/* Buttons Section (aligned to right) */}
|
||||||
<div className="col-md-8 col-12 text-end mb-1">
|
<div className="col-md-8 col-12 text-end mb-1">
|
||||||
{ManageInfra && (
|
{ManageInfra && (
|
||||||
@ -162,11 +155,10 @@ const ProjectInfra = ({ data, onDataChange, eachSiteEngineer }) => {
|
|||||||
<div className="row ">
|
<div className="row ">
|
||||||
{isLoading && <p>Loading....</p>}
|
{isLoading && <p>Loading....</p>}
|
||||||
{projectInfra && projectInfra?.length > 0 && (
|
{projectInfra && projectInfra?.length > 0 && (
|
||||||
<InfraTable
|
<InfraTable
|
||||||
buildings={projectInfra}
|
buildings={projectInfra}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
// handleFloor={submitData}
|
serviceId={selectedService}
|
||||||
// signalRHandler ={signalRHandler}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{!isLoading && projectInfra?.length == 0 && <div className="mt-5"><p>No Infra Avaiable</p></div>}
|
{!isLoading && projectInfra?.length == 0 && <div className="mt-5"><p>No Infra Avaiable</p></div>}
|
||||||
|
@ -202,23 +202,20 @@ export const useProjectInfra = (projectId) => {
|
|||||||
return { projectInfra, isLoading, error, isFetched };
|
return { projectInfra, isLoading, error, isFetched };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useProjectTasks = (workAreaId, IsExpandedArea = false) => {
|
export const useProjectTasks = (workAreaId, serviceId = null, isExpandedArea = false) => {
|
||||||
const {
|
const { data, isLoading, error } = useQuery({
|
||||||
data: ProjectTaskList,
|
queryKey: ["WorkItems", workAreaId, serviceId],
|
||||||
isLoading,
|
|
||||||
error,
|
|
||||||
} = useQuery({
|
|
||||||
queryKey: ["WorkItems", workAreaId],
|
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await ProjectRepository.getProjectTasksByWorkArea(workAreaId);
|
const res = await ProjectRepository.getProjectTasksByWorkArea(workAreaId, serviceId);
|
||||||
return res.data;
|
return res.data; // return actual task list
|
||||||
},
|
},
|
||||||
enabled: !!workAreaId && !!IsExpandedArea,
|
enabled: !!workAreaId && isExpandedArea, // only fetch if workAreaId exists and area is expanded
|
||||||
onError: (error) => {
|
onError: (err) => {
|
||||||
showToast(error.message || "Error while Fetching project Tasks", "error");
|
showToast(err.message || "Error while fetching project tasks", "error");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return { ProjectTaskList, isLoading, error };
|
|
||||||
|
return { ProjectTaskList: data, isLoading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useProjectTasksByEmployee = (employeeId, fromDate, toDate) => {
|
export const useProjectTasksByEmployee = (employeeId, fromDate, toDate) => {
|
||||||
|
@ -24,7 +24,6 @@ const ProjectRepository = {
|
|||||||
api.get(`/api/Project/employees/get/${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),
|
|
||||||
|
|
||||||
manageProjectAllocation: (data) => api.post("/api/project/allocation", data),
|
manageProjectAllocation: (data) => api.post("/api/project/allocation", data),
|
||||||
|
|
||||||
@ -44,13 +43,19 @@ const ProjectRepository = {
|
|||||||
|
|
||||||
getProjectDetails: (id) => api.get(`/api/project/details/${id}`),
|
getProjectDetails: (id) => api.get(`/api/project/details/${id}`),
|
||||||
getProjectInfraByproject: (id) => api.get(`/api/project/infra-details/${id}`),
|
getProjectInfraByproject: (id) => api.get(`/api/project/infra-details/${id}`),
|
||||||
getProjectTasksByWorkArea: (id) => api.get(`/api/project/tasks/${id}`),
|
getProjectTasksByWorkArea: (workAreaId, serviceId) => {
|
||||||
|
let url = `/api/project/tasks/${workAreaId}`;
|
||||||
|
if (serviceId) {
|
||||||
|
url += `?serviceId=${serviceId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.get(url);
|
||||||
|
},
|
||||||
getProjectTasksByEmployee: (id, fromDate, toDate) =>
|
getProjectTasksByEmployee: (id, fromDate, toDate) =>
|
||||||
api.get(
|
api.get(
|
||||||
`/api/project/tasks-employee/${id}?fromDate=${fromDate}&toDate=${toDate}`
|
`/api/project/tasks-employee/${id}?fromDate=${fromDate}&toDate=${toDate}`
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
||||||
// Permission Managment for Employee at Project Level
|
// Permission Managment for Employee at Project Level
|
||||||
|
|
||||||
getProjectLevelEmployeeList: (projectId) => api.get(`/api/Project/get/proejct-level/employees/${projectId}`),
|
getProjectLevelEmployeeList: (projectId) => api.get(`/api/Project/get/proejct-level/employees/${projectId}`),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user