diff --git a/src/frontend/src/views/Dashboard/index.tsx b/src/frontend/src/views/Dashboard/index.tsx index 6feb591a..2837f2c9 100644 --- a/src/frontend/src/views/Dashboard/index.tsx +++ b/src/frontend/src/views/Dashboard/index.tsx @@ -1,8 +1,62 @@ -import { FlexRow } from '@Components/common/Layouts'; +import { useGetRequestedTasksListQuery } from '@Api/dashboard'; +import { FlexColumn, FlexRow } from '@Components/common/Layouts'; import { DashboardSidebar, DashboardCard } from '@Components/Dashboard'; -import { dashboardCards } from '@Constants/dashboard'; +import { Button } from '@Components/RadixComponents/Button'; +import { + dashboardCardsForDroneOperator, + dashboardCardsForProjectCreator, +} from '@Constants/dashboard'; +import { postTaskStatus } from '@Services/project'; +import { useMutation } from '@tanstack/react-query'; +import { useMemo } from 'react'; +import { toast } from 'react-toastify'; export default function Dashboard() { + const signedInAs = localStorage.getItem('signedInAs') || 'Project Creator'; + const dashboardCards = + signedInAs === 'Project Creator' + ? dashboardCardsForProjectCreator + : dashboardCardsForDroneOperator; + + const { data: requestedTasks } = useGetRequestedTasksListQuery(); + + const { mutate: respondToRequest } = useMutation({ + mutationFn: postTaskStatus, + onSuccess: () => { + toast.success('Responded to the request'); + }, + onError: (err: any) => { + toast.error(err.message); + }, + }); + + const requestedForMappingTasks: any[] = + useMemo( + () => + // @ts-ignore + requestedTasks?.reduce((acc: any[], curr: Record) => { + if (curr?.state === 'REQUEST_FOR_MAPPING') return [...acc, curr]; + return acc; + }, []), + [requestedTasks], + ) || []; + + const handleReject = (taskId: string, projectId: string) => { + respondToRequest({ + projectId, + taskId, + data: { event: 'bad' }, + }); + }; + + const handleApprove = (taskId: string, projectId: string) => { + respondToRequest({ + projectId, + taskId, + data: { event: 'map' }, + }); + }; + return (
@@ -17,9 +71,49 @@ export default function Dashboard() { key={card.id} title={card.title} value={card.value} + active={card.title === 'Request Logs'} /> ))} +
+

+ Request Logs +

+ + {requestedForMappingTasks?.map((task: Record) => ( +
+
+ The Task #{task.task_id} is requested for + Mapping +
+
+ + +
+
+ ))} +
+