Fixed state sync issue by clearing cache and re-fetching project data after task creation.
This commit is contained in:
parent
8d4c9e4f39
commit
dc5f452881
@ -12,7 +12,7 @@ import ProjectModal from "./ProjectModal";
|
||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||
import { MANAGE_PROJECT_INFRA } from "../../utils/constants";
|
||||
import InfraTable from "./Infrastructure/InfraTable";
|
||||
import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
||||
import { cacheData, clearCacheKey, getCachedData } from "../../slices/apiDataManager";
|
||||
import { useProjectDetails } from "../../hooks/useProjects";
|
||||
|
||||
const ProjectInfra = ({
|
||||
@ -21,7 +21,7 @@ const ProjectInfra = ({
|
||||
eachSiteEngineer,
|
||||
}) => {
|
||||
const [expandedBuildings, setExpandedBuildings] = useState([]);
|
||||
const { projects_Details, loading } = useProjectDetails(data.id);
|
||||
const { projects_Details,refetch, loading } = useProjectDetails(data.id);
|
||||
const [project, setProject] = useState(projects_Details);
|
||||
const [modalConfig, setModalConfig] = useState({ type: null, data: null });
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
@ -110,7 +110,6 @@ const ProjectInfra = ({
|
||||
};
|
||||
|
||||
const handleTaskModelFormSubmit = (updatedModel) => {
|
||||
// debugger
|
||||
if (updatedModel.id == "") updatedModel.id = 0;
|
||||
const updatedProject = { ...project };
|
||||
|
||||
@ -119,7 +118,6 @@ const ProjectInfra = ({
|
||||
onDataChange("task-change");
|
||||
showToast("Details updated successfully.", "success");
|
||||
// setClearFormTrigger( true );
|
||||
|
||||
if (response?.data[0]) {
|
||||
const { workItemId, workItem } = response.data[0];
|
||||
|
||||
@ -140,8 +138,8 @@ const ProjectInfra = ({
|
||||
existingItem.workItemId ===
|
||||
workItem.workItemId
|
||||
)
|
||||
? workArea.workItems // If the workItemId already exists, keep the current workItems
|
||||
: [...workArea.workItems, workItem],
|
||||
? [...workArea.workItems] // Create a new array to trigger re-render
|
||||
: [...workArea.workItems, workItem],
|
||||
}
|
||||
: workArea
|
||||
),
|
||||
@ -151,15 +149,18 @@ const ProjectInfra = ({
|
||||
}
|
||||
: building
|
||||
);
|
||||
|
||||
updatedProject.buildings = updatedBuildings;
|
||||
// workItem update, but having local state issue there for needed to calling api
|
||||
clearCacheKey( "projectInfo" )
|
||||
refetch()
|
||||
|
||||
setProject(updatedProject);
|
||||
cacheData("projectInfo", {
|
||||
projectId: updatedProject.id,
|
||||
data: updatedProject,
|
||||
});
|
||||
console.log(project);
|
||||
|
||||
setProject( updatedProject );
|
||||
closeTaskModel()
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user