2022-11-10 17:30:27 -05:00
|
|
|
import { useContext, useEffect, useState } from 'react';
|
|
|
|
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
|
|
|
// @ts-ignore
|
|
|
|
import { Tabs, TabList, Tab } from '@carbon/react';
|
|
|
|
import TaskShow from './TaskShow';
|
|
|
|
import ErrorContext from '../contexts/ErrorContext';
|
|
|
|
import MyTasks from './MyTasks';
|
2022-11-11 11:07:21 -05:00
|
|
|
import TasksForMyOpenProcesses from './TasksForMyOpenProcesses';
|
2022-11-10 17:30:27 -05:00
|
|
|
|
|
|
|
export default function HomePageRoutes() {
|
|
|
|
const location = useLocation();
|
|
|
|
const setErrorMessage = (useContext as any)(ErrorContext)[1];
|
|
|
|
const [selectedTabIndex, setSelectedTabIndex] = useState<number>(0);
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setErrorMessage(null);
|
2022-11-11 10:28:08 -05:00
|
|
|
let newSelectedTabIndex = 0;
|
2022-11-11 11:07:21 -05:00
|
|
|
if (location.pathname.match(/^\/tasks\/for-my-open-processes/)) {
|
2022-11-11 10:28:08 -05:00
|
|
|
newSelectedTabIndex = 1;
|
|
|
|
}
|
|
|
|
setSelectedTabIndex(newSelectedTabIndex);
|
2022-11-10 17:30:27 -05:00
|
|
|
}, [location, setErrorMessage]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-11-11 11:07:21 -05:00
|
|
|
<Tabs selectedIndex={selectedTabIndex}>
|
2022-11-10 17:30:27 -05:00
|
|
|
<TabList aria-label="List of tabs">
|
2022-11-11 10:28:08 -05:00
|
|
|
<Tab onClick={() => navigate('/tasks/my-tasks')}>My Tasks</Tab>
|
2022-11-11 11:07:21 -05:00
|
|
|
<Tab onClick={() => navigate('/tasks/for-my-open-processes')}>
|
|
|
|
Tasks for My Open Processes
|
2022-11-10 17:30:27 -05:00
|
|
|
</Tab>
|
|
|
|
</TabList>
|
|
|
|
</Tabs>
|
2022-11-11 10:28:08 -05:00
|
|
|
<br />
|
2022-11-10 17:30:27 -05:00
|
|
|
<Routes>
|
|
|
|
<Route path="/" element={<MyTasks />} />
|
2022-11-11 11:07:21 -05:00
|
|
|
<Route path="my-tasks" element={<MyTasks />} />
|
2022-11-10 17:30:27 -05:00
|
|
|
<Route path=":process_instance_id/:task_id" element={<TaskShow />} />
|
2022-11-11 11:07:21 -05:00
|
|
|
<Route
|
|
|
|
path="for-my-open-processes"
|
|
|
|
element={<TasksForMyOpenProcesses />}
|
|
|
|
/>
|
2022-11-10 17:30:27 -05:00
|
|
|
</Routes>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|