Add copy for multi-glass scenarios.

This commit is contained in:
Chloe Herd 2023-07-25 14:14:02 -04:00
parent 843105a9ac
commit e9fd49f137

View file

@ -23,17 +23,39 @@ export default {
editClicked() { editClicked() {
this.$emit("edit-clicked"); this.$emit("edit-clicked");
}, },
getAnswersNullSafe(widgetName) {
const rawAnswers = this.getCmsContent(widgetName, "Answers");
return rawAnswers ? rawAnswers : [];
},
getLocationAnswer(damageLocation) { getLocationAnswer(damageLocation) {
if(!this.locationAnswers) { return this.locationAnswers?.find((answer) => answer.Name === damageLocation);
return undefined; },
} getGlassPieces(damageLocation) {
return this.damage?.glassToReplace?.filter(
return this.locationAnswers.find((answer) => answer.Name === damageLocation); (item) => item.glassLocation === damageLocation
);
},
generateBulletedListFromAnswers(answers) {
let list = "<ul>";
answers.forEach((answer) => {
list += `<li>${answer.Text}</li>`;
});
list += "</ul>";
return list;
}, },
}, },
computed: { computed: {
displayContent() { displayContent() {
return [...this.windshieldCopy]; return [
...this.windshieldCopy,
...this.driverSideCopy,
...this.passengerSideCopy,
...this.rearCopy,
];
}, },
hasWindshieldDamage() { hasWindshieldDamage() {
return ( return (
@ -43,6 +65,21 @@ export default {
) )
); );
}, },
hasDriverSideDamage() {
const driverPieces = this.getGlassPieces(damageLocationsSelected.DRIVER);
return !!driverPieces?.length;
},
hasPassengerSideDamage() {
const passengerPieces = this.getGlassPieces(damageLocationsSelected.PASSENGER);
return !!passengerPieces?.length;
},
hasRearDamage() {
const rearPieces = this.getGlassPieces(damageLocationsSelected.REAR);
return !!rearPieces?.length;
},
windshieldCopy() { windshieldCopy() {
const answerContent = this.getLocationAnswer(damageLocationsSelected.WINDSHIELD); const answerContent = this.getLocationAnswer(damageLocationsSelected.WINDSHIELD);
@ -52,8 +89,53 @@ export default {
return []; return [];
} }
}, },
driverSideCopy() {
const answerContent = this.getLocationAnswer(damageLocationsSelected.DRIVER);
const damageAnswers = this.getAnswersNullSafe(answerContent?.SubWidgetName);
const damageAnswersOnOrder = damageAnswers?.filter((answer) =>
this.damage?.glassToReplace?.some(
(glassPiece) => answer.Name === glassPiece.glassName
)
);
if (this.hasDriverSideDamage) {
return [
answerContent?.Text,
this.generateBulletedListFromAnswers(damageAnswersOnOrder),
];
} else {
return [];
}
},
passengerSideCopy() {
const answerContent = this.getLocationAnswer(damageLocationsSelected.PASSENGER);
const damageAnswers = this.getAnswersNullSafe(answerContent?.SubWidgetName);
const damageAnswersOnOrder = damageAnswers?.filter((answer) =>
this.damage?.glassToReplace?.some(
(glassPiece) => answer.Name === glassPiece.glassName
)
);
if (this.hasPassengerSideDamage) {
return [
answerContent?.Text,
this.generateBulletedListFromAnswers(damageAnswersOnOrder),
];
} else {
return [];
}
},
rearCopy() {
const answerContent = this.getLocationAnswer(damageLocationsSelected.REAR);
if (this.hasRearDamage) {
return [answerContent?.Text];
} else {
return [];
}
},
locationAnswers() { locationAnswers() {
return this.getCmsContent(this.damageLocationsWidgetName, "Answers"); return this.getAnswersNullSafe(this.damageLocationsWidgetName);
}, },
}, },
components: { components: {