CSR-111 Reset answers if they change
This commit is contained in:
parent
f4f2ae3a7d
commit
6e0c9688d3
3 changed files with 54 additions and 2 deletions
|
|
@ -58,6 +58,7 @@ const storeActions = {
|
|||
SAVE_REGISTRATION_ADDRESS_LOOKUP: "saveRegistrationAddressLookup",
|
||||
SAVE_GLASS_PARTS: "saveGlassParts",
|
||||
SAVE_PART_QUESTION_ANSWERS: "savePartQuestionAnswers",
|
||||
RESET_MOLDING_AND_CAPABILITY_QUESTIONS_IF_NEEDED: "resetMoldingAndCapabilityQuestionAnswersIfNeeded",
|
||||
SAVE_MOLDING_QUESTION_ANSWERS: "saveMoldingQuestionAnswers",
|
||||
SAVE_CAPABILITY_QUESTION_ANSWERS: "saveCapabilityQuestionAnswers"
|
||||
};
|
||||
|
|
|
|||
|
|
@ -188,6 +188,8 @@ export default {
|
|||
throw new Error("Could not match any parts to the selected parts");
|
||||
}
|
||||
|
||||
await this.dispatchStoreAction(this.storeActions.RESET_MOLDING_AND_CAPABILITY_QUESTIONS_IF_NEEDED, matchedParts, false);
|
||||
|
||||
// Navigate to the next page
|
||||
this.navigateForward(matchedParts);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1007,20 +1007,69 @@ export const actions = {
|
|||
!previousResultsArray.every((x, i) => x.result === partQuestionAnswersArray[i].result);
|
||||
|
||||
if (havePartQuestionAnswersChanged) {
|
||||
context.commit(storeMutations.UPDATE_GLASS_PARTS, null);
|
||||
context.commit(storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS, null);
|
||||
context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null);
|
||||
state.applicationUser.pageData[fmgPageValues.MOLDING_QUESTIONS] = null;
|
||||
state.applicationUser.pageData[fmgPageValues.CAPABILITY_QUESTIONS] = null;
|
||||
context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.VEHICLE_PARTS, data: null });
|
||||
context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.MOLDING_QUESTIONS, data: null });
|
||||
context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null });
|
||||
}
|
||||
|
||||
//Save new values
|
||||
context.commit(storeMutations.UPDATE_PART_QUESTION_ANSWERS, partQuestionAnswersArray);
|
||||
},
|
||||
resetMoldingAndCapabilityQuestionAnswersIfNeeded(context, matchedParts) {
|
||||
const previousResultsArray = [{ parts: context.getters.lineItems.glassParts }];
|
||||
|
||||
function getAllPartNumbers(partsOrQuestions) {
|
||||
return [...partsOrQuestions].map(glass => glass.parts).flat().map(part => part.partNumber).sort().join(",");
|
||||
}
|
||||
|
||||
const previouslySelectedPartNumbers = getAllPartNumbers(previousResultsArray);
|
||||
const currentlySelectedPartNumbers = getAllPartNumbers(matchedParts);
|
||||
|
||||
const haveSelectedVehiclePartsChanged = previouslySelectedPartNumbers !== currentlySelectedPartNumbers;
|
||||
|
||||
if (haveSelectedVehiclePartsChanged) {
|
||||
context.commit(storeMutations.UPDATE_GLASS_PARTS, null);
|
||||
context.commit(storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS, null);
|
||||
context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null);
|
||||
context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.MOLDING_QUESTIONS, data: null });
|
||||
context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null });
|
||||
}
|
||||
|
||||
console.log(previousResultsArray)
|
||||
console.log(matchedParts)
|
||||
console.log(haveSelectedVehiclePartsChanged)
|
||||
},
|
||||
saveMoldingQuestionAnswers(context, moldingQuestionAnswers) {
|
||||
const previousResultsArray = context.getters.damage.moldingQuestionAnswers;
|
||||
// TODO NOT ACCURATE!! answerData/answerQuestions keeps changing, partNum is undefined a lot
|
||||
const haveMoldingQuestionAnswersChanged = previousResultsArray?.length !== moldingQuestionAnswers.length ||
|
||||
!previousResultsArray.every((x, i) =>
|
||||
x.answeredQuestions &&
|
||||
x.answeredQuestions.length === moldingQuestionAnswers[i].answeredQuestions?.length &&
|
||||
x.answeredQuestions.every((y, j) => y.selectedAnswerText === moldingQuestionAnswers[i].answeredQuestions[j].selectedAnswerText));
|
||||
|
||||
if (haveMoldingQuestionAnswersChanged) {
|
||||
// TODO reset glass parts
|
||||
context.commit(storeMutations.UPDATE_GLASS_PARTS, null);
|
||||
context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null);
|
||||
context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null });
|
||||
}
|
||||
|
||||
//Save new values
|
||||
context.commit(storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS, moldingQuestionAnswers);
|
||||
},
|
||||
saveCapabilityQuestionAnswers(context, capabilityQuestionAnswers) {
|
||||
const previousResultsArray = context.getters.damage.capabilityQuestionAnswers;
|
||||
const haveCapabilityQuestionAnswersChanged = previousResultsArray?.length !== capabilityQuestionAnswers.length ||
|
||||
!previousResultsArray.every((x, i) => x.result === capabilityQuestionAnswers[i].result);
|
||||
|
||||
if (haveCapabilityQuestionAnswersChanged) {
|
||||
context.commit(storeMutations.UPDATE_GLASS_PARTS, null);
|
||||
}
|
||||
|
||||
//Save new values
|
||||
context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, capabilityQuestionAnswers);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue