-
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
WAITP-1452: Recent survey response page #5157
Merged
tcaiger
merged 27 commits into
datatrak-web-epic
from
waitp-1452-recent-survey-response
Nov 13, 2023
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
eaaf19f
WAITP-1478 Add types definition for RecentSurveyResponseRoute
EMcQ-BES 78c41d8
WAITP-1478 Regen types
EMcQ-BES 3f2b785
WAITP-1478 Add route for RecentSurveyResponse
EMcQ-BES 86bbac7
WAITP-1478 Fixup export
EMcQ-BES ee927d9
WAITP-1478 Update url
EMcQ-BES ffad9f1
WAITP-1478 Regen types
EMcQ-BES 52bc53b
WAITP-1478 Merge branch 'datatrak-web-epic' into waitp-1478-recent-su…
EMcQ-BES 33796e9
useSurveyResponse
tcaiger a60ad2c
survey review screen
tcaiger f537152
Merge branch 'datatrak-web-epic' into waitp-1452-recent-survey-response
tcaiger fe2ad00
wip set default values
tcaiger 9dcfbb9
set up route
tcaiger 2794127
Update useLogin.ts
tcaiger c7b6535
refactor survey context to be at survey level
tcaiger 83a599d
Merge branch 'datatrak-web-epic' into waitp-1452-refactor-survey-context
tcaiger 093cfac
Merge branch 'waitp-1452-refactor-survey-context' into waitp-1452-rec…
tcaiger ad4ca1f
remove bad merge
tcaiger 713410a
survey data
tcaiger d0634e3
basic working setup
tcaiger 428c54f
Merge branch 'datatrak-web-epic' into waitp-1452-recent-survey-response
tcaiger b330e94
remove debug changes
tcaiger 62fbb4f
split out paginator
tcaiger aed8a00
put page back in survey layout
tcaiger 25604c9
refactor layout components
tcaiger 762168b
Update index.ts
tcaiger 006c683
Update SurveyContext.tsx
tcaiger 862e048
Update SurveyReviewSection.tsx
tcaiger 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
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
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
16 changes: 16 additions & 0 deletions
16
packages/datatrak-web/src/api/queries/useSurveyResponse.ts
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import { useQuery } from 'react-query'; | ||
import { DatatrakWebSingleSurveyResponseRequest } from '@tupaia/types'; | ||
import { get } from '../api'; | ||
|
||
export const useSurveyResponse = (surveyResponseId?: string) => { | ||
return useQuery( | ||
['surveyResponse', surveyResponseId], | ||
(): Promise<DatatrakWebSingleSurveyResponseRequest.ResBody> => | ||
get(`surveyResponse/${surveyResponseId}`), | ||
{ enabled: !!surveyResponseId }, | ||
); | ||
}; |
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
83 changes: 83 additions & 0 deletions
83
packages/datatrak-web/src/features/Survey/Components/SurveyPaginator.tsx
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { useOutletContext } from 'react-router-dom'; | ||
import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos'; | ||
import { useSurveyForm } from '../SurveyContext'; | ||
import { Button } from '../../../components'; | ||
import { useIsMobile } from '../../../utils'; | ||
|
||
const FormActions = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 1rem 0.5rem; | ||
border-top: 1px solid ${props => props.theme.palette.divider}; | ||
button:last-child { | ||
margin-left: auto; | ||
} | ||
${({ theme }) => theme.breakpoints.up('md')} { | ||
padding: 1rem; | ||
} | ||
`; | ||
|
||
const ButtonGroup = styled.div` | ||
display: flex; | ||
button, | ||
a { | ||
&:last-child { | ||
margin-left: 1rem; | ||
} | ||
} | ||
`; | ||
|
||
const BackButton = styled(Button).attrs({ | ||
startIcon: <ArrowBackIosIcon />, | ||
variant: 'text', | ||
color: 'default', | ||
})` | ||
${({ theme }) => theme.breakpoints.down('md')} { | ||
padding-left: 0.8rem; | ||
.MuiButton-startIcon { | ||
margin-right: 0.25rem; | ||
} | ||
} | ||
`; | ||
|
||
type SurveyLayoutContextT = { isLoading: boolean; onStepPrevious: () => void }; | ||
|
||
export const SurveyPaginator = () => { | ||
const { isLast, isReviewScreen, openCancelConfirmation } = useSurveyForm(); | ||
const isMobile = useIsMobile(); | ||
const { isLoading, onStepPrevious } = useOutletContext<SurveyLayoutContextT>(); | ||
|
||
const getNextButtonText = () => { | ||
if (isReviewScreen) return 'Submit'; | ||
if (isLast) { | ||
return isMobile ? 'Review' : 'Review and submit'; | ||
} | ||
return 'Next'; | ||
}; | ||
|
||
const nextButtonText = getNextButtonText(); | ||
|
||
return ( | ||
<FormActions> | ||
<BackButton onClick={onStepPrevious} disabled={isLoading}> | ||
Back | ||
</BackButton> | ||
<ButtonGroup> | ||
<Button onClick={openCancelConfirmation} variant="outlined" disabled={isLoading}> | ||
Cancel | ||
</Button> | ||
<Button type="submit" disabled={isLoading}> | ||
{nextButtonText} | ||
</Button> | ||
</ButtonGroup> | ||
</FormActions> | ||
); | ||
}; |
79 changes: 79 additions & 0 deletions
79
packages/datatrak-web/src/features/Survey/Components/SurveyReviewSection.tsx
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import React from 'react'; | ||
import { QuestionType } from '@tupaia/types'; | ||
import { SurveyQuestionGroup } from './SurveyQuestionGroup.tsx'; | ||
import { useSurveyForm } from '../SurveyContext'; | ||
import { formatSurveyScreenQuestions, getSurveyScreenNumber } from '../utils'; | ||
import styled from 'styled-components'; | ||
import { Typography } from '@material-ui/core'; | ||
|
||
const Section = styled.section` | ||
padding: 1rem 0; | ||
&:first-child { | ||
padding-top: 0; | ||
} | ||
`; | ||
|
||
const SectionHeader = styled(Typography).attrs({ | ||
variant: 'h3', | ||
})` | ||
font-size: 1rem; | ||
font-weight: ${({ theme }) => theme.typography.fontWeightMedium}; | ||
margin-bottom: 1rem; | ||
${({ theme }) => theme.breakpoints.up('sm')} { | ||
font-size: 1.125rem; | ||
} | ||
`; | ||
|
||
const Fieldset = styled.fieldset.attrs({ | ||
disabled: true, | ||
})` | ||
border: none; | ||
margin: 0; | ||
padding: 0; | ||
input, | ||
label, | ||
button, | ||
.MuiInputBase-root, | ||
link { | ||
pointer-events: none; | ||
} | ||
`; | ||
export const SurveyReviewSection = () => { | ||
const { visibleScreens } = useSurveyForm(); | ||
|
||
if (!visibleScreens || !visibleScreens.length) { | ||
return null; | ||
} | ||
|
||
// split the questions into sections by screen so it's easier to read the long form | ||
const questionSections = visibleScreens.map(screen => { | ||
const { surveyScreenComponents } = screen; | ||
const screenNumber = getSurveyScreenNumber(visibleScreens, screen); | ||
const heading = surveyScreenComponents[0].text; | ||
const firstQuestionIsInstruction = surveyScreenComponents[0].type === QuestionType.Instruction; | ||
|
||
// if the first question is an instruction, don't display it, because it will be displayed as the heading | ||
const questionsToDisplay = firstQuestionIsInstruction | ||
? surveyScreenComponents.slice(1) | ||
: surveyScreenComponents; | ||
return { | ||
heading, | ||
questions: formatSurveyScreenQuestions(questionsToDisplay, screenNumber), | ||
}; | ||
}); | ||
return ( | ||
<Fieldset> | ||
{questionSections.map(({ heading, questions }, index) => ( | ||
<Section key={index}> | ||
<SectionHeader>{heading}</SectionHeader> | ||
<SurveyQuestionGroup questions={questions} /> | ||
</Section> | ||
))} | ||
</Fieldset> | ||
); | ||
}; |
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
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
Oops, something went wrong.
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.
Just need to reorder these imports