diff --git a/src/components/Project/Infrastructure/TaskModel.jsx b/src/components/Project/Infrastructure/TaskModel.jsx
index 79b95e4f..791b99ee 100644
--- a/src/components/Project/Infrastructure/TaskModel.jsx
+++ b/src/components/Project/Infrastructure/TaskModel.jsx
@@ -2,6 +2,9 @@ import React, { useState, useEffect } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from "zod";
+import {useDispatch} from "react-redux";
+import {changeMaster} from "../../../slices/localVariablesSlice";
+import useMaster from "../../../hooks/masterHook/useMaster";
// Define Zod validation schema
const taskSchema = z.object({
@@ -23,11 +26,12 @@ const defaultModel = {
const TaskModel = ({
project,
- activities,
onSubmit,
clearTrigger,
onClearComplete,onClose
-}) => {
+} )=>{
+ const dispatch = useDispatch()
+ const {data:activities,loading} = useMaster()
const [formData, setFormData] = useState(defaultModel);
const [selectedBuilding, setSelectedBuilding] = useState(null);
const [selectedFloor, setSelectedFloor] = useState(null);
@@ -90,8 +94,6 @@ const TaskModel = ({
const onSubmitForm = ( data ) =>
{
-
-
onSubmit( data );
setSelectedActivity(null),
setSelectedWorkArea(null)
@@ -104,6 +106,8 @@ const TaskModel = ({
useEffect( () =>
{
+
+ dispatch(changeMaster("Activity")),
() =>{
resetVlaue ()
}
diff --git a/src/components/Project/ProjectInfra.jsx b/src/components/Project/ProjectInfra.jsx
index 70e84b6a..9f6bc6e7 100644
--- a/src/components/Project/ProjectInfra.jsx
+++ b/src/components/Project/ProjectInfra.jsx
@@ -17,7 +17,6 @@ import { useProjectDetails } from "../../hooks/useProjects";
const ProjectInfra = ({
data,
- activityMaster,
onDataChange,
eachSiteEngineer,
}) => {
@@ -57,130 +56,6 @@ const ProjectInfra = ({
setIsBuildingModalOpen(true);
};
- const submitData = async (infraObject) => {
- try {
- 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,
- floors: [],
- });
- }
-
- updatedProject.buildings = updatedBuildings;
-
- // Update the cache for buildings
- cacheData("projectInfo", {
- projectId: updatedProject.id,
- data: updatedProject,
- });
- setProject((prevProject) => ({
- ...prevProject,
- buildings: updatedBuildings,
- }));
- }
- // 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, workAreas: [] }] // 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) {
- 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: [] },
- ],
- }
- : 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 {
- console.error("Unsupported data type for submitData", entity);
- }
- } catch (Err) {
- console.log(Err);
- showToast("Somthing wrong", "error");
- }
- handleClose();
- };
-
const closeBuildingModel = () => {
setIsBuildingModalOpen(false);
};
@@ -292,6 +167,139 @@ const ProjectInfra = ({
});
};
+
+ const submitData = async (infraObject) => {
+ try
+ {
+ debugger
+
+ 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,
+ floors: [],
+ });
+ }
+
+ updatedProject.buildings = updatedBuildings;
+
+ // Update the cache for buildings
+ cacheData("projectInfo", {
+ projectId: updatedProject.id,
+ data: updatedProject,
+ });
+ setProject((prevProject) => ({
+ ...prevProject,
+ buildings: updatedBuildings,
+ } ) );
+ closeBuildingModel()
+ }
+ // 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, workAreas: [] }] // 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 );
+ closeFloorModel()
+ }
+ // Handle the work area data
+ else if ( entity.workArea )
+ {
+ 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: [] },
+ ],
+ }
+ : floor
+ ),
+ }
+ : building
+ );
+
+ updatedProject.buildings = updatedBuildings;
+
+ // Update the cache for work areas
+ cacheData("projectInfo", {
+ projectId: updatedProject.id,
+ data: updatedProject,
+ });
+ setProject( updatedProject );
+ closeWorkAreaModel()
+ }
+ // Handle the task (workItem) data
+ else {
+ console.error("Unsupported data type for submitData", entity);
+ }
+ } catch (Err) {
+ console.log(Err);
+ showToast("Somthing wrong", "error");
+ }
+ handleClose();
+ };
+
+
const toggleBuilding = (id) => {
setExpandedBuildings((prev) =>
prev.includes(id) ? prev.filter((bid) => bid !== id) : [...prev, id]
@@ -400,7 +408,7 @@ const ProjectInfra = ({
>