Skip to content

Commit

Permalink
added fix to ensure survey answer persistence when moving to an alrea…
Browse files Browse the repository at this point in the history
…dy answered question
  • Loading branch information
cShingleton committed Sep 22, 2017
1 parent 21ba429 commit 634f0d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 13 additions & 3 deletions js/scenes/Surveys/Pages/Surveys.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Surveys = ({
question,
questions,
nextQuestion,
nextQuestionFunc,
previousQuestionFunc,
prevQuestion,
selectedValue,
Expand Down Expand Up @@ -59,7 +60,7 @@ const Surveys = ({
completePerc={questions.indexOf(question) + 1}
totalSteps={questions.length + 1}
/>
<RightNavArrow navAction={() => nextQuestion()} />
<RightNavArrow navAction={() => nextQuestionFunc(nextQuestion.question)} />
</View>
</View>
</ScrollView>
Expand All @@ -69,7 +70,8 @@ const Surveys = ({
export default Surveys;

Surveys.defaultProps = {
prevQuestion: null
prevQuestion: null,
nextQuestion: null
};

Surveys.propTypes = {
Expand All @@ -95,7 +97,15 @@ Surveys.propTypes = {
value: PropTypes.number
}))
})).isRequired,
nextQuestion: PropTypes.func.isRequired,
nextQuestion: PropTypes.shape({
quality: PropTypes.string,
question: PropTypes.string,
answers: PropTypes.arrayOf(PropTypes.shape({
answer: PropTypes.string,
value: PropTypes.number
}))
}),
nextQuestionFunc: PropTypes.func.isRequired,
previousQuestionFunc: PropTypes.func.isRequired,
prevQuestion: PropTypes.shape({
quality: PropTypes.string,
Expand Down
11 changes: 8 additions & 3 deletions js/scenes/Surveys/SurveysContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ class SurveysContainer extends Component {
goToSurveyComplete();
}

nextQuestion = () => {
nextQuestion = (nextQuestion) => {
const selectedAnswer = this.props.surveyAnswers[nextQuestion];
if (this.state.selectedValue === -1) {
this.setState({ showWarningModal: true });
} else {
this.setState({ n: this.state.n + 1, selectedValue: -1 });
this.setState({
n: this.state.n + 1,
selectedValue: (selectedAnswer) ? selectedAnswer.value : -1
});
}
}

Expand Down Expand Up @@ -104,9 +108,10 @@ class SurveysContainer extends Component {
displayGoalModal={this.displayGoalModal}
questions={questions}
question={questions[n]}
nextQuestion={this.nextQuestion}
nextQuestionFunc={this.nextQuestion}
previousQuestionFunc={this.previousQuestion}
prevQuestion={questions[n - 1]}
nextQuestion={questions[n + 1]}
selectedValue={selectedValue}
/>
);
Expand Down

0 comments on commit 634f0d3

Please sign in to comment.