Resolve data loading issue in DailyTask by defaulting to first project #64

Merged
vikas.nale merged 1 commits from pramod_Bug#184 into Issue_May_2W 2025-05-06 12:19:42 +00:00
Collaborator

Issue:
After a page refresh in DailyTask.jsx, selectedProject was coming as undefined.
Because of this, project-related data like daily tasks were not loading.

Fixed
I have added fallback logic in DailyTask.jsx to handle cases where selectedProject is undefined or 1 on page refresh.
Now it sets the first project by default if no project is selected and ensures the data loads correctly.
Wrapped inside a one-time useEffect using a local initialized flag to avoid repeated dispatch.

  useEffect(() => {
    if (!project_lodaing && projects.length > 0 && !initialized) {
     if (selectedProject === 1 || selectedProject === undefined) {
        dispatch(setProjectId(projects[0].id));
      }

      setInitialized(true);
    }
  }, [project_lodaing, projects, projectId, selectedProject, initialized]);

Now, on refresh, the project is selected automatically, and all task-related data loads correctly.

**Issue:** After a page refresh in DailyTask.jsx, selectedProject was coming as undefined. Because of this, project-related data like daily tasks were not loading. **Fixed** I have added fallback logic in DailyTask.jsx to handle cases where selectedProject is undefined or 1 on page refresh. Now it sets the first project by default if no project is selected and ensures the data loads correctly. Wrapped inside a one-time useEffect using a local initialized flag to avoid repeated dispatch. ``` useEffect(() => { if (!project_lodaing && projects.length > 0 && !initialized) { if (selectedProject === 1 || selectedProject === undefined) { dispatch(setProjectId(projects[0].id)); } setInitialized(true); } }, [project_lodaing, projects, projectId, selectedProject, initialized]); ``` Now, on refresh, the project is selected automatically, and all task-related data loads correctly.
pramod.mahajan added 1 commit 2025-05-06 05:33:33 +00:00
- added fallback logic to select first project if selectedProject is undefined or 1
- used initialized flag to prevent multiple dispatches
vikas.nale merged commit 7bb7b37b60 into Issue_May_2W 2025-05-06 12:19:42 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/marco.pms.web#64
No description provided.