diff --git a/packages/datatrak-web-server/src/routes/TaskRoute.ts b/packages/datatrak-web-server/src/routes/TaskRoute.ts index 3c4ee61a53..af54de4782 100644 --- a/packages/datatrak-web-server/src/routes/TaskRoute.ts +++ b/packages/datatrak-web-server/src/routes/TaskRoute.ts @@ -28,6 +28,7 @@ const FIELDS = [ 'repeat_schedule', 'survey_id', 'entity_id', + 'survey_response_id', ]; export class TaskRoute extends Route { diff --git a/packages/datatrak-web/src/api/mutations/useLogout.ts b/packages/datatrak-web/src/api/mutations/useLogout.ts index 14466b4814..1b7d2cd93c 100644 --- a/packages/datatrak-web/src/api/mutations/useLogout.ts +++ b/packages/datatrak-web/src/api/mutations/useLogout.ts @@ -5,7 +5,7 @@ import { useMutation, useQueryClient } from 'react-query'; import { post } from '../api'; -import { setTaskFilterSetting } from '../../utils'; +import { removeTaskFilterSetting } from '../../utils'; export const useLogout = () => { const queryClient = useQueryClient(); @@ -13,9 +13,9 @@ export const useLogout = () => { return useMutation('logout', () => post('logout'), { onSuccess: () => { queryClient.invalidateQueries(); - setTaskFilterSetting('all_assignees_tasks', false); - setTaskFilterSetting('show_completed_tasks', false); - setTaskFilterSetting('show_cancelled_tasks', false); + removeTaskFilterSetting('all_assignees_tasks'); + removeTaskFilterSetting('show_completed_tasks'); + removeTaskFilterSetting('show_cancelled_tasks'); }, }); }; diff --git a/packages/datatrak-web/src/features/Tasks/TasksTable/ActionButton.tsx b/packages/datatrak-web/src/features/Tasks/TasksTable/ActionButton.tsx index e448cad31f..0bde4ab494 100644 --- a/packages/datatrak-web/src/features/Tasks/TasksTable/ActionButton.tsx +++ b/packages/datatrak-web/src/features/Tasks/TasksTable/ActionButton.tsx @@ -51,10 +51,12 @@ export const ActionButton = ({ task }: ActionButtonProps) => { ); } - const surveyLink = generatePath(ROUTES.SURVEY, { + const path = generatePath(ROUTES.SURVEY, { surveyCode: survey.code, countryCode: entity.countryCode, }); + // Link needs to include page number because if the redirect happens, the "from" state is lost + const surveyLink = `${path}/1`; return ( { - const location = useLocation(); - if (!task) return null; - const { assigneeId, survey, entity, status } = task; - if (status === TaskStatus.cancelled || status === TaskStatus.completed) return null; - if (!assigneeId) { - return Assign; - } - - const surveyLink = generatePath(ROUTES.SURVEY, { - surveyCode: survey.code, - countryCode: entity.countryCode, - }); - return ( - - Complete - - ); -}; diff --git a/packages/datatrak-web/src/utils/index.ts b/packages/datatrak-web/src/utils/index.ts index 672d643364..d1005e21a3 100644 --- a/packages/datatrak-web/src/utils/index.ts +++ b/packages/datatrak-web/src/utils/index.ts @@ -9,4 +9,8 @@ export { useFromLocation } from './useFromLocation'; export * from './date'; export * from './detectDevice'; export { gaEvent } from './ga'; -export { setTaskFilterSetting, getTaskFilterSetting } from './taskFilterSettings'; +export { + setTaskFilterSetting, + getTaskFilterSetting, + removeTaskFilterSetting, +} from './taskFilterSettings'; diff --git a/packages/datatrak-web/src/utils/taskFilterSettings.ts b/packages/datatrak-web/src/utils/taskFilterSettings.ts index 6f145ceda7..049f870758 100644 --- a/packages/datatrak-web/src/utils/taskFilterSettings.ts +++ b/packages/datatrak-web/src/utils/taskFilterSettings.ts @@ -22,3 +22,7 @@ export const setTaskFilterSetting = (cookieName: TaskFilterType, value: boolean) ...(!isDev && { domain: '.tupaia.org' }), }); }; + +export const removeTaskFilterSetting = (cookieName: TaskFilterType): boolean => { + return Cookies.remove(cookieName); +}; diff --git a/packages/datatrak-web/src/views/Tasks/TaskDetailsPage.tsx b/packages/datatrak-web/src/views/Tasks/TaskDetailsPage.tsx index 8f17cbe7e5..302359a6cd 100644 --- a/packages/datatrak-web/src/views/Tasks/TaskDetailsPage.tsx +++ b/packages/datatrak-web/src/views/Tasks/TaskDetailsPage.tsx @@ -3,16 +3,18 @@ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd */ -import React from 'react'; +import React, { useState } from 'react'; import { generatePath, useParams } from 'react-router-dom'; import styled from 'styled-components'; +import { Typography } from '@material-ui/core'; import { TaskStatus } from '@tupaia/types'; -import { SpinningLoader } from '@tupaia/ui-components'; +import { Modal, ModalCenteredContent, SpinningLoader } from '@tupaia/ui-components'; import { Button } from '../../components'; import { TaskDetails, TaskPageHeader, TaskActionsMenu } from '../../features'; import { useTask } from '../../api'; import { ROUTES } from '../../constants'; import { useFromLocation } from '../../utils'; +import { Task } from '../../types'; const ButtonWrapper = styled.div` display: flex; @@ -20,12 +22,34 @@ const ButtonWrapper = styled.div` flex: 1; `; -export const TaskDetailsPage = () => { - const { taskId } = useParams(); - const { data: task, isLoading } = useTask(taskId); +const ErrorModal = ({ isOpen, onClose }) => { + return ( + + + + This response has since been deleted in the admin panel. Please contact your system + administrator for further questions. + + + + ); +}; + +const ButtonComponent = ({ task, openErrorModal }: { task?: Task; openErrorModal: () => void }) => { + const from = useFromLocation(); - const showCompleteButton = - task && task.taskStatus !== TaskStatus.completed && task.taskStatus !== TaskStatus.cancelled; + if (!task) return null; const surveyUrl = task ? generatePath(ROUTES.SURVEY_SCREEN, { @@ -35,21 +59,43 @@ export const TaskDetailsPage = () => { }) : ''; - const from = useFromLocation(); + if (task.taskStatus === TaskStatus.cancelled) return null; + if (task.taskStatus === TaskStatus.completed) { + if (!task.surveyResponseId) + return ( + + ); + return ( + + ); + } + return ( + + ); +}; + +export const TaskDetailsPage = () => { + const [errorModalOpen, setErrorModalOpen] = useState(false); + const { taskId } = useParams(); + const { data: task, isLoading } = useTask(taskId); + return ( <> - {showCompleteButton && ( - - - - - )} + + setErrorModalOpen(true)} /> + {task && } + {isLoading && } {task && } + setErrorModalOpen(false)} /> ); };