diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 01e28d90f..ea3fdcb62 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -63,6 +63,10 @@ const endpoints = { url: "/parts/api/v1/parts/capability-questions", method: "GET" }, + ApplyCapabilityAnswerToPart: { + url: "/parts/api/v1/parts/apply-capability-answer-to-part", + method: "POST" + }, SaveOrder: { url: "/order/api/v1/order/save", method: "POST", diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 3173243e0..a80694834 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -22,6 +22,7 @@ const storeActions = { GET_PARTS_OR_QUESTIONS: "getPartsOrQuestions", GET_PARTS: "getParts", GET_CAPABILITY_QUESTIONS: "getCapabilityQuestions", + GET_PART_FROM_CAPABILITY_QUESTION_ANSWER: "getPartFromCapabilityQuestionAnswer", SAVE_ORDER: "saveOrder", LOAD_ORDER: "loadOrder", UPDATE_STORE_WITH_SAVE_ORDER_RESPONSE: "updateStoreWithSaveOrderResponse", @@ -56,6 +57,7 @@ const storeActions = { SAVE_REGISTRATION_ADDRESS_LOOKUP: "saveRegistrationAddressLookup", SAVE_GLASS_PARTS: "saveGlassParts", SAVE_PART_QUESTION_ANSWERS: "savePartQuestionAnswers", + SAVE_CAPABILITY_QUESTION_ANSWERS: "saveCapabilityQuestionAnswers" }; export { storeActions }; diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index cce109c43..ba0adc7cb 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -17,6 +17,7 @@ const storeMutations = { UPDATE_NUMBER_OF_CHIPS: "updateNumberOfChips", UPDATE_GLASS_TO_REPLACE: "updateGlassToReplace", UPDATE_PART_QUESTION_ANSWERS: "updatePartQuestionAnswers", + UPDATE_CAPABILITY_QUESTION_ANSWERS: "updateCapabilityQuestionAnswers", UPDATE_GLASS_PARTS: "updateGlassParts", UPDATE_OTHER_PARTS: "updateOtherParts", diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index d5086aaf5..b2b38d07e 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -6,13 +6,10 @@ v-slot="{ meta }" >
-
-

CAPABILITY QUESTIONS TEMPORARY PLACEHOLDER

- CQD: {{ capabilityQuestionsData }} - - - + { vm.setCmsContent(resultMap.cmsContent); - - resultMap.capabilityQuestions.forEach(question => { - console.log(question.answers) - question.answers = question.answers.map(answer => { - return { - ...answer, - answerResult: answer.answerResult1 - } - }) - // question.answers = question.answers - }) - vm.capabilityQuestionsData = { - partQuestions: resultMap.capabilityQuestions - }; - console.log("CQ: ", resultMap.capabilityQuestions) }); }, data() { return { - selectedModel: [], - capabilityQuestionsData: [], - currentPartNum: 0, + selectedAnswer: [], + // TODO This shouldn't be an object with property `partQuestions` + capabilityQuestionsData: { + partQuestions: store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS).capabilityQuestions + } }; }, computed: { AlertFewMoreQuestionsHeader() { - return this.getCmsContent("AlertPartsQuestions", "HeadlineText"); + return this.getCmsContent("AdditionalPartsQuestionsAlert", "HeadlineText"); }, AlertFewMoreQuestionsCopy() { - return this.getCmsContent("AlertPartsQuestions", "BodyText"); + return this.getCmsContent("AdditionalPartsQuestionsAlert", "BodyText"); }, + windshieldPart() { + return this.pageData.partsOrQuestions.find(x => x.glassLocation === damageLocationsSelected.WINDSHIELD); + }, + windshieldPartInfo() { + return this.windshieldPart.parts[0]; + }, + pageData() { + return this.$store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); + } }, methods: { arePagePrerequisitesValid() { const capabilityQuestionsPageData = store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); return capabilityQuestionsPageData && Object.keys(capabilityQuestionsPageData).length > 0; }, - showThisPartQuestionChain(part, i) { - if (part.partQuestions?.length < 1) { return false; } // return false if only one partQuestion - if (this.currentPartNum === i || part.answerData?.answerResult.length > 0) { return true; } - return false; - }, - // backButtonAction() { - // // route to move backwards - // this.$router.navigate( - // this.navigationScenarios.CLICKED_BACK, - // this.$route - // ); - // }, async forwardButtonAction() { - // TODO: TO COME - // if questions are answered: + console.log(this.windshieldPartInfo); + console.log(this.selectedAnswer) + const selectedAnswerResult1 = this.selectedAnswer.answerResult; + const selectedAnswerResult2 = this.pageData.capabilityQuestions[0].answers.find(x => x.answerResult1 === selectedAnswerResult1).answerResult2; - this.$router.navigate( - this.navigationScenarios.CLICKED_FORWARD, - this.$route - ); - }, - }, - watch: { - selectedModel(model) { - this.capabilityQuestionsData[model.partIndex].answerData = { - answerResult: model.answerResult, - answeredQuestions: model.answeredQuestions, - } - this.currentPartNum = model.partIndex + 1; + this.dispatchStoreAction(storeActions.SAVE_CAPABILITY_QUESTION_ANSWERS, { + glassName: this.windshieldPart.glassName, + glassLocation: this.windshieldPart.glassLocation, + result1: selectedAnswerResult1, + result2: selectedAnswerResult2 + }); + + const partFromCapabilityQuestionAnswer = (await this.dispatchStoreAction(storeActions.GET_PART_FROM_CAPABILITY_QUESTION_ANSWER)).data; + let partsOrQuestions = this.pageData.partsOrQuestions; + partsOrQuestions.find(partOrQuestion => partOrQuestion.glassLocation === damageLocationsSelected.WINDSHIELD).parts = partFromCapabilityQuestionAnswer; + + this.navigateForward(partsOrQuestions); }, }, components: { diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 6f218f24b..ab27a6c18 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -3,6 +3,8 @@ import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigat import { storeMutations } from "@/constants/store-mutations.js"; import { damageLocationsSelected } from "@/constants/damage-locations-selected"; import { navigationScenarios } from "../router/router-constants/navigation-scenarios"; +import { storeActions } from "@/constants/store-actions"; +import store from "@/store"; export default { methods: { @@ -22,6 +24,7 @@ export default { return pq.parts?.some(part => part.requiresCapabilityQuestions === true); }); }, + // method to only include keys listed for lineItems.glassParts in // https://safelite.atlassian.net/wiki/spaces/DC/pages/17137665/Catalog+Front-End+State#glassParts reducedGlassPartsArray(glassParts) { @@ -63,7 +66,7 @@ export default { return this.comparePageIndices(currentPage, fmgPage) > 0; }, // Can't use `this` because navigateForward is also called from vin-pages-mixin - navigateForward(partsOrQuestions, vm) { + async navigateForward(partsOrQuestions, vm) { const self = vm ?? this; const currentPage = self.$route.query.fmgPage; @@ -86,18 +89,30 @@ export default { } else if (hasCapabilityQuestions && this.currentPageComesBeforePage(currentPage, fmgPageValues.CAPABILITY_QUESTIONS)) { // if has capability questions // go to capability-questions page and pass the partsData - self.$router.navigate(self.navigationScenarios.HAS_CAPABILITY_QUESTIONS, self.$route, {}, {}, { - carId: self.$store.getters.vehicle.carId, - partNumber: partsOrQuestions.filter(x => x.glassLocation === damageLocationsSelected.WINDSHIELD)[0].parts[0].partNumber + + const windshieldPart = partsOrQuestions.filter(x => x.glassLocation === damageLocationsSelected.WINDSHIELD)[0].parts[0]; + let capabilityQuestions = (await store.dispatch(storeActions.GET_CAPABILITY_QUESTIONS, { + carId: store.getters.vehicle.carId, + partNumber: windshieldPart.partNumber + })).data; + + capabilityQuestions.forEach(question => { + question.answers = question.answers.map(answer => { + return { + ...answer, + answerResult: answer.answerResult1 + } + }) }); + + self.$router.navigate(self.navigationScenarios.HAS_CAPABILITY_QUESTIONS, self.$route, {}, {}, { partsOrQuestions, capabilityQuestions }); } else { // if single parts only const collectedGlassParts = this.reducedGlassPartsArray(partsOrQuestions); // save to store lineItems.glassParts self.$store.commit(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts); - // go to heritage quote page - self.$refs.loadingModal.showModal(); - navigateToHeritageFunnel(); + + self.$router.navigate(self.navigationScenarios.ANSWERED_ALL_QUESTIONS, self.$route); } }, backButtonAction() { diff --git a/src/mixins/vin-pages-mixin.js b/src/mixins/vin-pages-mixin.js index 8d829dd9f..6e030688d 100644 --- a/src/mixins/vin-pages-mixin.js +++ b/src/mixins/vin-pages-mixin.js @@ -4,7 +4,6 @@ import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigat import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; export default { - mixins: [vehicleQuestionsMixin], methods: { async navigateForwardWithSingleCarMatch() { const result = await this.dispatchStoreAction(storeActions.GET_PARTS_OR_QUESTIONS); diff --git a/src/router/router-constants/navigation-scenarios.js b/src/router/router-constants/navigation-scenarios.js index 8000f45d7..7cca25d09 100644 --- a/src/router/router-constants/navigation-scenarios.js +++ b/src/router/router-constants/navigation-scenarios.js @@ -24,6 +24,7 @@ const navigationScenarios = { SELECTED_PROVIDE_VIN_DIFFERENT_WAY: "SELECTED_PROVIDE_VIN_DIFFERENT_WAY", CLICKED_BACK_WITH_PART_QUESTION_ANSWERS: "CLICKED_BACK_WITH_PART_QUESTION_ANSWERS", CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS: "CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS", + ANSWERED_ALL_QUESTIONS: "ANSWERED_ALL_QUESTIONS", HAS_PART_QUESTIONS: "HAS_PART_QUESTIONS", HAS_MULTIPLE_PARTS_TO_CHOOSE: "HAS_MULTIPLE_PARTS_TO_CHOOSE", HAS_MOLDING_QUESTIONS: "HAS_MOLDING_QUESTIONS", diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 3e1246250..34c5263cf 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -251,7 +251,7 @@ const routingTable = function(store) { destinationFmgPageValue: fmgPageValues.CAPABILITY_QUESTIONS, }, { - scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_SINGLE_PART, + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, destinationFmgPageValue: fmgPageValues.QUOTE, }, ] @@ -284,7 +284,7 @@ const routingTable = function(store) { destinationFmgPageValue: fmgPageValues.CAPABILITY_QUESTIONS, }, { - scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_SINGLE_PART, + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, destinationFmgPageValue: fmgPageValues.QUOTE, }, ], @@ -309,7 +309,7 @@ const routingTable = function(store) { destinationFmgPageValue: fmgPageValues.CAPABILITY_QUESTIONS, }, { - scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_SINGLE_PART, + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, destinationFmgPageValue: fmgPageValues.QUOTE, } ] @@ -334,7 +334,7 @@ const routingTable = function(store) { destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS }, { - scenario: navigationScenarios.CLICKED_FORWARD, + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, destinationFmgPageValue: fmgPageValues.QUOTE }, ] diff --git a/src/store/index.js b/src/store/index.js index f6c8f83d8..71d508e8d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -49,6 +49,7 @@ const getDefaultState = () => { numberOfChips: null, glassToReplace: null, partQuestionAnswers: null, + capabilityQuestionAnswers: null }, lineItems: { glassParts: null @@ -126,6 +127,9 @@ export const mutations = { updatePartQuestionAnswers(state, answersArray) { state.order.damage.partQuestionAnswers = answersArray; }, + updateCapabilityQuestionAnswers(state, answersArray) { + state.order.damage.capabilityQuestionAnswers = answersArray; + }, updateGlassParts(state, partsData) { state.order.lineItems.glassParts = partsData; }, @@ -277,6 +281,7 @@ export const mutations = { resetGlassPartsState(state) { state.order.lineItems.glassParts = null; state.order.damage.partQuestionAnswers = null; + state.order.damage.capabilityQuestionAnswers = null; state.applicationUser.pageData[fmgPageValues.PART_QUESTIONS] = null; state.applicationUser.pageData[fmgPageValues.VEHICLE_PARTS] = null; state.applicationUser.pageData[fmgPageValues.MOLDING_QUESTIONS] = null; @@ -729,6 +734,22 @@ export const actions = { }) }, + getPartFromCapabilityQuestionAnswer(context, selectedAnswerResult1) { + const pageData = context.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); + + const part = pageData.partsOrQuestions.find(x => x.glassLocation === damageLocationsSelected.WINDSHIELD).parts[0]; + const capabilityQuestionAnswers = context.getters.damage.capabilityQuestionAnswers; + + return globalMethods.callHttpClient({ + method: endpoints.ApplyCapabilityAnswerToPart.method, + endpoint: endpoints.ApplyCapabilityAnswerToPart.url, + payload: { + part, + capabilityAnswerResults: capabilityQuestionAnswers + } + }) + }, + // Order API Actions saveOrder(context) { const vehicle = context.getters.vehicle; @@ -958,10 +979,22 @@ export const actions = { } }, savePartQuestionAnswers(context, partQuestionAnswersArray) { + // if part question answers have changed, reset subsequent question answers + const previousResultsArray = context.getters.damage.partQuestionAnswers; + const havePartQuestionAnswersChanged = previousResultsArray.length !== partQuestionAnswersArray.length || + !previousResultsArray.every((x, i) => x.result === partQuestionAnswersArray[i].result); + + if (havePartQuestionAnswersChanged) { + context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null); + } + //Save new values context.commit(storeMutations.UPDATE_PART_QUESTION_ANSWERS, partQuestionAnswersArray); }, - + saveCapabilityQuestionAnswers(context, capabilityQuestionAnswers) { + //Save new values + context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, capabilityQuestionAnswers); + }, // Misc order actions saveServiceLocation(context, serviceLocationInfo) { context.commit(storeMutations.UPDATE_SERVICE_LOCATION, serviceLocationInfo);