Skip to content

Commit 2281ca6

Browse files
Merge pull request #4715 from OneCommunityGlobal/venkataramanan_fix_wbs_back_button_issue
Venkataramanan 🔥 WBS back button to go directly to WBS
2 parents 1329864 + d016672 commit 2281ca6

1 file changed

Lines changed: 39 additions & 12 deletions

File tree

src/components/Projects/WBS/SameFolderTasks/SameFolderTasks.jsx

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import axios from 'axios';
44
import { connect } from 'react-redux';
55
import { ENDPOINTS } from '~/utils/URL';
66
import { Table } from 'reactstrap';
7+
import { useHistory } from 'react-router-dom';
8+
79
import EditTaskModal from '../WBSDetail/EditTask/EditTaskModal';
810
import { getPopupById } from '../../../../actions/popupEditorAction';
911
import { TASK_DELETE_POPUP_ID } from '../../../../constants/popupId';
1012

1113
function SameFolderTasks(props) {
1214
const { taskId } = props.match.params;
15+
const history = useHistory();
1316

1417
let isMounted = true;
1518

@@ -22,48 +25,64 @@ function SameFolderTasks(props) {
2225
const [projectId, setProjectId] = useState('');
2326
const [wbsName, setWbsName] = useState('');
2427

28+
const noOtherTasksInFolder = task.mother === null || task.mother === taskId;
29+
2530
useEffect(() => {
2631
const fetchTaskData = async () => {
2732
try {
2833
const res = await axios.get(ENDPOINTS.GET_TASK(taskId));
2934
if (isMounted) {
3035
setTask(res?.data || {});
31-
setWBSId(res?.data.wbsId || '');
36+
setWBSId(res?.data?.wbsId || '');
3237
}
3338
} catch (error) {
3439
// eslint-disable-next-line no-console
3540
console.log(error);
3641
}
3742
};
43+
3844
fetchTaskData();
3945

4046
return () => {
4147
isMounted = false;
4248
};
49+
// eslint-disable-next-line react-hooks/exhaustive-deps
4350
}, []);
4451

4552
useEffect(() => {
4653
const fetchWBSData = async () => {
4754
try {
55+
if (!wbsId) return;
4856
const res = await axios.get(ENDPOINTS.GET_WBS(wbsId));
4957
if (isMounted) {
50-
setProjectId(res?.data?.projectId);
51-
setWbsName(res?.data?.wbsName);
58+
setProjectId(res?.data?.projectId || '');
59+
setWbsName(res?.data?.wbsName || '');
5260
}
5361
} catch (error) {
5462
// eslint-disable-next-line no-console
5563
console.log(error);
5664
}
5765
};
5866

59-
fetchAllTasks();
60-
fetchWBSData();
67+
if (wbsId) {
68+
setLoading(true);
69+
fetchAllTasks();
70+
fetchWBSData();
71+
}
6172

6273
return () => {
6374
isMounted = false;
6475
};
76+
// eslint-disable-next-line react-hooks/exhaustive-deps
6577
}, [wbsId]);
6678

79+
useEffect(() => {
80+
if (!noOtherTasksInFolder) return;
81+
if (!wbsId || !projectId || !wbsName) return;
82+
83+
history.replace(`/wbs/tasks/${wbsId}/${projectId}/${encodeURIComponent(wbsName)}`);
84+
}, [noOtherTasksInFolder, wbsId, projectId, wbsName, history]);
85+
6786
const fetchAllTasks = async () => {
6887
try {
6988
const res = await axios.get(ENDPOINTS.TASKS(task.wbsId, task.level, task.mother));
@@ -75,19 +94,24 @@ function SameFolderTasks(props) {
7594
} catch (error) {
7695
// eslint-disable-next-line no-console
7796
console.log(error);
97+
setLoading(false);
7898
}
7999
};
80100

81-
if (task.mother === null || task.mother === taskId) {
101+
if (noOtherTasksInFolder) {
82102
return (
83-
<div className="App">
84-
<p>There are no other tasks in this task&apos;s folder.</p>
85-
<a href={`/wbs/tasks/${wbsId}/${projectId}/${wbsName}`}>
86-
Click here to visit the source WBS ({wbsName}) that contains this task
87-
</a>
103+
<div className="d-flex justify-content-center align-items-center pt-4">
104+
<output
105+
className="spinner-border text-success"
106+
aria-live="polite"
107+
aria-busy="true"
108+
>
109+
<span className="sr-only">Loading...</span>
110+
</output>
88111
</div>
89112
);
90113
}
114+
91115
return (
92116
<div className="container">
93117
{loading ? (
@@ -201,7 +225,10 @@ function SameFolderTasks(props) {
201225
<span className="dot">{element.name.substring(0, 2)}</span>
202226
</a>
203227
);
204-
} catch (error) { }
228+
} catch (error) {
229+
console.error('Failed to render element:', error);
230+
return null;
231+
}
205232
})}
206233
</td>
207234
<td>

0 commit comments

Comments
 (0)