From 8dbce6dd4968e38e505294d7e42f2d7994069911 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Mon, 30 Jun 2025 21:36:54 +0530 Subject: [PATCH] Fixed issue where query remained disabled and cache was undefined --- .../Project/Infrastructure/WorkArea.jsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/Project/Infrastructure/WorkArea.jsx b/src/components/Project/Infrastructure/WorkArea.jsx index 66c88548..6acf26a0 100644 --- a/src/components/Project/Infrastructure/WorkArea.jsx +++ b/src/components/Project/Infrastructure/WorkArea.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"; import WorkItem from "./WorkItem"; import { useProjectDetails } from "../../../hooks/useProjects"; import { cacheData, getCachedData } from "../../../slices/apiDataManager"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { refreshData } from "../../../slices/localVariablesSlice"; import ProjectRepository from "../../../repositories/ProjectRepository"; import showToast from "../../../services/toastService"; @@ -17,7 +17,12 @@ import ProgressDonutChart from "../../Charts/ProgressDonutChart"; import ProgressBar from "../../common/ProgressBar"; import { componentsToColor } from "pdf-lib"; -const WorkArea = ({ workArea, floor, forBuilding }) => { +const WorkArea = ( {workArea, floor, forBuilding} ) => +{ + const selectedProject = useSelector( ( store ) => store.localVariables.projectId ) + const { projects_Details, loading, error, refetch } = useProjectDetails( + selectedProject + ); const [workItems, setWorkItems] = useState([]); const dispatch = useDispatch(); const [Project, setProject] = useState(); @@ -48,15 +53,16 @@ const WorkArea = ({ workArea, floor, forBuilding }) => { }, [workItems]); useEffect(() => { - const project = getCachedData("projectInfo"); - setProject(project); + // const project = getCachedData("projectInfo"); + setProject( projects_Details ); + - if (!project || !forBuilding?.id || !floor?.id || !workArea?.id) return; - const building = project.buildings?.find((b) => b.id === forBuilding.id); + if (!projects_Details || !forBuilding?.id || !floor?.id || !workArea?.id) return; + const building = projects_Details.buildings?.find((b) => b.id === forBuilding.id); const floors = building?.floors?.find((f) => f.id === floor.id); const workAreas = floor?.workAreas?.find((wa) => wa.id === workArea.id); setWorkItems(workAreas?.workItems || []); - }, [workArea, floor, floor]); + }, [workArea, floor, floor,loading]); const HanldeDeleteActivity = async (workItemId) => { try {