set selectedProject on page refresh in DailyTask.jsx

- added fallback logic to select first project if selectedProject is undefined or 1
- used initialized flag to prevent multiple dispatches
This commit is contained in:
Pramod Mahajan 2025-05-06 11:00:13 +05:30
parent 029254e548
commit 8483114f4d

View File

@ -32,9 +32,7 @@ const DailyTask = () => {
// Sync projectId (either from URL or pick first accessible one)
useEffect(() => {
if (!project_lodaing && projects.length > 0 && !initialized) {
if (projectId) {
dispatch(setProjectId(projectId));
} else if (!selectedProject) {
if (selectedProject === 1 || selectedProject === undefined) {
dispatch(setProjectId(projects[0].id));
}
@ -77,7 +75,6 @@ const DailyTask = () => {
selectTask(task);
openModal();
};
return (
<>
<div
@ -160,21 +157,26 @@ const DailyTask = () => {
</tr>
</thead>
<tbody className="table-border-bottom-0">
{TaskLists?.length === 0 && !task_loading && (
<tr>
<td colSpan={7} className="text-center">
No Task Found
</td>
</tr>
)}
{task_loading && (
{task_loading && (
<tr>
<td colSpan={7} className="text-center">
<p>Loading..</p>
</td>
</tr>
)}
{project_lodaing && <tr>
<td colSpan={7} className="text-center">
Loading...
</td>
</tr>}
{TaskLists?.length === 0 && !task_loading && !project_lodaing &&(
<tr>
<td colSpan={7} className="text-center">
No Task Found
</td>
</tr>
)}
{TaskLists.map((task, index) => {
return (