diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index ea40af19d..592d2d668 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -164,6 +164,10 @@ const endpoints = { url: "/experiments/api/v1/experiments/run", method: "POST", }, + GetInsuranceCompanyList: { + url: "/account/api/v1/account/insurance-companies", + method: "GET", + }, }; export { endpoints }; diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 9b6fdb865..491d717b9 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -51,6 +51,7 @@ const storeActions = { GET_SIGNATURE: "getSignature", VALIDATE_ORDER_PROMO_AND_SAVE_SERVER_DATA: "validateOrderPromoAndSaveServerData", REVALIDATE_ORDER_PROMOS_AND_SAVE_SERVER_DATA: "revalidateOrderPromosAndSaveServerData", + GET_INSURANCE_COMPANY_LIST: "getInsuranceCompanyList", // DEPENDENCY MUTATIONS RESET_DAMAGE_STATE_AND_DEPENDENCIES: "resetDamageAndDependencies", diff --git a/src/layouts/insurance-lookup/insurance-lookup.vue b/src/layouts/insurance-lookup/insurance-lookup.vue index 8584806e9..1d58dfdd7 100644 --- a/src/layouts/insurance-lookup/insurance-lookup.vue +++ b/src/layouts/insurance-lookup/insurance-lookup.vue @@ -51,6 +51,7 @@ import { required, regex } from "@/helpers/validation-rules"; 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 store from "@/store"; import vinPagesMixin from "@/mixins/vin-pages-mixin"; @@ -76,6 +77,11 @@ export default { async beforeRouteEnter(to, from, next) { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); + const insuranceCompanyListPromise = baseMixin.methods.dispatchStoreActionWithLogging( + storeActions.GET_INSURANCE_COMPANY_LIST, + {}, + "insurance-lookup" + ); // Settle promises and get results const promiseResultMap = [ @@ -83,15 +89,31 @@ export default { resultKey: "cmsContent", promise: cmsContentPromise, }, + { + resultKey: "insuranceCompanyList", + promise: insuranceCompanyListPromise, + }, ]; const resultMap = await settleAllPromises(promiseResultMap); - // Call the "next" function to complete the transition to this page. next((vm) => { vm.setCmsContent(resultMap.cmsContent); + vm.insuranceCompanyList = resultMap.insuranceCompanyList; }); }, + data() { + return { + insuranceCompanyList: [], + } + }, + computed: { + insuranceCompanyListTags() { + return this.insuranceCompanyList.map(item => { + return item.accountName; + }) + } + }, methods: { arePagePrerequisitesValid() { return store.getters.vehicle.carId !== null; @@ -110,34 +132,13 @@ export default { }, mounted() { const select = this.handleAutocompleteSelect; - // Temporary list of insurance companies for testing - var tags = [ - "21st Century Insurance", - "Farmers Insurance", - "Grange Insurance", - "Liberty Mutual Insurance", - "State Auto Insurance", - "State Farm Insurance", - "Travelers Insurance", - "AAA", - "AAA Ohio", - "AAA Indiana", - "AAA Florida", - "American Autombile Insurance Co", - "American Automobile Association", - "American Insurance", - ]; - tags.sort(); //Sort list alphabetically $("#autocomplete").autocomplete({ - source: tags, + source: this.insuranceCompanyListTags, position: { my: "left top+6", }, minLength: 0, // Necessary to display menu when clearing input - select: function (event, ui) { - select(ui.item.value); - }, // Bold matching letters as you type in the input search: function (event, ui) { setTimeout(() => { diff --git a/src/store/index.js b/src/store/index.js index ffc6e6e08..bb8436d8a 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2421,6 +2421,28 @@ export const actions = { return revalidateResponse?.data; }, + // List all insurance companies + async getInsuranceCompanyList(context, { pageNameToLog }) { + const insuranceCompanyList = await globalMethods.callHttpClient({ + method: endpoints.GetInsuranceCompanyList.method, + endpoint: endpoints.GetInsuranceCompanyList.url, + payload: {}, + logApiCall: true, + pageNameToLog: pageNameToLog, + }); + console.log(insuranceCompanyList); + return insuranceCompanyList.data.sort((a, b) => { + const nameA = a.accountName.toUpperCase(); + const nameB = b.accountName.toUpperCase(); + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } + return 0; + }); + }, // Misc order actions saveSchedule(context, scheduleInfo) {