diff --git a/src/App.js b/src/App.js index 6559671b12c30ea36b0ccef32cbc2652e5adbcc0..b60c0f53237a522cdb4c63fbcf080455a5327983 100644 --- a/src/App.js +++ b/src/App.js @@ -36,7 +36,6 @@ import OperationalSeasons from './OperationalSeasons'; import AnotherBuilding from './AnotherBuilding'; import UserError from './UserError'; import Referral from './Referral'; -import { questionTree } from './constants'; import { connect } from 'react-redux'; import { submitContact, @@ -68,8 +67,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: , + />, congrats: { - 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 = () => { + resetQuestions() { return { addressSearch: { title: 'What is your building address?', @@ -796,10 +790,55 @@ class App extends React.Component { prev: 'referral', next: 'thankYou', }, - order: [], }; } + resetState = () => { + let questions = this.state.questions; + let count = 0; + 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; + count += 1; + } + } + } + this.setState({ questions: this.baseState }); + return count; + } + + setOrder = () => { + // 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', + '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', 'feedback'] + } + } else if (this.props.building.data.surveyId === 2) { + order = ['addressSearch', 'buildingTypeSubType', 'buildingNeeds', 'buildingOperatingChallenges', 'buildingHeatingSystem', 'buildingCoolingSystem', + 'buildingPastImprovement', 'buildingFutureImprovement', 'buildingElectricityShutoff', 'buildingMedicalDevices', 'feedback'] + } else if (this.props.building.data.surveyId === 3) { + order = ['addressSearch', 'buildingTypeSubType', 'buildingNeeds', 'buildingOperatingChallenges', 'buildingHeatingSystem', 'buildingCoolingSystem', + 'buildingPastImprovement', 'buildingFutureImprovement', 'feedback'] + } + return order; + } + getMeta = () => { let metaObj = { buildingId: '', @@ -836,14 +875,6 @@ class App extends React.Component { questionAnswers[questions[question].id] = value; } - if (question === 'anotherBuilding') { - questions['churchBuildingType']['prev'] = 'anotherBuilding'; - } - - const updatedOrder = questions.order.filter(item => item !== question); - updatedOrder.push(question); - questions.order = updatedOrder; - const metaObj = this.getMeta(); this.setState({ questions }, () => { if (['addressSearch', 'anotherBuilding'].includes(question)) { @@ -888,88 +919,199 @@ 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 }); + } + + 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; - 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)){ + let order = this.state.order; + + if (question === 'anotherBuilding') { + questions['churchBuildingType']['prev'] = 'anotherBuilding'; + } + + if (question === 'buildingTypes' && !this.state.isEdit){ + 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) { + // 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['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 the next page from unit breakdown will be financial interest. - else{ + } else { + questions['buildingTypes'].next = 'fuels'; 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['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))) || - [2,3].includes(this.props.building.data.surveyId)){ - questions['buildingCoolingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'buildingCoolingSystem'; - } - else if (this.props.building.data.surveyId === 1 && question === 'buildingCoolingSystem') { - questions['buildingCoolingSystem'].next = 'churchCoolingSystemAge'; - questions['buildingPastImprovement'].prev = 'churchCoolingSystemPlan' + + // 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'); + 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'; + } } - if([2,3].includes(this.props.building.data.surveyId) && this.state.miniSplitCheckBox === true) { - questions['buildingHeatingSystem'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = '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, - }); + // 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'; + } } - else{ - questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + + + // 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'); + 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'; + } else { + questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + questions['buildingCoolingSystem'].prev = 'buildingHeatingSystem'; + } + } + + + // 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'; + } } - // 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. + + // 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, - }); - // Store heating system plan answer in cooling system plan - if(question==='heatingSystemPlan') { + if(question === 'buildingHeatingSystem') { this.props.onSubmitAnswer({ - questionId: ["66"], - answerId: [value], + 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'; } - // Store heating system age answer in cooling system age - if(question==='heatingSystemAge') { + + if(question === 'fuels') { + if(this.state.isEdit && order.includes('heatingSystemAge')) { + questions[question].next = 'reviewAnswers'; + } else if (!order.includes('heatingSystemAge')){ + let indexofHeatingfuel = order.indexOf(question); + order.splice(indexofHeatingfuel+1, 0, "heatingSystemAge"); + } + questions[question].next = 'heatingSystemAge'; + } + + if(question === 'heatingSystemAge') { this.props.onSubmitAnswer({ questionId: ["65"], answerId: [value], @@ -977,36 +1119,54 @@ 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(!order.includes("churchCoolingSystemAge")) { + let indexofCoolingSystem = order.indexOf('buildingCoolingSystem'); + order.splice(indexofCoolingSystem+1, 0, "churchCoolingSystemAge"); + } + if(this.state.isEdit && order.includes('heatingSystemPlan')) { + questions[question].next = 'reviewAnswers'; + } else if (!order.includes('heatingSystemPlan')){ + let indexofHeatingAge = order.indexOf(question); + order.splice(indexofHeatingAge+1, 0, "heatingSystemPlan"); + } + questions[question].next = 'heatingSystemPlan'; } - questions['heatingSystemPlan'].next = 'buildingPastImprovement'; - questions['buildingPastImprovement'].prev = 'heatingSystemPlan'; - } else { - questions['heatingSystemPlan'].next = 'buildingCoolingSystem'; + + 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(!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'; + } + } + this.setState({ questions, order }); + } else if (!this.state.isEdit){ + 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'; - } - 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)){ + 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; + + if (this.state.isEdit) { + questions[question].next = 'reviewAnswers' + } else { + 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"], + 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'; + } else { + questions['buildingHeatingSystem'].next = 'buildingCoolingSystem'; + } + + } + + milwaukeeQuestionChain = (question, value) => { + + let questions = this.state.questions; + let order = this.state.order; + + if (this.state.isEdit) { + questions[question].next = 'reviewAnswers' + } else { + 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"], + 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'; + } 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 = () => { @@ -1079,9 +1332,17 @@ class App extends React.Component { } prevQuestion = (question) => { + let questions = this.state.questions; + if ((this.props.building.data.surveyId === 1 && question === 'buildingTypes')) { + 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 }); @@ -1090,6 +1351,34 @@ class App extends React.Component { this.setState({ anotherBuildingSubmitted: false, }); } + resetQuestionnaire = () => { + this.setState({ isEdit: false }, () => { + this.resetState(); + }); + } + + editAnswer = (question) => { + let questions = this.state.questions; + this.setState({ isEdit: true }); + if (this.props.building.data.surveyId === 1 && question === 'buildingTypes') { + let count = this.resetState(); + let order = this.setOrder(); + this.setState({ order, count, selectedBuilding: questions[question].value }, () => { + if (order.length === this.state.count+1) { + questions['buildingTypes'].next = 'reviewAnswers'; + this.setState({ questions }); + } + }); + } else if (this.props.building.data.surveyId === 1 && + (question === 'buildingHeatingSystem' || question === 'buildingCoolingSystem')) { + console.log('heating/cooling system'); + } else { + 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 @@ -1204,6 +1493,7 @@ class App extends React.Component { render() { const building = this.props.building.data; 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 && building.status == 400) { @@ -1237,6 +1527,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: , utilityBills: , comfortIssues: , financeInterest: , waitList: , contact: , reviewAnswers: , buildingTypeSubType: , buildingOperatingChallenges: , buildingHeatingSystem: , buildingCoolingSystem: , buildingElectricityShutoff: , buildingMedicalDevices: , churchCoolingSystemPlan: , buildingPastImprovement: , buildingFutureImprovement: , anotherBuilding: -
- logo -

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

- - Learn React - -
- - ); -} - -export default App; diff --git a/src/BackButton.js b/src/BackButton.js new file mode 100644 index 0000000000000000000000000000000000000000..85203c4e2981392854b632b213793cd0ee581cf3 --- /dev/null +++ b/src/BackButton.js @@ -0,0 +1,22 @@ +import React from "react"; +import './index.css'; + +export default class BackButton extends React.Component { + + render() { + + const spanBack = !this.props.isEdit ? ( + + {'<'} Back + + ) : ''; + + return ( +
+ {spanBack} +
+ ); + } +} \ No newline at end of file diff --git a/src/BuildingCoolingSystem.js b/src/BuildingCoolingSystem.js index 24ffb97a48d4f3ec32db55473dcf6e255edba6ae..846f811f45d8975e62bd3a001cb0a4c416921cf2 100644 --- a/src/BuildingCoolingSystem.js +++ b/src/BuildingCoolingSystem.js @@ -2,6 +2,7 @@ import React from "react"; import { Row, Col, Button, Label, Input, UncontrolledTooltip } from 'reactstrap'; import './index.css'; import ReactGA from 'react-ga'; +import BackButton from './BackButton'; export default class BuildingCoolingSystem extends React.Component { constructor(props) { @@ -69,7 +70,11 @@ export default class BuildingCoolingSystem extends React.Component { label: "building-cooling-system" }); } - this.setState({ answer }); + this.setState({ answer }, () => { + if(this.props.isEdit && this.state.answer !== 106) { + this.props.setMiniSplitforCooling(false); + } + }); } setReferral = () => { @@ -77,6 +82,7 @@ export default class BuildingCoolingSystem extends React.Component { } render() { + const referralButton = this.state.answer === 12 && this.props.surveyId === 1? @@ -152,12 +158,10 @@ export default class BuildingCoolingSystem extends React.Component { - - {'<'} Back - + diff --git a/src/ChurchCoolingSystemPlan.js b/src/ChurchCoolingSystemPlan.js index 0210aa62389fbd5595a547f8ad252333f94c67cb..8d542c5dde338e8611cb6659e0a023b8e7dce345 100644 --- a/src/ChurchCoolingSystemPlan.js +++ b/src/ChurchCoolingSystemPlan.js @@ -3,7 +3,7 @@ import { Row, Col, Button } from 'reactstrap'; import './index.css'; import starIcon from './utils/images/icon-star.svg'; import ReactGA from 'react-ga'; - +import BackButton from './BackButton'; export default class ChurchCoolingSystemPlan extends React.Component { constructor(props) { @@ -62,6 +62,7 @@ export default class ChurchCoolingSystemPlan extends React.Component { } render() { + let message = ""; if ([0, 1].includes(this.props.answerIds.indexOf(this.state.answer))) { message = ( @@ -102,12 +103,10 @@ export default class ChurchCoolingSystemPlan extends React.Component { - - {'<'} Back - +