diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index ee9ecdbad..6848285b8 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -89,7 +89,7 @@ export default { modelValue: [Array, String], validationRules: String, suppressError: Boolean, - useTextForValue: Boolean + useTextForValue: Boolean, }, computed: { formattedGroupName() { diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index f5ec4841d..ee1d81c09 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -88,7 +88,7 @@ export default { data() { return { selectedModel: [], - partsQuestionsData: this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS).partsOrQuestions.filter((p) => { + partsQuestionsData: store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions.filter((p) => { if (Array.isArray(p.partQuestions) && p.partQuestions.length > 0) { return { glassName: p.glassName, diff --git a/src/layouts/vehicle-damage/side-door-options/side-door-options.vue b/src/layouts/vehicle-damage/side-door-options/side-door-options.vue index b4df1121e..284c3eee6 100644 --- a/src/layouts/vehicle-damage/side-door-options/side-door-options.vue +++ b/src/layouts/vehicle-damage/side-door-options/side-door-options.vue @@ -112,7 +112,7 @@ export default ({ this.selectedValues = this.getSideDoorReplacementOptions(this.selectedValues.selectedDoorSides, this.selectedValues.selectedDriverSideReplaceOptions, newValue); } }, - answersToDisplay(){ + answersToDisplay(){ const filteredAnswers = Array.isArray(this.answersFromCms) ? this.answersFromCms.filter(ans => { diff --git a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue index 608cf55cb..b46a2f9bc 100644 --- a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue +++ b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue @@ -48,6 +48,7 @@ import { getCustomTransformValue } from "@/constants/dynamictext-mapper"; import { defineRule } from "vee-validate"; import { required } from "@/helpers/validation-rules"; import { errorMessages } from "@/constants/error-messages"; +import store from "@/store"; export default { name: "glass-part-question", @@ -152,7 +153,7 @@ export default { }, PartDataFromApi() { - return this.$store.getters.pageData(this.$route.query.fmgPage) ?? {}; + return store.getters.pageData(this.$route.query.fmgPage) ?? {}; }, }, methods: { diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index ce5727ce3..c35699c4e 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -63,9 +63,11 @@ import store from "@/store"; import { Form } from "vee-validate"; import { storeActions } from "@/constants/store-actions"; + import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; export default { name: "vehicle-parts", + mixins: [vehicleQuestionsMixin], async beforeRouteEnter(to, from, next) { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); @@ -173,19 +175,16 @@ methods: { arePagePrerequisitesValid() { // Check if isRepair is populated and if the pageData we need is here (Parts data) - if ( - store.getters.damage.isRepair != null && - Object.keys(store.getters.pageData(fmgPageValues.VEHICLE_PARTS)) - .length !== 0 - ) { - return true; - } - - return false; + return store.getters.damage.isRepair != null && + Object.keys(store.getters.pageData(fmgPageValues.VEHICLE_PARTS)).length !== 0; }, backButtonAction() { + console.log(this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)) + const hasPartQuestions = this.hasPartQuestions(this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS).partsOrQuestions); + const backNavigationScenario = hasPartQuestions ? this.navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS : this.navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS; + this.$router.navigate( - this.navigationScenarios.CLICKED_BACK, + backNavigationScenario, this.$route ); }, diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js new file mode 100644 index 000000000..7a8f3832f --- /dev/null +++ b/src/mixins/vehicle-questions-mixin.js @@ -0,0 +1,10 @@ +export default { + methods: { + hasPartQuestions(partsOrQuestions) { + return partsOrQuestions.some(pq => pq.partQuestions?.length > 0); + }, + hasGlassLocationWithMultipleParts(partsOrQuestions) { + return partsOrQuestions.some(pq => pq.parts?.length > 1); + } + } +} \ No newline at end of file diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/mixins/vin-pages-mixin.js b/src/mixins/vin-pages-mixin.js index fce96c980..31fa44cf7 100644 --- a/src/mixins/vin-pages-mixin.js +++ b/src/mixins/vin-pages-mixin.js @@ -2,15 +2,17 @@ import store from "@/store"; import { storeActions } from "@/constants/store-actions.js"; import { storeMutations } from "@/constants/store-mutations.js"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; export default { + mixins: [vehicleQuestionsMixin], methods: { async navigateForwardWithSingleCarMatch() { const result = await this.dispatchStoreAction(storeActions.GET_PARTS_OR_QUESTIONS); const partsOrQuestions = result.data.partsOrQuestions; - const hasPartsQuestions = partsOrQuestions.some(pq => pq.partQuestions?.length > 0); - const hasGlassLocationWithMultipleParts = partsOrQuestions.some(pq => pq.parts?.length > 1); + const hasPartsQuestions = this.hasPartQuestions(partsOrQuestions); + const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(partsOrQuestions); if (hasPartsQuestions) { this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data); @@ -23,6 +25,6 @@ export default { this.$refs.loadingModal.showModal(); navigateToHeritageFunnel(); } - } + }, } } \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index d2a5ee154..d086cc89a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -173,8 +173,11 @@ async function navigate(scenario, currentRoute, optionalQuery = {}, optionalPara if (destinationFmgPageValue !== undefined) { // We're always pushing the same path, just changing query strings. Make sure our optional query strings get combined with our fmgPage one. - // Append page data to the store for the NEXT page, if any. It will be an empty object if none is provided. - baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData); + // Update page data to the store for next page if provided. Otherwise, use existing page data or override with empty object + const existingPageData = store.getters.pageData(destinationFmgPageValue) ?? {}; + if (Object.keys(optionalPageData).length > 0 && Object.keys(existingPageData).length === 0) { + baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData); + } // if cookie and referralNumber/Date exists OR an emailAddress has been saved if ((getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) || store.getters.order.customer?.emailAddress) { diff --git a/src/router/router-constants/navigation-scenarios.js b/src/router/router-constants/navigation-scenarios.js index 5768c55de..61de8147f 100644 --- a/src/router/router-constants/navigation-scenarios.js +++ b/src/router/router-constants/navigation-scenarios.js @@ -19,7 +19,9 @@ const navigationScenarios = { SELECTED_HOME_ADDRESS: "SELECTED_HOME_ADDRESS", ANSWERED_QUESTIONS_WITH_SINGLE_PART: "ANSWERED_QUESTIONS_WITH_SINGLE_PART", ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS: "ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS", - SELECTED_PROVIDE_VIN_DIFFERENT_WAY: "SELECTED_PROVIDE_VIN_DIFFERENT_WAY" + 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" }; export { navigationScenarios }; diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 25463bd8b..0c729607f 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -82,10 +82,6 @@ const routingTable = function(store) { { fmgPageValue: fmgPageValues.VEHICLE_PARTS, maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, - }, { scenario: navigationScenarios.SELECTED_PARTS, destinationFmgPageValue: fmgPageValues.QUOTE, @@ -94,6 +90,14 @@ const routingTable = function(store) { scenario: navigationScenarios.CLICKED_FORWARD, destinationFmgPageValue: fmgPageValues.REVEAL, }, + { + scenario: navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS, + }, + { + scenario: navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, + }, ], }, { diff --git a/src/store/index.js b/src/store/index.js index 90932c8bb..200389734 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,6 +5,7 @@ import { getDateForSavedSessionTimeout } from "@/helpers/heritage-integration/se import createPersistedState from "vuex-persistedstate"; import globalMethods from "@/global-methods"; import { storeActions } from "../constants/store-actions"; +import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; // Export State const getDefaultState = () => { @@ -264,7 +265,10 @@ export const mutations = { state.order.vehicle.registration.lastName = null; }, resetGlassPartsState(state) { + console.log("resetGlassPartsState") state.order.lineItems.glassParts = null; + state.order.damage.partQuestionAnswers = null; + state.applicationUser.pageData[fmgPageValues.PART_QUESTIONS] = null; }, resetState(state) { Object.assign(state, getDefaultState()); @@ -701,7 +705,7 @@ export const actions = { accountNumber: accountNumber?.toString() }, }).then((response) => { - context.commit(storeMutations.RESET_STATE); + // context.commit(storeMutations.RESET_STATE); context.commit(storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, response.data); return response; }); @@ -854,6 +858,7 @@ export const actions = { }, savePartQuestionAnswers(context, partQuestionAnswersArray) { //Save new values + // context.dispatch(storeActions.SAVE_GLASS_PARTS, null); context.commit(storeMutations.UPDATE_PART_QUESTION_ANSWERS, partQuestionAnswersArray); }, diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.vue b/src/ux-components/list-button-horizontal/list-button-horizontal.vue index 2fef5119f..5bcfcc706 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.vue +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.vue @@ -92,10 +92,10 @@ export default { : this.selectedValues[0]; } }, - unmounted() { // needed to clear this button's selectedValues if it is removed - this.checkValue = false; - this.handleCheckChange(); - }, + // unmounted() { // needed to clear this button's selectedValues if it is removed + // this.checkValue = false; + // this.handleCheckChange(); + // }, methods: { displayLoader() { this.isLoaderDisplayed = true; diff --git a/src/ux-components/list-button/list-button.vue b/src/ux-components/list-button/list-button.vue index 34b6f92e0..cef450bb6 100644 --- a/src/ux-components/list-button/list-button.vue +++ b/src/ux-components/list-button/list-button.vue @@ -92,10 +92,10 @@ export default { : this.selectedValues[0]; } }, - unmounted() { // needed to clear this button's selectedValues if it is removed - this.checkValue = false; - this.handleCheckChange(); - }, + // unmounted() { // needed to clear this button's selectedValues if it is removed + // this.checkValue = false; + // this.handleCheckChange(); + // }, methods: { displayLoader() { this.isLoaderDisplayed = true; diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index a4ef7eac8..002fb14ac 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -110,10 +110,6 @@ export default { this.checkValue = this.selectedValues == this.value || this.modelValue == this.value; } }, - unmounted() { // needed to clear this button's selectedValues if it is removed - this.checkValue = false; - this.handleCheckChange(); - }, computed: { getLabelClasses() { if (this.isWide) { @@ -185,7 +181,7 @@ export default { const fieldOptions = { type: inputType, - checkedValue: props.value, // EX: "Single" or "Passenger" + // checkedValue: props.value, // EX: "Single" or "Passenger" potentialInitialValue: props.selectedValues, };