From 1ac05c353b59b84542760f7c174782fb793e3141 Mon Sep 17 00:00:00 2001 From: FrankRua Date: Mon, 21 Mar 2022 12:05:10 -0400 Subject: [PATCH 1/2] CSR-98 to CSR-99 --- src/constants/endpoints.js | 4 + src/constants/store-actions.js | 3 + src/constants/store-mutations.js | 1 + src/global-methods.js | 1 - src/helpers/heritage-integration-helper.js | 36 +-- src/layouts/address-poc/address-poc.vue | 233 ------------------ .../button-question-examples.vue | 138 ----------- src/layouts/nested-radio-poc/nested-radio.vue | 74 ------ src/router/index.js | 29 +-- src/store/index.js | 27 ++ 10 files changed, 59 insertions(+), 487 deletions(-) delete mode 100644 src/layouts/address-poc/address-poc.vue delete mode 100644 src/layouts/button-question-examples/button-question-examples.vue delete mode 100644 src/layouts/nested-radio-poc/nested-radio.vue diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index c547bd28c..03c03cf6c 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -50,6 +50,10 @@ const endpoints = { SaveOrder: { url: "/order/api/v1/order/save", method: "POST", + }, + LoadOrder: { + url: "/order/api/v1/order/load", + method: "POST", } }; diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 84ecf77e6..c0e6893a4 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -13,6 +13,9 @@ const storeActions = { LOOKUP_VEHICLE_BY_VIN: "lookupVehicleByVin", GET_PARTS_OR_QUESTIONS: "getPartsOrQuestions", SAVE_ORDER: "saveOrder", + LOAD_ORDER: "loadOrder", + SET_REFERRAL_INFORMATION: "setReferralInformation", + SET_LOAD_ORDER_DATA: "setLoadOrderData", // DEPENDENCY MUTATIONS RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies", diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index d6ee3b321..47dfcacca 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -33,6 +33,7 @@ const storeMutations = { // OTHER MUTATIONS UPDATE_PAGE_DATA: "updatePageData", + SET_LOAD_ORDER_INFO: "setLoadOrderInformation" }; diff --git a/src/global-methods.js b/src/global-methods.js index 7d82a2590..8efd163aa 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -12,7 +12,6 @@ export default { apiGatewayUrl = "https://localhost:44346"; } - // const apiGatewayUrl = applicationConfig.CONSUMER_APIGATEWAY_URL; const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "FixMyGlass", diff --git a/src/helpers/heritage-integration-helper.js b/src/helpers/heritage-integration-helper.js index a994ad057..cc2f9379e 100644 --- a/src/helpers/heritage-integration-helper.js +++ b/src/helpers/heritage-integration-helper.js @@ -1,21 +1,16 @@ import { storeActions } from "@/constants/store-actions.js"; -import { storeMutations } from "@/constants/store-mutations.js"; import { cookieNames } from "@/constants/cookie-names"; +import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import store from "@/store"; import router from "@/router"; -import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import baseMixin from "../mixins/base-mixin"; // Read info from heritage funnel and reset state or load referral export function handleInfoFromHeritageFunnel() { const orderInfo = getHeritageCookieValue(); - console.log("A") - console.log(orderInfo) - console.log(document.cookie) if (orderInfo?.ShouldResetState) { - console.log("B") - store.dispatch(storeActions.RESET_STATE); + baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE); deleteHeritageCookie(); } else if (orderInfo?.DidHeritageFunnelUpdateLast) { @@ -47,17 +42,30 @@ export async function navigateToHeritageFunnel() { } export async function saveOrder() { - console.log("HI") const savedOrderInfo = (await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER)).data; - store.commit(storeMutations.UPDATE_REFERRAL_NUMBER, savedOrderInfo.referralNumber); - store.commit(storeMutations.UPDATE_REFERRAL_DATE, savedOrderInfo.referralDate); - store.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, savedOrderInfo.referralCorrelationId); + // Save the referral information back from the store. + await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SET_REFERRAL_INFORMATION, { + referralNumber: savedOrderInfo.referralNumber, + correlationId: savedOrderInfo.referralCorrelationId, + referralDate: savedOrderInfo.referralDate, + }) + + // Set cookie properties. setHeritageCookieProperties({ DidHeritageFunnelUpdateLast: false }) } +export async function loadOrder() { + const loadOrderInfo = (await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOAD_ORDER)).data; + + // Save the data from the loaded order to state. + await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SET_LOAD_ORDER_DATA, { loadOrderInfo }); +} + +// --------- PRIVATE FUNCTIONS --------- + /* Start cookie related functions */ export function getHeritageCookieValue() { console.log("A") @@ -83,7 +91,7 @@ function setHeritageCookieValue(cookieValue) { let cookieValueJson = cookieValue; if (typeof cookieValue == "object") cookieValueJson = JSON.stringify(cookieValue); - + document.cookie = `${cookieNames.ORDER_INFO}=${cookieValueJson}; path=/`; } @@ -91,7 +99,7 @@ function setHeritageCookieProperties(properties) { if (typeof properties == "object") { let cookie = getHeritageCookieValue(); - if (cookie != null) { + if (cookie !== null) { Object.keys(properties).forEach(key => { cookie[key] = properties[key]; }); @@ -100,4 +108,4 @@ function setHeritageCookieProperties(properties) { } } } -/* End cookie related functions */ \ No newline at end of file +/* End cookie related functions */ diff --git a/src/layouts/address-poc/address-poc.vue b/src/layouts/address-poc/address-poc.vue deleted file mode 100644 index 8bb42a659..000000000 --- a/src/layouts/address-poc/address-poc.vue +++ /dev/null @@ -1,233 +0,0 @@ - - - diff --git a/src/layouts/button-question-examples/button-question-examples.vue b/src/layouts/button-question-examples/button-question-examples.vue deleted file mode 100644 index 6df20ddf1..000000000 --- a/src/layouts/button-question-examples/button-question-examples.vue +++ /dev/null @@ -1,138 +0,0 @@ - - - \ No newline at end of file diff --git a/src/layouts/nested-radio-poc/nested-radio.vue b/src/layouts/nested-radio-poc/nested-radio.vue deleted file mode 100644 index d0a78d085..000000000 --- a/src/layouts/nested-radio-poc/nested-radio.vue +++ /dev/null @@ -1,74 +0,0 @@ - - - - - diff --git a/src/router/index.js b/src/router/index.js index abc7a1991..2e9ed4db1 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,17 +5,15 @@ import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js" import { routingTable } from "@/router/router-constants/routing-table.js"; import { globalEvents, globalEventTypes } from "@/constants/events"; import { routerParameterKeys } from '@/router/router-constants/router-parameter-keys' +import { handleInfoFromHeritageFunnel, saveOrder, getHeritageCookieValue } from "@/helpers/heritage-integration-helper"; + import baseMixin from "@/mixins/base-mixin"; import eventBus from "@/helpers/event-bus/event-bus"; import store from "@/store"; -import { handleInfoFromHeritageFunnel, saveOrder, getHeritageCookieValue } from "@/helpers/heritage-integration-helper"; // Components import ComponentTest from "@/layouts/component-test/component-test.vue"; -import AddressPOC from "@/layouts/address-poc/address-poc.vue"; import FormTest from "@/layouts/form-test/form-test.vue"; -import NestedRadio from "@/layouts/nested-radio-poc/nested-radio.vue"; -import buttonQuestionExamples from "@/layouts/button-question-examples/button-question-examples.vue" const routes = [ { @@ -28,26 +26,6 @@ const routes = [ name: "FormTest", component: FormTest, }, - { - path: "/address-poc", // This is a temporary route for testing. - name: "AddressPOC", - component: AddressPOC, - }, - { - path: "/form-test", // This is a temporary route for testing. - name: "FormTest", - component: FormTest, - }, - { - path: "/nested-radio", // This is a temporary route for testing. - name: "NestedRadio", - component: NestedRadio, - }, - { - path: "/button-question-examples", // This is a temporary route for testing. - name: "buttonQuestionExamples", - component: buttonQuestionExamples, - }, { path: "/", name: "root", @@ -139,9 +117,6 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery return; } - console.log(scenario) - console.log(currentRoute) - // Match our maps up and navigate if we have a destination. const matchingScenarioMap = getNavigationMap(scenario, currentRoute); const destinationFmgPageValue = matchingScenarioMap.destinationFmgPageValue; diff --git a/src/store/index.js b/src/store/index.js index f453aa340..dc93571d8 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -139,6 +139,11 @@ export const mutations = { }, resetState(state) { Object.assign(state, getDefaultState()); + }, + + // Misc Mutations + setLoadOrderInformation(state, orderInformation) { + } } @@ -287,6 +292,16 @@ export const actions = { }); }, + // Misc Actions + setReferralInformation(context, { referralNumber, referralDate, correlationId }) { + context.commit(storeMutations.UPDATE_REFERRAL_NUMBER, referralNumber); + context.commit(storeMutations.UPDATE_REFERRAL_DATE, referralDate); + context.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, correlationId); + }, + setLoadOrderData(context, { loadOrderData }) { + + }, + // Parts API Actions getPartsOrQuestions(context, { carId, glassArray, zipCode, vin = '' }) { return globalMethods.callHttpClient({ @@ -324,6 +339,18 @@ export const actions = { }, }); }, + + loadOrder(context, {referralNumber, referralDate, correlationId}) { + return globalMethods.callHttpClient({ + method: endpoints.LoadOrder.method, + endpoint: endpoints.LoadOrder.url, + payload: { + referralNumber: referralNumber, + referralDate: referralDate, + correlationId: correlationId + }, + }); + } } export default createStore({ From a279c9d0119b0a7873141334c89503c59ef2b8a7 Mon Sep 17 00:00:00 2001 From: FrankRua Date: Mon, 21 Mar 2022 12:50:32 -0400 Subject: [PATCH 2/2] Load init --- src/constants/store-mutations.js | 1 + src/helpers/heritage-integration-helper.js | 21 ++++++++-------- .../heritage-integration-helper.spec.js | 8 +++--- src/router/index.js | 4 +-- src/store/index.js | 25 ++++++++++++++++++- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index 47dfcacca..2636464bd 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -19,6 +19,7 @@ const storeMutations = { UPDATE_REFERRAL_NUMBER: "updateReferralNumber", UPDATE_REFERRAL_DATE: "updateReferralDate", UPDATE_REFERRAL_CORRELATION_ID: "updateReferralCorrelationId", + UPDATE_PARENT_ACCT_NUMBER: "updateParentAcctNumber", // EVENT BUS MUTATIONS ADD_EVENT_TO_BUS: "addEventToBus", diff --git a/src/helpers/heritage-integration-helper.js b/src/helpers/heritage-integration-helper.js index cc2f9379e..e4534631f 100644 --- a/src/helpers/heritage-integration-helper.js +++ b/src/helpers/heritage-integration-helper.js @@ -6,22 +6,23 @@ import router from "@/router"; import baseMixin from "../mixins/base-mixin"; // Read info from heritage funnel and reset state or load referral -export function handleInfoFromHeritageFunnel() { +export async function loadReferralFromHeritageFunnelIfPresent() { const orderInfo = getHeritageCookieValue(); - if (orderInfo?.ShouldResetState) { + // Do nothing if there is no cookie. + if(orderInfo === null){ + return; + } + + // Reset state if cookie says to. + if (orderInfo.ShouldResetState) { baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE); deleteHeritageCookie(); - } - else if (orderInfo?.DidHeritageFunnelUpdateLast) { - // Load referral here - - // setHeritageCookieProperties({ - // ShouldResetState: false - // }) + return; } - console.log("D") + // Load referral if there is a cookie, and it doesn't indicate it needs a state reset. + await loadOrder(); } export async function navigateToHeritageFunnel() { diff --git a/src/helpers/heritage-integration-helper.spec.js b/src/helpers/heritage-integration-helper.spec.js index 78f673e84..f99187474 100644 --- a/src/helpers/heritage-integration-helper.spec.js +++ b/src/helpers/heritage-integration-helper.spec.js @@ -19,7 +19,7 @@ describe("saveOrder", () => { } } - describe("handleInfoFromHeritageFunnel", () => { + describe("loadReferralFromHeritageFunnelIfPresent", () => { // test("ShouldResetState == true => heritage cookie is deleted", () => { // // Arrange // // TODO CSR-98 Can we not mock this?? @@ -42,7 +42,7 @@ describe("saveOrder", () => { // console.log(document.cookie) // // Act - // helper.handleInfoFromHeritageFunnel(); + // helper.loadReferralFromHeritageFunnelIfPresent(); // // Assert // console.log(document.cookie) @@ -54,7 +54,7 @@ describe("saveOrder", () => { // helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = false); // // Act - // helper.handleInfoFromHeritageFunnel(); + // helper.loadReferralFromHeritageFunnelIfPresent(); // // Assert // expect(helper.getHeritageCookieValue).toHaveBeenCalled(); @@ -65,7 +65,7 @@ describe("saveOrder", () => { // helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = true); // // Act - // helper.handleInfoFromHeritageFunnel(); + // helper.loadReferralFromHeritageFunnelIfPresent(); // // Assert // expect(helper.getHeritageCookieValue).toHaveBeenCalled(); diff --git a/src/router/index.js b/src/router/index.js index 2e9ed4db1..1aebd3b77 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,7 +5,7 @@ import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js" import { routingTable } from "@/router/router-constants/routing-table.js"; import { globalEvents, globalEventTypes } from "@/constants/events"; import { routerParameterKeys } from '@/router/router-constants/router-parameter-keys' -import { handleInfoFromHeritageFunnel, saveOrder, getHeritageCookieValue } from "@/helpers/heritage-integration-helper"; +import { loadReferralFromHeritageFunnelIfPresent, saveOrder, getHeritageCookieValue } from "@/helpers/heritage-integration-helper"; import baseMixin from "@/mixins/base-mixin"; import eventBus from "@/helpers/event-bus/event-bus"; @@ -33,7 +33,7 @@ const routes = [ // On entering the concept funnel if (from.redirectedFrom === undefined) { // Read cookie information, decide what to do next - handleInfoFromHeritageFunnel(); + loadReferralFromHeritageFunnelIfPresent(); } // If we have no query string, or we don't have the FmgPage query string. diff --git a/src/store/index.js b/src/store/index.js index dc93571d8..14d90744b 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -33,6 +33,7 @@ const getDefaultState = () => { referralNumber: null, referralDate: null, referralCorrelationId: null, + parentAccountNumber: null, }, applicationUser: { eventBus: [], @@ -97,6 +98,10 @@ export const mutations = { updateReferralDate(state, referralDate) { state.order.referralDate = referralDate; }, + updateParentAcctNumber(state, parentAcctNumber) { + state.order.parentAccountNumber = parentAcctNumber; + }, + // EVENT BUS MUTATIONS addEventToBus(state, event) { @@ -143,7 +148,25 @@ export const mutations = { // Misc Mutations setLoadOrderInformation(state, orderInformation) { - + state.order.referralNumber = orderInformation.ReferralNumber; + state.order.referralDate = orderInformation.ReferralDate; + state.order.referralCorrelationId = orderInformation.CorrelationId; + state.order.vehicle = { + year: orderInformation.Year, + make: orderInformation.Make, + model: orderInformation.Model, + style: orderInformation.Style, + carId: orderInformation.CarId, + category: orderInformation.Category, + imageUrl: orderInformation.ImageUrl, + imageVifNumber: orderInformation.ImageVifNumber, + imageColor: orderInformation.ImageColor + }; + state.order.damage.glassToReplace = orderInformation.GlassToReplace; + state.order.damage.isRepair = orderInformation.IsRepair; + state.order.damage.numberOfChips = orderInformation.NumberOfChips; + state.order.lineItems.glassParts = orderInformation.Parts; + state.order.parentAccountNumber = orderInformation.ParentAccountNumber; } }