Fetched workItem from cache instead of props to resolve state inconsistency issue.
This commit is contained in:
parent
df7303b724
commit
ebc03cb9eb
@ -1,8 +1,23 @@
|
|||||||
import React, { useEffect } from "react";
|
import React, { useEffect,useState } from "react";
|
||||||
import WorkItem from "./WorkItem";
|
import WorkItem from "./WorkItem";
|
||||||
|
import {useProjectDetails} from "../../../hooks/useProjects";
|
||||||
|
import {getCachedData} from "../../../slices/apiDataManager";
|
||||||
|
|
||||||
|
const WorkArea = ( {workArea, floor, forBuilding} ) =>{
|
||||||
|
const [workItems,setWorkItems] =useState([])
|
||||||
|
|
||||||
|
useEffect( () =>
|
||||||
|
{
|
||||||
|
const project = getCachedData( "projectInfo" )
|
||||||
|
if (!project || !forBuilding?.id || !floor?.id || !workArea?.id) return;
|
||||||
|
|
||||||
|
const building = project.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] );
|
||||||
|
|
||||||
const WorkArea = ({ workArea, floor, forBuilding }) => {
|
|
||||||
useEffect(() => {}, [workArea]);
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={workArea.id}>
|
<React.Fragment key={workArea.id}>
|
||||||
<tr>
|
<tr>
|
||||||
@ -25,7 +40,7 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{workArea?.workItems && workArea.workItems.length > 0 ? (
|
{(workItems && workItems.length > 0) && (
|
||||||
<tr className="overflow-auto">
|
<tr className="overflow-auto">
|
||||||
<td colSpan={4}>
|
<td colSpan={4}>
|
||||||
<table className="table mx-1">
|
<table className="table mx-1">
|
||||||
@ -72,7 +87,8 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : null}
|
)}
|
||||||
|
{!workItems && <p>No item</p>}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user