CSR-1891: use term mapping to update co list

This commit is contained in:
Adam Caouette 2024-03-11 16:28:35 -04:00
parent 0403ad22d8
commit 7057f6bf52

View file

@ -41,35 +41,24 @@ import loadingModal from "@/fmg-components/loading-modal/loading-modal.vue";
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import { settleAllPromises } from "@/helpers/layout-helper"; import { settleAllPromises } from "@/helpers/layout-helper";
import { storeActions } from "@/constants/store-actions"; import { storeActions } from "@/constants/store-actions";
import { errorMessages } from "@/constants/error-messages";
import {
getDamageString,
getIsWindshieldOnly,
isGlassAvailableForCarId,
} from "@/helpers/damage-helper";
import { required, regex } from "@/helpers/validation-rules";
import { Form, defineRule } from "vee-validate"; import { Form, defineRule } from "vee-validate";
import { getFunnelCookie } from "@/helpers/heritage-integration/cookie-helper";
import { routerParams } from "@/router/router-constants/router-params";
import baseMixin from "@/mixins/base-mixin.js"; import baseMixin from "@/mixins/base-mixin.js";
import store from "@/store"; import store from "@/store";
import vinPagesMixin from "@/mixins/vin-pages-mixin"; import vinPagesMixin from "@/mixins/vin-pages-mixin";
import $ from "jquery"; import $ from "jquery";
// DEFINE VALIDATION RULES // MAPPNG
defineRule("zip-required", required(errorMessages.SERVICE_ZIP_REQUIRED)); const termMapping = [
defineRule("zip-format", regex(/(^\d{5}$)|(^\d{5}-\d{4}$)/, errorMessages.SERVICE_ZIP_FORMAT)); {
defineRule("email-address-required", required(errorMessages.EMAIL_ADDRESS_REQUIRED)); term: "1ST",
defineRule( altTerm: "FIRST",
"email-address-format", },
regex( {
/^([a-zA-Z0-9_\-.+]+)@([a-zA-Z0-9-]+)\.([a-zA-Z]{2,})$/, term: "AAA",
errorMessages.EMAIL_ADDRESS_FORMAT altTerm: "American"
) }
); ];
defineRule("vin-required", required(errorMessages.VIN_REQUIRED));
defineRule("vin-format", regex(/^[a-hA-Hj-nJ-NpPr-zR-Z0-9]{17}$/, errorMessages.VIN_FORMAT));
export default { export default {
name: "insurance-company", name: "insurance-company",
@ -96,73 +85,36 @@ export default {
]; ];
const resultMap = await settleAllPromises(promiseResultMap); const resultMap = await settleAllPromises(promiseResultMap);
const searchableInsuranceCompanyList = resultMap.insuranceCompanyList.map(( insuranceCompany ) => {
insuranceCompany.altTerms = "";
termMapping.forEach((matchingTerm) => {
if (insuranceCompany.accountName.toUpperCase().includes(matchingTerm.term.toUpperCase())) {
insuranceCompany.altTerms = insuranceCompany.altTerms + matchingTerm.altTerm?.toUpperCase() + " ";
}
});
return insuranceCompany;
});
console.log("searchableInsuranceCompanyList: ", searchableInsuranceCompanyList);
// Call the "next" function to complete the transition to this page. // Call the "next" function to complete the transition to this page.
next((vm) => { next((vm) => {
vm.setCmsContent(resultMap.cmsContent); vm.setCmsContent(resultMap.cmsContent);
vm.insuranceCompanyList = resultMap.insuranceCompanyList; vm.originalList = resultMap.insuranceCompanyList;
vm.searchableInsuranceCompanyList = searchableInsuranceCompanyList;
}); });
}, },
data() { data() {
return { return {
insuranceCompanyList: [], searchableInsuranceCompanyList: [],
originalList: [],
}; };
}, },
computed: {
insuranceCompanyListTags() {
// return this.insuranceCompanyList.map((item) => {
// return item.accountName;
// });
const termMap = [
{
term: "1st",
altTerm: "FIRST",
}
];
const doTest = (testTerm) => {
return termMap.find((matchingTerm) => {
if (testTerm.includes(matchingTerm.term)) return matchingTerm.altTerm;
return;
});
};
return this.insuranceCompanyList.map((item) => {
// return item.accountName;
return {
label: item.accountName,
altTerms: doTest(item.accountName) ? doTest(item.accountName) : "",
}
});
// return [
// {
// "label": "1ST INSURANCE",
// "altTerms": "FIRST"
// },
// {
// "label": "AAA INSURANCE",
// "altTerms": "AMERICAN AUTOMOTIVE AUTOMOBILE ASSOCIATION TRIPLE"
// },
// {
// "label": "AMERICAN ROADS INSURANCE",
// "altTerms": ""
// },
// {
// "label": "DONT USE US INSURANCE",
// "altTerms": ""
// },
// {
// "label": "FIRST PIONEER INSURANCE",
// "altTerms": "1ST"
// },
// ];
},
},
methods: { methods: {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return store.getters.vehicle.carId !== null; return store.getters.vehicle.carId !== null;
@ -170,13 +122,11 @@ export default {
findMatches(request, response) { findMatches(request, response) {
const matches = []; const matches = [];
const term = request?.term?.toUpperCase(); const term = request?.term?.toUpperCase();
console.log(this.insuranceCompanyListTags); this.originalList.forEach((company, index) => {
this.insuranceCompanyListTags.forEach((tag, index) => { if (company.accountName.indexOf(term) !== -1 || company.altTerms.indexOf(term) !== -1) {
if (tag.label.indexOf(term) !== -1 || tag.altTerms.indexOf(term) !== -1) { matches.push(company.accountName);
matches.push(tag);
} }
}); });
response(matches); response(matches);
}, },
backButtonAction() { backButtonAction() {
@ -207,7 +157,7 @@ export default {
}, 5); }, 5);
}, },
}); });
}, 5); }, 0);
}, },
components: { components: {
funnelHeader, funnelHeader,