From 4815fd0861d872d80f4487d08af077c74a40ec45 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Thu, 4 Jun 2020 13:20:23 -0400 Subject: [PATCH 01/33] continue to review page after edit --- src/App.js | 21 +++++++++++++++++++++ src/ReviewAnswers.js | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 13d7d288d..16b69210d 100644 --- a/src/App.js +++ b/src/App.js @@ -86,6 +86,7 @@ class App extends React.Component { miniSplitCheckBox: false, anotherBuildingSubmitted: false, isReferral: false, + isEdit: false, }; } @@ -838,6 +839,13 @@ class App extends React.Component { if (question === 'anotherBuilding') { questions['churchBuildingType']['prev'] = 'anotherBuilding'; } + console.log(this.state.isEdit); + if (this.state.isEdit) { + console.log('before', questions[question]) + questions[question]['next'] = 'reviewAnswers'; + console.log('after', questions[question]) + this.setState({ questions, isEdit: false }); + } const updatedOrder = questions.order.filter(item => item !== question); updatedOrder.push(question); @@ -891,6 +899,12 @@ class App extends React.Component { updateQuestionChain = (question, value) => { let questions = this.state.questions; + // console.log(this.state.isEdit, question); + // if (this.state.isEdit) { + // console.log('yessss', questions[question]); + // questions['buildingCoolingSystem'].next = 'reviewAnswers'; + // console.log('after', questions[question]) + // } if (question === 'buildingTypes'){ // Set the next question for building types. // If religious institute next page -> Church Building Type @@ -1167,6 +1181,12 @@ class App extends React.Component { }); } + setEdit = (question) => { + this.setState({ + isEdit: true, + }); + } + submitReferral = (form) => { const metaObj = this.getMeta(); this.props.onSubmitReferral({ @@ -1348,6 +1368,7 @@ class App extends React.Component { questions={this.state.questions} form={this.state.form} editAnswer={this.setQuestion} + setEdit={this.setEdit} />, buildingTypeSubType: { this.props.editAnswer(question); + this.setEdit(question); + } + + setEdit = (question) => { + this.props.setEdit(question); } submit = () => { -- GitLab From 8957289e64108c0c8089d8e800b54c3b1b4fa92c Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Thu, 4 Jun 2020 13:33:45 -0400 Subject: [PATCH 02/33] removed comments --- src/App.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/App.js b/src/App.js index 16b69210d..34fe965ba 100644 --- a/src/App.js +++ b/src/App.js @@ -899,12 +899,6 @@ class App extends React.Component { updateQuestionChain = (question, value) => { let questions = this.state.questions; - // console.log(this.state.isEdit, question); - // if (this.state.isEdit) { - // console.log('yessss', questions[question]); - // questions['buildingCoolingSystem'].next = 'reviewAnswers'; - // console.log('after', questions[question]) - // } if (question === 'buildingTypes'){ // Set the next question for building types. // If religious institute next page -> Church Building Type -- GitLab From 33fc421fd5744098375e2a491ed2cbfd02e7f046 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 4 Jun 2020 14:40:53 -0400 Subject: [PATCH 03/33] add function to edit answer --- src/App.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/App.js b/src/App.js index 34fe965ba..e98330d82 100644 --- a/src/App.js +++ b/src/App.js @@ -839,13 +839,6 @@ class App extends React.Component { if (question === 'anotherBuilding') { questions['churchBuildingType']['prev'] = 'anotherBuilding'; } - console.log(this.state.isEdit); - if (this.state.isEdit) { - console.log('before', questions[question]) - questions[question]['next'] = 'reviewAnswers'; - console.log('after', questions[question]) - this.setState({ questions, isEdit: false }); - } const updatedOrder = questions.order.filter(item => item !== question); updatedOrder.push(question); @@ -1097,6 +1090,14 @@ class App extends React.Component { this.setState({ anotherBuildingSubmitted: false, }); } + editAnswer = (question) => { + let questions = this.state.questions; + questions[question]['next'] = 'reviewAnswers'; + this.setState({ questions }, () => { + this.setQuestion(question); + }); + } + setQuestion = (question) => { let questions = this.state.questions; // If the current question is financeInterset set financeInterset as prev page for contact @@ -1175,12 +1176,6 @@ class App extends React.Component { }); } - setEdit = (question) => { - this.setState({ - isEdit: true, - }); - } - submitReferral = (form) => { const metaObj = this.getMeta(); this.props.onSubmitReferral({ @@ -1361,8 +1356,7 @@ class App extends React.Component { submit={this.submit} questions={this.state.questions} form={this.state.form} - editAnswer={this.setQuestion} - setEdit={this.setEdit} + editAnswer={this.editAnswer} />, buildingTypeSubType: Date: Thu, 4 Jun 2020 14:45:58 -0400 Subject: [PATCH 04/33] removed unnecessary states --- src/App.js | 1 - src/ReviewAnswers.js | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/App.js b/src/App.js index e98330d82..aa2bf7d3d 100644 --- a/src/App.js +++ b/src/App.js @@ -86,7 +86,6 @@ class App extends React.Component { miniSplitCheckBox: false, anotherBuildingSubmitted: false, isReferral: false, - isEdit: false, }; } diff --git a/src/ReviewAnswers.js b/src/ReviewAnswers.js index 1466b6dc2..15379b965 100644 --- a/src/ReviewAnswers.js +++ b/src/ReviewAnswers.js @@ -22,11 +22,6 @@ export default class ReviewAnswers extends React.Component { editAnswer = (question) => { this.props.editAnswer(question); - this.setEdit(question); - } - - setEdit = (question) => { - this.props.setEdit(question); } submit = () => { -- GitLab From d552e04f225eaa9f7e645700213daea0d0bfa1e3 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 4 Jun 2020 21:17:34 -0400 Subject: [PATCH 05/33] Temprory commit --- src/App.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index aa2bf7d3d..8509239f9 100644 --- a/src/App.js +++ b/src/App.js @@ -819,6 +819,7 @@ class App extends React.Component { } nextQuestion = (question, answer, value) => { + console.log(this.state.questions); const questionAnswers = {}; const questions = this.state.questions; if (Array.isArray(answer) === true && questions[question]['questions'] !== undefined) { @@ -890,6 +891,9 @@ class App extends React.Component { } updateQuestionChain = (question, value) => { + console.log(question); + console.log(value); + console.log(this.state.questions); let questions = this.state.questions; if (question === 'buildingTypes'){ // Set the next question for building types. @@ -1019,6 +1023,7 @@ class App extends React.Component { anotherBuilding={this.anotherBuilding} />; } + console.log(this.state.questions); } anotherBuilding = () => { @@ -1090,9 +1095,25 @@ class App extends React.Component { } editAnswer = (question) => { + console.log(question); + console.log(this.state.questions); let questions = this.state.questions; - questions[question]['next'] = 'reviewAnswers'; + console.log(questions[question].next); + questions[question].next = 'reviewAnswers'; + console.log(questions[question].next); + console.log(questions); + + // let questions = { + // ...state, + // questions: { + // ...state.questions, + // loading: true, + // error: false, + // }, + // }; + this.setState({ questions }, () => { + console.log(this.state.questions); this.setQuestion(question); }); } -- GitLab From 9a4a69db46a341d1ca22c51f8f0c15f003eaa017 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 5 Jun 2020 11:52:35 -0400 Subject: [PATCH 06/33] temporary commit --- src/App.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/App.js b/src/App.js index 8509239f9..96f5f2800 100644 --- a/src/App.js +++ b/src/App.js @@ -1099,7 +1099,9 @@ class App extends React.Component { console.log(this.state.questions); let questions = this.state.questions; console.log(questions[question].next); + questions[question].prev = 'prev'; questions[question].next = 'reviewAnswers'; + questions[question].value = 'value'; console.log(questions[question].next); console.log(questions); @@ -1484,6 +1486,8 @@ class App extends React.Component { } else if (this.state.anotherBuildingSubmitted) { content = questions['churchBuildingType']; } else { + console.log(this.state.questions); + console.log(this.state.question); content = questions[this.state.question]; } } else if (Object.keys(this.state.pages).indexOf(this.state.question) > -1) { -- GitLab From 874be0a7f91585d0b56b2fc7211daffa96c99c1e Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 5 Jun 2020 12:33:54 -0400 Subject: [PATCH 07/33] changing dict key value but still not working --- src/App.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/App.js b/src/App.js index aa2bf7d3d..449eb19bd 100644 --- a/src/App.js +++ b/src/App.js @@ -1091,6 +1091,12 @@ class App extends React.Component { editAnswer = (question) => { let questions = this.state.questions; + if ([2, 3].includes(this.props.building.data.surveyId) && question === 'buildingCoolingSystem') { + questions['buildingCoolingSystem'].next = 'reviewAnswers'; + } + if ([2, 3].includes(this.props.building.data.surveyId) && question === 'buildingHeatingSystem') { + questions['buildingCoolingSystem'].next = 'reviewAnswers'; + } questions[question]['next'] = 'reviewAnswers'; this.setState({ questions }, () => { this.setQuestion(question); -- GitLab From f9059bd60f6fa4f02c71d2a0352fdb958400b3e4 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 5 Jun 2020 13:58:55 -0400 Subject: [PATCH 08/33] Fix push not working issue --- src/App.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index 1e71c4a13..4e4cf28e5 100644 --- a/src/App.js +++ b/src/App.js @@ -1104,11 +1104,11 @@ class App extends React.Component { if ([2, 3].includes(this.props.building.data.surveyId) && question === 'buildingHeatingSystem') { questions['buildingCoolingSystem'].next = 'reviewAnswers'; } - questions[question]['next'] = 'reviewAnswers'; + // questions[question]['next'] = 'reviewAnswers'; console.log(questions[question].next); - questions[question].prev = 'prev'; + // questions[question].prev = 'prev'; questions[question].next = 'reviewAnswers'; - questions[question].value = 'value'; + // questions[question].value = 'value'; console.log(questions[question].next); console.log(questions); -- GitLab From 3e52250f27ac868f07431fdc8c53a64d0697332e Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 5 Jun 2020 15:36:28 -0400 Subject: [PATCH 09/33] Update question order after complete edit answer --- src/App.js | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/src/App.js b/src/App.js index 4e4cf28e5..c8031e26b 100644 --- a/src/App.js +++ b/src/App.js @@ -86,6 +86,7 @@ class App extends React.Component { miniSplitCheckBox: false, anotherBuildingSubmitted: false, isReferral: false, + isEdit: false, }; } @@ -819,7 +820,6 @@ class App extends React.Component { } nextQuestion = (question, answer, value) => { - console.log(this.state.questions); const questionAnswers = {}; const questions = this.state.questions; if (Array.isArray(answer) === true && questions[question]['questions'] !== undefined) { @@ -840,9 +840,9 @@ class App extends React.Component { questions['churchBuildingType']['prev'] = 'anotherBuilding'; } - const updatedOrder = questions.order.filter(item => item !== question); - updatedOrder.push(question); - questions.order = updatedOrder; + if(!questions.order.includes(question)) { + questions.order.push(question); + } const metaObj = this.getMeta(); this.setState({ questions }, () => { @@ -891,9 +891,6 @@ class App extends React.Component { } updateQuestionChain = (question, value) => { - console.log(question); - console.log(value); - console.log(this.state.questions); let questions = this.state.questions; if (question === 'buildingTypes'){ // Set the next question for building types. @@ -936,7 +933,9 @@ class App extends React.Component { questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' } - if([2,3].includes(this.props.building.data.surveyId) && this.state.miniSplitCheckBox === true) { + if([2,3].includes(this.props.building.data.surveyId) + && this.state.miniSplitCheckBox === true + && this.state.isEdit === false ) { questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; this.props.onSubmitAnswer({ @@ -946,8 +945,9 @@ class App extends React.Component { buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); - } - else{ + } else if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } else{ questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; } // Heating System for NYC Church PNS. @@ -1023,7 +1023,6 @@ class App extends React.Component { anotherBuilding={this.anotherBuilding} />; } - console.log(this.state.questions); } anotherBuilding = () => { @@ -1095,34 +1094,9 @@ class App extends React.Component { } editAnswer = (question) => { - console.log(question); - console.log(this.state.questions); let questions = this.state.questions; - if ([2, 3].includes(this.props.building.data.surveyId) && question === 'buildingCoolingSystem') { - questions['buildingCoolingSystem'].next = 'reviewAnswers'; - } - if ([2, 3].includes(this.props.building.data.surveyId) && question === 'buildingHeatingSystem') { - questions['buildingCoolingSystem'].next = 'reviewAnswers'; - } - // questions[question]['next'] = 'reviewAnswers'; - console.log(questions[question].next); - // questions[question].prev = 'prev'; questions[question].next = 'reviewAnswers'; - // questions[question].value = 'value'; - console.log(questions[question].next); - console.log(questions); - - // let questions = { - // ...state, - // questions: { - // ...state.questions, - // loading: true, - // error: false, - // }, - // }; - - this.setState({ questions }, () => { - console.log(this.state.questions); + this.setState({ isEdit: true, questions }, () => { this.setQuestion(question); }); } @@ -1493,8 +1467,6 @@ class App extends React.Component { } else if (this.state.anotherBuildingSubmitted) { content = questions['churchBuildingType']; } else { - console.log(this.state.questions); - console.log(this.state.question); content = questions[this.state.question]; } } else if (Object.keys(this.state.pages).indexOf(this.state.question) > -1) { -- GitLab From bce60a8dc99408878a75a880f87a04e18e0f82e4 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Mon, 8 Jun 2020 13:36:58 -0400 Subject: [PATCH 10/33] review page no cooling system question --- src/App.js | 9 +++++++-- src/ReviewAnswers.js | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index c8031e26b..49439a882 100644 --- a/src/App.js +++ b/src/App.js @@ -918,7 +918,7 @@ class App extends React.Component { questions['waitList'].prev = 'heatingSystemPlan'; } // For NYC Church survey, set feedback as the next page of building future improvement. - if (this.props.building.data.surveyId === 1) { + if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32) { questions['buildingFutureImprovement'].next = 'feedback'; questions['feedback'].prev = 'buildingFutureImprovement'; } @@ -928,7 +928,7 @@ class App extends React.Component { questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; } - else if (this.props.building.data.surveyId === 1 && question === 'buildingCoolingSystem') { + else if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' } @@ -945,6 +945,11 @@ class App extends React.Component { buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); + // console.log('before', this.state.questions); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + this.setState({ questions }); + // console.log('after', this.state.questions); } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; } else{ diff --git a/src/ReviewAnswers.js b/src/ReviewAnswers.js index 15379b965..a71575cb8 100644 --- a/src/ReviewAnswers.js +++ b/src/ReviewAnswers.js @@ -36,7 +36,9 @@ export default class ReviewAnswers extends React.Component { } render() { + console.log('review', this.props.questions); const questions = this.props.questions; + // console.log(questions); const phoneNumber = this.props.form.PHONE === 0 ? 'N/A' : this.props.form.PHONE; const content = (
@@ -47,6 +49,9 @@ export default class ReviewAnswers extends React.Component { { questions.order .map(question => { + console.log('order', questions.order); + // console.log('map q', questions); + // console.log('what is this', questions[question].questions); if (questions[question].questions !== undefined) { if (questions[question].questions.filter(question => ![0, ""].includes(question.value)).length > 0) { const smallQuestions = (question !== 'buildingWaterImprovement') ? -- GitLab From 17651281a745ea1e365ca66d016a03508dc817d4 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Mon, 8 Jun 2020 13:52:09 -0400 Subject: [PATCH 11/33] Add cooling system question to review order --- src/App.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/App.js b/src/App.js index 49439a882..c8c666021 100644 --- a/src/App.js +++ b/src/App.js @@ -948,6 +948,12 @@ class App extends React.Component { // console.log('before', this.state.questions); questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; questions.buildingCoolingSystem.value = 106; + + // Add cooling system question into review order + if(!questions.order.includes("buildingCoolingSystem")) { + questions.order.push("buildingCoolingSystem"); + } + this.setState({ questions }); // console.log('after', this.state.questions); } else if (this.state.isEdit) { -- GitLab From 7c0ce771d7f44c58afdb4674c306c8bd55fc1e65 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Mon, 8 Jun 2020 14:02:16 -0400 Subject: [PATCH 12/33] BI-1387 Complete --- src/App.js | 2 -- src/ReviewAnswers.js | 5 ----- 2 files changed, 7 deletions(-) diff --git a/src/App.js b/src/App.js index c8c666021..d66951f48 100644 --- a/src/App.js +++ b/src/App.js @@ -945,7 +945,6 @@ class App extends React.Component { buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); - // console.log('before', this.state.questions); questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; questions.buildingCoolingSystem.value = 106; @@ -955,7 +954,6 @@ class App extends React.Component { } this.setState({ questions }); - // console.log('after', this.state.questions); } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; } else{ diff --git a/src/ReviewAnswers.js b/src/ReviewAnswers.js index a71575cb8..15379b965 100644 --- a/src/ReviewAnswers.js +++ b/src/ReviewAnswers.js @@ -36,9 +36,7 @@ export default class ReviewAnswers extends React.Component { } render() { - console.log('review', this.props.questions); const questions = this.props.questions; - // console.log(questions); const phoneNumber = this.props.form.PHONE === 0 ? 'N/A' : this.props.form.PHONE; const content = (
@@ -49,9 +47,6 @@ export default class ReviewAnswers extends React.Component { { questions.order .map(question => { - console.log('order', questions.order); - // console.log('map q', questions); - // console.log('what is this', questions[question].questions); if (questions[question].questions !== undefined) { if (questions[question].questions.filter(question => ![0, ""].includes(question.value)).length > 0) { const smallQuestions = (question !== 'buildingWaterImprovement') ? -- GitLab From dd797f7bb786763cbee0f77f5823736438551e2b Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Mon, 8 Jun 2020 14:13:06 -0400 Subject: [PATCH 13/33] BI-1390 Complete --- src/App.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/App.js b/src/App.js index d66951f48..90917e6ad 100644 --- a/src/App.js +++ b/src/App.js @@ -934,10 +934,7 @@ class App extends React.Component { } if([2,3].includes(this.props.building.data.surveyId) - && this.state.miniSplitCheckBox === true - && this.state.isEdit === false ) { - questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; + && this.state.miniSplitCheckBox === true ) { this.props.onSubmitAnswer({ questionId: ["17"], answerId: [106], @@ -947,13 +944,17 @@ class App extends React.Component { }); questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; questions.buildingCoolingSystem.value = 106; - // Add cooling system question into review order if(!questions.order.includes("buildingCoolingSystem")) { questions.order.push("buildingCoolingSystem"); } - this.setState({ questions }); + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } else { + questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; + } } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; } else{ -- GitLab From 861c548f9f6d08ef68734241affc47d7ebcb3b56 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Mon, 8 Jun 2020 15:37:53 -0400 Subject: [PATCH 14/33] BI-1389 Complete --- src/App.js | 4 +++- src/BuildingCoolingSystem.js | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 90917e6ad..2ea7a8d01 100644 --- a/src/App.js +++ b/src/App.js @@ -957,7 +957,7 @@ class App extends React.Component { } } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; - } else{ + } else { questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; } // Heating System for NYC Church PNS. @@ -1408,9 +1408,11 @@ class App extends React.Component { prevQuestion={this.prevQuestion} nextQuestion={this.nextQuestion} setBuildingCoolingSystem={this.setBuildingCoolingSystem} + setMiniSplitforCooling={this.setMiniSplitforCooling} answer={this.state.questions['buildingCoolingSystem'].value} answerIds={this.state.questions['buildingCoolingSystem'].answerIds} setReferral={this.setReferral} + isEdit={this.state.isEdit} surveyId={this.props.building.data.surveyId} />, buildingElectricityShutoff: { + if(this.props.isEdit && this.state.answer !== 106) { + this.props.setMiniSplitforCooling(false); + } + }); } setReferral = () => { -- GitLab From 66bab330c2b4fddd96406d43b45ca923dae439ef Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Wed, 10 Jun 2020 13:53:24 -0400 Subject: [PATCH 15/33] BI-1397 Complete --- src/App.js | 145 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 113 insertions(+), 32 deletions(-) diff --git a/src/App.js b/src/App.js index 2ea7a8d01..2048789c6 100644 --- a/src/App.js +++ b/src/App.js @@ -822,6 +822,7 @@ class App extends React.Component { nextQuestion = (question, answer, value) => { const questionAnswers = {}; const questions = this.state.questions; + console.log(questions.order); if (Array.isArray(answer) === true && questions[question]['questions'] !== undefined) { Object.keys(questions[question]['questions']).forEach(i => { questions[question]['questions'][i]['answer'] = answer[i]; @@ -840,8 +841,26 @@ class App extends React.Component { questions['churchBuildingType']['prev'] = 'anotherBuilding'; } - if(!questions.order.includes(question)) { - questions.order.push(question); + if (this.props.building.data.surveyId === 1) { + if (questions['buildingTypes'].value === 20) { + questions.order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'waitList', 'feedback'] + } else if ([21, 22].includes(questions['buildingTypes'].value)) { + questions.order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'utilityBills', 'comfortIssues', 'financeInterest', 'feedback'] + } else if([23, 33].includes(questions['buildingTypes'].value)) { + questions.order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'financeInterest', 'feedback'] + } else if (questions['buildingTypes'].value === 32) { + questions.order = ["addressSearch", "buildingTypes", "churchBuildingType", "churchHoursPerWeek", "operationalSeasons", + "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "fuels", "heatingSystemAge", + "heatingSystemPlan", "buildingCoolingSystem", "churchCoolingSystemAge", "churchCoolingSystemPlan", "buildingPastImprovement", + "buildingFutureImprovement"] + } + } else { + if (!questions.order.includes(question)) { + questions.order.push(question); + } } const metaObj = this.getMeta(); @@ -892,6 +911,22 @@ class App extends React.Component { updateQuestionChain = (question, value) => { let questions = this.state.questions; + + // Review Page Question Order + // if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { + // if ([21, 22, 23, 32, 33].includes(value)) { + // if(questions.order.includes('waitList')) { + // let index = questions.order.indexOf('waitList') + // questions.order.splice(index, 1); + // } + // } else if (value === 20) { + // if(questions.order.includes('waitList')) { + // let index = questions.order.indexOf('waitList') + // questions.order.splice(index, 1); + // } + // } + // } + if (question === 'buildingTypes'){ // Set the next question for building types. // If religious institute next page -> Church Building Type @@ -923,43 +958,52 @@ class App extends React.Component { questions['feedback'].prev = 'buildingFutureImprovement'; } // If the cooling system type is 'I don't have' or 'I don't know' we will skip Cooling sys age and replacement plan. - if ((this.props.building.data.surveyId === 1 && question === 'buildingCoolingSystem' && ([107,33,12].includes(value))) || - [2,3].includes(this.props.building.data.surveyId)){ + if ((this.props.building.data.surveyId === 1 && question === 'buildingCoolingSystem' && ([107,33,12].includes(value)))){ questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; - } - else if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { + let indexofCoolingAge = questions.order.indexOf('churchCoolingSystemAge'); + let indexofCoolingPlan = questions.order.indexOf('churchCoolingSystemPlan'); + questions.order.splice(indexofCoolingAge, 1); + questions.order.splice(indexofCoolingPlan, 1); + } else if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' } - if([2,3].includes(this.props.building.data.surveyId) - && this.state.miniSplitCheckBox === true ) { - this.props.onSubmitAnswer({ - questionId: ["17"], - answerId: [106], - surveyId: this.props.building.data.surveyId, - buildingId: this.props.building.data.buildingId, - userId: this.props.building.data.userId, - }); - questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; - questions.buildingCoolingSystem.value = 106; - // Add cooling system question into review order - if(!questions.order.includes("buildingCoolingSystem")) { - questions.order.push("buildingCoolingSystem"); - } - this.setState({ questions }); - if(this.state.isEdit) { + if([2,3].includes(this.props.building.data.surveyId)) { + questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + + if (this.state.miniSplitCheckBox === true ) { + this.props.onSubmitAnswer({ + questionId: ["17"], + answerId: [106], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + // Add cooling system question into review order + if(!questions.order.includes("buildingCoolingSystem")) { + questions.order.push("buildingCoolingSystem"); + } + this.setState({ questions }); + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + this.setState({ isEdit: false }); + } else { + questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; + } + } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; - } else { - questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; - } - } else if (this.state.isEdit) { - questions[question].next = 'reviewAnswers'; + this.setState({ isEdit: false }) + } } else { questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; } + // Heating System for NYC Church PNS. if (this.props.building.data.surveyId === 1 && questions['buildingTypes']['value'] === 32){ // If minisplit is also used for cooling system -> We will skip all 3 cooling sys questions. @@ -971,6 +1015,12 @@ class App extends React.Component { buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + // Add cooling system question into review order + if(!questions.order.includes("buildingCoolingSystem")) { + questions.order.push("buildingCoolingSystem"); + } // Store heating system plan answer in cooling system plan if(question==='heatingSystemPlan') { this.props.onSubmitAnswer({ @@ -980,6 +1030,11 @@ class App extends React.Component { buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); + questions.churchCoolingSystemPlan.answer = questions.heatingSystemPlan.answer; + questions.churchCoolingSystemPlan.value = value; + if(!questions.order.includes(question)) { + questions.order.push(question); + } } // Store heating system age answer in cooling system age if(question==='heatingSystemAge') { @@ -990,9 +1045,15 @@ class App extends React.Component { buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); + questions.churchCoolingSystemAge.answer = questions.heatingSystemAge.answer; + questions.churchCoolingSystemAge.value = value; + if(!questions.order.includes(question)) { + questions.order.push(question); + } } questions['heatingSystemPlan'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; + this.setState({ questions }); } else { questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; } @@ -1009,6 +1070,12 @@ class App extends React.Component { if ([101,33,12].includes(value)) { questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; questions['buildingCoolingSystem'].prev = 'buildingHeatingSystem'; + let indexofHeatingFuel = questions.order.indexOf('fuels'); + let indexofHeatingAge = questions.order.indexOf('heatingSystemAge'); + let indexofHeatingPlan = questions.order.indexOf('heatingSystemPlan'); + questions.order.splice(indexofHeatingFuel, 1); + questions.order.splice(indexofHeatingAge, 1); + questions.order.splice(indexofHeatingPlan, 1); } else { questions['buildingHeatingSystem'].next = 'fuels'; @@ -1018,6 +1085,16 @@ class App extends React.Component { questions['heatingSystemAge'].next = 'heatingSystemPlan'; } + // If address is of NYC and user edits the answer from review page + // if (this.props.building.data.surveyId === 1 && this.state.isEdit) { + // if (question === 'buildingTypes') { + // this.setState({ isEdit: false }) + // } + // else { + // questions[question].next = 'reviewAnswers'; + // } + // } + // If building type is not single fam and fuel type is natural gas or dual fuel -> display congrats page. if (questions['unitBreakdown']['value'] !== 20 && question === 'fuels' && [4,6].includes(value)){ this.setState({ buildingQualified: true}); @@ -1105,10 +1182,14 @@ class App extends React.Component { editAnswer = (question) => { let questions = this.state.questions; - questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: true, questions }, () => { + if (this.props.building.data.surveyId === 1) { this.setQuestion(question); - }); + } else { + questions[question].next = 'reviewAnswers'; + this.setState({ isEdit: true, questions }, () => { + this.setQuestion(question); + }); + } } setQuestion = (question) => { -- GitLab From d59b5794874146342cd4441b8c1da3f25ab2cd7d Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Tue, 16 Jun 2020 13:26:34 -0400 Subject: [PATCH 16/33] new functions - refactoring code --- src/App.js | 444 +++++++----- src/AppOld.js | 1654 +++++++++++++++++++++++++++++++++++++++++- src/ReviewAnswers.js | 4 +- 3 files changed, 1889 insertions(+), 213 deletions(-) diff --git a/src/App.js b/src/App.js index 2048789c6..0d259988a 100644 --- a/src/App.js +++ b/src/App.js @@ -35,7 +35,6 @@ import ChurchHoursPerWeek from './ChurchHoursPerWeek'; import OperationalSeasons from './OperationalSeasons'; import AnotherBuilding from './AnotherBuilding'; import Referral from './Referral'; -import { questionTree } from './constants'; import { connect } from 'react-redux'; import { submitContact, @@ -67,8 +66,8 @@ class App extends React.Component { }, prevQuestion: '', question: 'addressSearch', // Set the first question as address search when initializing - reviewQuestions: [], questions: this.resetQuestions(), + order: [], pages: { thankYou: { - const segments = window.location.href.split("ref_id="); - const ref_id = segments.length === 2 ? segments.pop() : ''; - if (ref_id !== '') { - this.props.onLoadReferral(ref_id); - this.setState({ isReferral: true }); - this.setQuestion('churchBuildingType'); - } - } - componentWillReceiveProps(nextProps) { // If user submitted another building search, use the new building object data if (nextProps.building !== undefined && this.props.building !== undefined && nextProps.building.data.userId !== this.props.building.data.userId && this.state.anotherBuildingSubmitted === true) { - this.props.onSubmitAnswer({ - questionId: ["6"], - answerId: [32], - surveyId: nextProps.building.data.surveyId, - buildingId: nextProps.building.data.buildingId, - userId: nextProps.building.data.userId, - }); + this.props.onSubmitAnswer({ + questionId: ["6"], + answerId: [32], + surveyId: nextProps.building.data.surveyId, + buildingId: nextProps.building.data.buildingId, + userId: nextProps.building.data.userId, + }); } if (nextProps.referral.data !== undefined && this.props.referral.data != undefined && nextProps.referral.data !== this.props.referral.data && nextProps.referral.data.referredTo !== undefined) { - let questions = this.state.questions; - questions['addressSearch'].answer = nextProps.referral.data.referredTo.address; - questions['addressSearch'].value = nextProps.referral.data.referredTo.address; - const submittedAnswers = nextProps.referral.data.submittedAnswers; - Object.keys(questions).forEach(question => { - if (questions[question].id !== undefined) { - const questionId = questions[question].id.toString(); - if (Object.keys(submittedAnswers).includes(questionId)) { - questions[question].answer = Array.isArray(questions[question].answer) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; - questions[question].value = Array.isArray(questions[question].value) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; - } - } else if (questions[question].questions !== undefined && Array.isArray(questions[question].questions)) { - questions[question].questions.entries(([index, subQuestion]) => { - const subQuestionId = subQuestion.id.toString(); - if (Object.keys(submittedAnswers).includes(subQuestion.id)) { - questions[question].questions[index].answer = Array.isArray(questions[question].questions[index].answer) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; - questions[question].questions[index].value = Array.isArray(questions[question].questions[index].value) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; - } - }); + let questions = this.state.questions; + questions['addressSearch'].answer = nextProps.referral.data.referredTo.address; + questions['addressSearch'].value = nextProps.referral.data.referredTo.address; + const submittedAnswers = nextProps.referral.data.submittedAnswers; + Object.keys(questions).forEach(question => { + if (questions[question].id !== undefined) { + const questionId = questions[question].id.toString(); + if (Object.keys(submittedAnswers).includes(questionId)) { + questions[question].answer = Array.isArray(questions[question].answer) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; + questions[question].value = Array.isArray(questions[question].value) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; } - }); - this.setState({ questions }); - } + } else if (questions[question].questions !== undefined && Array.isArray(questions[question].questions)) { + questions[question].questions.entries(([index, subQuestion]) => { + const subQuestionId = subQuestion.id.toString(); + if (Object.keys(submittedAnswers).includes(subQuestion.id)) { + questions[question].questions[index].answer = Array.isArray(questions[question].questions[index].answer) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; + questions[question].questions[index].value = Array.isArray(questions[question].questions[index].value) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; + } + }); + } + }); + this.setState({ questions }); + } } resetQuestions = () => { @@ -796,10 +785,39 @@ class App extends React.Component { prev: 'referral', next: 'thankYou', }, - order: [], }; } + setOrder = () => { + + let questions = this.state.questions; + let order = [] + + if (this.props.building.data.surveyId === 1) { + if (questions['buildingTypes'].value === 20) { + order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'waitList', 'feedback'] + } else if ([21, 22].includes(questions['buildingTypes'].value)) { + order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'utilityBills', 'comfortIssues', 'financeInterest', 'feedback'] + } else if([23, 33].includes(questions['buildingTypes'].value)) { + order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'financeInterest', 'feedback'] + } else if (questions['buildingTypes'].value === 32) { + order = ["addressSearch", "buildingTypes", "churchBuildingType", "churchHoursPerWeek", "operationalSeasons", + "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "fuels", "heatingSystemAge", "heatingSystemPlan", + "buildingCoolingSystem", "churchCoolingSystemAge", "churchCoolingSystemPlan", "buildingPastImprovement", "buildingFutureImprovement"] + } + } else if (this.props.building.data.surveyId === 2) { + order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", + "buildingPastImprovement", "buildingFutureImprovement", "buildingElectricityShutoff", "buildingMedicalDevices", "feedback"] + } else if (this.props.building.data.surveyId === 3) { + order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", + "buildingPastImprovement", "buildingFutureImprovement", "feedback"] + } + return order; + } + getMeta = () => { let metaObj = { buildingId: '', @@ -822,7 +840,7 @@ class App extends React.Component { nextQuestion = (question, answer, value) => { const questionAnswers = {}; const questions = this.state.questions; - console.log(questions.order); + if (Array.isArray(answer) === true && questions[question]['questions'] !== undefined) { Object.keys(questions[question]['questions']).forEach(i => { questions[question]['questions'][i]['answer'] = answer[i]; @@ -837,32 +855,6 @@ class App extends React.Component { questionAnswers[questions[question].id] = value; } - if (question === 'anotherBuilding') { - questions['churchBuildingType']['prev'] = 'anotherBuilding'; - } - - if (this.props.building.data.surveyId === 1) { - if (questions['buildingTypes'].value === 20) { - questions.order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', - 'heatingSystemAge', 'heatingSystemPlan', 'waitList', 'feedback'] - } else if ([21, 22].includes(questions['buildingTypes'].value)) { - questions.order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', - 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'utilityBills', 'comfortIssues', 'financeInterest', 'feedback'] - } else if([23, 33].includes(questions['buildingTypes'].value)) { - questions.order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', - 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'financeInterest', 'feedback'] - } else if (questions['buildingTypes'].value === 32) { - questions.order = ["addressSearch", "buildingTypes", "churchBuildingType", "churchHoursPerWeek", "operationalSeasons", - "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "fuels", "heatingSystemAge", - "heatingSystemPlan", "buildingCoolingSystem", "churchCoolingSystemAge", "churchCoolingSystemPlan", "buildingPastImprovement", - "buildingFutureImprovement"] - } - } else { - if (!questions.order.includes(question)) { - questions.order.push(question); - } - } - const metaObj = this.getMeta(); this.setState({ questions }, () => { if (['addressSearch', 'anotherBuilding'].includes(question)) { @@ -907,107 +899,107 @@ class App extends React.Component { this.updateQuestionChain(question, value); window.scrollTo(0, 0); + } updateQuestionChain = (question, value) => { + + if(question === 'buildingTypes' || question === 'buildingTypeSubType') { + let order = this.setOrder(); + this.setState({ order }, () => {console.log('done', this.state.order)}); + } + + if(this.props.building.data.surveyId === 1) { + this.nycQuestionChain(question, value) + } else if (this.props.building.data.surveyId === 2) { + this.oaklandQuestionChain(question, value) + } else if (this.props.building.data.surveyId === 3) { + this.milwaukeeQuestionChain(question, value) + } + } + + nycQuestionChain = (question, value) => { + let questions = this.state.questions; + let order = this.state.order; - // Review Page Question Order - // if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { - // if ([21, 22, 23, 32, 33].includes(value)) { - // if(questions.order.includes('waitList')) { - // let index = questions.order.indexOf('waitList') - // questions.order.splice(index, 1); - // } - // } else if (value === 20) { - // if(questions.order.includes('waitList')) { - // let index = questions.order.indexOf('waitList') - // questions.order.splice(index, 1); - // } - // } - // } + if (question === 'anotherBuilding') { + questions['churchBuildingType']['prev'] = 'anotherBuilding'; + } if (question === 'buildingTypes'){ - // Set the next question for building types. - // If religious institute next page -> Church Building Type - // Else fuel types - questions['buildingTypes'].next = value === 32 ? 'churchBuildingType' : 'fuels'; - // If the building type is multifam or mixed use, we will display unit breakdown, utility bills and comfort issues. - if ([21,22].includes(value)){ + + if (value === 20) { + questions['heatingSystemPlan'].next = 'waitList'; + questions['waitList'].prev = 'heatingSystemPlan'; + } else if (value === 32) { + questions['buildingTypes'].next = 'churchBuildingType'; + questions['buildingFutureImprovement'].next = 'feedback'; + questions['feedback'].prev = 'buildingFutureImprovement'; + } else if ([21,22].includes(value)){ questions['heatingSystemPlan'].next = 'unitBreakdown'; questions['unitBreakdown'].next = 'utilityBills'; questions['utilityBills'].prev = 'unitBreakdown'; questions['reviewAnswers'].next = 'congrats'; - } - // Else the next page from unit breakdown will be financial interest. - else{ + } else { questions['heatingSystemPlan'].next = 'unitBreakdown'; questions['unitBreakdown'].prev = 'heatingSystemPlan'; questions['unitBreakdown'].next = 'financeInterest'; questions['financeInterest'].prev = 'unitBreakdown'; } } - // If the building type is single family the next page of heating system plan will be wait list. - if (question === 'buildingTypes' && value === 20){ - questions['heatingSystemPlan'].next = 'waitList'; - questions['waitList'].prev = 'heatingSystemPlan'; - } - // For NYC Church survey, set feedback as the next page of building future improvement. - if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32) { - questions['buildingFutureImprovement'].next = 'feedback'; - questions['feedback'].prev = 'buildingFutureImprovement'; - } - // If the cooling system type is 'I don't have' or 'I don't know' we will skip Cooling sys age and replacement plan. - if ((this.props.building.data.surveyId === 1 && question === 'buildingCoolingSystem' && ([107,33,12].includes(value)))){ - questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; - let indexofCoolingAge = questions.order.indexOf('churchCoolingSystemAge'); - let indexofCoolingPlan = questions.order.indexOf('churchCoolingSystemPlan'); - questions.order.splice(indexofCoolingAge, 1); - questions.order.splice(indexofCoolingPlan, 1); - } else if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { + + if (questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem' && [107,33,12].includes(value)) { + + let indexofCoolingAge = order.indexOf('churchCoolingSystemAge'); + order.splice(indexofCoolingAge, 1); + + let indexofCoolingPlan = order.indexOf('churchCoolingSystemPlan'); + order.splice(indexofCoolingPlan, 1); + + this.setState({ questions, order }); + + if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } else { + questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + } + } else if (questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' } - if([2,3].includes(this.props.building.data.surveyId)) { - questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + if (questions['buildingTypes'].value === 32 && question === 'buildingHeatingSystem' && [101,33,12].includes(value)) { - if (this.state.miniSplitCheckBox === true ) { - this.props.onSubmitAnswer({ - questionId: ["17"], - answerId: [106], - surveyId: this.props.building.data.surveyId, - buildingId: this.props.building.data.buildingId, - userId: this.props.building.data.userId, - }); - questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; - questions.buildingCoolingSystem.value = 106; - // Add cooling system question into review order - if(!questions.order.includes("buildingCoolingSystem")) { - questions.order.push("buildingCoolingSystem"); - } - this.setState({ questions }); - if(this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: false }); - } else { - questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; - } - } else if (this.state.isEdit) { + let indexofHeatingFuel = order.indexOf('fuels'); + order.splice(indexofHeatingFuel, 1); + + let indexofHeatingAge = order.indexOf('heatingSystemAge'); + order.splice(indexofHeatingAge, 1); + + let indexofHeatingPlan = order.indexOf('heatingSystemPlan'); + order.splice(indexofHeatingPlan, 1); + + this.setState({ questions, order }); + + if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: false }) - } - } else { - questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + } else { + questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + questions['buildingCoolingSystem'].prev = 'buildingHeatingSystem'; + } + } else if (questions['buildingTypes'].value === 32 && question === 'buildingHeatingSystem') { + questions['buildingHeatingSystem'].next = 'fuels'; + questions['buildingCoolingSystem'].prev = 'heatingSystemPlan'; + questions['fuels'].next = 'heatingSystemAge'; + questions['heatingSystemAge'].next = 'heatingSystemPlan'; } - // Heating System for NYC Church PNS. - if (this.props.building.data.surveyId === 1 && questions['buildingTypes']['value'] === 32){ - // If minisplit is also used for cooling system -> We will skip all 3 cooling sys questions. + if (questions['buildingTypes']['value'] === 32 && question === 'buildingHeatingSystem') { + if(this.state.miniSplitCheckBox === true) { + this.props.onSubmitAnswer({ questionId: ["17"], answerId: [106], @@ -1017,11 +1009,13 @@ class App extends React.Component { }); questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; questions.buildingCoolingSystem.value = 106; - // Add cooling system question into review order - if(!questions.order.includes("buildingCoolingSystem")) { - questions.order.push("buildingCoolingSystem"); + if(!order.includes("buildingCoolingSystem")) { + order.push("buildingCoolingSystem"); } - // Store heating system plan answer in cooling system plan + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } + if(question==='heatingSystemPlan') { this.props.onSubmitAnswer({ questionId: ["66"], @@ -1032,11 +1026,14 @@ class App extends React.Component { }); questions.churchCoolingSystemPlan.answer = questions.heatingSystemPlan.answer; questions.churchCoolingSystemPlan.value = value; - if(!questions.order.includes(question)) { - questions.order.push(question); + if(!order.includes(question)) { + order.push(question); + } + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; } } - // Store heating system age answer in cooling system age + if(question==='heatingSystemAge') { this.props.onSubmitAnswer({ questionId: ["65"], @@ -1047,56 +1044,30 @@ class App extends React.Component { }); questions.churchCoolingSystemAge.answer = questions.heatingSystemAge.answer; questions.churchCoolingSystemAge.value = value; - if(!questions.order.includes(question)) { - questions.order.push(question); + if(!order.includes(question)) { + order.push(question); + } + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; } } + questions['heatingSystemPlan'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; - this.setState({ questions }); + this.setState({ questions, order }); + } else if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; } else { questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; } - // Set back button pages questions['buildingNeeds'].prev = 'operationalSeasons' questions['fuels'].prev = 'buildingHeatingSystem' questions['heatingSystemAge'].prev = 'fuels' - } - else{ + } else { questions['fuels'].prev = 'buildingTypes' } - if (this.props.building.data.surveyId === 1 && question === 'buildingHeatingSystem' && questions['buildingTypes']['value'] === 32){ - // If the heating system type is 'I don't know' or 'I don't have' we will skip next 3 heating sys related questions. - if ([101,33,12].includes(value)) { - questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; - questions['buildingCoolingSystem'].prev = 'buildingHeatingSystem'; - let indexofHeatingFuel = questions.order.indexOf('fuels'); - let indexofHeatingAge = questions.order.indexOf('heatingSystemAge'); - let indexofHeatingPlan = questions.order.indexOf('heatingSystemPlan'); - questions.order.splice(indexofHeatingFuel, 1); - questions.order.splice(indexofHeatingAge, 1); - questions.order.splice(indexofHeatingPlan, 1); - } - else { - questions['buildingHeatingSystem'].next = 'fuels'; - questions['buildingCoolingSystem'].prev = 'heatingSystemPlan' - } - questions['fuels'].next = 'heatingSystemAge'; - questions['heatingSystemAge'].next = 'heatingSystemPlan'; - } - // If address is of NYC and user edits the answer from review page - // if (this.props.building.data.surveyId === 1 && this.state.isEdit) { - // if (question === 'buildingTypes') { - // this.setState({ isEdit: false }) - // } - // else { - // questions[question].next = 'reviewAnswers'; - // } - // } - - // If building type is not single fam and fuel type is natural gas or dual fuel -> display congrats page. - if (questions['unitBreakdown']['value'] !== 20 && question === 'fuels' && [4,6].includes(value)){ + if (questions['unitBreakdown']['value'] !== 20 && question === 'fuels' && [4,6].includes(value)) { this.setState({ buildingQualified: true}); this.state.pages.congrats = ; } + + } + + oaklandQuestionChain = (question, value) => { + + let questions = this.state.questions; + let order = this.state.order; + + questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + + if (this.state.miniSplitCheckBox === true ) { + this.props.onSubmitAnswer({ + questionId: ["17"], + answerId: [106], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + if(!order.includes("buildingCoolingSystem")) { + order.push("buildingCoolingSystem"); + } + this.setState({ questions, order }); + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } else { + questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; + } + } else if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + this.setState({ isEdit: false }) + } else { + questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + } + + } + + milwaukeeQuestionChain = (question, value) => { + + let questions = this.state.questions; + let order = this.state.order; + + questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + + if (this.state.miniSplitCheckBox === true ) { + this.props.onSubmitAnswer({ + questionId: ["17"], + answerId: [106], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + if(!order.includes("buildingCoolingSystem")) { + order.push("buildingCoolingSystem"); + } + this.setState({ questions, order }); + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } else { + questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; + } + } else if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + this.setState({ isEdit: false }) + } else { + questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + } + + } + + loadReferral = () => { + const segments = window.location.href.split("ref_id="); + const ref_id = segments.length === 2 ? segments.pop() : ''; + if (ref_id !== '') { + this.props.onLoadReferral(ref_id); + this.setState({ isReferral: true }); + this.setQuestion('churchBuildingType'); + } } anotherBuilding = () => { @@ -1182,11 +1238,14 @@ class App extends React.Component { editAnswer = (question) => { let questions = this.state.questions; - if (this.props.building.data.surveyId === 1) { + if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { this.setQuestion(question); } else { questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: true, questions }, () => { + this.setState({ + isEdit: true, + questions, + }, () => { this.setQuestion(question); }); } @@ -1304,10 +1363,13 @@ class App extends React.Component { } render() { + const building = this.props.building; let addressSearchMessage = ""; + // TODO: Explain why search success is set to true in render function? let addressSearchSuccess = true; + if (building.data !== undefined && building.data.success === false && building.data.message !== undefined) { addressSearchSuccess = false; addressSearchMessage = this.props.building.data.message; @@ -1451,6 +1513,7 @@ class App extends React.Component { questions={this.state.questions} form={this.state.form} editAnswer={this.editAnswer} + order={this.state.order} />, buildingTypeSubType: -
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); +class App extends React.Component { + constructor(props) { + super(props); + // this.setOrder = this.setOrder.bind(this); + this.state = { + submitted: false, + disabled: true, + surveyId: -1, + buildingId: -1, + buildingQualified: false, + form: { + FNAME: '', + LNAME: '', + EMAIL: '', + PHONE: '', + }, + prevQuestion: '', + question: 'addressSearch', // Set the first question as address search when initializing + questions: this.resetQuestions(), + order: [], + pages: { + thankYou: , + congrats: , + }, + multiFamilyAnswerId: 21, + miniSplitCheckBox: false, + anotherBuildingSubmitted: false, + isReferral: false, + isEdit: false, + }; + } + + componentDidMount() { + this.loadReferral(); + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.initialize('UA-67611405-11'); + ReactGA.pageview('/intake'); + } + } + + loadReferral = () => { + const segments = window.location.href.split("ref_id="); + const ref_id = segments.length === 2 ? segments.pop() : ''; + if (ref_id !== '') { + this.props.onLoadReferral(ref_id); + this.setState({ isReferral: true }); + this.setQuestion('churchBuildingType'); + } + } + + componentWillReceiveProps(nextProps) { + // If user submitted another building search, use the new building object data + if (nextProps.building !== undefined && this.props.building !== undefined && + nextProps.building.data.userId !== this.props.building.data.userId && + this.state.anotherBuildingSubmitted === true) { + this.props.onSubmitAnswer({ + questionId: ["6"], + answerId: [32], + surveyId: nextProps.building.data.surveyId, + buildingId: nextProps.building.data.buildingId, + userId: nextProps.building.data.userId, + }); + } + + if (nextProps.referral.data !== undefined && this.props.referral.data != undefined && + nextProps.referral.data !== this.props.referral.data && + nextProps.referral.data.referredTo !== undefined) { + let questions = this.state.questions; + questions['addressSearch'].answer = nextProps.referral.data.referredTo.address; + questions['addressSearch'].value = nextProps.referral.data.referredTo.address; + const submittedAnswers = nextProps.referral.data.submittedAnswers; + Object.keys(questions).forEach(question => { + if (questions[question].id !== undefined) { + const questionId = questions[question].id.toString(); + if (Object.keys(submittedAnswers).includes(questionId)) { + questions[question].answer = Array.isArray(questions[question].answer) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; + questions[question].value = Array.isArray(questions[question].value) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; + } + } else if (questions[question].questions !== undefined && Array.isArray(questions[question].questions)) { + questions[question].questions.entries(([index, subQuestion]) => { + const subQuestionId = subQuestion.id.toString(); + if (Object.keys(submittedAnswers).includes(subQuestion.id)) { + questions[question].questions[index].answer = Array.isArray(questions[question].questions[index].answer) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; + questions[question].questions[index].value = Array.isArray(questions[question].questions[index].value) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; + } + }); + } + }); + this.setState({ questions }); + } + } + + resetQuestions = () => { + return { + addressSearch: { + title: 'What is your building address?', + answer: '', + value: '', + prev: 'addressSearch', + next: '', + }, + fuels: { + id: 1, + title: 'What type of fuel do you use to heat your building?', + answer: '', + value: '', + answerIds: [3, 4, 5, 6, 33], + answers: { 3: 'fuelOil', 4: 'naturalGas', 5: 'electricResistance', 6: 'dualFuel', 33: 'other' }, + prev: 'buildingTypes', + next: 'heatDistribution', + }, + heatDistribution: { + id: 2, + title: 'How is heat distributed in the building?', + answer: '', + value: '', + answerIds: [8, 9, 10, 11, 12], + answers: { 8: 'steam', 9: 'hotWater', 10: 'electricBaseboard', 11: 'forcedAir', 12: 'other' }, + prev: 'fuels', + next: 'separateBoiler', + }, + separateBoiler: { + id: 11, + title: 'Is the hot water prepared by the same boiler, or a separate water heater?', + answer: '', + value: 0, + answerIds: [111, 112, 12], + prev: 'heatDistribution', + next: 'heatingSystemAge', + }, + heatingSystemAge: { + id: 3, + title: 'About how old is your heating system?', + answer: '', + value: 0, + answerIds: [13, 14, 15, 16, 12], + prev: 'separateBoiler', + next: 'heatingSystemPlan', + }, + heatingSystemPlan: { + id: 4, + title: 'How soon do you plan in replacing your heating system?', + answer: '', + value: 0, + answerIds: [17, 18, 19, 12], + prev: 'heatingSystemAge', + next: '', + }, + churchBuildingType: { + id: 62, + title: 'Please tell us what kind of building you have.', + answer: '', + value: 0, + answerIds: [124, 125, 126, 137], + prev: 'addressSearch', + next: 'churchHoursPerWeek', + }, + churchHoursPerWeek: { + id: 63, + title: 'How many hours per week is the building occupied?', + answer: '', + value: 0, + answerIds: [127, 128, 129, 130], + prev: 'churchBuildingType', + next: 'operationalSeasons', + }, + operationalSeasons:{ + id: 64, + title: 'Which season(s) is the building operational?', + answer: [], + value: [], + answerIds: [131, 132, 133, 134], + answers: { + 131: 'Spring', + 132: 'Summer', + 133: 'Fall', + 134: 'Winter'}, + prev: 'churchHoursPerWeek', + next: 'buildingNeeds', + }, + unitBreakdown: { + title: 'Tell us about your building.', + questionIds: [52, 53, 54, 55, 56, 57], + answers: [0, 0, 0, 0, 0, 0], + prev: 'heatingSystemPlan', + next: '', + }, + buildingTypes: { + id: 6, + 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: 'fuels', + }, + utilityBills: { + title: 'Who pays the following utility bills?', + questions: [ + { + id: 5, + title: 'Heat and hot water', + answer: '', + value: 0, + answerIds: [24, 25], + }, + { + id: 8, + title: 'Electricity in unit', + answer: '', + value: 0, + answerIds: [24, 25], + }, + ], + prev: 'unitBreakdown', + next: 'comfortIssues', + }, + comfortIssues: { + id: 7, + title: 'In the winter, which of the following tenant comfort issues apply?', + answer: [], + value: [], + answerIds: [26, 27, 28, 29, 30, 31], + answers: { 26: 'tooHot', 27: 'windowsOpen', 28: 'tooCold', 29: 'spaceHeaters', 30: 'draft', 31: 'noComplaint' }, + prev: 'utilityBills', + next: 'financeInterest', + }, + financeInterest: { + id: 9, + title: 'Would you be interested in learning more about our no money down energy system lease options?', + answer: '', + value: 0, + answerIds: [1, 2], + prev: '', + next: 'feedback', + }, + waitList: { + id: 10, + title: 'Would you like to join our Waitlist?', + answer: '', + value: 0, + answerIds: [1, 2], + prev: 'buildingTypes', + next: 'feedback', + }, + feedback: { + questionIds: [58], + title: 'How did you hear about us?', + answers: '', + prev: '', + next: 'contact', + }, + contact: { + title: 'Your Information', + prev: 'feedback', + next: 'reviewAnswers', + }, + reviewAnswers: { + prev: 'waitList', + next: 'thankYou', + }, + buildingTypeSubType: { + title: 'What type of building do you own?', + id: 12, + answer: '', + value: 0, + questions: [ + { + id: 12, + title: '', + answer: '', + value: 0, + answerIds: [34, 109, 35, 36, 37, 38, 33], + }, + { + id: 13, + title: '', + answer: '', + value: 0, + answerIds: { + '34': [39, 40, 41, 42, 43, 44, 45, 46, 47], + '35': [52, 53, 54], + '36': [61, 62, 63, 64, 65, 33], + '37': [66, 67, 68, 69, 70], + '38': [71, 72, 73, 74, 33], + }, + }, + ], + prev: 'addressSearch', + next: 'buildingNeeds', + }, + buildingNeeds: { + id: 14, + title: 'What are your current building needs?', + answer: [], + value: [], + answerIds: [75, 76, 77, 78, 79, 80, 81, 82, 83, 33], + answers: { + 75: 'GainGeneralEducation', + 76: 'LowerUtilityBills', + 77: 'ResolveHeatingIssues', + 78: 'ResolveCoolingIssues', + 79: 'ImproveOccupantComfort', + 80: 'SubstantialBuildingRenovations', + 81: 'HelpFindingContractors', + 82: 'AdviceOnEnergyWaterEfficiency', + 83: 'HelpFinancingEnergyProject', + 33: 'other', + }, + prev: 'buildingTypeSubType', + next: 'buildingOperatingChallenges', + }, + buildingOperatingChallenges: { + id: 15, + title: 'What are your biggest building operating challenges?', + answer: [], + value: [], + answerIds: [84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 33], + answers: { + 84: 'NotEnoughResources', + 85: 'EquipmentBreaksDown', + 86: 'HighUtilityBilOil', + 87: 'HighUtilityBilNaturalGas', + 88: 'HighUtilityBilElectricity', + 89: 'HighUtilityBillWater', + 90: 'PoorInsulation', + 91: 'TooCold', + 92: 'TooDrafty', + 93: 'TooHot', + 94: 'NotEnoughDomesticHotWater', + 95: 'BuildingViolations', + 33: 'Other', + }, + prev: 'buildingNeeds', + next: 'buildingHeatingSystem', + }, + buildingHeatingSystem: { + id: 16, + title: 'What type of heating system does your building have?', + answer: '', + value: '', + answerIds: [96, 97, 98, 99, 100, 136, 101, 33, 12], + prev: 'buildingOperatingChallenges', + next: 'buildingCoolingSystem', + miniSplitCheckBox: false, + }, + buildingCoolingSystem: { + id: 17, + title: 'What type of cooling system does your building have?', + answer: '', + value: '', + answerIds: [102, 103, 104, 105, 106, 107, 108, 113, 136, 33, 12], + prev: 'buildingHeatingSystem', + next: 'buildingPastImprovement', + }, + buildingElectricityShutoff: { + title: 'Building Electricity Shutoffs', + questions: [ + { + id: 59, + title: 'Did your building experience electricity shutoff during recent PGE wildfire mitigation blackouts?', + answer: '', + value: 0, + answerIds: [1, 2], + }, + { + id: 61, + title: 'Do you expect your building to experience blackouts going forward?', + answer: '', + value: 0, + answerIds: [1, 2, 12], + }, + ], + prev: 'buildingFutureImprovement', + next: 'buildingMedicalDevices', + }, + buildingMedicalDevices: { + id: 60, + title: 'Do residents of your building use electrically connected medical devices?', + answer: '', + value: '', + answerIds: [1, 2, 12], + prev: 'buildingElectricityShutoff', + next: 'feedback', + }, + churchCoolingSystemAge: { + id: 65, + title: 'How old is the cooling system?', + answer: '', + value: '', + answerIds: [13, 14, 15, 16, 12], + prev: 'buildingCoolingSystem', + next: 'churchCoolingSystemPlan', + }, + churchCoolingSystemPlan: { + id: 66, + title: 'How soon do you plan in replacing your cooling system?', + answer: '', + value: 0, + answerIds: [17, 18, 19, 12], + prev: 'churchCoolingSystemAge', + next: 'buildingPastImprovement', + }, + buildingPastImprovement: { + title: 'Any Energy or Water Improvements in the past 5 years?', + questions: [ + { + id: 18, + name: 'newHeatingSystem', + title: 'Install a new heating system', + answer: 2, + value: '', + answerIds: [96, 97, 98, 99, 100, 33, 12], + checked: false, + }, + { + id: 19, + name: 'newCoolingSystem', + title: 'Install a new cooling system', + answer: 2, + value: '', + answerIds: [102, 103, 104, 105, 106, 108, 113, 33, 12], + checked: false, + }, + { + id: 20, + name: 'newControls', + title: 'Install new controls', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 21, + name: 'convertHeatingFuel', + title: 'Convert heating fuel', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 22, + name: 'convertHeatingSystem', + title: 'Convert heating system', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 23, + name: 'newDomesticHotwaterSystem', + title: 'Install new domestic hotwater system', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 24, + name: 'addInsulation', + title: 'Add insulation', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 25, + name: 'airSealBuildingEnvelope', + title: 'Air seal the building envelope', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 26, + name: 'newWindows', + title: 'New windows', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 27, + name: 'newRoof', + title: 'New roof', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 28, + name: 'solarPanels', + title: 'Solar panels', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 29, + name: 'toilets', + title: 'Toilets', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 30, + name: 'lowFlowShowerheadsFaucets', + title: 'Low flow showerheads & faucets', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 31, + name: 'ledLighting', + title: 'LED lighting', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 32, + name: 'other', + title: 'Other', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 33, + name: 'none', + title: 'None', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 34, + name: 'notSure', + title: 'I\'m not sure', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + ], + prev: 'buildingCoolingSystem', + next: 'buildingFutureImprovement', + }, + buildingFutureImprovement: { + title: 'Any Energy or Water Improvements within coming year or so?', + questions: [ + { + id: 35, + name: 'newHeatingSystem', + title: 'Install a new heating system', + answer: 2, + value: '', + answerIds: [96, 97, 98, 99, 100, 33, 12], + checked: false, + }, + { + id: 36, + name: 'newCoolingSystem', + title: 'Install a new cooling system', + answer: 2, + value: '', + answerIds: [102, 103, 104, 105, 106, 108, 113, 33, 12], + checked: false, + }, + { + id: 37, + name: 'newControls', + title: 'Install new controls', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 38, + name: 'convertHeatingFuel', + title: 'Convert heating fuel', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 39, + name: 'convertHeatingSystem', + title: 'Convert heating system', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 40, + name: 'newDomesticHotwaterSystem', + title: 'Install new domestic hotwater system', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 41, + name: 'addInsulation', + title: 'Add insulation', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 42, + name: 'airSealBuildingEnvelope', + title: 'Air seal the building envelope', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 43, + name: 'newWindows', + title: 'New windows', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 44, + name: 'newRoof', + title: 'New roof', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 45, + name: 'solarPanels', + title: 'Solar panels', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 46, + name: 'toilets', + title: 'Toilets', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 47, + name: 'lowFlowShowerheadsFaucets', + title: 'Low flow showerheads & faucets', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 48, + name: 'ledLighting', + title: 'LED lighting', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 49, + name: 'other', + title: 'Other', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 50, + name: 'none', + title: 'None', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + { + id: 51, + name: 'notSure', + title: 'I\'m not sure', + answer: '', + value: 0, + answerIds: [1, 2], + checked: false, + }, + ], + prev: 'buildingPastImprovement', + next: 'feedback', + }, + anotherBuilding: { + title: '', + answer: '', + value: '', + prev: 'anotherBuilding', + next: 'churchBuildingType', + }, + referral: { + title: '', + answer: '', + value: '', + prev: 'referral', + next: 'thankYou', + }, + order: [], + }; + } + + getMeta = () => { + let metaObj = { + buildingId: '', + userId: '', + surveyId: 1 + }; + + if (this.props.referral.data !== undefined && this.props.referral.data.referredTo !== undefined) { + metaObj.userId = this.props.referral.data.referredTo.userId; + metaObj.buildingId = this.props.referral.data.referredTo.buildingId; + } + if (this.props.building.data !== undefined && this.props.building.data.buildingId !== undefined) { + metaObj.buildingId = this.props.building.data.buildingId; + metaObj.userId = this.props.building.data.userId; + metaObj.surveyId = this.props.building.data.surveyId; + } + return metaObj; + } + + setOrder = () => { + + let questions = this.state.questions; + console.log('set order', questions['buildingTypes'].value) + let order = [] + + if (this.props.building.data.surveyId === 1) { + if (questions['buildingTypes'].value === 20) { + order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'waitList', 'feedback'] + } else if ([21, 22].includes(questions['buildingTypes'].value)) { + order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'utilityBills', 'comfortIssues', 'financeInterest', 'feedback'] + } else if([23, 33].includes(questions['buildingTypes'].value)) { + order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', + 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'financeInterest', 'feedback'] + } else if (questions['buildingTypes'].value === 32) { + order = ["addressSearch", "buildingTypes", "churchBuildingType", "churchHoursPerWeek", "operationalSeasons", + "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "fuels", "heatingSystemAge", "heatingSystemPlan", + "buildingCoolingSystem", "churchCoolingSystemAge", "churchCoolingSystemPlan", "buildingPastImprovement", "buildingFutureImprovement"] + } + } else if (this.props.building.data.surveyId === 2) { + order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", + "buildingPastImprovement", "buildingFutureImprovement", "buildingElectricityShutoff", "buildingMedicalDevices", "feedback"] + } else if (this.props.building.data.surveyId === 3) { + order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", + "buildingPastImprovement", "buildingFutureImprovement", "feedback"] + } + return order; + } + + nextQuestion = (question, answer, value) => { + const questionAnswers = {}; + const questions = this.state.questions; + // console.log('next q', questions.order); + + if (Array.isArray(answer) === true && questions[question]['questions'] !== undefined) { + Object.keys(questions[question]['questions']).forEach(i => { + questions[question]['questions'][i]['answer'] = answer[i]; + questions[question]['questions'][i]['value'] = value[i]; + questionAnswers[questions[question]['questions'][i].id] = value[i]; + }); + } else if (Array.isArray(answer) === true && Array.isArray(questions[question]['questionIds']) === true) { + questions[question]['answers'] = value; + } else { + questions[question].answer = answer; + questions[question].value = value; + questionAnswers[questions[question].id] = value; + } + + if (question === 'anotherBuilding') { + questions['churchBuildingType']['prev'] = 'anotherBuilding'; + } + + const metaObj = this.getMeta(); + this.setState({ questions }, () => { + if (['addressSearch', 'anotherBuilding'].includes(question)) { + this.props.onSubmitBuilding({ + address: this.state.questions[question].value, + }); + // If user clicks on 'continue' button on another building search page + if (question === 'anotherBuilding') { + this.setState({ anotherBuildingSubmitted: true }); + } + } else if (question === 'unitBreakdown' || question === 'feedback'){ + this.setQuestion(this.state.questions[question].next); + this.props.onSubmitUserAnswer({ + questionId: questions[question]['questionIds'], + answers: questions[question]['answers'], + surveyId: metaObj.surveyId, + buildingId: metaObj.buildingId, + userId: metaObj.userId, + }); + this.setState({ anotherBuildingSubmitted: false }); + } else { + this.setQuestion(this.state.questions[question].next); + if (question === 'churchBuildingType' && this.state.isReferral){ + this.props.onSubmitAnswer({ + questionId: ["6"], + answerId: [32], + surveyId: metaObj.surveyId, + buildingId: metaObj.buildingId, + userId: metaObj.userId, + }); + } + this.props.onSubmitAnswer({ + questionId: Object.keys(questionAnswers), + answerId: Object.values(questionAnswers), + surveyId: metaObj.surveyId, + buildingId: metaObj.buildingId, + userId: metaObj.userId, + }); + this.setState({ anotherBuildingSubmitted: false }); + } + }); + + this.updateQuestionChain(question, value); + window.scrollTo(0, 0); + } + + updateQuestionChain = (question, value) => { + console.log(this.props.building.data.surveyId) + let questions = this.state.questions; + if(question === 'buildingTypes') { + console.log('building type') + let order = this.setOrder(); + this.setState({ order }, () => {console.log('done', this.state.order)}); + } + console.log(this.state.anotherBuildingSubmitted) + if (question === 'buildingTypes'){ + // Set the next question for building types. + // If religious institute next page -> Church Building Type + // Else fuel types + questions['buildingTypes'].next = value === 32 ? 'churchBuildingType' : 'fuels'; + // If the building type is multifam or mixed use, we will display unit breakdown, utility bills and comfort issues. + if ([21,22].includes(value)){ + questions['heatingSystemPlan'].next = 'unitBreakdown'; + questions['unitBreakdown'].next = 'utilityBills'; + questions['utilityBills'].prev = 'unitBreakdown'; + questions['reviewAnswers'].next = 'congrats'; + } + // Else the next page from unit breakdown will be financial interest. + else{ + questions['heatingSystemPlan'].next = 'unitBreakdown'; + questions['unitBreakdown'].prev = 'heatingSystemPlan'; + questions['unitBreakdown'].next = 'financeInterest'; + questions['financeInterest'].prev = 'unitBreakdown'; + } + } + // If the building type is single family the next page of heating system plan will be wait list. + if (question === 'buildingTypes' && value === 20){ + questions['heatingSystemPlan'].next = 'waitList'; + questions['waitList'].prev = 'heatingSystemPlan'; + } + // For NYC Church survey, set feedback as the next page of building future improvement. + if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32) { + questions['buildingFutureImprovement'].next = 'feedback'; + questions['feedback'].prev = 'buildingFutureImprovement'; + } + + // If the cooling system type is 'I don't have' or 'I don't know' we will skip Cooling sys age and replacement plan. + if ((this.props.building.data.surveyId === 1 && question === 'buildingCoolingSystem' && ([107,33,12].includes(value)))){ + let indexofCoolingAge = questions.order.indexOf('churchCoolingSystemAge'); + // console.log(indexofCoolingAge) + questions.order.splice(indexofCoolingAge, 1); + let indexofCoolingPlan = questions.order.indexOf('churchCoolingSystemPlan'); + // console.log(indexofCoolingPlan) + questions.order.splice(indexofCoolingPlan, 1); + // console.log(questions.order) + this.setState({ questions }); + if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } else { + questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + } + } else if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { + questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; + questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' + } + + if([2,3].includes(this.props.building.data.surveyId)) { + questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + + if (this.state.miniSplitCheckBox === true ) { + this.props.onSubmitAnswer({ + questionId: ["17"], + answerId: [106], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + // Add cooling system question into review order + if(!questions.order.includes("buildingCoolingSystem")) { + questions.order.push("buildingCoolingSystem"); + } + this.setState({ questions }); + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + // this.setState({ isEdit: false }); + } else { + questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; + } + } else if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + this.setState({ isEdit: false }) + } + } else { + questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + } + + // Heating System for NYC Church PNS. + if (this.props.building.data.surveyId === 1 && questions['buildingTypes']['value'] === 32){ + // If minisplit is also used for cooling system -> We will skip all 3 cooling sys questions. + if(this.state.miniSplitCheckBox === true) { + this.props.onSubmitAnswer({ + questionId: ["17"], + answerId: [106], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + // Add cooling system question into review order + if(!questions.order.includes("buildingCoolingSystem")) { + questions.order.push("buildingCoolingSystem"); + } + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + // this.setState({ isEdit: false }); + } + // Store heating system plan answer in cooling system plan + if(question==='heatingSystemPlan') { + this.props.onSubmitAnswer({ + questionId: ["66"], + answerId: [value], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.churchCoolingSystemPlan.answer = questions.heatingSystemPlan.answer; + questions.churchCoolingSystemPlan.value = value; + if(!questions.order.includes(question)) { + questions.order.push(question); + } + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + // this.setState({ isEdit: false }); + } + } + // Store heating system age answer in cooling system age + if(question==='heatingSystemAge') { + this.props.onSubmitAnswer({ + questionId: ["65"], + answerId: [value], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.churchCoolingSystemAge.answer = questions.heatingSystemAge.answer; + questions.churchCoolingSystemAge.value = value; + if(!questions.order.includes(question)) { + questions.order.push(question); + } + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + // this.setState({ isEdit: false }); + } + } + questions['heatingSystemPlan'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; + this.setState({ questions }); + } else if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + // this.setState({ isEdit: false }) + } else { + questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; + } + // Set back button pages + questions['buildingNeeds'].prev = 'operationalSeasons' + questions['fuels'].prev = 'buildingHeatingSystem' + questions['heatingSystemAge'].prev = 'fuels' + } + else{ + questions['fuels'].prev = 'buildingTypes' + } + if (this.props.building.data.surveyId === 1 && question === 'buildingHeatingSystem' && questions['buildingTypes']['value'] === 32){ + // If the heating system type is 'I don't know' or 'I don't have' we will skip next 3 heating sys related questions. + if ([101,33,12].includes(value)) { + let indexofHeatingFuel = questions.order.indexOf('fuels'); + questions.order.splice(indexofHeatingFuel, 1); + let indexofHeatingAge = questions.order.indexOf('heatingSystemAge'); + questions.order.splice(indexofHeatingAge, 1); + let indexofHeatingPlan = questions.order.indexOf('heatingSystemPlan'); + questions.order.splice(indexofHeatingPlan, 1); + if (this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } else { + questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + questions['buildingCoolingSystem'].prev = 'buildingHeatingSystem'; + } + this.setState({ questions }); + } else { + questions['buildingHeatingSystem'].next = 'fuels'; + questions['buildingCoolingSystem'].prev = 'heatingSystemPlan' + } + questions['fuels'].next = 'heatingSystemAge'; + questions['heatingSystemAge'].next = 'heatingSystemPlan'; + } + + // If building type is not single fam and fuel type is natural gas or dual fuel -> display congrats page. + if (questions['unitBreakdown']['value'] !== 20 && question === 'fuels' && [4,6].includes(value)){ + this.setState({ buildingQualified: true}); + this.state.pages.congrats = ; + } else { + this.state.pages.congrats = ; + } + } + + anotherBuilding = () => { + // When user starts new loop of questionnaire, we reset all the answers + const questions = this.resetQuestions(); + questions['addressSearch'].value = this.state.questions['addressSearch'].value; + questions['buildingTypes'].value = this.state.questions['buildingTypes'].value; + this.setState({ + questions, + question: 'anotherBuilding', + }); + } + + submitContact = (contact) => { + const isWorshipBuilding = this.state.questions.buildingTypes.value === 32 ? true : false; + const metaObj = this.getMeta(); + this.setQuestion(this.state.questions['contact'].next); + this.setState({ + form: { + FNAME: contact.FNAME, + LNAME: contact.LNAME, + PHONE: contact.PHONE, + EMAIL: contact.EMAIL, + buildingId: metaObj.buildingId, + userId: metaObj.userId, + }, + }, () => { + this.props.onSubmitContact({ + firstName: this.state.form.FNAME, + lastName: this.state.form.LNAME, + phoneNumber: this.state.form.PHONE, + email: this.state.form.EMAIL, + buildingId: metaObj.buildingId, + userId: metaObj.userId, + surveyId: this.props.building.data.surveyId, + isWorshipBuilding + }); + }); + } + + submitSubscriber = (contact) => { + this.setState({ + form: { + FNAME: contact.FNAME, + LNAME: contact.LNAME, + PHONE: contact.PHONE, + EMAIL: contact.EMAIL, + }, + }, () => { + this.props.onSubmitSubscriber({ + firstName: this.state.form.FNAME, + lastName: this.state.form.LNAME, + phoneNumber: this.state.form.PHONE, + email: this.state.form.EMAIL, + }); + }); + } + + prevQuestion = (question) => { + if (question === 'referral') { + const defaultQuestions = this.resetQuestions(); + let questions = this.state.questions; + const preQuestion = questions['referral'].prev; + questions[preQuestion].next = defaultQuestions[preQuestion].next; + this.setState({ questions }); + } + this.setQuestion(this.state.questions[question].prev); + this.setState({ anotherBuildingSubmitted: false, }); + } + + editAnswer = (question) => { + let questions = this.state.questions; + if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { + this.setQuestion(question); + } else { + questions[question].next = 'reviewAnswers'; + this.setState({ isEdit: true, questions }, () => { + this.setQuestion(question); + }); + } + } + + setQuestion = (question) => { + let questions = this.state.questions; + // If the current question is financeInterset set financeInterset as prev page for contact + if (this.props.building.data.surveyId === 1 && question === 'financeInterest') { + questions['feedback'].prev = 'financeInterest'; + this.setState({ + questions, + }); + } + // If the current question is waitList set waitList as prev page for contact + if (this.props.building.data.surveyId === 1 && question === 'waitList') { + questions['feedback'].prev = 'waitList'; + this.setState({ + questions, + }); + } + // If the survey ID is 2 or 3, set buildingFutureWaterImprovement as prev page for contact + if ([2, 3].includes(this.props.building.data.surveyId) && question === 'buildingNeeds') { + questions['feedback'].prev = this.props.building.data.surveyId === 3 ? 'buildingFutureImprovement' : 'buildingMedicalDevices'; + questions['buildingFutureImprovement'].next = this.props.building.data.surveyId === 3 ? 'feedback' : 'buildingElectricityShutoff'; + this.setState({ + questions, + }); + } + + this.setState({ + question, + prevQuestion: Object.keys(this.state.questions).includes(question) ? this.state.questions[question].prev : '', + }); + } + + submit = () => { + // Assign property values for last pages (thankyou and congrats) + const isSingleFamily = this.state.questions.buildingTypes.value === 20 || this.state.questions.waitList.value === 1 ? true : false; + const isWorshipBuilding = this.state.questions.buildingTypes.value === 32 ? true : false; + const anotherBuilding = this.state.questions.buildingTypes.value === 32 ? this.anotherBuilding : null; + const isWaitList = this.state.questions.waitList.value === 1 ? true : false; + const isOakland = this.props.building.data.surveyId === 2 ? true : false; + const isMilwaukee = this.props.building.data.surveyId === 3 ? true : false; + + this.state.pages.thankYou = ; + + const metaObj = this.getMeta(); + this.setState({ + submitted: true, + }, () => { + this.props.onSubmitQuestionnaire({ + firstName: this.state.form.FNAME, + lastName: this.state.form.LNAME, + email: this.state.form.EMAIL, + phone: this.state.form.PHONE, + buildingQualified: this.state.buildingQualified, + surveyId: metaObj.surveyId, + buildingId: metaObj.buildingId, + userId: metaObj.userId, + address: this.state.questions['addressSearch'].value, + }); + }); + this.setQuestion(this.state.questions.reviewAnswers.next); + } + + setReferral = (question) => { + let questions = this.state.questions; + questions[question].next = 'referral'; + questions['referral'].prev = question; + this.setState({ + question: 'referral', + questions, + }); + } + + submitReferral = (form) => { + const metaObj = this.getMeta(); + this.props.onSubmitReferral({ + referralFromFirstName: form.referralFromFirstName, + referralFromLastName: form.referralFromLastName, + referralFromEmail: form.referralFromEmail, + referralToFirstName: form.referralToFirstName, + referralToLastName: form.referralToLastName, + referralToEmail: form.referralToEmail, + referralFromUserId: metaObj.userId, + buildingId: metaObj.buildingId, + address: this.state.questions['addressSearch'].value, + }); + this.setQuestion('thankYou'); + } + + setMiniSplitforCooling = (miniSplitCheckBox) => { + this.setState({ + miniSplitCheckBox + }); + } + + handleInputChange = (event) => { + const val = event.target.value; + const name = event.target.name; + this.setState({ + form: { + ...this.state.form, + [name]: val, + }, + }); + } + + render() { + // console.log('render', this.props); + const building = this.props.building; + let addressSearchMessage = ""; + // TODO: Explain why search success is set to true in render function? + let addressSearchSuccess = true; + if (building.data !== undefined && building.data.success === false && building.data.message !== undefined) { + addressSearchSuccess = false; + addressSearchMessage = this.props.building.data.message; + } else { + addressSearchSuccess = true; + } + + // If user landed to questionnaire from referral link in Email, we need to show address to first question + const referralAddress = this.props.referral.data.referredTo !== undefined ? + this.props.referral.data.referredTo.address : ''; + + // Generating an object to represent all the questions in our survey + // Each key value pair associates a title with a component that either handles one question or a set of questions + // each time we render this is being generated... why? + const questions = { + addressSearch: , + fuels: , + heatDistribution: , + separateBoiler: , + heatingSystemAge: , + heatingSystemPlan: , + churchCoolingSystemAge: , + churchBuildingType: , + churchHoursPerWeek: , + operationalSeasons: , + unitBreakdown: , + feedback: , + buildingTypes: , + utilityBills: , + comfortIssues: , + financeInterest: , + waitList: , + contact: , + reviewAnswers: , + buildingTypeSubType: , + buildingNeeds: , + buildingOperatingChallenges: , + buildingHeatingSystem: , + buildingCoolingSystem: , + buildingElectricityShutoff: , + buildingMedicalDevices: , + churchCoolingSystemPlan: , + buildingPastImprovement: , + buildingFutureImprovement: , + anotherBuilding: , + referral: , + }; + + let content = ""; + // TODO: In plain english what does this if statement mean + 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' && 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 if (this.state.anotherBuildingSubmitted) { + content = questions['churchBuildingType']; + } else { + content = questions[this.state.question]; + } + } else if (Object.keys(this.state.pages).indexOf(this.state.question) > -1) { + // If question index is not out of bounds display content of either the Thank you or congrats page + content = this.state.pages[this.state.question]; + } else { + content = questions[this.state.question]; + } + + // TODO: What is this.props.num ? + return ( +
+ + + + {this.props.num} + + + {content} + + +
+ ); + } } -export default App; +const mapStatetoProps = state => { + return { + building: state.building, + questions: state.questions, + contact: state.contact, + complete: state.complete, + referral: state.referral, + } +} + +const mapDispatchtoProps = dispatch => { + return { + onSubmitBuilding: (data) => dispatch(submitBuilding(data)), + onSubmitAnswer: (data) => dispatch(submitAnswer(data)), + onSubmitUserAnswer: (data) => dispatch(submitUserAnswer(data)), + onSubmitContact: (data) => dispatch(submitContact(data)), + onSubmitQuestionnaire: (data) => dispatch(submitQuestionnaire(data)), + onLoadReferral: (ref_id) => dispatch(loadReferral(ref_id)), + onSubmitReferral: (data) => dispatch(submitReferral(data)), + onSubmitSubscriber: (data) => dispatch(submitSubscriber(data)), + } +}; + +export default connect(mapStatetoProps, mapDispatchtoProps)(App); diff --git a/src/ReviewAnswers.js b/src/ReviewAnswers.js index 15379b965..916d2e3a9 100644 --- a/src/ReviewAnswers.js +++ b/src/ReviewAnswers.js @@ -36,7 +36,9 @@ export default class ReviewAnswers extends React.Component { } render() { + console.log('review', this.props.order) const questions = this.props.questions; + const order = this.props.order; const phoneNumber = this.props.form.PHONE === 0 ? 'N/A' : this.props.form.PHONE; const content = (
@@ -45,7 +47,7 @@ export default class ReviewAnswers extends React.Component {
{ - questions.order + order .map(question => { if (questions[question].questions !== undefined) { if (questions[question].questions.filter(question => ![0, ""].includes(question.value)).length > 0) { -- GitLab From 19c9e9f34abd7284d806e8d1198ac85da06490c3 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Tue, 16 Jun 2020 13:37:52 -0400 Subject: [PATCH 17/33] Added comments --- src/App.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 0d259988a..cda94e9fa 100644 --- a/src/App.js +++ b/src/App.js @@ -789,7 +789,7 @@ class App extends React.Component { } setOrder = () => { - + // This function will initialize question order based on city and building type. let questions = this.state.questions; let order = [] @@ -906,7 +906,7 @@ class App extends React.Component { if(question === 'buildingTypes' || question === 'buildingTypeSubType') { let order = this.setOrder(); - this.setState({ order }, () => {console.log('done', this.state.order)}); + this.setState({ order }); } if(this.props.building.data.surveyId === 1) { @@ -930,13 +930,16 @@ class App extends React.Component { if (question === 'buildingTypes'){ if (value === 20) { + // When building type is single family questions['heatingSystemPlan'].next = 'waitList'; questions['waitList'].prev = 'heatingSystemPlan'; } else if (value === 32) { + // When building type is religeous questions['buildingTypes'].next = 'churchBuildingType'; questions['buildingFutureImprovement'].next = 'feedback'; questions['feedback'].prev = 'buildingFutureImprovement'; } else if ([21,22].includes(value)){ + // When building type is multi family or Mixed Use(Commercial/Residential) questions['heatingSystemPlan'].next = 'unitBreakdown'; questions['unitBreakdown'].next = 'utilityBills'; questions['utilityBills'].prev = 'unitBreakdown'; @@ -949,6 +952,7 @@ class App extends React.Component { } } + // When building type is church and question is building cooling system and user selects either Other, No cooling system or I'm not sure if (questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem' && [107,33,12].includes(value)) { let indexofCoolingAge = order.indexOf('churchCoolingSystemAge'); @@ -970,6 +974,7 @@ class App extends React.Component { questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' } + // When building type is church and question is building heating system and user selects either Other, No heating system or I'm not sure if (questions['buildingTypes'].value === 32 && question === 'buildingHeatingSystem' && [101,33,12].includes(value)) { let indexofHeatingFuel = order.indexOf('fuels'); @@ -996,6 +1001,7 @@ class App extends React.Component { questions['heatingSystemAge'].next = 'heatingSystemPlan'; } + // When building type is church and question is building heating system and user selectes Mini Heat Pump System for both heating and cooling system if (questions['buildingTypes']['value'] === 32 && question === 'buildingHeatingSystem') { if(this.state.miniSplitCheckBox === true) { @@ -1092,6 +1098,7 @@ class App extends React.Component { questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + // When user selectes Mini Heat Pump System for both heating and cooling system if (this.state.miniSplitCheckBox === true ) { this.props.onSubmitAnswer({ questionId: ["17"], @@ -1129,6 +1136,7 @@ class App extends React.Component { questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; + // When user selectes Mini Heat Pump System for both heating and cooling system if (this.state.miniSplitCheckBox === true ) { this.props.onSubmitAnswer({ questionId: ["17"], -- GitLab From 21f1445b9efacbbf02eaef0fac039f297e8c4725 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Tue, 16 Jun 2020 14:14:50 -0400 Subject: [PATCH 18/33] NYC Church BIS - minisplit heat pump system logic --- src/App.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/App.js b/src/App.js index cda94e9fa..566501f6e 100644 --- a/src/App.js +++ b/src/App.js @@ -840,7 +840,6 @@ class App extends React.Component { nextQuestion = (question, answer, value) => { const questionAnswers = {}; const questions = this.state.questions; - if (Array.isArray(answer) === true && questions[question]['questions'] !== undefined) { Object.keys(questions[question]['questions']).forEach(i => { questions[question]['questions'][i]['answer'] = answer[i]; @@ -922,7 +921,6 @@ class App extends React.Component { let questions = this.state.questions; let order = this.state.order; - if (question === 'anotherBuilding') { questions['churchBuildingType']['prev'] = 'anotherBuilding'; } @@ -1002,10 +1000,8 @@ class App extends React.Component { } // When building type is church and question is building heating system and user selectes Mini Heat Pump System for both heating and cooling system - if (questions['buildingTypes']['value'] === 32 && question === 'buildingHeatingSystem') { - + if (questions['buildingTypes']['value'] === 32) { if(this.state.miniSplitCheckBox === true) { - this.props.onSubmitAnswer({ questionId: ["17"], answerId: [106], @@ -1022,16 +1018,22 @@ class App extends React.Component { questions[question].next = 'reviewAnswers'; } - if(question==='heatingSystemPlan') { + if(question === 'fuels') { + if(this.state.isEdit) { + questions[question].next = 'reviewAnswers'; + } + } + + if(question === 'heatingSystemAge') { this.props.onSubmitAnswer({ - questionId: ["66"], + questionId: ["65"], answerId: [value], surveyId: this.props.building.data.surveyId, buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); - questions.churchCoolingSystemPlan.answer = questions.heatingSystemPlan.answer; - questions.churchCoolingSystemPlan.value = value; + questions.churchCoolingSystemAge.answer = questions.heatingSystemAge.answer; + questions.churchCoolingSystemAge.value = value; if(!order.includes(question)) { order.push(question); } @@ -1040,16 +1042,16 @@ class App extends React.Component { } } - if(question==='heatingSystemAge') { + if(question === 'heatingSystemPlan') { this.props.onSubmitAnswer({ - questionId: ["65"], + questionId: ["66"], answerId: [value], surveyId: this.props.building.data.surveyId, buildingId: this.props.building.data.buildingId, userId: this.props.building.data.userId, }); - questions.churchCoolingSystemAge.answer = questions.heatingSystemAge.answer; - questions.churchCoolingSystemAge.value = value; + questions.churchCoolingSystemPlan.answer = questions.heatingSystemPlan.answer; + questions.churchCoolingSystemPlan.value = value; if(!order.includes(question)) { order.push(question); } @@ -1057,11 +1059,10 @@ class App extends React.Component { questions[question].next = 'reviewAnswers'; } } - questions['heatingSystemPlan'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; this.setState({ questions, order }); - } else if (this.state.isEdit) { + } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; } else { questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; @@ -1247,7 +1248,11 @@ class App extends React.Component { editAnswer = (question) => { let questions = this.state.questions; if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { - this.setQuestion(question); + this.setState({ + isEdit: false, + }, () => { + this.setQuestion(question); + }); } else { questions[question].next = 'reviewAnswers'; this.setState({ -- GitLab From c02368d9b577da14f34d80b1951acbd1ec4a170e Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Tue, 16 Jun 2020 16:36:36 -0400 Subject: [PATCH 19/33] BI-1392 Complete --- src/App.js | 33 ++++++++++++++++++++------------- src/ReviewAnswers.js | 1 - 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/App.js b/src/App.js index 566501f6e..e2fd17d8a 100644 --- a/src/App.js +++ b/src/App.js @@ -75,7 +75,7 @@ class App extends React.Component { oakland={false} milwaukee={false} anotherBuilding={this.anotherBuilding} - />, + />, congrats: { + resetQuestions() { return { addressSearch: { title: 'What is your building address?', @@ -788,11 +790,17 @@ class App extends React.Component { }; } + resetState() { + let address = this.state.questions.addressSearch.value; + this.baseState['addressSearch'].answer = address; + this.baseState['addressSearch'].value = address; + this.setState({ questions: this.baseState }); + } + setOrder = () => { - // This function will initialize question order based on city and building type. + // This function will initialize question order based on city and building type let questions = this.state.questions; let order = [] - if (this.props.building.data.surveyId === 1) { if (questions['buildingTypes'].value === 20) { order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', @@ -1063,8 +1071,8 @@ class App extends React.Component { questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; this.setState({ questions, order }); } else if (this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - } else { + questions[question].next = 'reviewAnswers'; + } else { questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; } questions['buildingNeeds'].prev = 'operationalSeasons' @@ -1122,7 +1130,6 @@ class App extends React.Component { } } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: false }) } else { questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; } @@ -1160,7 +1167,6 @@ class App extends React.Component { } } else if (this.state.isEdit) { questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: false }) } else { questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; } @@ -1248,20 +1254,17 @@ class App extends React.Component { editAnswer = (question) => { let questions = this.state.questions; if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { + this.resetState(); this.setState({ isEdit: false, - }, () => { - this.setQuestion(question); }); } else { questions[question].next = 'reviewAnswers'; this.setState({ isEdit: true, - questions, - }, () => { - this.setQuestion(question); }); } + this.setQuestion(question); } setQuestion = (question) => { @@ -1289,6 +1292,10 @@ class App extends React.Component { }); } + if (this.state.isEdit) { + this.setState({ isEdit: false }) + } + this.setState({ question, prevQuestion: Object.keys(this.state.questions).includes(question) ? this.state.questions[question].prev : '', diff --git a/src/ReviewAnswers.js b/src/ReviewAnswers.js index 916d2e3a9..d4c5a94dc 100644 --- a/src/ReviewAnswers.js +++ b/src/ReviewAnswers.js @@ -36,7 +36,6 @@ export default class ReviewAnswers extends React.Component { } render() { - console.log('review', this.props.order) const questions = this.props.questions; const order = this.props.order; const phoneNumber = this.props.form.PHONE === 0 ? 'N/A' : this.props.form.PHONE; -- GitLab From 50991f1fc4cb1f38960041b0c2f1b4a80294027f Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Thu, 18 Jun 2020 14:33:10 -0400 Subject: [PATCH 20/33] BI-1391 complete --- src/App.js | 133 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 33 deletions(-) diff --git a/src/App.js b/src/App.js index e2fd17d8a..55253e648 100644 --- a/src/App.js +++ b/src/App.js @@ -790,7 +790,7 @@ class App extends React.Component { }; } - resetState() { + resetState = () => { let address = this.state.questions.addressSearch.value; this.baseState['addressSearch'].answer = address; this.baseState['addressSearch'].value = address; @@ -812,16 +812,17 @@ class App extends React.Component { order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'financeInterest', 'feedback'] } else if (questions['buildingTypes'].value === 32) { - order = ["addressSearch", "buildingTypes", "churchBuildingType", "churchHoursPerWeek", "operationalSeasons", - "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "fuels", "heatingSystemAge", "heatingSystemPlan", - "buildingCoolingSystem", "churchCoolingSystemAge", "churchCoolingSystemPlan", "buildingPastImprovement", "buildingFutureImprovement"] + order = ['addressSearch', 'buildingTypes', 'churchBuildingType', 'churchHoursPerWeek', 'operationalSeasons', + 'buildingNeeds', 'buildingOperatingChallenges', 'buildingHeatingSystem', 'fuels', 'heatingSystemAge', 'heatingSystemPlan', + 'buildingCoolingSystem', 'churchCoolingSystemAge', 'churchCoolingSystemPlan', 'buildingPastImprovement', + 'buildingFutureImprovement', 'feedback'] } } else if (this.props.building.data.surveyId === 2) { - order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", - "buildingPastImprovement", "buildingFutureImprovement", "buildingElectricityShutoff", "buildingMedicalDevices", "feedback"] + order = ['buildingTypeSubType', 'buildingNeeds', 'buildingOperatingChallenges', 'buildingHeatingSystem', 'buildingCoolingSystem', + 'buildingPastImprovement', 'buildingFutureImprovement', 'buildingElectricityShutoff', 'buildingMedicalDevices', 'feedback'] } else if (this.props.building.data.surveyId === 3) { - order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", - "buildingPastImprovement", "buildingFutureImprovement", "feedback"] + order = ['buildingTypeSubType', 'buildingNeeds', 'buildingOperatingChallenges', 'buildingHeatingSystem', 'buildingCoolingSystem', + 'buildingPastImprovement', 'buildingFutureImprovement', 'feedback'] } return order; } @@ -975,11 +976,33 @@ class App extends React.Component { questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; } - } else if (questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { - questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; - questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' } + // For cooling system questions for NYC Church BIS + if (questions['buildingTypes'].value === 32 + && question === 'buildingCoolingSystem' + && ![107,33,12].includes(value)) { + if (this.state.isEdit) { + if (!order.includes('churchCoolingSystemAge')) { + questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; + questions['churchCoolingSystemAge'].next = 'churchCoolingSystemPlan'; + questions['churchCoolingSystemPlan'].next = 'reviewAnswers'; + let indexofCoolingSystem = order.indexOf('buildingCoolingSystem'); + order.splice(indexofCoolingSystem+1, 0, "churchCoolingSystemAge"); + let indexofCoolingAge = order.indexOf('churchCoolingSystemAge'); + order.splice(indexofCoolingAge+1, 0, "churchCoolingSystemPlan"); + this.setState({ questions, order }); + } else { + questions['buildingCoolingSystem'].next = 'reviewAnswers'; + } + this.setState({ questions, order }); + } else { + questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; + questions['churchCoolingSystemAge'].next = 'churchCoolingSystemPlan'; + } + } + + // When building type is church and question is building heating system and user selects either Other, No heating system or I'm not sure if (questions['buildingTypes'].value === 32 && question === 'buildingHeatingSystem' && [101,33,12].includes(value)) { @@ -1000,11 +1023,37 @@ class App extends React.Component { questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; questions['buildingCoolingSystem'].prev = 'buildingHeatingSystem'; } - } else if (questions['buildingTypes'].value === 32 && question === 'buildingHeatingSystem') { - questions['buildingHeatingSystem'].next = 'fuels'; - questions['buildingCoolingSystem'].prev = 'heatingSystemPlan'; - questions['fuels'].next = 'heatingSystemAge'; - questions['heatingSystemAge'].next = 'heatingSystemPlan'; + } + + + // For heating system questions for NYC Church BIS + if (questions['buildingTypes'].value === 32 + && question === 'buildingHeatingSystem' + && this.state.miniSplitCheckBox === false + && ![101,33,12].includes(value)) { + if (this.state.isEdit) { + if (!order.includes('fuels')) { + questions['buildingHeatingSystem'].next = 'fuels'; + questions['fuels'].next = 'heatingSystemAge'; + questions['heatingSystemAge'].next = 'heatingSystemPlan'; + questions['heatingSystemPlan'].next = 'reviewAnswers'; + let indexofHeatingSystem = order.indexOf('buildingHeatingSystem'); + order.splice(indexofHeatingSystem+1, 0, "fuels"); + let indexofHeatingfuel = order.indexOf('fuels'); + order.splice(indexofHeatingfuel+1, 0, "heatingSystemAge"); + let indexofHeatingAge = order.indexOf('heatingSystemAge'); + order.splice(indexofHeatingAge+1, 0, "heatingSystemPlan"); + this.setState({ questions, order }); + } else { + questions['buildingHeatingSystem'].next = 'reviewAnswers'; + } + this.setState({ questions, order }); + } else { + questions['buildingHeatingSystem'].next = 'fuels'; + questions['buildingCoolingSystem'].prev = 'heatingSystemPlan'; + questions['fuels'].next = 'heatingSystemAge'; + questions['heatingSystemAge'].next = 'heatingSystemPlan'; + } } // When building type is church and question is building heating system and user selectes Mini Heat Pump System for both heating and cooling system @@ -1022,13 +1071,21 @@ class App extends React.Component { if(!order.includes("buildingCoolingSystem")) { order.push("buildingCoolingSystem"); } - if(this.state.isEdit) { + if(this.state.isEdit && order.includes('fuels')) { questions[question].next = 'reviewAnswers'; + } else { + let indexofHeatingSystem = order.indexOf('buildingHeatingSystem'); + order.splice(indexofHeatingSystem+1, 0, "fuels"); + questions[question].next = 'fuels'; } if(question === 'fuels') { - if(this.state.isEdit) { + if(this.state.isEdit && order.includes('heatingSystemAge')) { questions[question].next = 'reviewAnswers'; + } else { + let indexofHeatingfuel = order.indexOf('fuels'); + order.splice(indexofHeatingfuel+1, 0, "heatingSystemAge"); + questions[question].next = 'heatingSystemAge'; } } @@ -1042,11 +1099,16 @@ class App extends React.Component { }); questions.churchCoolingSystemAge.answer = questions.heatingSystemAge.answer; questions.churchCoolingSystemAge.value = value; - if(!order.includes(question)) { - order.push(question); + if(!order.includes("churchCoolingSystemAge")) { + let indexofCoolingSystem = order.indexOf('buildingCoolingSystem'); + order.splice(indexofCoolingSystem+1, 0, "churchCoolingSystemAge"); } - if(this.state.isEdit) { + if(this.state.isEdit && order.includes('heatingSystemPlan')) { questions[question].next = 'reviewAnswers'; + } else { + let indexofHeatingAge = order.indexOf('heatingSystemAge'); + order.splice(indexofHeatingAge+1, 0, "heatingSystemPlan"); + questions[question].next = 'heatingSystemPlan'; } } @@ -1060,25 +1122,25 @@ class App extends React.Component { }); questions.churchCoolingSystemPlan.answer = questions.heatingSystemPlan.answer; questions.churchCoolingSystemPlan.value = value; - if(!order.includes(question)) { - order.push(question); + if(!order.includes("churchCoolingSystemPlan")) { + let indexofCoolingAge = order.indexOf('churchCoolingSystemAge'); + order.splice(indexofCoolingAge+1, 0, "churchCoolingSystemPlan"); } if(this.state.isEdit) { questions[question].next = 'reviewAnswers'; + } else { + questions['heatingSystemPlan'].next = 'buildingPastImprovement'; + questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; } } - questions['heatingSystemPlan'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; this.setState({ questions, order }); - } else if (this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - } else { - questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; + } else if (!this.state.isEdit ){ + questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; } questions['buildingNeeds'].prev = 'operationalSeasons' questions['fuels'].prev = 'buildingHeatingSystem' questions['heatingSystemAge'].prev = 'fuels' - } else { + } else { questions['fuels'].prev = 'buildingTypes' } @@ -1258,6 +1320,11 @@ class App extends React.Component { this.setState({ isEdit: false, }); + } else if(this.props.building.data.surveyId === 1 && + (question === 'buildingHeatingSystem' || question === 'buildingCoolingSystem')) { + this.setState({ + isEdit: true, + }); } else { questions[question].next = 'reviewAnswers'; this.setState({ @@ -1292,9 +1359,9 @@ class App extends React.Component { }); } - if (this.state.isEdit) { - this.setState({ isEdit: false }) - } + // if (this.state.isEdit) { + // this.setState({ isEdit: false }) + // } this.setState({ question, -- GitLab From d38085dd63ca3f0eda5e31280ce531cb195295a8 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Thu, 18 Jun 2020 15:11:23 -0400 Subject: [PATCH 21/33] BI-1428 solved --- src/BuildingNeeds.js | 2 +- src/BuildingOperatingChallenges.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BuildingNeeds.js b/src/BuildingNeeds.js index a3d776a85..f9be055ba 100644 --- a/src/BuildingNeeds.js +++ b/src/BuildingNeeds.js @@ -99,7 +99,7 @@ export default class BuildingNeeds extends React.Component { className="button" onClick={this.nextQuestion} disabled={ - this.state.answerIds === 0 + (this.state.answerIds).length === 0 } > Continue > diff --git a/src/BuildingOperatingChallenges.js b/src/BuildingOperatingChallenges.js index 7963ab739..2f2d89756 100644 --- a/src/BuildingOperatingChallenges.js +++ b/src/BuildingOperatingChallenges.js @@ -102,7 +102,7 @@ export default class BuildingOperatingChallenges extends React.Component { className="button" onClick={this.nextQuestion} disabled={ - this.state.answerIds === 0 + (this.state.answerIds).length === 0 } > Continue > -- GitLab From bc2d1b97b0231927a67ed3702708f658fabe6689 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 19 Jun 2020 14:24:13 -0400 Subject: [PATCH 22/33] when building type is changed in NYC BIS --- src/App.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index 55253e648..8591f61f8 100644 --- a/src/App.js +++ b/src/App.js @@ -791,9 +791,15 @@ class App extends React.Component { } resetState = () => { - let address = this.state.questions.addressSearch.value; - this.baseState['addressSearch'].answer = address; - this.baseState['addressSearch'].value = address; + let questions = this.state.questions; + for (var key in questions) { + if (questions.hasOwnProperty(key)) { + if (questions[key].value !== 0 && questions[key].value !== undefined && questions[key].value.length !== 0) { + this.baseState[key].answer = questions[key].answer; + this.baseState[key].value = questions[key].value; + } + } + } this.setState({ questions: this.baseState }); } @@ -1316,6 +1322,7 @@ class App extends React.Component { editAnswer = (question) => { let questions = this.state.questions; if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { + console.log('edit', questions); this.resetState(); this.setState({ isEdit: false, -- GitLab From a53158083a6c2cc3db6f4dd7dd07672e9d4b43da Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 19 Jun 2020 15:59:00 -0400 Subject: [PATCH 23/33] All edge cases covered + testing done + back button working --- src/App.js | 75 ++- src/AppOld.js | 1636 ------------------------------------------------- 2 files changed, 43 insertions(+), 1668 deletions(-) delete mode 100644 src/AppOld.js diff --git a/src/App.js b/src/App.js index 8591f61f8..192f5b1cd 100644 --- a/src/App.js +++ b/src/App.js @@ -944,6 +944,7 @@ class App extends React.Component { if (value === 20) { // When building type is single family + questions['buildingTypes'].next = 'fuels'; questions['heatingSystemPlan'].next = 'waitList'; questions['waitList'].prev = 'heatingSystemPlan'; } else if (value === 32) { @@ -953,11 +954,17 @@ class App extends React.Component { questions['feedback'].prev = 'buildingFutureImprovement'; } else if ([21,22].includes(value)){ // When building type is multi family or Mixed Use(Commercial/Residential) + questions['buildingTypes'].next = 'fuels'; questions['heatingSystemPlan'].next = 'unitBreakdown'; questions['unitBreakdown'].next = 'utilityBills'; + questions['utilityBills'].next = 'comfortIssues'; + questions['comfortIssues'].next = 'financeInterest'; + questions['financeInterest'].prev = 'comfortIssues'; + questions['comfortIssues'].prev = 'utilityBills'; questions['utilityBills'].prev = 'unitBreakdown'; questions['reviewAnswers'].next = 'congrats'; } else { + questions['buildingTypes'].next = 'fuels'; questions['heatingSystemPlan'].next = 'unitBreakdown'; questions['unitBreakdown'].prev = 'heatingSystemPlan'; questions['unitBreakdown'].next = 'financeInterest'; @@ -1065,34 +1072,36 @@ class App extends React.Component { // When building type is church and question is building heating system and user selectes Mini Heat Pump System for both heating and cooling system if (questions['buildingTypes']['value'] === 32) { if(this.state.miniSplitCheckBox === true) { - this.props.onSubmitAnswer({ - questionId: ["17"], - answerId: [106], - surveyId: this.props.building.data.surveyId, - buildingId: this.props.building.data.buildingId, - userId: this.props.building.data.userId, - }); - questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; - questions.buildingCoolingSystem.value = 106; - if(!order.includes("buildingCoolingSystem")) { - order.push("buildingCoolingSystem"); - } - if(this.state.isEdit && order.includes('fuels')) { - questions[question].next = 'reviewAnswers'; - } else { - let indexofHeatingSystem = order.indexOf('buildingHeatingSystem'); - order.splice(indexofHeatingSystem+1, 0, "fuels"); + if(question === 'buildingHeatingSystem') { + this.props.onSubmitAnswer({ + questionId: ["17"], + answerId: [106], + surveyId: this.props.building.data.surveyId, + buildingId: this.props.building.data.buildingId, + userId: this.props.building.data.userId, + }); + questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; + questions.buildingCoolingSystem.value = 106; + if(!order.includes("buildingCoolingSystem")) { + order.push("buildingCoolingSystem"); + } + if(this.state.isEdit && order.includes('fuels')) { + questions[question].next = 'reviewAnswers'; + } else if (!order.includes('fuels')) { + let indexofHeatingSystem = order.indexOf(question); + order.splice(indexofHeatingSystem+1, 0, "fuels"); + } questions[question].next = 'fuels'; } if(question === 'fuels') { if(this.state.isEdit && order.includes('heatingSystemAge')) { questions[question].next = 'reviewAnswers'; - } else { - let indexofHeatingfuel = order.indexOf('fuels'); + } else if (!order.includes('heatingSystemAge')){ + let indexofHeatingfuel = order.indexOf(question); order.splice(indexofHeatingfuel+1, 0, "heatingSystemAge"); - questions[question].next = 'heatingSystemAge'; } + questions[question].next = 'heatingSystemAge'; } if(question === 'heatingSystemAge') { @@ -1111,11 +1120,11 @@ class App extends React.Component { } if(this.state.isEdit && order.includes('heatingSystemPlan')) { questions[question].next = 'reviewAnswers'; - } else { - let indexofHeatingAge = order.indexOf('heatingSystemAge'); + } else if (!order.includes('heatingSystemPlan')){ + let indexofHeatingAge = order.indexOf(question); order.splice(indexofHeatingAge+1, 0, "heatingSystemPlan"); - questions[question].next = 'heatingSystemPlan'; } + questions[question].next = 'heatingSystemPlan'; } if(question === 'heatingSystemPlan') { @@ -1140,7 +1149,7 @@ class App extends React.Component { } } this.setState({ questions, order }); - } else if (!this.state.isEdit ){ + } else if (!this.state.isEdit){ questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; } questions['buildingNeeds'].prev = 'operationalSeasons' @@ -1308,9 +1317,17 @@ class App extends React.Component { } prevQuestion = (question) => { + let questions = this.state.questions; + if ((this.props.building.data.surveyId === 1 && question === 'buildingTypes') || this.state.isEdit) { + this.resetState(); + } + if(question === 'buildingTypes' || question === 'buildingTypeSubType') { + let order = this.setOrder(); + this.setState({ order, questions }); + } + if (question === 'referral') { const defaultQuestions = this.resetQuestions(); - let questions = this.state.questions; const preQuestion = questions['referral'].prev; questions[preQuestion].next = defaultQuestions[preQuestion].next; this.setState({ questions }); @@ -1322,12 +1339,11 @@ class App extends React.Component { editAnswer = (question) => { let questions = this.state.questions; if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { - console.log('edit', questions); this.resetState(); this.setState({ isEdit: false, }); - } else if(this.props.building.data.surveyId === 1 && + } else if (this.props.building.data.surveyId === 1 && (question === 'buildingHeatingSystem' || question === 'buildingCoolingSystem')) { this.setState({ isEdit: true, @@ -1366,10 +1382,6 @@ class App extends React.Component { }); } - // if (this.state.isEdit) { - // this.setState({ isEdit: false }) - // } - this.setState({ question, prevQuestion: Object.keys(this.state.questions).includes(question) ? this.state.questions[question].prev : '', @@ -1457,7 +1469,6 @@ class App extends React.Component { } render() { - const building = this.props.building; let addressSearchMessage = ""; diff --git a/src/AppOld.js b/src/AppOld.js deleted file mode 100644 index 871e04ca0..000000000 --- a/src/AppOld.js +++ /dev/null @@ -1,1636 +0,0 @@ -import React from "react"; -import { Row, Col} from 'reactstrap'; -import 'bootstrap/dist/css/bootstrap.css'; -import SideBar from './SideBar'; -import AddressSearch from './AddressSearch'; -import Fuels from './Fuels'; -import HeatDistribution from './HeatDistribution'; -import SeparateBoiler from './SeparateBoiler'; -import HeatingSystemAge from './HeatingSystemAge'; -import HeatingSystemPlan from './HeatingSystemPlan'; -import UnitBreakdown from './UnitBreakdown'; -import Feedback from './Feedback'; -import BuildingTypes from './BuildingTypes'; -import UtilityBills from './UtilityBills'; -import ComfortIssues from './ComfortIssues'; -import ThankYou from './ThankYou'; -import Congrats from './Congrats'; -import FinanceInterest from './FinanceInterest'; -import WaitList from './WaitList'; -import Contact from './Contact'; -import ReviewAnswers from './ReviewAnswers'; -import BuildingNeeds from './BuildingNeeds'; -import BuildingOperatingChallenges from './BuildingOperatingChallenges'; -import BuildingCoolingSystem from './BuildingCoolingSystem'; -import BuildingHeatingSystem from './BuildingHeatingSystem'; -import BuildingTypeSubType from './BuildingTypeSubType'; -import BuildingPastImprovement from './BuildingPastImprovement'; -import BuildingFutureImprovement from './BuildingFutureImprovement'; -import BuildingElectricityShutoff from './BuildingElectricityShutoff'; -import BuildingMedicalDevices from './BuildingMedicalDevices'; -import ChurchCoolingSystemPlan from './ChurchCoolingSystemPlan'; -import ChurchCoolingSystemAge from './ChurchCoolingSystemAge'; -import ChurchBuildingType from './ChurchBuildingType'; -import ChurchHoursPerWeek from './ChurchHoursPerWeek'; -import OperationalSeasons from './OperationalSeasons'; -import AnotherBuilding from './AnotherBuilding'; -import Referral from './Referral'; -import { questionTree } from './constants'; -import { connect } from 'react-redux'; -import { - submitContact, - submitAnswer, - submitBuilding, - submitQuestionnaire, - submitUserAnswer, - submitReferral, - loadReferral, - submitSubscriber, -} from './actions'; -import './App.css'; -import ReactGA from 'react-ga'; - -class App extends React.Component { - constructor(props) { - super(props); - // this.setOrder = this.setOrder.bind(this); - this.state = { - submitted: false, - disabled: true, - surveyId: -1, - buildingId: -1, - buildingQualified: false, - form: { - FNAME: '', - LNAME: '', - EMAIL: '', - PHONE: '', - }, - prevQuestion: '', - question: 'addressSearch', // Set the first question as address search when initializing - questions: this.resetQuestions(), - order: [], - pages: { - thankYou: , - congrats: , - }, - multiFamilyAnswerId: 21, - miniSplitCheckBox: false, - anotherBuildingSubmitted: false, - isReferral: false, - isEdit: false, - }; - } - - componentDidMount() { - this.loadReferral(); - if(process.env.REACT_APP_ENVIRONMENT==='production'){ - ReactGA.initialize('UA-67611405-11'); - ReactGA.pageview('/intake'); - } - } - - loadReferral = () => { - const segments = window.location.href.split("ref_id="); - const ref_id = segments.length === 2 ? segments.pop() : ''; - if (ref_id !== '') { - this.props.onLoadReferral(ref_id); - this.setState({ isReferral: true }); - this.setQuestion('churchBuildingType'); - } - } - - componentWillReceiveProps(nextProps) { - // If user submitted another building search, use the new building object data - if (nextProps.building !== undefined && this.props.building !== undefined && - nextProps.building.data.userId !== this.props.building.data.userId && - this.state.anotherBuildingSubmitted === true) { - this.props.onSubmitAnswer({ - questionId: ["6"], - answerId: [32], - surveyId: nextProps.building.data.surveyId, - buildingId: nextProps.building.data.buildingId, - userId: nextProps.building.data.userId, - }); - } - - if (nextProps.referral.data !== undefined && this.props.referral.data != undefined && - nextProps.referral.data !== this.props.referral.data && - nextProps.referral.data.referredTo !== undefined) { - let questions = this.state.questions; - questions['addressSearch'].answer = nextProps.referral.data.referredTo.address; - questions['addressSearch'].value = nextProps.referral.data.referredTo.address; - const submittedAnswers = nextProps.referral.data.submittedAnswers; - Object.keys(questions).forEach(question => { - if (questions[question].id !== undefined) { - const questionId = questions[question].id.toString(); - if (Object.keys(submittedAnswers).includes(questionId)) { - questions[question].answer = Array.isArray(questions[question].answer) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; - questions[question].value = Array.isArray(questions[question].value) ? submittedAnswers[questionId] : submittedAnswers[questionId][0]; - } - } else if (questions[question].questions !== undefined && Array.isArray(questions[question].questions)) { - questions[question].questions.entries(([index, subQuestion]) => { - const subQuestionId = subQuestion.id.toString(); - if (Object.keys(submittedAnswers).includes(subQuestion.id)) { - questions[question].questions[index].answer = Array.isArray(questions[question].questions[index].answer) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; - questions[question].questions[index].value = Array.isArray(questions[question].questions[index].value) ? submittedAnswers[subQuestionId] : submittedAnswers[subQuestionId][0]; - } - }); - } - }); - this.setState({ questions }); - } - } - - resetQuestions = () => { - return { - addressSearch: { - title: 'What is your building address?', - answer: '', - value: '', - prev: 'addressSearch', - next: '', - }, - fuels: { - id: 1, - title: 'What type of fuel do you use to heat your building?', - answer: '', - value: '', - answerIds: [3, 4, 5, 6, 33], - answers: { 3: 'fuelOil', 4: 'naturalGas', 5: 'electricResistance', 6: 'dualFuel', 33: 'other' }, - prev: 'buildingTypes', - next: 'heatDistribution', - }, - heatDistribution: { - id: 2, - title: 'How is heat distributed in the building?', - answer: '', - value: '', - answerIds: [8, 9, 10, 11, 12], - answers: { 8: 'steam', 9: 'hotWater', 10: 'electricBaseboard', 11: 'forcedAir', 12: 'other' }, - prev: 'fuels', - next: 'separateBoiler', - }, - separateBoiler: { - id: 11, - title: 'Is the hot water prepared by the same boiler, or a separate water heater?', - answer: '', - value: 0, - answerIds: [111, 112, 12], - prev: 'heatDistribution', - next: 'heatingSystemAge', - }, - heatingSystemAge: { - id: 3, - title: 'About how old is your heating system?', - answer: '', - value: 0, - answerIds: [13, 14, 15, 16, 12], - prev: 'separateBoiler', - next: 'heatingSystemPlan', - }, - heatingSystemPlan: { - id: 4, - title: 'How soon do you plan in replacing your heating system?', - answer: '', - value: 0, - answerIds: [17, 18, 19, 12], - prev: 'heatingSystemAge', - next: '', - }, - churchBuildingType: { - id: 62, - title: 'Please tell us what kind of building you have.', - answer: '', - value: 0, - answerIds: [124, 125, 126, 137], - prev: 'addressSearch', - next: 'churchHoursPerWeek', - }, - churchHoursPerWeek: { - id: 63, - title: 'How many hours per week is the building occupied?', - answer: '', - value: 0, - answerIds: [127, 128, 129, 130], - prev: 'churchBuildingType', - next: 'operationalSeasons', - }, - operationalSeasons:{ - id: 64, - title: 'Which season(s) is the building operational?', - answer: [], - value: [], - answerIds: [131, 132, 133, 134], - answers: { - 131: 'Spring', - 132: 'Summer', - 133: 'Fall', - 134: 'Winter'}, - prev: 'churchHoursPerWeek', - next: 'buildingNeeds', - }, - unitBreakdown: { - title: 'Tell us about your building.', - questionIds: [52, 53, 54, 55, 56, 57], - answers: [0, 0, 0, 0, 0, 0], - prev: 'heatingSystemPlan', - next: '', - }, - buildingTypes: { - id: 6, - 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: 'fuels', - }, - utilityBills: { - title: 'Who pays the following utility bills?', - questions: [ - { - id: 5, - title: 'Heat and hot water', - answer: '', - value: 0, - answerIds: [24, 25], - }, - { - id: 8, - title: 'Electricity in unit', - answer: '', - value: 0, - answerIds: [24, 25], - }, - ], - prev: 'unitBreakdown', - next: 'comfortIssues', - }, - comfortIssues: { - id: 7, - title: 'In the winter, which of the following tenant comfort issues apply?', - answer: [], - value: [], - answerIds: [26, 27, 28, 29, 30, 31], - answers: { 26: 'tooHot', 27: 'windowsOpen', 28: 'tooCold', 29: 'spaceHeaters', 30: 'draft', 31: 'noComplaint' }, - prev: 'utilityBills', - next: 'financeInterest', - }, - financeInterest: { - id: 9, - title: 'Would you be interested in learning more about our no money down energy system lease options?', - answer: '', - value: 0, - answerIds: [1, 2], - prev: '', - next: 'feedback', - }, - waitList: { - id: 10, - title: 'Would you like to join our Waitlist?', - answer: '', - value: 0, - answerIds: [1, 2], - prev: 'buildingTypes', - next: 'feedback', - }, - feedback: { - questionIds: [58], - title: 'How did you hear about us?', - answers: '', - prev: '', - next: 'contact', - }, - contact: { - title: 'Your Information', - prev: 'feedback', - next: 'reviewAnswers', - }, - reviewAnswers: { - prev: 'waitList', - next: 'thankYou', - }, - buildingTypeSubType: { - title: 'What type of building do you own?', - id: 12, - answer: '', - value: 0, - questions: [ - { - id: 12, - title: '', - answer: '', - value: 0, - answerIds: [34, 109, 35, 36, 37, 38, 33], - }, - { - id: 13, - title: '', - answer: '', - value: 0, - answerIds: { - '34': [39, 40, 41, 42, 43, 44, 45, 46, 47], - '35': [52, 53, 54], - '36': [61, 62, 63, 64, 65, 33], - '37': [66, 67, 68, 69, 70], - '38': [71, 72, 73, 74, 33], - }, - }, - ], - prev: 'addressSearch', - next: 'buildingNeeds', - }, - buildingNeeds: { - id: 14, - title: 'What are your current building needs?', - answer: [], - value: [], - answerIds: [75, 76, 77, 78, 79, 80, 81, 82, 83, 33], - answers: { - 75: 'GainGeneralEducation', - 76: 'LowerUtilityBills', - 77: 'ResolveHeatingIssues', - 78: 'ResolveCoolingIssues', - 79: 'ImproveOccupantComfort', - 80: 'SubstantialBuildingRenovations', - 81: 'HelpFindingContractors', - 82: 'AdviceOnEnergyWaterEfficiency', - 83: 'HelpFinancingEnergyProject', - 33: 'other', - }, - prev: 'buildingTypeSubType', - next: 'buildingOperatingChallenges', - }, - buildingOperatingChallenges: { - id: 15, - title: 'What are your biggest building operating challenges?', - answer: [], - value: [], - answerIds: [84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 33], - answers: { - 84: 'NotEnoughResources', - 85: 'EquipmentBreaksDown', - 86: 'HighUtilityBilOil', - 87: 'HighUtilityBilNaturalGas', - 88: 'HighUtilityBilElectricity', - 89: 'HighUtilityBillWater', - 90: 'PoorInsulation', - 91: 'TooCold', - 92: 'TooDrafty', - 93: 'TooHot', - 94: 'NotEnoughDomesticHotWater', - 95: 'BuildingViolations', - 33: 'Other', - }, - prev: 'buildingNeeds', - next: 'buildingHeatingSystem', - }, - buildingHeatingSystem: { - id: 16, - title: 'What type of heating system does your building have?', - answer: '', - value: '', - answerIds: [96, 97, 98, 99, 100, 136, 101, 33, 12], - prev: 'buildingOperatingChallenges', - next: 'buildingCoolingSystem', - miniSplitCheckBox: false, - }, - buildingCoolingSystem: { - id: 17, - title: 'What type of cooling system does your building have?', - answer: '', - value: '', - answerIds: [102, 103, 104, 105, 106, 107, 108, 113, 136, 33, 12], - prev: 'buildingHeatingSystem', - next: 'buildingPastImprovement', - }, - buildingElectricityShutoff: { - title: 'Building Electricity Shutoffs', - questions: [ - { - id: 59, - title: 'Did your building experience electricity shutoff during recent PGE wildfire mitigation blackouts?', - answer: '', - value: 0, - answerIds: [1, 2], - }, - { - id: 61, - title: 'Do you expect your building to experience blackouts going forward?', - answer: '', - value: 0, - answerIds: [1, 2, 12], - }, - ], - prev: 'buildingFutureImprovement', - next: 'buildingMedicalDevices', - }, - buildingMedicalDevices: { - id: 60, - title: 'Do residents of your building use electrically connected medical devices?', - answer: '', - value: '', - answerIds: [1, 2, 12], - prev: 'buildingElectricityShutoff', - next: 'feedback', - }, - churchCoolingSystemAge: { - id: 65, - title: 'How old is the cooling system?', - answer: '', - value: '', - answerIds: [13, 14, 15, 16, 12], - prev: 'buildingCoolingSystem', - next: 'churchCoolingSystemPlan', - }, - churchCoolingSystemPlan: { - id: 66, - title: 'How soon do you plan in replacing your cooling system?', - answer: '', - value: 0, - answerIds: [17, 18, 19, 12], - prev: 'churchCoolingSystemAge', - next: 'buildingPastImprovement', - }, - buildingPastImprovement: { - title: 'Any Energy or Water Improvements in the past 5 years?', - questions: [ - { - id: 18, - name: 'newHeatingSystem', - title: 'Install a new heating system', - answer: 2, - value: '', - answerIds: [96, 97, 98, 99, 100, 33, 12], - checked: false, - }, - { - id: 19, - name: 'newCoolingSystem', - title: 'Install a new cooling system', - answer: 2, - value: '', - answerIds: [102, 103, 104, 105, 106, 108, 113, 33, 12], - checked: false, - }, - { - id: 20, - name: 'newControls', - title: 'Install new controls', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 21, - name: 'convertHeatingFuel', - title: 'Convert heating fuel', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 22, - name: 'convertHeatingSystem', - title: 'Convert heating system', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 23, - name: 'newDomesticHotwaterSystem', - title: 'Install new domestic hotwater system', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 24, - name: 'addInsulation', - title: 'Add insulation', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 25, - name: 'airSealBuildingEnvelope', - title: 'Air seal the building envelope', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 26, - name: 'newWindows', - title: 'New windows', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 27, - name: 'newRoof', - title: 'New roof', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 28, - name: 'solarPanels', - title: 'Solar panels', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 29, - name: 'toilets', - title: 'Toilets', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 30, - name: 'lowFlowShowerheadsFaucets', - title: 'Low flow showerheads & faucets', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 31, - name: 'ledLighting', - title: 'LED lighting', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 32, - name: 'other', - title: 'Other', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 33, - name: 'none', - title: 'None', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 34, - name: 'notSure', - title: 'I\'m not sure', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - ], - prev: 'buildingCoolingSystem', - next: 'buildingFutureImprovement', - }, - buildingFutureImprovement: { - title: 'Any Energy or Water Improvements within coming year or so?', - questions: [ - { - id: 35, - name: 'newHeatingSystem', - title: 'Install a new heating system', - answer: 2, - value: '', - answerIds: [96, 97, 98, 99, 100, 33, 12], - checked: false, - }, - { - id: 36, - name: 'newCoolingSystem', - title: 'Install a new cooling system', - answer: 2, - value: '', - answerIds: [102, 103, 104, 105, 106, 108, 113, 33, 12], - checked: false, - }, - { - id: 37, - name: 'newControls', - title: 'Install new controls', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 38, - name: 'convertHeatingFuel', - title: 'Convert heating fuel', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 39, - name: 'convertHeatingSystem', - title: 'Convert heating system', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 40, - name: 'newDomesticHotwaterSystem', - title: 'Install new domestic hotwater system', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 41, - name: 'addInsulation', - title: 'Add insulation', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 42, - name: 'airSealBuildingEnvelope', - title: 'Air seal the building envelope', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 43, - name: 'newWindows', - title: 'New windows', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 44, - name: 'newRoof', - title: 'New roof', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 45, - name: 'solarPanels', - title: 'Solar panels', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 46, - name: 'toilets', - title: 'Toilets', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 47, - name: 'lowFlowShowerheadsFaucets', - title: 'Low flow showerheads & faucets', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 48, - name: 'ledLighting', - title: 'LED lighting', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 49, - name: 'other', - title: 'Other', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 50, - name: 'none', - title: 'None', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - { - id: 51, - name: 'notSure', - title: 'I\'m not sure', - answer: '', - value: 0, - answerIds: [1, 2], - checked: false, - }, - ], - prev: 'buildingPastImprovement', - next: 'feedback', - }, - anotherBuilding: { - title: '', - answer: '', - value: '', - prev: 'anotherBuilding', - next: 'churchBuildingType', - }, - referral: { - title: '', - answer: '', - value: '', - prev: 'referral', - next: 'thankYou', - }, - order: [], - }; - } - - getMeta = () => { - let metaObj = { - buildingId: '', - userId: '', - surveyId: 1 - }; - - if (this.props.referral.data !== undefined && this.props.referral.data.referredTo !== undefined) { - metaObj.userId = this.props.referral.data.referredTo.userId; - metaObj.buildingId = this.props.referral.data.referredTo.buildingId; - } - if (this.props.building.data !== undefined && this.props.building.data.buildingId !== undefined) { - metaObj.buildingId = this.props.building.data.buildingId; - metaObj.userId = this.props.building.data.userId; - metaObj.surveyId = this.props.building.data.surveyId; - } - return metaObj; - } - - setOrder = () => { - - let questions = this.state.questions; - console.log('set order', questions['buildingTypes'].value) - let order = [] - - if (this.props.building.data.surveyId === 1) { - if (questions['buildingTypes'].value === 20) { - order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', - 'heatingSystemAge', 'heatingSystemPlan', 'waitList', 'feedback'] - } else if ([21, 22].includes(questions['buildingTypes'].value)) { - order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', - 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'utilityBills', 'comfortIssues', 'financeInterest', 'feedback'] - } else if([23, 33].includes(questions['buildingTypes'].value)) { - order = ['addressSearch', 'buildingTypes', 'fuels', 'heatDistribution', 'separateBoiler', - 'heatingSystemAge', 'heatingSystemPlan', 'unitBreakdown', 'financeInterest', 'feedback'] - } else if (questions['buildingTypes'].value === 32) { - order = ["addressSearch", "buildingTypes", "churchBuildingType", "churchHoursPerWeek", "operationalSeasons", - "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "fuels", "heatingSystemAge", "heatingSystemPlan", - "buildingCoolingSystem", "churchCoolingSystemAge", "churchCoolingSystemPlan", "buildingPastImprovement", "buildingFutureImprovement"] - } - } else if (this.props.building.data.surveyId === 2) { - order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", - "buildingPastImprovement", "buildingFutureImprovement", "buildingElectricityShutoff", "buildingMedicalDevices", "feedback"] - } else if (this.props.building.data.surveyId === 3) { - order = ["buildingTypeSubType", "buildingNeeds", "buildingOperatingChallenges", "buildingHeatingSystem", "buildingCoolingSystem", - "buildingPastImprovement", "buildingFutureImprovement", "feedback"] - } - return order; - } - - nextQuestion = (question, answer, value) => { - const questionAnswers = {}; - const questions = this.state.questions; - // console.log('next q', questions.order); - - if (Array.isArray(answer) === true && questions[question]['questions'] !== undefined) { - Object.keys(questions[question]['questions']).forEach(i => { - questions[question]['questions'][i]['answer'] = answer[i]; - questions[question]['questions'][i]['value'] = value[i]; - questionAnswers[questions[question]['questions'][i].id] = value[i]; - }); - } else if (Array.isArray(answer) === true && Array.isArray(questions[question]['questionIds']) === true) { - questions[question]['answers'] = value; - } else { - questions[question].answer = answer; - questions[question].value = value; - questionAnswers[questions[question].id] = value; - } - - if (question === 'anotherBuilding') { - questions['churchBuildingType']['prev'] = 'anotherBuilding'; - } - - const metaObj = this.getMeta(); - this.setState({ questions }, () => { - if (['addressSearch', 'anotherBuilding'].includes(question)) { - this.props.onSubmitBuilding({ - address: this.state.questions[question].value, - }); - // If user clicks on 'continue' button on another building search page - if (question === 'anotherBuilding') { - this.setState({ anotherBuildingSubmitted: true }); - } - } else if (question === 'unitBreakdown' || question === 'feedback'){ - this.setQuestion(this.state.questions[question].next); - this.props.onSubmitUserAnswer({ - questionId: questions[question]['questionIds'], - answers: questions[question]['answers'], - surveyId: metaObj.surveyId, - buildingId: metaObj.buildingId, - userId: metaObj.userId, - }); - this.setState({ anotherBuildingSubmitted: false }); - } else { - this.setQuestion(this.state.questions[question].next); - if (question === 'churchBuildingType' && this.state.isReferral){ - this.props.onSubmitAnswer({ - questionId: ["6"], - answerId: [32], - surveyId: metaObj.surveyId, - buildingId: metaObj.buildingId, - userId: metaObj.userId, - }); - } - this.props.onSubmitAnswer({ - questionId: Object.keys(questionAnswers), - answerId: Object.values(questionAnswers), - surveyId: metaObj.surveyId, - buildingId: metaObj.buildingId, - userId: metaObj.userId, - }); - this.setState({ anotherBuildingSubmitted: false }); - } - }); - - this.updateQuestionChain(question, value); - window.scrollTo(0, 0); - } - - updateQuestionChain = (question, value) => { - console.log(this.props.building.data.surveyId) - let questions = this.state.questions; - if(question === 'buildingTypes') { - console.log('building type') - let order = this.setOrder(); - this.setState({ order }, () => {console.log('done', this.state.order)}); - } - console.log(this.state.anotherBuildingSubmitted) - if (question === 'buildingTypes'){ - // Set the next question for building types. - // If religious institute next page -> Church Building Type - // Else fuel types - questions['buildingTypes'].next = value === 32 ? 'churchBuildingType' : 'fuels'; - // If the building type is multifam or mixed use, we will display unit breakdown, utility bills and comfort issues. - if ([21,22].includes(value)){ - questions['heatingSystemPlan'].next = 'unitBreakdown'; - questions['unitBreakdown'].next = 'utilityBills'; - questions['utilityBills'].prev = 'unitBreakdown'; - questions['reviewAnswers'].next = 'congrats'; - } - // Else the next page from unit breakdown will be financial interest. - else{ - questions['heatingSystemPlan'].next = 'unitBreakdown'; - questions['unitBreakdown'].prev = 'heatingSystemPlan'; - questions['unitBreakdown'].next = 'financeInterest'; - questions['financeInterest'].prev = 'unitBreakdown'; - } - } - // If the building type is single family the next page of heating system plan will be wait list. - if (question === 'buildingTypes' && value === 20){ - questions['heatingSystemPlan'].next = 'waitList'; - questions['waitList'].prev = 'heatingSystemPlan'; - } - // For NYC Church survey, set feedback as the next page of building future improvement. - if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32) { - questions['buildingFutureImprovement'].next = 'feedback'; - questions['feedback'].prev = 'buildingFutureImprovement'; - } - - // If the cooling system type is 'I don't have' or 'I don't know' we will skip Cooling sys age and replacement plan. - if ((this.props.building.data.surveyId === 1 && question === 'buildingCoolingSystem' && ([107,33,12].includes(value)))){ - let indexofCoolingAge = questions.order.indexOf('churchCoolingSystemAge'); - // console.log(indexofCoolingAge) - questions.order.splice(indexofCoolingAge, 1); - let indexofCoolingPlan = questions.order.indexOf('churchCoolingSystemPlan'); - // console.log(indexofCoolingPlan) - questions.order.splice(indexofCoolingPlan, 1); - // console.log(questions.order) - this.setState({ questions }); - if (this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - } else { - questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; - } - } else if (this.props.building.data.surveyId === 1 && questions['buildingTypes'].value === 32 && question === 'buildingCoolingSystem') { - questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; - questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' - } - - if([2,3].includes(this.props.building.data.surveyId)) { - questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; - - if (this.state.miniSplitCheckBox === true ) { - this.props.onSubmitAnswer({ - questionId: ["17"], - answerId: [106], - surveyId: this.props.building.data.surveyId, - buildingId: this.props.building.data.buildingId, - userId: this.props.building.data.userId, - }); - questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; - questions.buildingCoolingSystem.value = 106; - // Add cooling system question into review order - if(!questions.order.includes("buildingCoolingSystem")) { - questions.order.push("buildingCoolingSystem"); - } - this.setState({ questions }); - if(this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - // this.setState({ isEdit: false }); - } else { - questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingHeatingSystem'; - } - } else if (this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: false }) - } - } else { - questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; - } - - // Heating System for NYC Church PNS. - if (this.props.building.data.surveyId === 1 && questions['buildingTypes']['value'] === 32){ - // If minisplit is also used for cooling system -> We will skip all 3 cooling sys questions. - if(this.state.miniSplitCheckBox === true) { - this.props.onSubmitAnswer({ - questionId: ["17"], - answerId: [106], - surveyId: this.props.building.data.surveyId, - buildingId: this.props.building.data.buildingId, - userId: this.props.building.data.userId, - }); - questions.buildingCoolingSystem.answer = "Minisplit heat pump systems"; - questions.buildingCoolingSystem.value = 106; - // Add cooling system question into review order - if(!questions.order.includes("buildingCoolingSystem")) { - questions.order.push("buildingCoolingSystem"); - } - if(this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - // this.setState({ isEdit: false }); - } - // Store heating system plan answer in cooling system plan - if(question==='heatingSystemPlan') { - this.props.onSubmitAnswer({ - questionId: ["66"], - answerId: [value], - surveyId: this.props.building.data.surveyId, - buildingId: this.props.building.data.buildingId, - userId: this.props.building.data.userId, - }); - questions.churchCoolingSystemPlan.answer = questions.heatingSystemPlan.answer; - questions.churchCoolingSystemPlan.value = value; - if(!questions.order.includes(question)) { - questions.order.push(question); - } - if(this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - // this.setState({ isEdit: false }); - } - } - // Store heating system age answer in cooling system age - if(question==='heatingSystemAge') { - this.props.onSubmitAnswer({ - questionId: ["65"], - answerId: [value], - surveyId: this.props.building.data.surveyId, - buildingId: this.props.building.data.buildingId, - userId: this.props.building.data.userId, - }); - questions.churchCoolingSystemAge.answer = questions.heatingSystemAge.answer; - questions.churchCoolingSystemAge.value = value; - if(!questions.order.includes(question)) { - questions.order.push(question); - } - if(this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - // this.setState({ isEdit: false }); - } - } - questions['heatingSystemPlan'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; - this.setState({ questions }); - } else if (this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - // this.setState({ isEdit: false }) - } else { - questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; - } - // Set back button pages - questions['buildingNeeds'].prev = 'operationalSeasons' - questions['fuels'].prev = 'buildingHeatingSystem' - questions['heatingSystemAge'].prev = 'fuels' - } - else{ - questions['fuels'].prev = 'buildingTypes' - } - if (this.props.building.data.surveyId === 1 && question === 'buildingHeatingSystem' && questions['buildingTypes']['value'] === 32){ - // If the heating system type is 'I don't know' or 'I don't have' we will skip next 3 heating sys related questions. - if ([101,33,12].includes(value)) { - let indexofHeatingFuel = questions.order.indexOf('fuels'); - questions.order.splice(indexofHeatingFuel, 1); - let indexofHeatingAge = questions.order.indexOf('heatingSystemAge'); - questions.order.splice(indexofHeatingAge, 1); - let indexofHeatingPlan = questions.order.indexOf('heatingSystemPlan'); - questions.order.splice(indexofHeatingPlan, 1); - if (this.state.isEdit) { - questions[question].next = 'reviewAnswers'; - } else { - questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; - questions['buildingCoolingSystem'].prev = 'buildingHeatingSystem'; - } - this.setState({ questions }); - } else { - questions['buildingHeatingSystem'].next = 'fuels'; - questions['buildingCoolingSystem'].prev = 'heatingSystemPlan' - } - questions['fuels'].next = 'heatingSystemAge'; - questions['heatingSystemAge'].next = 'heatingSystemPlan'; - } - - // If building type is not single fam and fuel type is natural gas or dual fuel -> display congrats page. - if (questions['unitBreakdown']['value'] !== 20 && question === 'fuels' && [4,6].includes(value)){ - this.setState({ buildingQualified: true}); - this.state.pages.congrats = ; - } else { - this.state.pages.congrats = ; - } - } - - anotherBuilding = () => { - // When user starts new loop of questionnaire, we reset all the answers - const questions = this.resetQuestions(); - questions['addressSearch'].value = this.state.questions['addressSearch'].value; - questions['buildingTypes'].value = this.state.questions['buildingTypes'].value; - this.setState({ - questions, - question: 'anotherBuilding', - }); - } - - submitContact = (contact) => { - const isWorshipBuilding = this.state.questions.buildingTypes.value === 32 ? true : false; - const metaObj = this.getMeta(); - this.setQuestion(this.state.questions['contact'].next); - this.setState({ - form: { - FNAME: contact.FNAME, - LNAME: contact.LNAME, - PHONE: contact.PHONE, - EMAIL: contact.EMAIL, - buildingId: metaObj.buildingId, - userId: metaObj.userId, - }, - }, () => { - this.props.onSubmitContact({ - firstName: this.state.form.FNAME, - lastName: this.state.form.LNAME, - phoneNumber: this.state.form.PHONE, - email: this.state.form.EMAIL, - buildingId: metaObj.buildingId, - userId: metaObj.userId, - surveyId: this.props.building.data.surveyId, - isWorshipBuilding - }); - }); - } - - submitSubscriber = (contact) => { - this.setState({ - form: { - FNAME: contact.FNAME, - LNAME: contact.LNAME, - PHONE: contact.PHONE, - EMAIL: contact.EMAIL, - }, - }, () => { - this.props.onSubmitSubscriber({ - firstName: this.state.form.FNAME, - lastName: this.state.form.LNAME, - phoneNumber: this.state.form.PHONE, - email: this.state.form.EMAIL, - }); - }); - } - - prevQuestion = (question) => { - if (question === 'referral') { - const defaultQuestions = this.resetQuestions(); - let questions = this.state.questions; - const preQuestion = questions['referral'].prev; - questions[preQuestion].next = defaultQuestions[preQuestion].next; - this.setState({ questions }); - } - this.setQuestion(this.state.questions[question].prev); - this.setState({ anotherBuildingSubmitted: false, }); - } - - editAnswer = (question) => { - let questions = this.state.questions; - if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { - this.setQuestion(question); - } else { - questions[question].next = 'reviewAnswers'; - this.setState({ isEdit: true, questions }, () => { - this.setQuestion(question); - }); - } - } - - setQuestion = (question) => { - let questions = this.state.questions; - // If the current question is financeInterset set financeInterset as prev page for contact - if (this.props.building.data.surveyId === 1 && question === 'financeInterest') { - questions['feedback'].prev = 'financeInterest'; - this.setState({ - questions, - }); - } - // If the current question is waitList set waitList as prev page for contact - if (this.props.building.data.surveyId === 1 && question === 'waitList') { - questions['feedback'].prev = 'waitList'; - this.setState({ - questions, - }); - } - // If the survey ID is 2 or 3, set buildingFutureWaterImprovement as prev page for contact - if ([2, 3].includes(this.props.building.data.surveyId) && question === 'buildingNeeds') { - questions['feedback'].prev = this.props.building.data.surveyId === 3 ? 'buildingFutureImprovement' : 'buildingMedicalDevices'; - questions['buildingFutureImprovement'].next = this.props.building.data.surveyId === 3 ? 'feedback' : 'buildingElectricityShutoff'; - this.setState({ - questions, - }); - } - - this.setState({ - question, - prevQuestion: Object.keys(this.state.questions).includes(question) ? this.state.questions[question].prev : '', - }); - } - - submit = () => { - // Assign property values for last pages (thankyou and congrats) - const isSingleFamily = this.state.questions.buildingTypes.value === 20 || this.state.questions.waitList.value === 1 ? true : false; - const isWorshipBuilding = this.state.questions.buildingTypes.value === 32 ? true : false; - const anotherBuilding = this.state.questions.buildingTypes.value === 32 ? this.anotherBuilding : null; - const isWaitList = this.state.questions.waitList.value === 1 ? true : false; - const isOakland = this.props.building.data.surveyId === 2 ? true : false; - const isMilwaukee = this.props.building.data.surveyId === 3 ? true : false; - - this.state.pages.thankYou = ; - - const metaObj = this.getMeta(); - this.setState({ - submitted: true, - }, () => { - this.props.onSubmitQuestionnaire({ - firstName: this.state.form.FNAME, - lastName: this.state.form.LNAME, - email: this.state.form.EMAIL, - phone: this.state.form.PHONE, - buildingQualified: this.state.buildingQualified, - surveyId: metaObj.surveyId, - buildingId: metaObj.buildingId, - userId: metaObj.userId, - address: this.state.questions['addressSearch'].value, - }); - }); - this.setQuestion(this.state.questions.reviewAnswers.next); - } - - setReferral = (question) => { - let questions = this.state.questions; - questions[question].next = 'referral'; - questions['referral'].prev = question; - this.setState({ - question: 'referral', - questions, - }); - } - - submitReferral = (form) => { - const metaObj = this.getMeta(); - this.props.onSubmitReferral({ - referralFromFirstName: form.referralFromFirstName, - referralFromLastName: form.referralFromLastName, - referralFromEmail: form.referralFromEmail, - referralToFirstName: form.referralToFirstName, - referralToLastName: form.referralToLastName, - referralToEmail: form.referralToEmail, - referralFromUserId: metaObj.userId, - buildingId: metaObj.buildingId, - address: this.state.questions['addressSearch'].value, - }); - this.setQuestion('thankYou'); - } - - setMiniSplitforCooling = (miniSplitCheckBox) => { - this.setState({ - miniSplitCheckBox - }); - } - - handleInputChange = (event) => { - const val = event.target.value; - const name = event.target.name; - this.setState({ - form: { - ...this.state.form, - [name]: val, - }, - }); - } - - render() { - // console.log('render', this.props); - const building = this.props.building; - let addressSearchMessage = ""; - // TODO: Explain why search success is set to true in render function? - let addressSearchSuccess = true; - if (building.data !== undefined && building.data.success === false && building.data.message !== undefined) { - addressSearchSuccess = false; - addressSearchMessage = this.props.building.data.message; - } else { - addressSearchSuccess = true; - } - - // If user landed to questionnaire from referral link in Email, we need to show address to first question - const referralAddress = this.props.referral.data.referredTo !== undefined ? - this.props.referral.data.referredTo.address : ''; - - // Generating an object to represent all the questions in our survey - // Each key value pair associates a title with a component that either handles one question or a set of questions - // each time we render this is being generated... why? - const questions = { - addressSearch: , - fuels: , - heatDistribution: , - separateBoiler: , - heatingSystemAge: , - heatingSystemPlan: , - churchCoolingSystemAge: , - churchBuildingType: , - churchHoursPerWeek: , - operationalSeasons: , - unitBreakdown: , - feedback: , - buildingTypes: , - utilityBills: , - comfortIssues: , - financeInterest: , - waitList: , - contact: , - reviewAnswers: , - buildingTypeSubType: , - buildingNeeds: , - buildingOperatingChallenges: , - buildingHeatingSystem: , - buildingCoolingSystem: , - buildingElectricityShutoff: , - buildingMedicalDevices: , - churchCoolingSystemPlan: , - buildingPastImprovement: , - buildingFutureImprovement: , - anotherBuilding: , - referral: , - }; - - let content = ""; - // TODO: In plain english what does this if statement mean - 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' && 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 if (this.state.anotherBuildingSubmitted) { - content = questions['churchBuildingType']; - } else { - content = questions[this.state.question]; - } - } else if (Object.keys(this.state.pages).indexOf(this.state.question) > -1) { - // If question index is not out of bounds display content of either the Thank you or congrats page - content = this.state.pages[this.state.question]; - } else { - content = questions[this.state.question]; - } - - // TODO: What is this.props.num ? - return ( -
- - - - {this.props.num} - - - {content} - - -
- ); - } -} - -const mapStatetoProps = state => { - return { - building: state.building, - questions: state.questions, - contact: state.contact, - complete: state.complete, - referral: state.referral, - } -} - -const mapDispatchtoProps = dispatch => { - return { - onSubmitBuilding: (data) => dispatch(submitBuilding(data)), - onSubmitAnswer: (data) => dispatch(submitAnswer(data)), - onSubmitUserAnswer: (data) => dispatch(submitUserAnswer(data)), - onSubmitContact: (data) => dispatch(submitContact(data)), - onSubmitQuestionnaire: (data) => dispatch(submitQuestionnaire(data)), - onLoadReferral: (ref_id) => dispatch(loadReferral(ref_id)), - onSubmitReferral: (data) => dispatch(submitReferral(data)), - onSubmitSubscriber: (data) => dispatch(submitSubscriber(data)), - } -}; - -export default connect(mapStatetoProps, mapDispatchtoProps)(App); -- GitLab From 3ca624a6476ce632eea6694a69799de41bd03f48 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Mon, 22 Jun 2020 13:38:28 -0400 Subject: [PATCH 24/33] BI-1430 complete --- src/App.js | 26 +++++++++++++++++++++++++- src/BuildingCoolingSystem.js | 15 +++++++++------ src/BuildingElectricityShutoff.js | 15 +++++++++------ src/BuildingFutureImprovement.js | 15 +++++++++------ src/BuildingHeatingSystem.js | 15 +++++++++------ src/BuildingMedicalDevices.js | 15 +++++++++------ src/BuildingNeeds.js | 15 +++++++++------ src/BuildingOperatingChallenges.js | 15 +++++++++------ src/BuildingPastImprovement.js | 15 +++++++++------ src/BuildingTypeSubType.js | 1 + src/ChurchBuildingType.js | 2 +- src/ChurchCoolingSystemAge.js | 17 ++++++++++------- src/ChurchCoolingSystemPlan.js | 15 +++++++++------ src/ChurchHoursPerWeek.js | 15 +++++++++------ src/ComfortIssues.js | 15 +++++++++------ src/Contact.js | 15 +++++++++------ src/Feedback.js | 15 +++++++++------ src/FinanceInterest.js | 16 ++++++++++------ src/Fuels.js | 17 +++++++++++------ src/HeatDistribution.js | 16 ++++++++++------ src/HeatingSystemAge.js | 15 +++++++++------ src/HeatingSystemPlan.js | 15 +++++++++------ src/OperationalSeasons.js | 15 +++++++++------ src/SeparateBoiler.js | 15 +++++++++------ src/UnitBreakdown.js | 15 +++++++++------ src/UtilityBills.js | 15 +++++++++------ src/WaitList.js | 15 +++++++++------ 27 files changed, 248 insertions(+), 147 deletions(-) diff --git a/src/App.js b/src/App.js index 192f5b1cd..b4f92ff2b 100644 --- a/src/App.js +++ b/src/App.js @@ -1318,7 +1318,7 @@ class App extends React.Component { prevQuestion = (question) => { let questions = this.state.questions; - if ((this.props.building.data.surveyId === 1 && question === 'buildingTypes') || this.state.isEdit) { + if ((this.props.building.data.surveyId === 1 && question === 'buildingTypes')) { this.resetState(); } if(question === 'buildingTypes' || question === 'buildingTypeSubType') { @@ -1505,6 +1505,7 @@ class App extends React.Component { answer={this.state.questions['fuels'].value} answerIds={this.state.questions['fuels'].answerIds} answers={this.state.questions['fuels'].answers} + isEdit={this.state.isEdit} />, heatDistribution: , separateBoiler: , heatingSystemAge: , heatingSystemPlan: , churchCoolingSystemAge: , churchBuildingType: , churchHoursPerWeek: , operationalSeasons: , unitBreakdown: , feedback: , buildingTypes: , comfortIssues: , financeInterest: , waitList: , contact: , reviewAnswers: , buildingOperatingChallenges: , buildingHeatingSystem: , buildingCoolingSystem: , buildingMedicalDevices: , churchCoolingSystemPlan: , buildingPastImprovement: , buildingFutureImprovement: , anotherBuilding: + {'<'} Back + ) : ''; + const referralButton = this.state.answer === 12 && this.props.surveyId === 1? @@ -155,12 +163,7 @@ export default class BuildingCoolingSystem extends React.Component { - - {'<'} Back - + {spanBack}
) : ""; - let backButton = this.props.isReferral ? "" : ( + let backButton = this.props.isReferral && !this.props.isEdit ? "" : ( + {'<'} Back + ) : ''; + const content = (
@@ -101,19 +109,14 @@ export default class ChurchCoolingSystemAge extends React.Component { - - {'<'} Back - + {spanBack} diff --git a/src/ChurchCoolingSystemPlan.js b/src/ChurchCoolingSystemPlan.js index 0210aa623..968f00ce3 100644 --- a/src/ChurchCoolingSystemPlan.js +++ b/src/ChurchCoolingSystemPlan.js @@ -62,6 +62,14 @@ export default class ChurchCoolingSystemPlan extends React.Component { } render() { + const spanBack = !this.props.isEdit ? + ( + {'<'} Back + ) : ''; + let message = ""; if ([0, 1].includes(this.props.answerIds.indexOf(this.state.answer))) { message = ( @@ -102,12 +110,7 @@ export default class ChurchCoolingSystemPlan extends React.Component { - - {'<'} Back - + {spanBack}