Fixed the error "project not found" in daily task planning
This commit is contained in:
parent
5995c74ae6
commit
ce40105ae5
@ -29,7 +29,7 @@ const InfraPlanning = () =>
|
||||
useEffect( () =>
|
||||
{
|
||||
dispatch(setProjectId(projects[0]?.id))
|
||||
})
|
||||
},[projects])
|
||||
|
||||
return (
|
||||
<div className="col-md-12 col-lg-12 col-xl-12 order-0 mb-4">
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
getCachedData,
|
||||
} from "../slices/apiDataManager"
|
||||
import ProjectRepository from "../repositories/ProjectRepository";
|
||||
import { useProfile } from "./useProfile";
|
||||
|
||||
|
||||
|
||||
@ -84,7 +85,7 @@ export const useEmployeesByProjectAllocated = ( selectedProject ) =>
|
||||
}
|
||||
|
||||
export const useProjectDetails =(projectId)=>{
|
||||
|
||||
const {profile} = useProfile();
|
||||
const [projects_Details, setProject_Details] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
@ -113,11 +114,11 @@ export const useProjectDetails =(projectId)=>{
|
||||
};
|
||||
|
||||
useEffect(()=>{
|
||||
if ( projectId )
|
||||
if ( profile && (projectId != undefined) )
|
||||
{
|
||||
fetchData()
|
||||
}
|
||||
},[projectId])
|
||||
},[projectId,profile])
|
||||
|
||||
return { projects_Details,loading,error,refetch:fetchData}
|
||||
|
||||
|
@ -6,10 +6,19 @@ import ProjectRepository from "../../repositories/ProjectRepository";
|
||||
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||
import InfraPlanning from "../../components/Activities/InfraPlanning";
|
||||
import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
||||
import { useProfile } from "../../hooks/useProfile";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useProjectDetails, useProjects } from "../../hooks/useProjects";
|
||||
import { setProjectId } from "../../slices/localVariablesSlice";
|
||||
|
||||
var projectId;
|
||||
const TaskPlannng = () => {
|
||||
|
||||
const {profile} = useProfile();
|
||||
const {projects,loading:project_listLoader,error:projects_error} = useProjects();
|
||||
const dispatch = useDispatch();
|
||||
const selectedProject = useSelector((store)=>store.localVariables.projectId);
|
||||
|
||||
|
||||
const [project, setProject] = useState(null);
|
||||
const [projectDetails, setProjectDetails] = useState(null);
|
||||
@ -17,6 +26,10 @@ const TaskPlannng = () => {
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
useEffect( () =>
|
||||
{
|
||||
dispatch(setProjectId(projects[0]?.id))
|
||||
},[projects])
|
||||
|
||||
const fetchActivities = async () => {
|
||||
try {
|
||||
@ -43,9 +56,9 @@ const TaskPlannng = () => {
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const project_cache = getCachedData(`projectinfo-${1}`);
|
||||
const project_cache = getCachedData(`projectinfo-${selectedProject}`);
|
||||
if (!project_cache) {
|
||||
ProjectRepository.getProjectByprojectId(1)
|
||||
ProjectRepository.getProjectByprojectId(selectedProject)
|
||||
.then((response) => {
|
||||
setProjectDetails(response);
|
||||
setProject(response);
|
||||
@ -73,14 +86,16 @@ const TaskPlannng = () => {
|
||||
};
|
||||
|
||||
const handleDataChange = (data) => {
|
||||
console.log("datachange")
|
||||
fetchData();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
projectId =1
|
||||
fetchData();
|
||||
if((projects.length != 0)){
|
||||
fetchData();
|
||||
fetchActivities();
|
||||
}, []);
|
||||
}
|
||||
}, [selectedProject]);
|
||||
|
||||
|
||||
return (
|
||||
|
Loading…
x
Reference in New Issue
Block a user