diff --git a/src/components/Project/Infrastructure/InfraTable.jsx b/src/components/Project/Infrastructure/InfraTable.jsx
new file mode 100644
index 00000000..90e6a0c1
--- /dev/null
+++ b/src/components/Project/Infrastructure/InfraTable.jsx
@@ -0,0 +1,69 @@
+import {useEffect, useState} from "react";
+import Building from "./Building";
+import Floor from "./Floor";
+
+const InfraTable = ( {buildings,assign} ) =>
+{
+ const [projectBuiling,setProjectBuilding] = useState([])
+ const [expandedBuildings, setExpandedBuildings] = useState([]);
+
+ const toggleBuilding = (buildingId) => {
+ setExpandedBuildings((prevExpanded) =>
+ prevExpanded.includes(buildingId)
+ ? prevExpanded.filter((id) => id !== buildingId)
+ : [...prevExpanded, buildingId]
+ );
+ };
+
+
+ const getContent = (building) => {
+ return building.floors.length > 0 ? (
+ building.floors.map((floor) =>
)
+ ) : (
+
+
+
+ No floors have been added yet. Please add floors to start managing your building.
+
+
+ |
+
+ );
+ };
+
+
+ useEffect( () =>
+ {
+ setProjectBuilding(buildings)
+ },[buildings])
+
+ return (
+
+ {projectBuiling && projectBuiling.length > 0 && (
+
+
+ {projectBuiling.map((building) => (
+
+ ))}
+
+
+ )}
+
+ );
+ };
+ export default InfraTable
\ No newline at end of file
diff --git a/src/components/Project/TaskModel.jsx b/src/components/Project/Infrastructure/TaskModel.jsx
similarity index 98%
rename from src/components/Project/TaskModel.jsx
rename to src/components/Project/Infrastructure/TaskModel.jsx
index 5451a35f..8061aff8 100644
--- a/src/components/Project/TaskModel.jsx
+++ b/src/components/Project/Infrastructure/TaskModel.jsx
@@ -14,9 +14,10 @@ const TaskModel = ({
onSubmit,
clearTrigger,
onClearComplete,
-}) => {
+} ) =>
+{
+
const [formData, setFormData] = useState(defaultModel);
-
const [selectedBuilding, setSelectedBuilding] = useState(null);
const [selectedFloor, setSelectedFloor] = useState(null);
const [selectedWorkArea, setSelectedWorkArea] = useState(null);
@@ -47,8 +48,8 @@ const TaskModel = ({
if (clearTrigger) {
let model = defaultModel;
model.floorId = selectedFloor.id;
- setFormData(defaultModel); // Clear form
- onClearComplete(); // Notify parent that clearing is done
+ setFormData(defaultModel);
+ onClearComplete();
}
}, [clearTrigger, onClearComplete]);
@@ -110,7 +111,8 @@ const TaskModel = ({
const handleSubmit = (e) => {
e.preventDefault();
- onSubmit(formData); // Pass the updated data to the parent
+ // onSubmit( formData ); // Pass the updated data to the parent
+ console.log(formData)
};
return (
diff --git a/src/components/Project/Infrastructure/WorkArea.jsx b/src/components/Project/Infrastructure/WorkArea.jsx
new file mode 100644
index 00000000..96ba4310
--- /dev/null
+++ b/src/components/Project/Infrastructure/WorkArea.jsx
@@ -0,0 +1,46 @@
+import React from "react";
+import WorkItem from "./WorkItem";
+
+const WorkArea = ({ workArea, floor,forBuilding }) => {
+ return (
+
+
+
+
+
+
+
+ {floor.floorName} - {workArea.areaName}
+
+
+
+
+ |
+
+
+ {workArea?.workItems && workArea.workItems.length > 0 ? (
+
+
+
+
+
+ | Activity |
+ Planned |
+ Completed |
+ Progress |
+ Actions |
+
+
+
+ {workArea.workItems.map((workItem) => (
+
+ ))}
+
+
+ |
+
+ ) : null}
+
+ );
+ };
+export default WorkArea;
\ No newline at end of file
diff --git a/src/components/Project/Infrastructure/WorkAreaModel.jsx b/src/components/Project/Infrastructure/WorkAreaModel.jsx
new file mode 100644
index 00000000..05a65612
--- /dev/null
+++ b/src/components/Project/Infrastructure/WorkAreaModel.jsx
@@ -0,0 +1,218 @@
+import React, { useState, useEffect } from "react";
+import { set, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+
+// Zod schema for form validation
+const workAreaSchema = z.object( {
+ id:z.string().nonempty("Floor is required"),
+
+ buildingId: z.string().nonempty("Building is required"),
+ floorId: z.string().nonempty("Floor is required"),
+ areaName: z.string().nonempty( "Work Area Name is required" ).min( 3, "Name must be at least 3 characters long" ),
+});
+
+// Default form data
+const defaultModel = {
+ id: "0",
+ areaName: "",
+ floorId: "0",
+};
+
+const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete }) => {
+ const [selectedBuilding, setSelectedBuilding] = useState(null);
+ const [ selectedFloor, setSelectedFloor ] = useState( null );
+ const [selectdWorkArea,setWorkArea] = useState()
+
+ const { register, handleSubmit, formState: { errors }, setValue, reset, watch } = useForm({
+ resolver: zodResolver(workAreaSchema), // Use Zod resolver for validation
+ defaultValues: defaultModel,
+ });
+
+ const floorId = watch( "floorId" ); // Watch the floorId for conditional rendering
+
+ useEffect(() => {
+ if (clearTrigger) {
+ reset(defaultModel); // Reset form to initial state
+ setSelectedBuilding(null);
+ setSelectedFloor(null);
+ onClearComplete();
+ }
+ }, [clearTrigger, onClearComplete, reset]);
+
+ const handleWorkAreaChange = ( e ) =>
+ {
+
+
+ const { value } = e.target;
+
+ if (value === "0") {
+ setValue("id", "0"); // Create New Work Area
+ setValue( "areaName", "" );
+
+ setWorkArea(String(0))
+ } else {
+ const workArea = selectedFloor?.workAreas.find((b) => b.id === Number(value));
+ if ( workArea )
+ {
+ setValue("id", String(workArea.id)); // Set id as a string
+ setValue("areaName", workArea.areaName);
+ setWorkArea(String(workArea.id))
+
+ }
+ }
+ };
+
+ const handleFloorChange = (e) => {
+ const { value } = e.target;
+ const floor = selectedBuilding?.floors.find((b) => b.id === Number(value));
+
+ if (floor) {
+ setSelectedFloor(floor);
+ setValue("floorId", floor.id); // Update floorId
+ setValue("id", "0"); // Reset Work Area ID for new area creation
+ setValue("areaName", ""); // Reset Work Area Name when changing floor
+ } else {
+ setSelectedFloor(null);
+ setValue("floorId", "0");
+ setValue("id", "0"); // Reset Work Area ID
+ setValue("areaName", ""); // Reset Work Area Name
+ }
+ };
+
+ const handleBuildingChange = (e) => {
+ const { value } = e.target;
+ const building = project.buildings.find((b) => b.id === Number(value));
+ setSelectedBuilding(building);
+ setSelectedFloor(null); // Reset selected floor on building change
+ reset(defaultModel); // Reset the form when a new building is selected
+ };
+
+ const onSubmitForm = ( data ) =>
+ {
+ console.log(data)
+ let WorkArea = {
+ id: data.id,
+ areaName: data.areaName,
+ floorId: data.floorId,
+ buildingId:data.buildingId
+ }
+ onSubmit(WorkArea); // Send the final data to the parent
+ };
+
+ const handleCancel = () => {
+ reset(defaultModel); // Reset the form to initial state
+ setSelectedFloor(null);
+ setSelectedBuilding(null);
+ };
+
+ return (
+
+
+
+
+
+
+
Manage Work Area
+
+
+
+
+
+
+ );
+};
+
+export default WorkAreaModel;
diff --git a/src/components/Project/Infrastructure/WorkItem.jsx b/src/components/Project/Infrastructure/WorkItem.jsx
new file mode 100644
index 00000000..b5d1f2cb
--- /dev/null
+++ b/src/components/Project/Infrastructure/WorkItem.jsx
@@ -0,0 +1,98 @@
+import React, { useState } from "react";
+import { useModal } from "../../../ModalContext";
+import AssignRoleModel from "../AssignRole";
+import {useParams} from "react-router-dom";
+
+const WorkItem = ( {workItem, forBuilding, forFloor, forWorkArea} ) =>{
+ const {projectId} = useParams()
+ const { openModal ,closedModal} = useModal();
+ const [itemName, setItemName] = useState('');
+ const getProgress = (planned, completed) => {
+ return (completed * 100) / planned + "%";
+ };
+
+ const handleAssignTask = () => {
+ console.log("Item Created:", itemName);
+ setItemName('');
+ };
+
+ const showCreateItemModal = (modalData) => {
+ openModal(
+
,
+ handleAssignTask ,"lg"
+ );
+ };
+
+ let assigndata = {
+ building: forBuilding,
+ floor: forFloor,
+ workArea: forWorkArea,
+ workItem
+ }
+ return (
+
+ |
+
+
+ {workItem.workItem.activityMaster
+ ? workItem.workItem.activityMaster.activityName
+ : "NA"}
+
+ |
+
+ {workItem.workItem ? workItem.workItem.plannedWork : "NA"}
+ |
+
+ {workItem.workItem ? workItem.workItem.completedWork : "NA"}
+ |
+
+
+ |
+
+
+ {!projectId && ( )}
+
+
+
+ |
+
+ );
+};
+
+export default WorkItem;
diff --git a/src/components/Project/ProjectInfra.jsx b/src/components/Project/ProjectInfra.jsx
index 56d16036..0f57d432 100644
--- a/src/components/Project/ProjectInfra.jsx
+++ b/src/components/Project/ProjectInfra.jsx
@@ -1,18 +1,20 @@
import React, { useState, useEffect } from "react";
import "./ProjectInfra.css";
-import BuildingModel from "./BuildingModel";
-import FloorModel from "./FloorModel";
+import BuildingModel from "./Infrastructure/BuildingModel";
+import FloorModel from "./Infrastructure/FloorModel";
import showToast from "../../services/toastService";
-import WorkAreaModel from "./WorkAreaModel";
-import TaskModel from "./TaskModel";
-import ProjectRepository from "../../repositories/ProjectRepository";
+import WorkAreaModel from "./Infrastructure/WorkAreaModel";
+import TaskModel from "./Infrastructure/TaskModel";
+import ProjectRepository, {TasksRepository} from "../../repositories/ProjectRepository";
import ProjectModal from "./ProjectModal";
import {useHasUserPermission} from "../../hooks/useHasUserPermission";
import {MANAGE_PROJECT_INFRA} from "../../utils/constants";
-// import AssignRoleModel from "./AssignRoleModel";
+import InfraTable from "./Infrastructure/InfraTable";
+import {cacheData} from "../../slices/apiDataManager";
+
+
const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) => {
-
const [expandedBuildings, setExpandedBuildings] = useState([]);
const [project, setProject] = useState(data);
const[modalConfig,setModalConfig] = useState({type:null,data:null});
@@ -27,7 +29,8 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
const [isAssignRoleModal,setIsAssingRoleModal] = useState(false)
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const [clearFormTrigger, setClearFormTrigger] = useState(false);
- const [CurrentBuilding,setCurrentBuilding] = useState("")
+ const [ CurrentBuilding, setCurrentBuilding ] = useState( "" )
+ const [showModal, setShowModal] = useState(false);
useEffect(() => {
setProject(data);
@@ -50,6 +53,188 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
setIsAssingRoleModal(true)
}
+
+
+
+
+ const openBuildingModel = (projectData) => {
+ setIsBuildingModalOpen(true);
+ };
+
+
+
+ const submitData = async (infraObject) => {
+
+ try
+ {
+ console.log(infraObject)
+ let response = await ProjectRepository.manageProjectInfra( infraObject );
+ const entity = response.data;
+
+ const updatedProject = { ...project };
+ // Handle the building data
+ if (entity.building) {
+ const { id, name, description } = entity.building;
+ const updatedBuildings = updatedProject.buildings.map((building) =>
+ building.id === id
+ ? { ...building, name, description }
+ : building
+ );
+
+ // Add building if it doesn't exist
+ if (!updatedProject.buildings.some((building) => building.id === id)) {
+ updatedBuildings.push({
+ id: id,
+ name,
+ description,
+ floor: [],
+ });
+ }
+
+ updatedProject.buildings = updatedBuildings;
+
+ // Update the cache for buildings
+ cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
+ setProject(updatedProject)
+ }
+ // Handle the floor data
+ else if ( entity.floor )
+ {
+ const { buildingId, id, floorName } = entity.floor;
+ const updatedBuildings = updatedProject.buildings.map((building) =>
+ building.id == buildingId
+ ? {
+ ...building,
+ floors: building.floors.map( ( floor ) =>
+
+ floor.id === id
+ ? {
+ ...floor,
+ floorName, // Update the floor name only
+ // Keep other properties as they are (including workArea)
+ }
+ : floor
+ )
+ // Add the new floor if it doesn't already exist
+ .concat(
+ !building.floors.some((floor) => floor.id === id)
+ ? [{ id: id, floorName, workArea: null }] // New floor added with workArea set to null
+ : []
+ ),
+ }
+ : building
+ );
+
+ updatedProject.buildings = updatedBuildings;
+
+ // Cache the updated project
+ cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
+ setProject(updatedProject)
+ }
+ // Handle the work area data
+ else if ( entity.workArea )
+ {
+ debugger
+
+ let buildingId = infraObject[0].workArea.buildingId
+
+ const { floorId, areaName, id } = entity.workArea;
+ // Check if the workArea exists, otherwise create a new one
+ const updatedBuildings = updatedProject.buildings.map((building) =>
+ building.id == buildingId
+ ? {
+ ...building,
+ floors: building.floors.map((floor) =>
+ floor.id == floorId
+ ? {
+ ...floor,
+ workAreas: floor.workAreas.some((workArea) => workArea.id === id)
+ ? floor.workAreas.map((workArea) =>
+ workArea.id === id
+ ? { ...workArea, areaName }
+ : workArea
+ )
+ : [
+ ...floor.workAreas,
+ { id, areaName, workItems: null },
+ ],
+ }
+ : floor
+ ),
+ }
+ : building
+ );
+
+ updatedProject.buildings = updatedBuildings;
+
+ // Update the cache for work areas
+ cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
+ setProject(updatedProject)
+ }
+ // Handle the task (workItem) data
+ else if (entity.workItem) {
+ const { buildingId, floorId, workAreaId, name, description } = entity.workItem;
+ const updatedBuildings = updatedProject.buildings.map((building) =>
+ building.id === buildingId
+ ? {
+ ...building,
+ floors: building.floors.map((floor) =>
+ floor.id === floorId
+ ? {
+ ...floor,
+ workAreas: floor.workAreas.map((workArea) =>
+ workArea.id === workAreaId
+ ? {
+ ...workArea,
+ tasks: workArea.tasks.map((task) =>
+ task.id === entity.workItem.id ? { ...task, name, description } : task
+ ),
+ }
+ : workArea
+ ),
+ }
+ : floor
+ ),
+ }
+ : building
+ );
+
+ updatedProject.buildings = updatedBuildings;
+
+
+ cacheData("projectInfo", { projectId: updatedProject.id, data: updatedProject });
+ }
+
+ else {
+ console.error("Unsupported data type for submitData", entity);
+ }
+ } catch ( Err )
+ {
+ showToast("Somthing wrong","error")
+ }
+
+
+
+
+ handleClose()
+ };
+
+
+ const closeBuildingModel = () => {
+ setIsBuildingModalOpen(false);
+ };
+ const handleBuildingModelFormSubmit = (buildingmodel) => {
+ if (buildingmodel.id == "" || buildingmodel.id == 0)
+ delete buildingmodel.id;
+ let data = [
+ {
+ building: buildingmodel,
+ floor: null,
+ workArea: null,
+ },
+ ];
+ submitData(data);
+ };
const handleFloorModelFormSubmit = (updatedFloor) => {
if (updatedFloor.id == "") delete updatedFloor.id;
@@ -62,49 +247,13 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
]);
};
- const submitData = (infraObject) => {
- ProjectRepository.manageProjectInfra(infraObject)
- .then((response) => {
- fetchData();
- onDataChange("building-change");
- showToast("Details updated successfully.", "success");
- setClearFormTrigger(true); // Set trigger to true
- })
- .catch((error) => {
- showToast(error.message, "error");
- });
- };
-
- const openBuildingModel = (projectData) => {
- setIsBuildingModalOpen(true);
- };
-
- const closeBuildingModel = () => {
- setIsBuildingModalOpen(false);
- };
- const handleBuildingModelFormSubmit = (buildingmodel) => {
- if (buildingmodel.id == "" || buildingmodel.id == 0)
- delete buildingmodel.id;
-
- let data = [
- {
- building: buildingmodel,
- floor: null,
- workArea: null,
- },
- ];
-
- submitData(data);
- };
-
const openWorkAreaModel = (projectData) => {
setIsWorkAreaModalOpen(true);
};
const closeWorkAreaModel = () => {
setIsWorkAreaModalOpen(false);
- // const modalBackdrop = document.querySelector(".modal-backdrop");
- // if (modalBackdrop) modalBackdrop.remove();
+
};
const handleWorkAreaModelFormSubmit = (updatedModel) => {
if (updatedModel.id == "") delete updatedModel.id;
@@ -124,19 +273,18 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
const closeTaskModel = () => {
setIsTaskModalOpen(false);
- // const modalBackdrop = document.querySelector(".modal-backdrop");
- // if (modalBackdrop) modalBackdrop.remove();
+
};
const handleTaskModelFormSubmit = (updatedModel) => {
if (updatedModel.id == "") updatedModel.id = 0;
- //console.log("Form submitted:", updatedModel); // Replace this with an API call or state update
+
ProjectRepository.manageProjectTasks([updatedModel])
.then((response) => {
onDataChange("task-change");
showToast("Details updated successfully.", "success");
- setClearFormTrigger(true); // Set trigger to true
+ setClearFormTrigger(true);
})
.catch((error) => {
showToast(error.message, "error");
@@ -149,297 +297,54 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
);
};
- const getContent = (building) => {
- let hasFloors =
- building.floors && building.floors.length > 0 ? true : false;
-
- return (
- <>
- {(() => {
- if (hasFloors) {
- return building.floors.map((floor) => (
-
-
- {floor.workAreas.length > 0 ? (
- floor.workAreas.map((workArea) => (
-
-
-
-
-
- {" "}
-
-
- {" "}
- {floor.floorName} - {workArea.areaName} {" "}
-
-
-
-
-
- |
-
- {workArea.workItems.length > 0 ? (
-
- {" "}
-
-
-
-
- | Activity |
- Planned |
- Complated |
- Progress |
- Actions |
-
-
-
- {workArea.workItems.map((workItem) => (
-
-
- |
-
-
- {workItem.workItem.activityMaster
- ? workItem.workItem.activityMaster
- .activityName
- : "NA"}
-
- |
-
- {workItem.workItem
- ? workItem.workItem.plannedWork
- : "NA"}
- |
-
- {workItem.workItem
- ? workItem.workItem.completedWork
- : "NA"}
- |
-
-
-
- |
-
-
-
-
-
-
- |
- {" "}
-
- ))}
-
- {" "}
- |
-
- ) : (
-
- )}
-
- ))
- ) : (
-
-
-
-
-
- {" "}
-
- {floor.floorName}
-
-
-
-
- |
-
-
- )}
-
- ));
- } else {
- return (
- <>
-
- |
- No Floors Added, Please add them
- {/*
-
- */}
- |
-
- >
- );
- }
- })()}
- >
- );
- };
-
- const getProgress = (planned, completed) => {
- return (completed * 100) / planned + "%";
- };
-
-
- // common modal
-
const handleModalData = (type,modaldata)=>{
setModalConfig({type:type,data:modaldata})
}
const openModal = () => {
- setIsModalOpen(true);
+ const modalElement = document.getElementById('building-model');
+ const modal = new Modal(modalElement, {
+ backdrop: false,
+ keyboard: true,
+ focus: true
+ });
+ modal.show()
};
const closeModal = () => {
setIsModalOpen(false);
setModalConfig(null)
- const modalElement = document.getElementById('project-modal');
+ const modalElement = document.getElementById('building-model');
if (modalElement) {
- modalElement.classList.remove('show');
- modalElement.style.display = 'none'; // Hide modal visually
- document.body.classList.remove('modal-open'); // Unlock body scroll
-
-
- const backdropElement = document.querySelector('.modal-backdrop');
- if (backdropElement) {
- backdropElement.classList.remove('modal-backdrop'); // Remove backdrop class
- backdropElement.style.display = 'none'; // Hide the backdrop element
- }
+ modalElement.classList.remove('show'); // Remove modal visibility class
+ modalElement.style.display = 'none'; // Hide the modal element
}
- const modalBackdropElement = document.querySelector('.modal-backdrop');
- if (modalBackdropElement) {
- modalBackdropElement.remove();
+
+ document.body.classList.remove('modal-open'); // Remove modal-open class from body
+
+ // Remove the modal backdrop
+ const backdropElement = document.querySelector('.modal-backdrop');
+ if (backdropElement) {
+ backdropElement.classList.remove('modal-backdrop'); // Remove backdrop class
+ backdropElement.style.display = 'none'; // Hide the backdrop element
}
document.body.style.overflow = 'auto';
};
- useEffect(() => {
- if (modalConfig !== null) {
- openModal();
- }
-
- }, [modalConfig,isModalOpen]);
+ const handleShow = () => setShowModal(true);
+ const handleClose = () => setShowModal( false );
return (
<>
- {isBuildingModalOpen && (
+
+ className={`modal fade ${showModal ? 'show' : ''}`}
+ tabIndex="-1"
+ role="dialog"
+ style={{ display: showModal ? 'block' : 'none' }}
+ aria-hidden={!showModal}
+ >
setClearFormTrigger(false)}
>
- )}
+
{isFloorModalOpen && (
)}
-
-
- {/* common Modal */}
+
{isModalOpen && (
)}
- {/*
*/}
@@ -522,14 +423,12 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
-
-
- {buildings && buildings.length > 0 && (
-
-
- {buildings.map((building) => (
-
- building.floors && building.floors.length > 0 && (
-
-
- | toggleBuilding(building.id)}
- >
-
-
-
- { building.name}
- {expandedBuildings.includes(building.id) ? (
-
- ) : (
-
- )}
-
-
- |
-
-
- {expandedBuildings.includes(building.id) && getContent(building)}
-
-
- )
-
- ))}
-
-
- )}
-
+
diff --git a/src/components/Project/ProjectModal.jsx b/src/components/Project/ProjectModal.jsx
index 21bd213b..0a740bd3 100644
--- a/src/components/Project/ProjectModal.jsx
+++ b/src/components/Project/ProjectModal.jsx
@@ -25,7 +25,8 @@ const ProjectModal = ({modalConfig,closeModal}) => {
{/* Modal Component */}
- {modalConfig?.type === "assignRole" &&
}
+ {modalConfig?.type === "assignRole" &&
}
+
diff --git a/src/components/Project/ProjectOverview.jsx b/src/components/Project/ProjectOverview.jsx
index bc45dc39..bf7ba756 100644
--- a/src/components/Project/ProjectOverview.jsx
+++ b/src/components/Project/ProjectOverview.jsx
@@ -3,7 +3,7 @@ import {useEmployeesByProjectAllocated} from "../../hooks/useProjects";
const ProjectOverview = ({project}) =>
{
- const {projectEmployees} = useEmployeesByProjectAllocated( project.id );
+ const {projectEmployees} = useEmployeesByProjectAllocated( project?.id );
let teamSize = projectEmployees.filter( ( emp ) => emp.isActive )
return (
diff --git a/src/components/Project/WorkAreaModel.jsx b/src/components/Project/WorkAreaModel.jsx
deleted file mode 100644
index 24e53753..00000000
--- a/src/components/Project/WorkAreaModel.jsx
+++ /dev/null
@@ -1,230 +0,0 @@
-import React, { useState, useEffect } from "react";
-
-const defaultModel = {
- id: "0",
- areaName: "",
- floorId: "0",
-};
-
-const WorkAreaModel = ({
- project,
- onSubmit,
- clearTrigger,
- onClearComplete,
-}) => {
- const [formData, setFormData] = useState(defaultModel);
-
- const [selectedBuilding, setSelectedBuilding] = useState(null);
- const [selectedFloor, setSelectedFloor] = useState(null);
-
- //if (floor && floor.id) setFormData(floor);
-
- useEffect(() => {
- if (selectedBuilding) {
- let building = project.buildings.find(
- (b) => b.id === selectedBuilding.id
- );
- setSelectedBuilding(building);
- }
-
- if (selectedFloor) {
- let floor = selectedBuilding.floors.find(
- (b) => b.id === Number(selectedFloor.id)
- );
- setSelectedFloor(floor);
- }
- }, [project]);
-
- useEffect(() => {
- if (clearTrigger) {
- let model = defaultModel;
- model.floorId = selectedFloor.id;
- setFormData(defaultModel); // Clear form
- onClearComplete(); // Notify parent that clearing is done
- }
- }, [clearTrigger, onClearComplete]);
-
- // Handle input change
- const handleChange = (e) => {
- const { name, value } = e.target;
- setFormData({ ...formData, [name]: value });
- };
-
- const handleWorkAreaChange = (e) => {
- const { name, value } = e.target;
- const workArea = selectedFloor.workAreas.find(
- (b) => b.id === Number(value)
- );
- if (workArea) {
- setFormData({
- id: workArea.id,
- floorId: workArea.floorId,
- areaName: workArea.areaName,
- });
- } else
- setFormData({
- id: "0",
- floorId: selectedFloor.id,
- areaName: "",
- });
- };
-
- const handleFloorChange = (e) => {
- const { name, value } = e.target;
- const floor = selectedBuilding.floors.find((b) => b.id === Number(value));
- setSelectedFloor(floor);
- if (floor) {
- setFormData({
- id: "0",
- floorId: floor.id,
- areaName: "",
- });
- } else {
- setSelectedFloor(null);
- setFormData({
- id: "0",
- floorId: "0",
- areaName: "",
- });
- }
- };
- const handleBuildigChange = (e) => {
- const { name, value } = e.target;
- const building = project.buildings.find((b) => b.id === Number(value));
- setSelectedBuilding(building);
- };
-
- // Handle form submission
- const handleSubmit = (e) => {
- e.preventDefault();
- formData.projectId = project.id;
-
- onSubmit(formData); // Pass the updated data to the parent
- };
-
- return (
-