Skip to content

Commit

Permalink
Merge pull request redacademy#129 from redacademy/survey-persist-answers
Browse files Browse the repository at this point in the history
added fix to ensure survey answer persistence
  • Loading branch information
codedavinci authored Sep 22, 2017
2 parents 21ba429 + b82851f commit 67ffa9e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 38 deletions.
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':
return initialState;
case 'SET_SURVEY_ANSWERS':
return {
...state,
Expand Down
4 changes: 2 additions & 2 deletions js/scenes/Speaker/SpeakerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { auth } from '../../config/firebase';
import Loader from '../../components/Loader';
import { goToSurvey } from '../../navigation/navHelpers';
import Speaker from './Speaker';
Expand Down Expand Up @@ -39,8 +40,7 @@ class SpeakerContainer extends Component {

checkRespondent = () => {
const currTalk = this.props.speakerData.item.talk_id;
// using a static id for testing
const currUser = 'dKJaZ8tuniPW1Ee2BduSQQ8wSsp2';
const currUser = auth.currentUser.uid;
return this.props.talkData[currTalk].respondents[currUser];
}

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

0 comments on commit 67ffa9e

Please sign in to comment.