From 1a47f83301923add9bd7052cca0cea199be5d08f Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Tue, 9 May 2023 12:13:04 -0400 Subject: [PATCH 1/5] Updates for weather Alerts --- src/constants/endpoints.js | 4 +++ src/constants/store-actions.js | 1 + src/layouts/schedule/schedule.vue | 50 +++++++++++++++++++++++++++++++ src/store/index.js | 9 ++++++ 4 files changed, 64 insertions(+) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 08f429b5e..ef94c7b18 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -90,6 +90,10 @@ const endpoints = { url: "/parts/api/v1/parts/supporting-items", method: "POST", }, + GetAlertReasons: { + url: "/location/api/v1/location/alert-reasons", + method: "GET", + }, GetProviderLocations: { url: "/location/api/v1/location/providers", method: "GET", diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index db15e9854..3edf8bec3 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -21,6 +21,7 @@ const storeActions = { LOOKUP_VIN_BY_PLATE: "lookupVinByPlate", LOOKUP_VIN_BY_ADDRESS: "lookupVinByAddress", LOOKUP_VIN_BY_IMAGE: "lookupVinByImage", + GET_ALERT_REASONS_BY_CTU: "getAlertReasonsByCtu", GET_PARTS_OR_QUESTIONS: "getPartsOrQuestions", GET_PARTS: "getParts", GET_WIPERS: "getWipers", diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index 02361128c..e3eb56525 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -18,6 +18,17 @@ + + // Components +import alert from "@/ux-components/alert/alert"; import funnelHeader from "@/fmg-components/funnel-header/funnel-header"; import funnelFooter from "@/fmg-components/funnel-footer/funnel-footer"; import funnelSubHeader from "@/fmg-components/funnel-sub-header/funnel-sub-header"; @@ -53,6 +65,8 @@ import { } from "@/helpers/cms-content-helper"; import { errorMessages } from "@/constants/error-messages"; import { required } from "@/helpers/validation-rules"; +import { storeActions } from "@/constants/store-actions"; +import store from "@/store"; defineRule("date-required", required(errorMessages.DATE_REQUIRED)); @@ -61,6 +75,7 @@ export default { data() { return { selectedDate: null, + weatherAlerts: [], mockSelectableDatesData: [ { year: 2023, month: 4, date: 13 }, { year: 2023, month: 4, date: 14 }, @@ -102,6 +117,9 @@ export default { // Splits content when brackets are found in text so that text can be looped through and router-link can be injected when needed return this.splitCopyOnCMSPlaceHolder(this.ChangeShopLinkText); }, + displayWeatherAlert() { + return this.weatherAlerts.length > 0; + }, }, methods: { doesCopyContainRouterLink, @@ -112,9 +130,37 @@ export default { return true; // NEED TODO - WHAT ARE PAGE REQ'S FOR THIS PAGE? }, + cmsHeadlineTextFound(widgetName) { + return this.getCmsContent(widgetName, "HeadlineText") !== "" + }, + async getAlertReasons(ctu) { + await this.dispatchStoreAction( + storeActions.GET_ALERT_REASONS_BY_CTU, + { + ctu: ctu, + } + ) + .then((response) => { + if (response.data) { + this.weatherAlerts = response.data.reduce((newObj, alert) => { + newObj.push({ + cmsWidgetName: `LocationAlert-${alert}`, + alertReason: alert, + }); + return newObj; + }, []); + } + }) + .catch(() => { + console.log("error fetching alert reasons.."); + }); + }, getAvailableDates(startDate, endDate) { return this.mockSelectableDatesData; }, + getServiceZipCtuCodeFromStore() { + return store.getters.order.serviceLocation.zipCodeCtu; + }, backButtonAction() { this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route); }, @@ -123,6 +169,7 @@ export default { }, }, components: { + alert, funnelHeader, funnelFooter, funnelSubHeader, @@ -130,6 +177,9 @@ export default { loadingModal, datePicker, }, + mounted() { + this.getAlertReasons(this.getServiceZipCtuCodeFromStore()); + }, }; diff --git a/src/store/index.js b/src/store/index.js index 1548dd702..a61df90d6 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -681,6 +681,15 @@ export const actions = { }); }, + // Location API Actions + getAlertReasonsByCtu(context, { ctu }) { + return globalMethods.callHttpClient({ + method: endpoints.GetAlertReasons.method, + endpoint: `${endpoints.GetAlertReasons.url}/${ctu}`, + payload: {}, + }); + }, + // Misc Actions updateStoreWithSaveSessionResponse( context, From 8a55e1dbdd52b21eb655393c355a544b10e21e2c Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Tue, 9 May 2023 14:09:50 -0400 Subject: [PATCH 2/5] more inline with other page patterns --- .../schedule/helpers/schedule-helper.js | 13 ++++++ src/layouts/schedule/schedule.vue | 45 ++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 src/layouts/schedule/helpers/schedule-helper.js diff --git a/src/layouts/schedule/helpers/schedule-helper.js b/src/layouts/schedule/helpers/schedule-helper.js new file mode 100644 index 000000000..1b743d8ac --- /dev/null +++ b/src/layouts/schedule/helpers/schedule-helper.js @@ -0,0 +1,13 @@ +import { storeActions } from "@/constants/store-actions"; +import baseMixin from "@/mixins/base-mixin.js"; + +export async function getAlertReasons(ctu) { + const alertReasons = await baseMixin.methods.dispatchStoreAction( + storeActions.GET_ALERT_REASONS_BY_CTU, + { + ctu: ctu, + } + ) + + return Promise.resolve(alertReasons); +} \ No newline at end of file diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index e3eb56525..bc980553d 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -57,6 +57,9 @@ import datePicker from "@/digital-components/date-picker/date-picker"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { settleAllPromises } from "@/helpers/layout-helper"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import { + getAlertReasons, +} from "@/layouts/schedule/helpers/schedule-helper"; import { doesCopyContainRouterLink, splitCopyOnCMSPlaceHolder, @@ -75,6 +78,7 @@ export default { data() { return { selectedDate: null, + alertReasons: [], weatherAlerts: [], mockSelectableDatesData: [ { year: 2023, month: 4, date: 13 }, @@ -94,19 +98,26 @@ export default { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); + const alertReasonsPromise = getAlertReasons(store.getters.order.serviceLocation.zipCodeCtu); + // Settle promises and get results const promiseResultMap = [ { resultKey: "cmsContent", promise: cmsContentPromise, }, + { + resultKey: "alertReasons", + promise: alertReasonsPromise, + }, ]; const resultMap = await settleAllPromises(promiseResultMap); - + // Call the "next" function to complete the transition to this page. next((vm) => { vm.setCmsContent(resultMap.cmsContent); + vm.setData(resultMap.alertReasons); }); }, computed: { @@ -130,25 +141,28 @@ export default { return true; // NEED TODO - WHAT ARE PAGE REQ'S FOR THIS PAGE? }, + setData(alertReasonsData) { + if (alertReasonsData) { + this.convertReasonsToCmsAlerts(alertReasonsData); + } + }, cmsHeadlineTextFound(widgetName) { return this.getCmsContent(widgetName, "HeadlineText") !== "" }, - async getAlertReasons(ctu) { - await this.dispatchStoreAction( - storeActions.GET_ALERT_REASONS_BY_CTU, - { - ctu: ctu, - } - ) + convertReasonsToCmsAlerts(data) { + this.weatherAlerts = data.reduce((newObj, alert) => { + newObj.push({ + cmsWidgetName: `LocationAlert-${alert}`, + alertReason: alert, + }); + return newObj; + }, []); + }, + async getWeatherAlertReasons(ctu) { + await getAlertReasons(ctu) .then((response) => { if (response.data) { - this.weatherAlerts = response.data.reduce((newObj, alert) => { - newObj.push({ - cmsWidgetName: `LocationAlert-${alert}`, - alertReason: alert, - }); - return newObj; - }, []); + this.convertReasonsToCmsAlerts(response.data); } }) .catch(() => { @@ -178,7 +192,6 @@ export default { datePicker, }, mounted() { - this.getAlertReasons(this.getServiceZipCtuCodeFromStore()); }, }; From 166d52467e22dc7d3082ed796becb5b532f35260 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Tue, 9 May 2023 15:39:48 -0400 Subject: [PATCH 3/5] remove unused import --- src/layouts/schedule/schedule.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index bc980553d..c4aeff7eb 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -68,7 +68,6 @@ import { } from "@/helpers/cms-content-helper"; import { errorMessages } from "@/constants/error-messages"; import { required } from "@/helpers/validation-rules"; -import { storeActions } from "@/constants/store-actions"; import store from "@/store"; defineRule("date-required", required(errorMessages.DATE_REQUIRED)); From 0307ab1c0ac549cefe3f43139fa92b118ee884ff Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Wed, 10 May 2023 10:56:08 -0400 Subject: [PATCH 4/5] unneeded variable --- src/layouts/schedule/schedule.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index c4aeff7eb..b2e8b0a05 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -77,7 +77,6 @@ export default { data() { return { selectedDate: null, - alertReasons: [], weatherAlerts: [], mockSelectableDatesData: [ { year: 2023, month: 4, date: 13 }, From 78ec13b7febee20a0f4e1a140d7ad93ed6935711 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Wed, 10 May 2023 11:07:49 -0400 Subject: [PATCH 5/5] prettier'd --- .../schedule/helpers/schedule-helper.js | 16 +++++------ src/layouts/schedule/schedule.vue | 27 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/layouts/schedule/helpers/schedule-helper.js b/src/layouts/schedule/helpers/schedule-helper.js index 1b743d8ac..005bd4b19 100644 --- a/src/layouts/schedule/helpers/schedule-helper.js +++ b/src/layouts/schedule/helpers/schedule-helper.js @@ -2,12 +2,12 @@ import { storeActions } from "@/constants/store-actions"; import baseMixin from "@/mixins/base-mixin.js"; export async function getAlertReasons(ctu) { - const alertReasons = await baseMixin.methods.dispatchStoreAction( - storeActions.GET_ALERT_REASONS_BY_CTU, - { - ctu: ctu, - } - ) + const alertReasons = await baseMixin.methods.dispatchStoreAction( + storeActions.GET_ALERT_REASONS_BY_CTU, + { + ctu: ctu, + } + ); - return Promise.resolve(alertReasons); -} \ No newline at end of file + return Promise.resolve(alertReasons); +} diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index b2e8b0a05..83c3562bf 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -57,9 +57,7 @@ import datePicker from "@/digital-components/date-picker/date-picker"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { settleAllPromises } from "@/helpers/layout-helper"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; -import { - getAlertReasons, -} from "@/layouts/schedule/helpers/schedule-helper"; +import { getAlertReasons } from "@/layouts/schedule/helpers/schedule-helper"; import { doesCopyContainRouterLink, splitCopyOnCMSPlaceHolder, @@ -111,7 +109,7 @@ export default { ]; const resultMap = await settleAllPromises(promiseResultMap); - + // Call the "next" function to complete the transition to this page. next((vm) => { vm.setCmsContent(resultMap.cmsContent); @@ -145,7 +143,7 @@ export default { } }, cmsHeadlineTextFound(widgetName) { - return this.getCmsContent(widgetName, "HeadlineText") !== "" + return this.getCmsContent(widgetName, "HeadlineText") !== ""; }, convertReasonsToCmsAlerts(data) { this.weatherAlerts = data.reduce((newObj, alert) => { @@ -158,14 +156,14 @@ export default { }, async getWeatherAlertReasons(ctu) { await getAlertReasons(ctu) - .then((response) => { - if (response.data) { - this.convertReasonsToCmsAlerts(response.data); - } - }) - .catch(() => { - console.log("error fetching alert reasons.."); - }); + .then((response) => { + if (response.data) { + this.convertReasonsToCmsAlerts(response.data); + } + }) + .catch(() => { + console.log("error fetching alert reasons.."); + }); }, getAvailableDates(startDate, endDate) { return this.mockSelectableDatesData; @@ -189,8 +187,7 @@ export default { loadingModal, datePicker, }, - mounted() { - }, + mounted() {}, };