Skip to content
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

added fix to ensure survey answer persistence #129

Merged
merged 5 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions js/redux/modules/actions/surveyActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export function setTalkData(talkData) {
return { type: 'SET_TALK_DATA', talkData }
}

export function resetSurvey() {
return { type: 'RESET_SURVEY' };
}

export function setSurveyAnswers(surveyAnswers) {
return { type: 'SET_SURVEY_ANSWERS', surveyAnswers };
Expand Down
2 changes: 2 additions & 0 deletions js/redux/modules/reducers/surveyReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const initialState = {

export function SurveyReducer(state = initialState, action) {
switch (action.type) {
case 'RESET_SURVEY':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the default case as a fallback
Ex:

case 'RESET_SURVEY': default: return state

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, should of thought of that. Thanks, Eddie.

return initialState;
case 'SET_SURVEY_ANSWERS':
return {
...state,
Expand Down
68 changes: 38 additions & 30 deletions js/scenes/SurveyComplete/SurveyComplete.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
import React from 'react'
import React, { Component } from 'react'
import { Text, View } from 'react-native';
import { connect } from 'react-redux';

import { resetSurvey } from '../../redux/modules/actions/surveyActions';
import { styles } from './styles';
import SurveyButton from '../../components/SurveyButton';
import { returnToHome, returnToEvents, returnToSpeaker } from '../../navigation/navHelpers';

const SurveyCompleteContainer = () => {
const buttons = [
{ text: "Home", action: returnToHome },
{ text: "Events", action: returnToEvents },
{ text: "Speaker's Page", action: returnToSpeaker }
];
class SurveyCompleteContainer extends Component {

return (
<View style={styles.sceneContainer}>
<View style={styles.background}>
<View style={styles.contentContainer}>
<Text style={styles.title}>Thanks!</Text>
<Text style={styles.text}>Your feedback has been submitted.</Text>
{buttons.map(button => (
<SurveyButton
key={button.text}
text={button.text}
onPress={() => button.action()}
cStyle={styles.buttonContainer}
/>
))}
static route = {
navigationBar: {
title: "Submit Complete",
renderLeft: () => null
}
}

componentDidMount() {
this.props.dispatch(resetSurvey());
}

render() {
const buttons = [
{ text: "Home", action: returnToHome },
{ text: "Events", action: returnToEvents },
{ text: "Speaker's Page", action: returnToSpeaker }
];
return (
<View style={styles.sceneContainer}>
<View style={styles.background}>
<View style={styles.contentContainer}>
<Text style={styles.title}>Thanks!</Text>
<Text style={styles.text}>Your feedback has been submitted.</Text>
{buttons.map(button => (
<SurveyButton
key={button.text}
text={button.text}
onPress={() => button.action()}
cStyle={styles.buttonContainer}
/>
))}
</View>
</View>
</View>
</View>
)
}

SurveyCompleteContainer.route = {
navigationBar: {
title: "Submit Complete",
renderLeft: () => null
)
}
}

export default SurveyCompleteContainer;
export default connect()(SurveyCompleteContainer);
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 && 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