diff --git a/src/App.js b/src/App.js index dc1a1552a2b86c4e976696753e990a34d901f587..62e03f3c12c6161be85583fcba8b2eda75c6324e 100644 --- a/src/App.js +++ b/src/App.js @@ -49,14 +49,6 @@ class App extends React.Component { EMAIL: '', PHONE: '', }, - factors: { - fuel: '', - heatDistribution: '', - heatingSystemAge: '', - heatingSystemPlan: '', - buildingTypes: '', - boiler: '', - }, prevQuestion: '', question: 'addressSearch', // Set the first question as address search when initializing reviewQuestions: [], @@ -92,7 +84,7 @@ class App extends React.Component { value: '', answerIds: [3, 4, 5, 6, 7], answers: { 3: 'fuelOil', 4: 'naturalGas', 5: 'electricResistance', 6: 'dualFuel', 7: 'other' }, - prev: 'addressSearch', + prev: 'buildingTypes', next: 'heatDistribution', }, heatDistribution: { @@ -137,17 +129,17 @@ class App extends React.Component { questionIds: [52, 53, 54, 55, 56, 57], answers: [0, 0, 0, 0, 0, 0], prev: 'heatingSystemPlan', - next: 'buildingTypes', + next: '', }, buildingTypes: { id: 6, - title: 'Which kind of building do you have?', + title: 'Which type of building do you have?', answer: '', value: '', answerIds: [20, 21, 23, 22, 32, 33], answers: { 20: 'singleFamily', 21: 'multiFamily', 23: 'coop', 22: 'mixedUse', 32: 'church', 33: 'other' }, prev: 'unitBreakdown', - next: '', + next: 'fuels', }, utilityBills: { title: 'Who pays the following utility bills?', @@ -167,7 +159,7 @@ class App extends React.Component { answerIds: [24, 25], }, ], - prev: 'buildingTypes', + prev: 'unitBreakdown', next: 'comfortIssues', }, comfortIssues: { @@ -708,6 +700,35 @@ class App extends React.Component { }); } }); + + this.updateQuestionChain(question, value); + } + + updateQuestionChain = (question, value) => { + let questions = this.state.questions; + if (question === 'buildingTypes'){ + if ([21,22].includes(value)){ + questions['heatingSystemPlan'].next = 'unitBreakdown'; + questions['unitBreakdown'].next = 'utilityBills'; + questions['utilityBills'].prev = 'unitBreakdown'; + questions['reviewAnswers'].next = 'congrats'; + } + else{ + questions['unitBreakdown'].next = 'financeInterest'; + questions['financeInterest'].prev = 'unitBreakdown'; + } + } + if (question === 'buildingTypes' && value === 20){ + questions['heatingSystemPlan'].next = 'waitList'; + questions['waitList'].prev = 'heatingSystemPlan'; + } + if (questions['unitBreakdown']['value'] !== 20 && + question === 'fuels' && [4,6].includes(value)){ + this.setState({ buildingQualified: true}); + this.state.pages.congrats = ; + } } submitContact = (contact) => { @@ -768,182 +789,6 @@ class App extends React.Component { }); } - setFuelType = (fuel) => { - this.setState({ - factors: { - ...this.state.factors, - fuel, - }, - }); - } - - setHeatDistribution = (heatDistribution) => { - this.setState({ - factors: { - ...this.state.factors, - heatDistribution, - }, - }); - } - - setSeparateBoiler = (boiler) => { - this.setState({ - factors: { - ...this.state.factors, - boiler, - }, - }); - } - - setHeatingSystemAge = (heatingSystemAge) => { - this.setState({ - factors: { - ...this.state.factors, - heatingSystemAge, - }, - }); - } - - setBuildingHeatingSystem = (buildingHeatingSystem) => { - this.setState({ - factors: { - ...this.state.factors, - buildingHeatingSystem, - }, - }); - } - - setBuildingCoolingSystem = (buildingCoolingSystem) => { - this.setState({ - factors: { - ...this.state.factors, - buildingCoolingSystem, - }, - }); - } - - setHeatingSystemPlan = (heatingSystemPlan) => { - this.setState({ - factors: { - ...this.state.factors, - heatingSystemPlan, - }, - }); - } - - setBuildingElectricityShutoff = (buildingElectricityShutoff) => { - this.setState({ - factors: { - ...this.state.factors, - buildingElectricityShutoff, - }, - }); - } - - setBuildingMedicalDevices = (buildingMedicalDevices) => { - this.setState({ - factors: { - ...this.state.factors, - buildingMedicalDevices, - }, - }); - } - - setBuildingType = (buildingTypes, answer, value) => { - this.setState({ - factors: { - ...this.state.factors, - buildingTypes, - }, - }, () => { - const questions = this.state.questions; - questions['buildingTypes'].answer = answer; - questions['buildingTypes'].value = value; - - if (value !== this.multiFamilyAnswerId) { - questions['utilityBills'].questions[0].answer = ''; - questions['utilityBills'].questions[1].answer = ''; - questions['utilityBills'].questions[0].value = 0; - questions['utilityBills'].questions[1].value = 0; - questions['comfortIssues'].answer = []; - questions['comfortIssues'].value = []; - } - - this.setState({ questions }, () => { - this.updateNextQuestion(value); - }); - }); - } - - updateNextQuestion = (answer) => { - let found = false; - questionTree.forEach(tree => { - if ( - tree.input.fuels.includes(this.state.factors.fuel) && - tree.input.heatDistribution.includes(this.state.factors.heatDistribution) && - tree.input.heatingSystemAge.includes(this.state.factors.heatingSystemAge) && - tree.input.heatingSystemPlan.includes(this.state.factors.heatingSystemPlan) && - tree.input.buildingTypes.includes(this.state.factors.buildingTypes) - ) { - found = true; - const questions = this.state.questions; - questions.buildingTypes.next = tree.output.nextQuestion; - questions[tree.output.finalQuestion].next = tree.output.finalPage; - - if (this.state.factors.fuel === 4 || this.state.factors.fuel === 6) { - this.setState({ buildingQualified: true}); - if (this.state.factors.buildingTypes === 21 || this.state.factors.buildingTypes === 22) { - questions.reviewAnswers.next = 'congrats'; - } - this.state.pages.congrats = ; - } - - if ((this.state.factors.buildingTypes === 21 || this.state.factors.buildingTypes === 22) && this.state.factors.heatDistribution !== 10) { - questions.financeInterest.prev = 'comfortIssues'; - this.setState({ buildingQualified: true}); - } else { - this.setState({ buildingQualified: true}); - questions.financeInterest.prev = 'buildingTypes'; - } - - if (this.state.factors.buildingTypes === 20) { - this.setState({ buildingQualified: false}); - } - - questions.contact.next = "reviewAnswers"; - this.setState({ questions }, () => { - this.setQuestion(tree.output.nextQuestion); - }); - } - }); - - if (found === false) { - const questions = this.state.questions; - if (this.state.factors.buildingTypes === 21 || this.state.factors.buildingTypes === 22) { - questions.buildingTypes.next = 'utilityBills'; - questions.financeInterest.prev = 'comfortIssues'; - } else { - questions.buildingTypes.next = 'financeInterest'; - questions.financeInterest.prev = 'buildingTypes'; - } - questions.reviewAnswers.next = 'thankYou'; - questions.contact.next = "reviewAnswers"; - this.setState({ questions }, () => { - this.setQuestion(questions.buildingTypes.next); - }); - } - - this.props.onSubmitAnswer({ - questionId: ["6"], - answerId: [answer], - buildingId: this.props.building.data.buildingId, - surveyId: this.props.building.data.surveyId, - userId: this.props.building.data.userId, - }); - } - submit = () => { // 20 is the id for single family building type if (this.state.questions.buildingTypes.value === 20) { @@ -1078,7 +923,6 @@ class App extends React.Component { prevQuestion={this.prevQuestion} nextQuestion={this.nextQuestion} setBuildingType={this.setBuildingType} - updateNextQuestion={this.updateNextQuestion} answer={this.state.questions['buildingTypes'].value} answerIds={this.state.questions['buildingTypes'].answerIds} answers={this.state.questions['buildingTypes'].answers} @@ -1189,15 +1033,11 @@ class App extends React.Component { if (this.props.building.data !== undefined && this.props.building.data.buildingId !== undefined && Object.keys(this.state.questions).indexOf(this.state.question) > -1) { - if (this.state.question === 'addressSearch') { - // If we are in the address search question and we have building data set the content to the next question depending on survey id - if(this.props.building.data.surveyId === 1) { - // For NYC go to the fuel type question - content = questions['fuels']; - } else if ([2, 3].includes(this.props.building.data.surveyId)) { - // For Oakland and NYC go to the Building Type/ Subtype question - content = questions['buildingTypeSubType']; - } + if (this.state.question === 'addressSearch' && this.props.building.data.surveyId === 1) { + content = questions['buildingTypes']; + } + else if (this.state.question === 'addressSearch' && [2,3].includes(this.props.building.data.surveyId)){ + content = questions['buildingTypeSubType']; } else { content = questions[this.state.question]; } diff --git a/src/BuildingTypes.js b/src/BuildingTypes.js index 26a4749ce4d57380f83022bba38829978abf1c68..d8ae558d35f4ade25eac659afd681c859cb010ac 100644 --- a/src/BuildingTypes.js +++ b/src/BuildingTypes.js @@ -45,8 +45,8 @@ export default class BuildingTypes extends React.Component { label: "building-type" }); } - this.props.setBuildingType( - this.state.answer, + this.props.nextQuestion( + 'buildingTypes', this.names[this.props.answerIds.indexOf(this.state.answer)], this.state.answer, ); @@ -101,14 +101,6 @@ export default class BuildingTypes extends React.Component { - - - {'<'} Back - - + + + {'<'} Back + + - Unfortunately, we're only serving multi-family buildings at this time. - Would you like to join our Waitlist? If so, we'll reach out if anything changes. + Unfortunately, your building doesn’t match with a profile we service at this time. + Please join our Waitlist so we can reach out if anything changes. diff --git a/src/constants.js b/src/constants.js index 501ccdcea42c27ebd012a664104f56d96ef6b184..edfb1ec44a4c6ffc7cd36126ddeedde67ddf4e2b 100644 --- a/src/constants.js +++ b/src/constants.js @@ -146,7 +146,7 @@ const initialQuestions = { }, buildingTypes: { id: 6, - title: 'Which kind of building do you have?', + title: 'Which type of building do you have?', answer: 0, value: '', answerIds: [20, 21, 22, 23, 32, 33],