updated project-infra-each modelForm able to taking recently added item
This commit is contained in:
parent
67a3648227
commit
c45130b611
@ -34,7 +34,7 @@ const BuildingModel = ({
|
|||||||
id: "",
|
id: "",
|
||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
projectId: project.id,
|
projectId: project?.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -48,7 +48,7 @@ const BuildingModel = ({
|
|||||||
return () => {
|
return () => {
|
||||||
setValue("name", null);
|
setValue("name", null);
|
||||||
};
|
};
|
||||||
}, [clearTrigger, onClearComplete, editingBuilding, project.id]);
|
}, [clearTrigger, onClearComplete, editingBuilding, project?.id]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@ -101,7 +101,7 @@ const BuildingModel = ({
|
|||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
></button>
|
></button>
|
||||||
<h5 className="text-center mb-2">
|
<h5 className="text-center mb-2">
|
||||||
Manage Buildings - {project.name}
|
Manage Buildings - {project?.name}
|
||||||
</h5>
|
</h5>
|
||||||
<form onSubmit={handleSubmit(onSubmitHandler)} className="row g-2">
|
<form onSubmit={handleSubmit(onSubmitHandler)} className="row g-2">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
@ -116,9 +116,9 @@ const BuildingModel = ({
|
|||||||
|
|
||||||
<option value="0">Add New Building</option>
|
<option value="0">Add New Building</option>
|
||||||
|
|
||||||
{buildings &&
|
{project &&
|
||||||
buildings?.length > 0 &&
|
project?.buildings?.length > 0 &&
|
||||||
buildings.map((building) => (
|
project?.buildings.map((building) => (
|
||||||
<option key={building.id} value={building.id}>
|
<option key={building.id} value={building.id}>
|
||||||
{building.name}
|
{building.name}
|
||||||
</option>
|
</option>
|
||||||
|
@ -26,10 +26,10 @@ const FloorModel = ({
|
|||||||
onClearComplete,
|
onClearComplete,
|
||||||
} ) =>
|
} ) =>
|
||||||
{
|
{
|
||||||
const [ buildings, setBuildings ] = useState( [] )
|
|
||||||
const projects_Details = getCachedData( "projectInfo" )
|
|
||||||
const [formData, setFormData] = useState(defaultModel);
|
const [formData, setFormData] = useState(defaultModel);
|
||||||
const [selectedBuilding, setSelectedBuilding] = useState({});
|
const [ selectedBuilding, setSelectedBuilding ] = useState( {} );
|
||||||
|
const [buildings, setBuildings] = useState(project?.buildings || []);
|
||||||
|
|
||||||
// Initialize the form with React Hook Form
|
// Initialize the form with React Hook Form
|
||||||
const {
|
const {
|
||||||
@ -56,6 +56,7 @@ const FloorModel = ({
|
|||||||
// Handle building selection change
|
// Handle building selection change
|
||||||
const handleBuildigChange = (e) => {
|
const handleBuildigChange = (e) => {
|
||||||
const buildingId = e.target.value;
|
const buildingId = e.target.value;
|
||||||
|
console.log(buildingId)
|
||||||
const building = buildings.find((b) => b.id === Number(buildingId));
|
const building = buildings.find((b) => b.id === Number(buildingId));
|
||||||
if (building) {
|
if (building) {
|
||||||
setSelectedBuilding(building);
|
setSelectedBuilding(building);
|
||||||
@ -84,7 +85,7 @@ const FloorModel = ({
|
|||||||
// Handle floor selection change
|
// Handle floor selection change
|
||||||
const handleFloorChange = (e) => {
|
const handleFloorChange = (e) => {
|
||||||
const id = e.target.value;
|
const id = e.target.value;
|
||||||
const floor = buildings[getValues("buildingId")].floors.find((b) => b.id === Number(id));
|
const floor = selectedBuilding.floors.find((b) => b.id === Number(id));
|
||||||
if (floor) {
|
if (floor) {
|
||||||
setFormData({
|
setFormData({
|
||||||
id: floor.id,
|
id: floor.id,
|
||||||
@ -108,12 +109,8 @@ const FloorModel = ({
|
|||||||
const onFormSubmit = (data) => {
|
const onFormSubmit = (data) => {
|
||||||
onSubmit(data);
|
onSubmit(data);
|
||||||
};
|
};
|
||||||
useEffect( () =>
|
|
||||||
{
|
|
||||||
setBuildings(projects_Details.data?.buildings)
|
|
||||||
}, [ projects_Details ] )
|
|
||||||
console.log(getValues("buildingId"))
|
|
||||||
console.log(buildings)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
|
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
|
||||||
@ -172,9 +169,9 @@ const FloorModel = ({
|
|||||||
</option>
|
</option>
|
||||||
) )} */}
|
) )} */}
|
||||||
|
|
||||||
{buildings &&
|
{selectedBuilding &&
|
||||||
buildings[getValues("buildingId")]?.length > 0 &&
|
selectedBuilding?.floors.length > 0 &&
|
||||||
buildings[getValues("buildingId")]?.map((floor) => (
|
selectedBuilding?.floors.map((floor) => (
|
||||||
<option key={floor.id} value={floor.id}>
|
<option key={floor.id} value={floor.id}>
|
||||||
{floor.floorName}
|
{floor.floorName}
|
||||||
</option>
|
</option>
|
||||||
|
@ -82,7 +82,7 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
|
|||||||
|
|
||||||
const handleBuildingChange = (e) => {
|
const handleBuildingChange = (e) => {
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
const building = project.buildings.find((b) => b.id === Number(value));
|
const building = project?.buildings.find((b) => b.id === Number(value));
|
||||||
setSelectedBuilding(building);
|
setSelectedBuilding(building);
|
||||||
setSelectedFloor(null); // Reset selected floor on building change
|
setSelectedFloor(null); // Reset selected floor on building change
|
||||||
reset(defaultModel); // Reset the form when a new building is selected
|
reset(defaultModel); // Reset the form when a new building is selected
|
||||||
@ -90,7 +90,7 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
|
|||||||
|
|
||||||
const onSubmitForm = ( data ) =>
|
const onSubmitForm = ( data ) =>
|
||||||
{
|
{
|
||||||
console.log(data)
|
|
||||||
let WorkArea = {
|
let WorkArea = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
areaName: data.areaName,
|
areaName: data.areaName,
|
||||||
@ -103,7 +103,8 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
|
|||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
reset(defaultModel); // Reset the form to initial state
|
reset(defaultModel); // Reset the form to initial state
|
||||||
setSelectedFloor(null);
|
setSelectedFloor(null);
|
||||||
setSelectedBuilding(null);
|
setSelectedBuilding( null );
|
||||||
|
onClose()
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -127,7 +128,7 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
|
|||||||
onChange={handleBuildingChange}
|
onChange={handleBuildingChange}
|
||||||
>
|
>
|
||||||
<option value="0">Select Building</option>
|
<option value="0">Select Building</option>
|
||||||
{project.buildings.map((building) => (
|
{project?.buildings?.map((building) => (
|
||||||
<option key={building.id} value={building.id}>
|
<option key={building.id} value={building.id}>
|
||||||
{building.name}
|
{building.name}
|
||||||
</option>
|
</option>
|
||||||
@ -171,7 +172,7 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
|
|||||||
onChange={handleWorkAreaChange}
|
onChange={handleWorkAreaChange}
|
||||||
>
|
>
|
||||||
<option value="0">Create New Work Area</option>
|
<option value="0">Create New Work Area</option>
|
||||||
{selectedFloor?.workAreas.map((workArea) => (
|
{selectedFloor?.workAreas?.map((workArea) => (
|
||||||
<option key={workArea.id} value={workArea.id}>
|
<option key={workArea.id} value={workArea.id}>
|
||||||
{workArea.areaName}
|
{workArea.areaName}
|
||||||
</option>
|
</option>
|
||||||
|
@ -20,12 +20,7 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
|||||||
setItemName("");
|
setItemName("");
|
||||||
};
|
};
|
||||||
|
|
||||||
// const showCreateItemModal = (modalData) => {
|
|
||||||
// openModal(
|
|
||||||
// <AssignRoleModel assignData={modalData} onClose={closedModal} />,
|
|
||||||
// handleAssignTask ,"lg"
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNewWorkItem(workItem);
|
setNewWorkItem(workItem);
|
||||||
|
@ -5,80 +5,69 @@ import FloorModel from "./Infrastructure/FloorModel";
|
|||||||
import showToast from "../../services/toastService";
|
import showToast from "../../services/toastService";
|
||||||
import WorkAreaModel from "./Infrastructure/WorkAreaModel";
|
import WorkAreaModel from "./Infrastructure/WorkAreaModel";
|
||||||
import TaskModel from "./Infrastructure/TaskModel";
|
import TaskModel from "./Infrastructure/TaskModel";
|
||||||
import ProjectRepository, {TasksRepository} from "../../repositories/ProjectRepository";
|
import ProjectRepository, {
|
||||||
|
TasksRepository,
|
||||||
|
} from "../../repositories/ProjectRepository";
|
||||||
import ProjectModal from "./ProjectModal";
|
import ProjectModal from "./ProjectModal";
|
||||||
import {useHasUserPermission} from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import {MANAGE_PROJECT_INFRA} from "../../utils/constants";
|
import { MANAGE_PROJECT_INFRA } from "../../utils/constants";
|
||||||
import InfraTable from "./Infrastructure/InfraTable";
|
import InfraTable from "./Infrastructure/InfraTable";
|
||||||
import {cacheData} from "../../slices/apiDataManager";
|
import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
||||||
|
import { useProjectDetails } from "../../hooks/useProjects";
|
||||||
|
|
||||||
|
const ProjectInfra = ({
|
||||||
|
data,
|
||||||
const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) => {
|
activityMaster,
|
||||||
|
onDataChange,
|
||||||
|
eachSiteEngineer,
|
||||||
|
}) => {
|
||||||
const [expandedBuildings, setExpandedBuildings] = useState([]);
|
const [expandedBuildings, setExpandedBuildings] = useState([]);
|
||||||
const [project, setProject] = useState(data);
|
const { projects_Details, loading } = useProjectDetails(data.id);
|
||||||
const[modalConfig,setModalConfig] = useState({type:null,data:null});
|
const [project, setProject] = useState(projects_Details);
|
||||||
const [ isModalOpen, setIsModalOpen ] = useState( false )
|
const [modalConfig, setModalConfig] = useState({ type: null, data: null });
|
||||||
const ManageInfra = useHasUserPermission(MANAGE_PROJECT_INFRA)
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
const ManageInfra = useHasUserPermission(MANAGE_PROJECT_INFRA);
|
||||||
|
|
||||||
const [buildings, setBuildings] = useState(data.buildings);
|
|
||||||
const [isBuildingModalOpen, setIsBuildingModalOpen] = useState(false);
|
const [isBuildingModalOpen, setIsBuildingModalOpen] = useState(false);
|
||||||
const [isFloorModalOpen, setIsFloorModalOpen] = useState(false);
|
const [isFloorModalOpen, setIsFloorModalOpen] = useState(false);
|
||||||
const [isWorkAreaModelOpen, setIsWorkAreaModalOpen] = useState(false);
|
const [isWorkAreaModelOpen, setIsWorkAreaModalOpen] = useState(false);
|
||||||
const [isTaskModelOpen, setIsTaskModalOpen] = useState(false);
|
const [isTaskModelOpen, setIsTaskModalOpen] = useState(false);
|
||||||
const [isAssignRoleModal,setIsAssingRoleModal] = useState(false)
|
const [isAssignRoleModal, setIsAssingRoleModal] = useState(false);
|
||||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
const [clearFormTrigger, setClearFormTrigger] = useState(false);
|
const [clearFormTrigger, setClearFormTrigger] = useState(false);
|
||||||
const [ CurrentBuilding, setCurrentBuilding ] = useState( "" )
|
const [CurrentBuilding, setCurrentBuilding] = useState("");
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setProject(data);
|
setProject(projects_Details);
|
||||||
setBuildings(data.buildings);
|
}, [data, projects_Details]);
|
||||||
}, [data]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const openFloorModel = (projectData) => {
|
const openFloorModel = (projectData) => {
|
||||||
setIsFloorModalOpen(true);
|
setIsFloorModalOpen(true);
|
||||||
};
|
};
|
||||||
const closeFloorModel = () => {
|
const closeFloorModel = () => {
|
||||||
setIsFloorModalOpen(false);
|
setIsFloorModalOpen(false);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const openAssignModel=(assignData)=>{
|
const openAssignModel = (assignData) => {
|
||||||
|
setCurrentBuilding(assignData);
|
||||||
setCurrentBuilding(assignData)
|
setIsAssingRoleModal(true);
|
||||||
setIsAssingRoleModal(true)
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const openBuildingModel = (projectData) => {
|
const openBuildingModel = (projectData) => {
|
||||||
setIsBuildingModalOpen(true);
|
setIsBuildingModalOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const submitData = async (infraObject) => {
|
const submitData = async (infraObject) => {
|
||||||
|
try {
|
||||||
try
|
let response = await ProjectRepository.manageProjectInfra(infraObject);
|
||||||
{
|
|
||||||
console.log(infraObject)
|
|
||||||
let response = await ProjectRepository.manageProjectInfra( infraObject );
|
|
||||||
const entity = response.data;
|
const entity = response.data;
|
||||||
|
|
||||||
const updatedProject = { ...project };
|
const updatedProject = { ...project };
|
||||||
// Handle the building data
|
// Handle the building data
|
||||||
if (entity.building) {
|
if (entity.building) {
|
||||||
const { id, name, description } = entity.building;
|
const { id, name, description } = entity.building;
|
||||||
const updatedBuildings = updatedProject.buildings.map((building) =>
|
const updatedBuildings = updatedProject?.buildings?.map((building) =>
|
||||||
building.id === id
|
building.id === id ? { ...building, name, description } : building
|
||||||
? { ...building, name, description }
|
|
||||||
: building
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add building if it doesn't exist
|
// Add building if it doesn't exist
|
||||||
@ -87,107 +76,111 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
id: id,
|
id: id,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
floor: [],
|
floors: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedProject.buildings = updatedBuildings;
|
updatedProject.buildings = updatedBuildings;
|
||||||
|
|
||||||
// Update the cache for buildings
|
// Update the cache for buildings
|
||||||
cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
|
cacheData("projectInfo", {
|
||||||
setProject(updatedProject)
|
projectId: updatedProject.id,
|
||||||
|
data: updatedProject,
|
||||||
|
});
|
||||||
|
setProject((prevProject) => ({
|
||||||
|
...prevProject,
|
||||||
|
buildings: updatedBuildings,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
// Handle the floor data
|
// Handle the floor data
|
||||||
else if ( entity.floor )
|
else if (entity.floor) {
|
||||||
{
|
|
||||||
const { buildingId, id, floorName } = entity.floor;
|
const { buildingId, id, floorName } = entity.floor;
|
||||||
const updatedBuildings = updatedProject.buildings.map((building) =>
|
const updatedBuildings = updatedProject?.buildings?.map((building) =>
|
||||||
building.id == buildingId
|
building.id == buildingId
|
||||||
? {
|
? {
|
||||||
...building,
|
...building,
|
||||||
floors: building.floors.map( ( floor ) =>
|
floors: building.floors
|
||||||
|
.map((floor) =>
|
||||||
floor.id === id
|
floor.id === id
|
||||||
? {
|
? {
|
||||||
...floor,
|
...floor,
|
||||||
floorName, // Update the floor name only
|
floorName, // Update the floor name only
|
||||||
// Keep other properties as they are (including workArea)
|
// Keep other properties as they are (including workArea)
|
||||||
}
|
}
|
||||||
: floor
|
: floor
|
||||||
)
|
)
|
||||||
// Add the new floor if it doesn't already exist
|
// Add the new floor if it doesn't already exist
|
||||||
.concat(
|
.concat(
|
||||||
!building.floors.some((floor) => floor.id === id)
|
!building.floors.some((floor) => floor.id === id)
|
||||||
? [{ id: id, floorName, workArea: null }] // New floor added with workArea set to null
|
? [{ id: id, floorName, workAreas: [] }] // New floor added with workArea set to null
|
||||||
: []
|
: []
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: building
|
: building
|
||||||
);
|
);
|
||||||
|
|
||||||
updatedProject.buildings = updatedBuildings;
|
updatedProject.buildings = updatedBuildings;
|
||||||
|
|
||||||
// Cache the updated project
|
// Cache the updated project
|
||||||
cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
|
cacheData("projectInfo", {
|
||||||
setProject(updatedProject)
|
projectId: updatedProject.id,
|
||||||
|
data: updatedProject,
|
||||||
|
});
|
||||||
|
setProject(updatedProject);
|
||||||
}
|
}
|
||||||
// Handle the work area data
|
// Handle the work area data
|
||||||
else if ( entity.workArea )
|
else if (entity.workArea) {
|
||||||
{
|
let buildingId = infraObject[0].workArea.buildingId;
|
||||||
|
|
||||||
|
|
||||||
let buildingId = infraObject[0].workArea.buildingId
|
|
||||||
|
|
||||||
const { floorId, areaName, id } = entity.workArea;
|
const { floorId, areaName, id } = entity.workArea;
|
||||||
// Check if the workArea exists, otherwise create a new one
|
// Check if the workArea exists, otherwise create a new one
|
||||||
const updatedBuildings = updatedProject.buildings.map((building) =>
|
const updatedBuildings = updatedProject.buildings.map((building) =>
|
||||||
building.id == buildingId
|
building.id == buildingId
|
||||||
? {
|
? {
|
||||||
...building,
|
...building,
|
||||||
floors: building.floors.map((floor) =>
|
floors: building.floors.map((floor) =>
|
||||||
floor.id == floorId
|
floor.id == floorId
|
||||||
? {
|
? {
|
||||||
...floor,
|
...floor,
|
||||||
workAreas: floor.workAreas.some((workArea) => workArea.id === id)
|
workAreas: floor.workAreas.some(
|
||||||
? floor.workAreas.map((workArea) =>
|
(workArea) => workArea.id === id
|
||||||
workArea.id === id
|
)
|
||||||
? { ...workArea, areaName }
|
? floor.workAreas.map((workArea) =>
|
||||||
: workArea
|
workArea.id === id
|
||||||
)
|
? { ...workArea, areaName }
|
||||||
: [
|
: workArea
|
||||||
...floor.workAreas,
|
)
|
||||||
{ id, areaName, workItems: null },
|
: [
|
||||||
],
|
...floor.workAreas,
|
||||||
}
|
{ id, areaName, workItems: [] },
|
||||||
: floor
|
],
|
||||||
),
|
}
|
||||||
}
|
: floor
|
||||||
|
),
|
||||||
|
}
|
||||||
: building
|
: building
|
||||||
);
|
);
|
||||||
|
|
||||||
updatedProject.buildings = updatedBuildings;
|
updatedProject.buildings = updatedBuildings;
|
||||||
|
|
||||||
// Update the cache for work areas
|
// Update the cache for work areas
|
||||||
cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
|
cacheData("projectInfo", {
|
||||||
setProject(updatedProject)
|
projectId: updatedProject.id,
|
||||||
|
data: updatedProject,
|
||||||
|
});
|
||||||
|
setProject(updatedProject);
|
||||||
}
|
}
|
||||||
// Handle the task (workItem) data
|
// Handle the task (workItem) data
|
||||||
|
|
||||||
else {
|
else {
|
||||||
console.error("Unsupported data type for submitData", entity);
|
console.error("Unsupported data type for submitData", entity);
|
||||||
}
|
}
|
||||||
} catch ( Err )
|
} catch (Err) {
|
||||||
{
|
console.log(Err);
|
||||||
showToast("Somthing wrong","error")
|
showToast("Somthing wrong", "error");
|
||||||
}
|
}
|
||||||
|
handleClose();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
handleClose()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const closeBuildingModel = () => {
|
const closeBuildingModel = () => {
|
||||||
setIsBuildingModalOpen(false);
|
setIsBuildingModalOpen(false);
|
||||||
};
|
};
|
||||||
@ -206,7 +199,6 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
};
|
};
|
||||||
const handleFloorModelFormSubmit = (updatedFloor) => {
|
const handleFloorModelFormSubmit = (updatedFloor) => {
|
||||||
if (updatedFloor.id == "") delete updatedFloor.id;
|
if (updatedFloor.id == "") delete updatedFloor.id;
|
||||||
|
|
||||||
submitData([
|
submitData([
|
||||||
{
|
{
|
||||||
building: null,
|
building: null,
|
||||||
@ -222,11 +214,9 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
|
|
||||||
const closeWorkAreaModel = () => {
|
const closeWorkAreaModel = () => {
|
||||||
setIsWorkAreaModalOpen(false);
|
setIsWorkAreaModalOpen(false);
|
||||||
|
|
||||||
};
|
};
|
||||||
const handleWorkAreaModelFormSubmit = (updatedModel) => {
|
const handleWorkAreaModelFormSubmit = (updatedModel) => {
|
||||||
if (updatedModel.id == "") delete updatedModel.id;
|
if (updatedModel.id == "") delete updatedModel.id;
|
||||||
|
|
||||||
submitData([
|
submitData([
|
||||||
{
|
{
|
||||||
building: null,
|
building: null,
|
||||||
@ -242,11 +232,10 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
|
|
||||||
const closeTaskModel = () => {
|
const closeTaskModel = () => {
|
||||||
setIsTaskModalOpen(false);
|
setIsTaskModalOpen(false);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTaskModelFormSubmit = ( updatedModel ) =>
|
const handleTaskModelFormSubmit = (updatedModel) => {
|
||||||
{
|
// debugger
|
||||||
if (updatedModel.id == "") updatedModel.id = 0;
|
if (updatedModel.id == "") updatedModel.id = 0;
|
||||||
const updatedProject = { ...project };
|
const updatedProject = { ...project };
|
||||||
|
|
||||||
@ -254,47 +243,49 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
onDataChange("task-change");
|
onDataChange("task-change");
|
||||||
showToast("Details updated successfully.", "success");
|
showToast("Details updated successfully.", "success");
|
||||||
// setClearFormTrigger( true );
|
// setClearFormTrigger( true );
|
||||||
|
|
||||||
|
|
||||||
if (response?.data[0]) {
|
if (response?.data[0]) {
|
||||||
const { workItemId,workItem} = response.data[0];
|
const { workItemId, workItem } = response.data[0];
|
||||||
|
|
||||||
const updatedBuildings = updatedProject.buildings.map((building) =>
|
const updatedBuildings = updatedProject.buildings.map((building) =>
|
||||||
building.id == updatedModel.buildingID
|
building.id == updatedModel.buildingID
|
||||||
? {
|
? {
|
||||||
...building,
|
...building,
|
||||||
floors: building.floors.map((floor) =>
|
floors: building.floors.map((floor) =>
|
||||||
floor.id == updatedModel.floorId
|
floor.id == updatedModel.floorId
|
||||||
? {
|
? {
|
||||||
...floor,
|
...floor,
|
||||||
workAreas: floor.workAreas.map((workArea) =>
|
workAreas: floor.workAreas.map((workArea) =>
|
||||||
workArea.id === workItem?.workAreaId
|
workArea.id === workItem?.workAreaId
|
||||||
? {
|
? {
|
||||||
...workArea,
|
...workArea,
|
||||||
workItems: workArea.workItems.some((existingItem) => existingItem.workItemId === workItem.workItemId)
|
workItems: workArea.workItems.some(
|
||||||
? workArea.workItems // If the workItemId already exists, keep the current workItems
|
(existingItem) =>
|
||||||
: [...workArea.workItems, workItem],
|
existingItem.workItemId ===
|
||||||
}
|
workItem.workItemId
|
||||||
: workArea
|
)
|
||||||
),
|
? workArea.workItems // If the workItemId already exists, keep the current workItems
|
||||||
}
|
: [...workArea.workItems, workItem],
|
||||||
: floor
|
}
|
||||||
),
|
: workArea
|
||||||
}
|
),
|
||||||
|
}
|
||||||
|
: floor
|
||||||
|
),
|
||||||
|
}
|
||||||
: building
|
: building
|
||||||
);
|
);
|
||||||
|
|
||||||
updatedProject.buildings = updatedBuildings;
|
updatedProject.buildings = updatedBuildings;
|
||||||
|
|
||||||
|
setProject(updatedProject);
|
||||||
cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
|
cacheData("projectInfo", {
|
||||||
setProject(updatedProject)
|
projectId: updatedProject.id,
|
||||||
|
data: updatedProject,
|
||||||
|
});
|
||||||
|
console.log(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
showToast(error.message, "error");
|
showToast(error.message, "error");
|
||||||
@ -307,55 +298,53 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleModalData = (type,modaldata)=>{
|
const handleModalData = (type, modaldata) => {
|
||||||
setModalConfig({type:type,data:modaldata})
|
setModalConfig({ type: type, data: modaldata });
|
||||||
}
|
};
|
||||||
const openModal = () => {
|
const openModal = () => {
|
||||||
const modalElement = document.getElementById('building-model');
|
const modalElement = document.getElementById("building-model");
|
||||||
const modal = new Modal(modalElement, {
|
const modal = new Modal(modalElement, {
|
||||||
backdrop: false,
|
backdrop: false,
|
||||||
keyboard: true,
|
keyboard: true,
|
||||||
focus: true
|
focus: true,
|
||||||
});
|
});
|
||||||
modal.show()
|
modal.show();
|
||||||
};
|
};
|
||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
setIsModalOpen(false);
|
setIsModalOpen(false);
|
||||||
setModalConfig(null)
|
setModalConfig(null);
|
||||||
|
|
||||||
|
const modalElement = document.getElementById("building-model");
|
||||||
const modalElement = document.getElementById('building-model');
|
|
||||||
if (modalElement) {
|
if (modalElement) {
|
||||||
modalElement.classList.remove('show'); // Remove modal visibility class
|
modalElement.classList.remove("show"); // Remove modal visibility class
|
||||||
modalElement.style.display = 'none'; // Hide the modal element
|
modalElement.style.display = "none"; // Hide the modal element
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.classList.remove('modal-open'); // Remove modal-open class from body
|
document.body.classList.remove("modal-open"); // Remove modal-open class from body
|
||||||
|
|
||||||
// Remove the modal backdrop
|
// Remove the modal backdrop
|
||||||
const backdropElement = document.querySelector('.modal-backdrop');
|
const backdropElement = document.querySelector(".modal-backdrop");
|
||||||
if (backdropElement) {
|
if (backdropElement) {
|
||||||
backdropElement.classList.remove('modal-backdrop'); // Remove backdrop class
|
backdropElement.classList.remove("modal-backdrop"); // Remove backdrop class
|
||||||
backdropElement.style.display = 'none'; // Hide the backdrop element
|
backdropElement.style.display = "none"; // Hide the backdrop element
|
||||||
}
|
}
|
||||||
document.body.style.overflow = 'auto';
|
document.body.style.overflow = "auto";
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleShow = () => setShowModal(true);
|
const handleShow = () => setShowModal(true);
|
||||||
const handleClose = () => setShowModal( false );
|
const handleClose = () => setShowModal(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={`modal fade ${showModal ? 'show' : ''}`}
|
className={`modal fade ${showModal ? "show" : ""}`}
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
style={{ display: showModal ? 'block' : 'none' }}
|
style={{ display: showModal ? "block" : "none" }}
|
||||||
aria-hidden={!showModal}
|
aria-hidden={!showModal}
|
||||||
>
|
>
|
||||||
<BuildingModel
|
<BuildingModel
|
||||||
project={data}
|
project={project}
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
onSubmit={handleBuildingModelFormSubmit}
|
onSubmit={handleBuildingModelFormSubmit}
|
||||||
clearTrigger={clearFormTrigger}
|
clearTrigger={clearFormTrigger}
|
||||||
@ -368,11 +357,11 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
id="floor-model"
|
id="floor-model"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
style={{ display: 'block' }}
|
style={{ display: "block" }}
|
||||||
aria-hidden="false"
|
aria-hidden="false"
|
||||||
>
|
>
|
||||||
<FloorModel
|
<FloorModel
|
||||||
project={data}
|
project={project}
|
||||||
onClose={closeFloorModel}
|
onClose={closeFloorModel}
|
||||||
onSubmit={handleFloorModelFormSubmit}
|
onSubmit={handleFloorModelFormSubmit}
|
||||||
clearTrigger={clearFormTrigger}
|
clearTrigger={clearFormTrigger}
|
||||||
@ -387,12 +376,11 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
id="work-area-model"
|
id="work-area-model"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
style={{ display: 'block' }}
|
style={{ display: "block" }}
|
||||||
aria-hidden="false"
|
aria-hidden="false"
|
||||||
>
|
>
|
||||||
<WorkAreaModel
|
<WorkAreaModel
|
||||||
project={data}
|
project={project}
|
||||||
// building={null}
|
|
||||||
onClose={closeWorkAreaModel}
|
onClose={closeWorkAreaModel}
|
||||||
onSubmit={handleWorkAreaModelFormSubmit}
|
onSubmit={handleWorkAreaModelFormSubmit}
|
||||||
clearTrigger={clearFormTrigger}
|
clearTrigger={clearFormTrigger}
|
||||||
@ -407,11 +395,11 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
id="task-model"
|
id="task-model"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
style={{ display: 'block' }}
|
style={{ display: "block" }}
|
||||||
aria-hidden="false"
|
aria-hidden="false"
|
||||||
>
|
>
|
||||||
<TaskModel
|
<TaskModel
|
||||||
project={data}
|
project={project}
|
||||||
activities={activityMaster}
|
activities={activityMaster}
|
||||||
onClose={closeTaskModel}
|
onClose={closeTaskModel}
|
||||||
onSubmit={handleTaskModelFormSubmit}
|
onSubmit={handleTaskModelFormSubmit}
|
||||||
@ -421,22 +409,23 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
{isModalOpen && (
|
{isModalOpen && (
|
||||||
<ProjectModal modalConfig={modalConfig} closeModal={closeModal} />
|
<ProjectModal modalConfig={modalConfig} closeModal={closeModal} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="col-md-12 col-lg-12 col-xl-12 order-0 mb-4">
|
<div className="col-md-12 col-lg-12 col-xl-12 order-0 mb-4">
|
||||||
<div className="card">
|
<div className="card">
|
||||||
|
|
||||||
<div className="card-body" style={{ padding: "0.5rem" }}>
|
<div className="card-body" style={{ padding: "0.5rem" }}>
|
||||||
<div className="align-items-center">
|
<div className="align-items-center">
|
||||||
<div className="row ">
|
<div className="row ">
|
||||||
<div className={`col-12 text-end mb-1 ${!ManageInfra && 'd-none'} `} >
|
<div
|
||||||
|
className={`col-12 text-end mb-1 ${
|
||||||
|
!ManageInfra && "d-none"
|
||||||
|
} `}
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="link-button link-button-sm m-1 "
|
className="link-button link-button-sm m-1 "
|
||||||
|
|
||||||
onClick={handleShow}
|
onClick={handleShow}
|
||||||
>
|
>
|
||||||
<i className="bx bx-plus-circle me-2"></i>
|
<i className="bx bx-plus-circle me-2"></i>
|
||||||
@ -450,8 +439,6 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
<i className="bx bx-plus-circle me-2"></i>
|
<i className="bx bx-plus-circle me-2"></i>
|
||||||
Manage Floors
|
Manage Floors
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="link-button m-1"
|
className="link-button m-1"
|
||||||
@ -471,7 +458,13 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row ">
|
<div className="row ">
|
||||||
<InfraTable buildings={project.buildings} project={data}/>
|
{loading && <p>Loading....</p>}
|
||||||
|
{project && project.buildings?.length > 0 && (
|
||||||
|
<InfraTable
|
||||||
|
buildings={project?.buildings}
|
||||||
|
project={project}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -91,14 +91,15 @@ export const useProjectDetails =(projectId)=>{
|
|||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
setLoading(true)
|
setLoading( true )
|
||||||
|
|
||||||
const project_cache = getCachedData("projectInfo");
|
const project_cache = getCachedData("projectInfo");
|
||||||
if (!project_cache || project_cache?.projectId !== projectId) {
|
if (!project_cache || project_cache?.projectId != projectId) {
|
||||||
ProjectRepository.getProjectByprojectId(projectId)
|
ProjectRepository.getProjectByprojectId(projectId)
|
||||||
.then( ( response ) =>
|
.then( ( response ) =>
|
||||||
{
|
{
|
||||||
setProject_Details( response.data );
|
setProject_Details( response.data );
|
||||||
cacheData("projectInfo", {projectId,data: response.data} );
|
cacheData("projectInfo", {projectId:projectId,data: response.data} );
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -25,7 +25,6 @@ const AttendancePage = () => {
|
|||||||
const { projects, loading: projectLoading } = useProjects();
|
const { projects, loading: projectLoading } = useProjects();
|
||||||
const {attendance, loading: attLoading} = useAttendace( selectedProject );
|
const {attendance, loading: attLoading} = useAttendace( selectedProject );
|
||||||
const [ attendances, setAttendances ] = useState();
|
const [ attendances, setAttendances ] = useState();
|
||||||
|
|
||||||
const [empRoles, setEmpRoles] = useState(null);
|
const [empRoles, setEmpRoles] = useState(null);
|
||||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
const [modelConfig, setModelConfig] = useState();
|
const [modelConfig, setModelConfig] = useState();
|
||||||
@ -71,7 +70,7 @@ const AttendancePage = () => {
|
|||||||
|
|
||||||
const handleSubmit = ( formData ) =>
|
const handleSubmit = ( formData ) =>
|
||||||
{
|
{
|
||||||
debugger
|
|
||||||
dispatch( markCurrentAttendance( formData ) ).then( ( action ) =>
|
dispatch( markCurrentAttendance( formData ) ).then( ( action ) =>
|
||||||
{
|
{
|
||||||
const updatedAttendance = attendances.map(item =>
|
const updatedAttendance = attendances.map(item =>
|
||||||
@ -146,7 +145,7 @@ const AttendancePage = () => {
|
|||||||
>
|
>
|
||||||
{!projectLoading && projects?.filter(project =>
|
{!projectLoading && projects?.filter(project =>
|
||||||
loginUser?.projects?.map(Number).includes(project.id)).map((project)=>(
|
loginUser?.projects?.map(Number).includes(project.id)).map((project)=>(
|
||||||
<option value={project.id}>{project.name}</option>
|
<option value={project.id} key={project.id}>{project.name}</option>
|
||||||
))}
|
))}
|
||||||
{projectLoading && <option value="Loading..." disabled>Loading...</option> }
|
{projectLoading && <option value="Loading..." disabled>Loading...</option> }
|
||||||
</select>
|
</select>
|
||||||
@ -179,7 +178,6 @@ const AttendancePage = () => {
|
|||||||
Logs
|
Logs
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li className={`nav-item ${!DoRegularized && 'd-none'}`}>
|
<li className={`nav-item ${!DoRegularized && 'd-none'}`}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -130,9 +130,8 @@ const LoginPage = () => {
|
|||||||
name="rememberMe"
|
name="rememberMe"
|
||||||
{...register("rememberMe")}
|
{...register("rememberMe")}
|
||||||
/>
|
/>
|
||||||
<label className="form-check-label ms-2" htmlFor="remember-me">
|
<label className="form-check-label ms-2" >
|
||||||
{" "}
|
Remember Me
|
||||||
Remember Me{" "}
|
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<Link
|
<Link
|
||||||
|
@ -14,6 +14,7 @@ import {MANAGE_PROJECT} from "../../utils/constants";
|
|||||||
const ProjectList = () =>
|
const ProjectList = () =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
const {profile: loginUser} = useProfile();
|
const {profile: loginUser} = useProfile();
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const {projects, loading, error, refetch} = useProjects();
|
const {projects, loading, error, refetch} = useProjects();
|
||||||
|
@ -35,7 +35,7 @@ axiosClient.interceptors.response.use(
|
|||||||
|
|
||||||
(response) => response,
|
(response) => response,
|
||||||
async (error) => {
|
async (error) => {
|
||||||
debugger;
|
|
||||||
const originalRequest = error.config;
|
const originalRequest = error.config;
|
||||||
|
|
||||||
if (!originalRequest) {
|
if (!originalRequest) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user