-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(datatrakWeb): RN-1339: View completed survey response from task #5789
Merged
alexd-bes
merged 10 commits into
rn-1339-survey-response-to-modal
from
rn-1339-view-completed-response
Jul 18, 2024
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ef8ae51
Create survey_response_id column
alexd-bes 8bbf28b
Update change handler
alexd-bes 030e6ff
Merge branch 'rn-1339-survey-response-to-modal' into rn-1339-view-com…
alexd-bes cd3ae75
View completed survey
alexd-bes b009a73
Error handling
alexd-bes 0c26118
Fix comment
alexd-bes 9648668
fix tasks button
tcaiger fe4a457
removeTaskFilterSetting on logout
tcaiger 632e2b6
Merge branch 'epic-tasks' into rn-1339-view-completed-response
alexd-bes aec25ed
PR fixes
alexd-bes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
* 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'; | ||
|
@@ -20,13 +21,35 @@ const ButtonWrapper = styled.div` | |
flex: 1; | ||
`; | ||
|
||
const ErrorModal = ({ isOpen, onClose }) => { | ||
return ( | ||
<Modal | ||
title="Error loading survey response" | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
buttons={[ | ||
{ | ||
text: 'Close', | ||
onClick: onClose, | ||
id: 'close', | ||
}, | ||
]} | ||
> | ||
<ModalCenteredContent> | ||
<Typography> | ||
This response has since been deleted in the admin panel. Please contact your system | ||
administrator for further questions. | ||
</Typography> | ||
</ModalCenteredContent> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export const TaskDetailsPage = () => { | ||
const [errorModalOpen, setErrorModalOpen] = useState(false); | ||
const { taskId } = useParams(); | ||
const { data: task, isLoading } = useTask(taskId); | ||
|
||
const showCompleteButton = | ||
task && task.taskStatus !== TaskStatus.completed && task.taskStatus !== TaskStatus.cancelled; | ||
|
||
const surveyUrl = task | ||
? generatePath(ROUTES.SURVEY_SCREEN, { | ||
countryCode: task?.entity?.countryCode, | ||
|
@@ -36,20 +59,41 @@ export const TaskDetailsPage = () => { | |
: ''; | ||
|
||
const from = useFromLocation(); | ||
|
||
const ButtonComponent = () => { | ||
if (!task) return null; | ||
if (task.taskStatus === TaskStatus.cancelled) return null; | ||
if (task.taskStatus === TaskStatus.completed) { | ||
if (!task.surveyResponseId) | ||
return ( | ||
<Button onClick={() => setErrorModalOpen(true)} variant="outlined"> | ||
View completed survey | ||
</Button> | ||
); | ||
return ( | ||
<Button to={`?responseId=${task.surveyResponseId}`} variant="outlined"> | ||
View completed survey | ||
</Button> | ||
); | ||
} | ||
return ( | ||
<Button to={surveyUrl} state={{ from }}> | ||
Complete | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this should be "Complete task" too? |
||
</Button> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<TaskPageHeader title="Task details"> | ||
{showCompleteButton && ( | ||
<ButtonWrapper> | ||
<Button to={surveyUrl} state={{ from }}> | ||
Complete | ||
</Button> | ||
<TaskActionsMenu {...task} /> | ||
</ButtonWrapper> | ||
)} | ||
<ButtonWrapper> | ||
<ButtonComponent /> | ||
{task && <TaskActionsMenu {...task} />} | ||
</ButtonWrapper> | ||
</TaskPageHeader> | ||
{isLoading && <SpinningLoader />} | ||
{task && <TaskDetails task={task} />} | ||
<ErrorModal isOpen={errorModalOpen} onClose={() => setErrorModalOpen(false)} /> | ||
</> | ||
); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be nice to make the ButtonComponent a stand alone component outside of the TaskDetails body and just pass in task as a prop.