diff --git a/src/frontend/src/components/ProjectDetailsV2/TaskSectionPopup.tsx b/src/frontend/src/components/ProjectDetailsV2/TaskSectionPopup.tsx index 0a46469b6d..7682c446e8 100644 --- a/src/frontend/src/components/ProjectDetailsV2/TaskSectionPopup.tsx +++ b/src/frontend/src/components/ProjectDetailsV2/TaskSectionPopup.tsx @@ -1,11 +1,54 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import CoreModules from '@/shared/CoreModules'; import AssetModules from '@/shared/AssetModules'; import { ProjectActions } from '@/store/slices/ProjectSlice'; +import environment from '@/environment'; +import { ProjectFilesById } from '@/api/Files'; +import QrcodeComponent from '@/components/QrcodeComponent'; -const TaskSectionPopup = ({ body }) => { +type TaskSectionPopupPropType = { + taskId: string | undefined; + body: React.JSX.Element; + feature: any; +}; + +const TaskSectionPopup = ({ taskId, body, feature }: TaskSectionPopupPropType) => { const dispatch = CoreModules.useAppDispatch(); + const [task_status, set_task_status] = useState('READY'); const taskModalStatus = CoreModules.useAppSelector((state) => state.project.taskModalStatus); + const params = CoreModules.useParams(); + const currentProjectId = environment.decode(params.id); + const projectData = CoreModules.useAppSelector((state) => state.project.projectTaskBoundries); + const projectIndex = projectData.findIndex((project) => project.id == currentProjectId); + + //qrcodecomponent + const projectName = CoreModules.useAppSelector((state) => state.project.projectInfo.title); + const token = CoreModules.useAppSelector((state) => state.login.loginToken); + const selectedTask = { + ...projectData?.[projectIndex]?.taskBoundries?.filter((indTask, i) => { + return indTask.id == taskId; + })?.[0], + }; + const checkIfTaskAssignedOrNot = + selectedTask?.locked_by_username === token?.username || selectedTask?.locked_by_username === null; + + // TODO fix multiple renders of component (6 times) + const { qrcode } = ProjectFilesById(selectedTask.odk_token, projectName, token?.username, taskId); + useEffect(() => { + if (projectIndex != -1) { + const currentStatus = { + ...projectData[projectIndex].taskBoundries.filter((task) => { + return task.id == taskId; + })[0], + }; + const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex( + (data) => data.label == currentStatus.task_status, + ); + const tasksStatus = + feature.id_ != undefined ? environment.tasksStatus[findCorrectTaskStatusIndex]?.['label'] : ''; + set_task_status(tasksStatus); + } + }, [projectData, taskId, feature]); return (
Status: {task_status}
+