From 60b7fe5d53c78f37475b5c8a5352950ef67436b7 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Mon, 11 Sep 2023 11:16:09 -0400 Subject: [PATCH] save endorsements answers to store --- src/store/index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/store/index.js b/src/store/index.js index a2bfbcd7..f213b2a8 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -58,7 +58,8 @@ const getDefaultState = () => ({ deductible: { repair: null, // numerical value; how much customer owes on deductible in repair case replace: null // numerical value; how much customer owes on deductible in replace case, - } + }, + endorsementQuestionAnswers: null, }, customer: { address: { @@ -817,6 +818,21 @@ export const useMainStore = defineStore({ this.applicationUser.saveSessionPromise = null; }, + saveEndorsementQuestionAnswers(endorsementQuestionAnswersArray) { + // if endorsement question answers have changed, reset question answers + const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue(this.order.policy.endorsementQuestionAnswers, 'result'); + const sortedEndorsementQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(endorsementQuestionAnswersArray, 'result'); + const haveEndorsementQuestionAnswersChanged = sortedPreviousResultsArray?.length !== sortedEndorsementQuestionAnswersArray.length + || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedEndorsementQuestionAnswersArray[i].result); + + if (haveEndorsementQuestionAnswersChanged) { + this.updateEndorsementQuestionAnswers(null); + } + + // Save new values + this.updateEndorsementQuestionAnswers(endorsementQuestionAnswersArray); + }, + saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, selectedWindshieldChipCount) { const selectedGlassPassedInSorted = selectedGlassToReplace.slice().sort(); const isGlassToReplaceTheSame = this.order.damage.glassToReplace?.length === selectedGlassToReplace.length @@ -1014,6 +1030,10 @@ export const useMainStore = defineStore({ } }, + updateEndorsementQuestionAnswers(answersArray) { + this.order.policy.endorsementQuestionAnswers = answersArray; + }, + updateIsRepair(isRepair) { this.order.damage.isRepair = isRepair; },