From f208cb031c30fbdb677a7874b9101e74b006fdc9 Mon Sep 17 00:00:00 2001 From: Katie Date: Mon, 27 Jun 2022 14:12:25 -0400 Subject: [PATCH] CSR-343 Save glassParts --- .../button-question/button-question.vue | 8 +-- .../glass-part-question.vue | 2 - src/layouts/vehicle-parts/vehicle-parts.vue | 57 ++++--------------- 3 files changed, 11 insertions(+), 56 deletions(-) diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 3c8ce6878..904089c34 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -130,7 +130,6 @@ export default { return this.modelValue; }, set: function(newValue) { - console.log(newValue) this.$emit("update:modelValue", newValue); } }, @@ -140,24 +139,19 @@ export default { if (this.useTextForValue){ return answer.Text } - // console.log(answer.Name ? answer.Name : answer) + return answer.Name ? answer.Name : answer; }, handleCheckedChanged(val) { - console.log(val) - console.log("A") if(this.selectingInitiatesLoad) { - console.log("B") this.selectedValues = [val.value]; } else { if(Array.isArray(this.selectedValues)) { - console.log("C") const newSelectedValues = this.selectedValues; val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1); this.selectedValues = newSelectedValues; } else { - console.log("D") this.selectedValues = val.value; } } 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 e010f82b5..994e2164a 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 @@ -4,7 +4,6 @@

{{ colorQuestionText }}

- {{ selectedPart }}
@@ -119,7 +118,6 @@ export default { return this.modelValue; }, set: function (newValue) { - console.log(newValue) this.$emit("update:modelValue", newValue); }, }, diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index e4eb22c69..790b54439 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -62,12 +62,7 @@ import { settleAllPromises } from "@/helpers/layout-helper"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import { storeMutations } from "@/constants/store-mutations"; import store from "@/store"; -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.OPTION_REQUIRED)); +import { Form } from "vee-validate"; export default { name: "vehicle-parts", @@ -166,53 +161,24 @@ methods: { this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); }, forwardButtonAction() { - const selectedGlassPartNumbers = []; const matchedParts = []; - // Compile all selected parts from the page. - for (let [key, value] of Object.entries(this.glassParts)) { - selectedGlassPartNumbers.push(value); - // for (let [glassKey, glassValue] of Object.entries(value)) { - // selectedGlassPartNumbers.push(glassValue[0]); - // } - } - - console.log(this.glassParts) - console.log(selectedGlassPartNumbers) - console.log(this.PartsFromApi.partsOrQuestions) - // Match them to the parts from the API. - for (let [key, value] of Object.entries(this.PartsFromApi.partsOrQuestions)) { - // const partsForGlassPart = value - const isMatched = selectedGlassPartNumbers.some( - (p) => p === value.partNumber - ); + this.PartsFromApi.partsOrQuestions.forEach(part => { + const selectedPartNumberForGlassLocationAndName = this.glassParts[`${part.glassLocation}-${part.glassName}`]; + const selectedPartData = part.parts.filter(part => part.partNumber == selectedPartNumberForGlassLocationAndName); - if (isMatched) { - // matchedParts.push(currentPart); - } - - // for (let [partKey, partValue] of Object.entries(value.parts)) { - // const currentPart = this.PartsFromApi.partsOrQuestions[key].parts[partKey]; - // const isMatched = selectedGlassPartNumbers.some( - // (p) => p === currentPart.partNumber - // ); - - // if (isMatched) { - // matchedParts.push(currentPart); - // } - // } - } - - console.log(matchedParts) + matchedParts.push(selectedPartData[0]); + }) // If no parts could be matched, throw an error. if (matchedParts.length === 0) { + this.$refs.funnelFooter.removeLoader(); throw new Error("Could not match any parts to the selected parts"); } - // // Save parts to the store. - // store.commit(storeMutations.UPDATE_GLASS_PARTS, matchedParts); + // Save parts to the store. + store.commit(storeMutations.UPDATE_GLASS_PARTS, matchedParts); // // Navigate to the next page. // this.$router.navigateAfterSave( @@ -227,10 +193,7 @@ methods: { LoadInitialPartsData() { const partsData = this.PartsFromApi; - const alreadyPopulatedPartsData = - this.$store.getters.lineItems.glassParts === null - ? {} - : this.$store.getters.lineItems.glassParts; + const alreadyPopulatedPartsData = this.$store.getters.lineItems.glassParts === null ? {} : this.$store.getters.lineItems.glassParts; partsData.partsOrQuestions.map((g) => { // If the part is already populated, use the value from the store and populate the v-model.