CSR-319: various refactorings from PR comments

This commit is contained in:
Adam Caouette 2022-03-09 12:06:39 -05:00
parent a3c8998345
commit d1785cf6fc

View file

@ -40,17 +40,18 @@ import alert from "@/ux-components/alert/alert";
import { defineRule } from "vee-validate"; import { defineRule } from "vee-validate";
import { required } from "@/helpers/validation-rules"; import { required } from "@/helpers/validation-rules";
import { errorMessages } from "@/constants/error-messages"; import { errorMessages } from "@/constants/error-messages";
import { damageLocationsSelected } from "@/constants/damage-locations-selected.js";
// DEFINE VALIDATION RULES // DEFINE VALIDATION RULES
defineRule("windshield-damage-type-required", required(errorMessages.WINDSHIELD_DAMAGE_TYPE_REQUIRED)); defineRule("windshield-damage-type-required", required(errorMessages.WINDSHIELD_DAMAGE_TYPE_REQUIRED));
defineRule("windshield-chip-count-required", required(errorMessages.WINDSHIELD_CHIP_COUNT_REQUIRED)); defineRule("windshield-chip-count-required", required(errorMessages.WINDSHIELD_CHIP_COUNT_REQUIRED));
defineRule("windshield-replace-options-required", required(errorMessages.WINSHIELD_REPLACE_OPTIONS_REQUIRED)); defineRule("windshield-replace-options-required", required(errorMessages.WINSHIELD_REPLACE_OPTIONS_REQUIRED));
defineRule("checkForRepairAndReplace", (value, [other]) => { defineRule("checkForRepairAndReplace", (value, [otherFieldValue]) => {
if (value.toString().toUpperCase().includes("REPAIR") && if (value.toString().toUpperCase().includes(damageLocationsSelected.REPAIR.toUpperCase()) &&
other.toString().toUpperCase().includes("WINDSHIELD") && otherFieldValue.toString().toUpperCase().includes(damageLocationsSelected.WINDSHIELD.toUpperCase()) &&
Array.isArray(other) && Array.isArray(otherFieldValue) &&
other.length > 1) otherFieldValue.length > 1)
{ {
return "checkForRepairAndReplace error" return "checkForRepairAndReplace error"
} }
@ -58,7 +59,7 @@ defineRule("checkForRepairAndReplace", (value, [other]) => {
}); });
defineRule("repairOnly", (value) => { defineRule("repairOnly", (value) => {
if (value.toString().toUpperCase() === 'REPAIR') { if (value.toString().toUpperCase() === damageLocationsSelected.REPAIR.toUpperCase()) {
return true; return true;
} }
return false; return false;
@ -69,7 +70,7 @@ export default ({
data(){ data(){
return { return {
isWindshieldReplaceAvailable: Boolean, windshieldAvailableReplacementOptions: Object,
} }
}, },
@ -87,7 +88,7 @@ export default ({
this.$refs.windshieldChipCountQuestion.initializeComponent(windshieldChipCountQuestionFromCms); this.$refs.windshieldChipCountQuestion.initializeComponent(windshieldChipCountQuestionFromCms);
this.$refs.replaceOptionsQuestion.initializeComponent(windshieldReplaceOptionsQuestionFromCms, windshieldAvailableReplacementOptions); this.$refs.replaceOptionsQuestion.initializeComponent(windshieldReplaceOptionsQuestionFromCms, windshieldAvailableReplacementOptions);
this.isWindshieldReplaceAvailable = !(Array.isArray(windshieldAvailableReplacementOptions) && windshieldAvailableReplacementOptions.length < 1); this.windshieldAvailableReplacementOptions = windshieldAvailableReplacementOptions;
}, },
getWindshieldOptions(selectedWindshieldDamageType, selectedWindshieldChipCount, selectedWindshieldReplaceOptions){ getWindshieldOptions(selectedWindshieldDamageType, selectedWindshieldChipCount, selectedWindshieldReplaceOptions){
return { return {
@ -131,7 +132,7 @@ export default ({
} }
}, },
isWindshieldDamageLocation() { isWindshieldDamageLocation() {
return this.selectedDamageLocations.some(selectedDamages => return this.selectedDamageLocations.some(selectedDamages =>
{ {
return Boolean(selectedDamages.toUpperCase() === "WINDSHIELD"); return Boolean(selectedDamages.toUpperCase() === "WINDSHIELD");
}); });
@ -146,6 +147,9 @@ export default ({
return this.selectedWindshieldDamageTypeValues.some(val => val.toUpperCase() === "REPLACE") && this.isWindshieldDamageLocation; return this.selectedWindshieldDamageTypeValues.some(val => val.toUpperCase() === "REPLACE") && this.isWindshieldDamageLocation;
}, },
isWindshieldReplaceAvailable() {
return !(Array.isArray(this.windshieldAvailableReplacementOptions) && this.windshieldAvailableReplacementOptions.length < 1);
},
showNoReplaceAvailableError() { showNoReplaceAvailableError() {
if (this.isReplaceOptionSelected && !this.isWindshieldReplaceAvailable) { if (this.isReplaceOptionSelected && !this.isWindshieldReplaceAvailable) {
return true; return true;