From cba0d2c0961c48ccd7917cf5f21504492fc846d4 Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 9 Feb 2024 13:42:03 +0545 Subject: [PATCH] fix qrCodeComponent: UI enhancement, component moved from projectDetails to taskSectionPopup --- .../ProjectDetailsV2/TaskSectionPopup.tsx | 60 +++++++++++++++++-- src/frontend/src/views/ProjectDetailsV2.tsx | 4 +- 2 files changed, 57 insertions(+), 7 deletions(-) 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 (
{ onClick={() => dispatch(ProjectActions.ToggleTaskModalStatus(false))} className={`fmtm-absolute fmtm-top-[17px] fmtm-right-[20px] ${ taskModalStatus ? '' : 'fmtm-hidden' - } fmtm-cursor-pointer`} + } fmtm-cursor-pointer fmtm-flex fmtm-items-center fmtm-gap-3`} > - + + +
-
+
+
+

Task: {taskId}

+

Status: {task_status}

+
+ {checkIfTaskAssignedOrNot && task_status === 'LOCKED_FOR_MAPPING' && } {body}
diff --git a/src/frontend/src/views/ProjectDetailsV2.tsx b/src/frontend/src/views/ProjectDetailsV2.tsx index f634271a05..ba6a12cf0e 100644 --- a/src/frontend/src/views/ProjectDetailsV2.tsx +++ b/src/frontend/src/views/ProjectDetailsV2.tsx @@ -17,7 +17,6 @@ import GenerateBasemap from '@/components/GenerateBasemap'; import { ProjectBuildingGeojsonService } from '@/api/SubmissionService'; import TaskSectionPopup from '@/components/ProjectDetailsV2/TaskSectionPopup'; import DialogTaskActions from '@/components/DialogTaskActions'; -import QrcodeComponent from '@/components/QrcodeComponent'; import MobileFooter from '@/components/ProjectDetailsV2/MobileFooter'; import MobileActivitiesContents from '@/components/ProjectDetailsV2/MobileActivitiesContents'; import BottomSheet from '@/components/common/BottomSheet'; @@ -513,10 +512,11 @@ const Home = () => { {featuresLayer != undefined && ( - } />