From 10bad18b5689e31e344b50aed9c3f3aaf74e0807 Mon Sep 17 00:00:00 2001 From: bmauger Date: Fri, 18 Mar 2022 12:18:43 -0400 Subject: [PATCH 1/4] WIP Do not merge. --- src/layouts/vin-lookup/vin-lookup.vue | 78 ++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 8dbb6cdc9..2920be727 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -1,9 +1,8 @@ @@ -50,134 +24,14 @@ import funnelFooter from "@/common-components/funnel-footer/funnel-footer"; import textboxQuestion from "@/common-components/textbox-question/textbox-question"; import vinInformation from "@/layouts/vin-lookup/vin-information/vin-information"; -// Supporting files -import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; -import { settleAllPromises } from "@/helpers/layout-helper"; -import { storeActions } from "@/constants/store-actions"; -import store from "@/store"; -import { storeMutations } from "@/constants/store-mutations"; -import baseMixin from "@/mixins/base-mixin"; -import { Form, defineRule } from "vee-validate"; -import { required } from "@/helpers/validation-rules"; -import { errorMessages } from "@/constants/error-messages"; - -// DEFINE VALIDATION RULES -defineRule("replace-options-required", required(errorMessages.REPLACE_OPTIONS_REQUIRED)); - export default { name: "vin-lookup", - async beforeRouteEnter(to, from, next) { - // Call APIs - const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); - const damageOptionsPromise = - baseMixin.methods.dispatchNonBlockingStoreAction( - storeActions.GET_DAMAGE_OPTIONS, - { carId: store.getters.vehicle.carId } - ); - - // Settle promises and get results - const promiseResultMap = [ - { - resultKey: "cmsContent", - promise: cmsContentPromise, - }, - { - resultKey: "damageOptions", - promise: damageOptionsPromise, - }, - ]; - - const resultMap = await settleAllPromises(promiseResultMap); - - // Call the "next" function to complete the transition to this page. - next((vm) => { - vm.$refs.funnelHeader.initializeComponent( - resultMap.cmsContent.FunnelHeaderWidget - ); - vm.$refs.vehicleBanner.initializeComponent( - resultMap.cmsContent.VehicleBannerWidget - ); - vm.$refs.funnelSubHeader.initializeComponent( - resultMap.cmsContent.FunnelSubHeaderWidget - ); - vm.$refs.funnelFooter.initializeComponent( - resultMap.cmsContent.FunnelFooterWidget - ); - }); - }, - methods: { - arePagePrerequisitesValid() { - return true; - }, - resetDependentState() { - store.dispatch(storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES); - }, - backButtonAction() { - // route to move backwards - this.$router.navigate( - this.navigationScenarios.CLICKED_BACK, - this.$route - ); - }, - async forwardButtonAction(zip, plate) { - const zipValidation = await this.validateZip(zip); - const vinLookup = await this.lookupVin(plate); - if (!zipValidation.isServiceable) { - this.newServiceZipRequired = true; - return; - } - if (!vinLookup.vin) { - this.vinNotValid = true; - return; - } - if (vinLookup.vehicle.carId !== store.getters.vehicle.carId) { - this.vinDoesNotMatchCarId = true; - return; - } - const partsData = await baseMixin.methods.dispatchNonBlockingStoreAction( - this.storeActions.GET_PARTS_OR_QUESTIONS, - { - carId: store.getters.vehicle.carId, - glassArray: store.getters.damage.glassToReplace, - zipCode: zip, - vin: vinLookup.vin - }, - false - ); - this.navigateForward(partsData); - }, - navigateForward(partsData){ - if(partsData.data.partsOrQuestions.partQuestions.length){ - this.$router.navigateAfterSave(this.navigationScenarios.CONTINUING_WITH_PARTS_QUESTION, this.$route, {}, {}, partsData.data); - return; - } else if(!partsData.data.partsOrQuestions.partQuestions.length && partsData.data.partsOrQuestions.parts.length > 1) { - this.$router.navigateAfterSave(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_PARTS, this.$route, {}, {}, partsData.data); - return; - } else { - this.$router.navigate(this.navigationScenarios.CONTINUING_WITH_SINGLE_PART, this.$route); - } - }, - validateZip(zip) { - return baseMixin.methods.dispatchNonBlockingStoreAction( - storeActions.VALIDATE_ZIP, - { zip } - ); - }, - lookupVin(plate, state) { - return baseMixin.methods.dispatchNonBlockingStoreAction( - storeActions.LOOKUP_VIN_BY_PLATE, - { plate, state } - ); - }, - }, components: { funnelHeader, vehicleBanner, funnelSubHeader, - textboxQuestion, vinInformation, funnelFooter, - Form, }, };