diff --git a/src/constants/application-config.js b/src/constants/application-config.js index 4b80d25d1..37555119a 100644 --- a/src/constants/application-config.js +++ b/src/constants/application-config.js @@ -1,5 +1,7 @@ const applicationConfig = { CONSUMER_APIGATEWAY_URL: process.env.VUE_APP_CONSUMER_API_GATEWAY, + HERITAGE_FUNNEL: process.env.VUE_APP_HERITAGE_FUNNEL, }; + export { applicationConfig }; 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..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", @@ -33,6 +34,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 41ff2543f..9ac3469e4 100644 --- a/src/helpers/heritage-integration-helper.js +++ b/src/helpers/heritage-integration-helper.js @@ -1,26 +1,28 @@ 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() { +// Read info from heritage funnel and reset state or load referral? +export async function loadReferralFromHeritageFunnelIfPresent() { const orderInfo = this.getHeritageCookieValue(); - if (orderInfo?.ShouldResetState) { - store.dispatch(storeActions.RESET_STATE); - deleteHeritageCookie(); + // Do nothing if there is no cookie. + if(orderInfo === null){ + return; } - else if (orderInfo?.DidHeritageFunnelUpdateLast) { - // Load referral here - // setHeritageCookieProperties({ - // ShouldResetState: false - // }) + // Reset state if cookie says to. + if (orderInfo?.ShouldResetState) { + baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE); + deleteHeritageCookie(); + return; } + + // Load referral if there is a cookie, and it doesn't indicate it needs a state reset. + await loadOrder(); } export async function navigateToHeritageFunnel() { @@ -42,15 +44,29 @@ export async function navigateToHeritageFunnel() { export async function saveOrder() { 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() { const cookieJson = document.cookie @@ -75,7 +91,7 @@ function setHeritageCookieValue(cookieValue) { let cookieValueJson = cookieValue; if (typeof cookieValue == "object") cookieValueJson = JSON.stringify(cookieValue); - + document.cookie = `${cookieNames.ORDER_INFO}=${cookieValueJson}; path=/`; } @@ -83,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]; }); @@ -92,4 +108,4 @@ function setHeritageCookieProperties(properties) { } } } -/* End cookie related functions */ \ No newline at end of file +/* End cookie related functions */ diff --git a/src/helpers/heritage-integration-helper.spec.js b/src/helpers/heritage-integration-helper.spec.js index 361a3de68..320cb1ae0 100644 --- a/src/helpers/heritage-integration-helper.spec.js +++ b/src/helpers/heritage-integration-helper.spec.js @@ -6,7 +6,9 @@ import { storeMutations } from "@/constants/store-mutations"; import store from "@/store"; import router from "@/router"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; -describe("handleInfoFromHeritageFunnel", () => { +import baseMixin from "@/mixins/base-mixin"; + +describe("loadReferralFromHeritageFunnelIfPresent", () => { afterEach(() => { removeAllTestCookies(); }); @@ -22,7 +24,7 @@ describe("handleInfoFromHeritageFunnel", () => { document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=${location.hostname}`; // Act - helper.handleInfoFromHeritageFunnel(); + helper.loadReferralFromHeritageFunnelIfPresent(); // Assert expect(document.cookie).toBe(""); @@ -32,25 +34,24 @@ describe("handleInfoFromHeritageFunnel", () => { // Arrange const getHeritageCookieValueMethod = jest.spyOn(helper, "getHeritageCookieValue") getHeritageCookieValueMethod.mockImplementation(() => { return { ShouldResetState: true, DidHeritageFunnelUpdateLast: false } }); - + const mockData = { actionList: [{ actionName: storeActions.RESET_STATE }], } - + setupMocksForJsFiles(mockData); - store.dispatch = jest.spyOn(store, "dispatch"); // Act - helper.handleInfoFromHeritageFunnel(); + helper.loadReferralFromHeritageFunnelIfPresent(); // Assert expect(getHeritageCookieValueMethod).toHaveBeenCalled(); - expect(store.dispatch).toHaveBeenCalledWith(storeActions.RESET_STATE); + expect(baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.RESET_STATE); getHeritageCookieValueMethod.mockRestore(); - store.dispatch.mockRestore(); + // store.dispatch.mockRestore(); }); test("Heritage cookie is null => store is unchanged", () => { @@ -69,7 +70,7 @@ describe("handleInfoFromHeritageFunnel", () => { setupMocksForJsFiles(mockData); // Act - helper.handleInfoFromHeritageFunnel(); + helper.loadReferralFromHeritageFunnelIfPresent(); // Assert expect(helper.getHeritageCookieValue).toHaveBeenCalled(); @@ -94,25 +95,29 @@ describe("saveOrder", () => { const mockOrderInfo = getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate); const mockData = { - actionList: [{ - actionName: storeActions.SAVE_ORDER, - data: mockOrderInfo, - }], + actionList: [ + { + actionName: storeActions.SAVE_ORDER, + data: mockOrderInfo, + }, + { + actionName: storeActions.SET_REFERRAL_INFORMATION + } + ], router: router } - - setupMocksForJsFiles(mockData); - store.commit = jest.spyOn(store, "commit"); + + const mocks = setupMocksForJsFiles(mockData); // Act await helper.saveOrder(); // Assert - expect(store.commit).toHaveBeenCalledTimes(3); - expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_REFERRAL_NUMBER, mockReferralNumber); - expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, mockCorrelationId); - expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_REFERRAL_DATE, mockReferralDate); - store.commit.mockRestore(); + expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.SET_REFERRAL_INFORMATION, { + referralNumber: mockReferralNumber, + referralDate: mockReferralDate, + correlationId: mockCorrelationId + }); }); test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => { @@ -200,7 +205,7 @@ describe("navigateToHeritageFunnel", () => { router: router } - setupMocksForJsFiles(mockData); + const mocks = setupMocksForJsFiles(mockData); // Act await helper.navigateToHeritageFunnel(); diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 623acbca8..046f9e435 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -83,4 +83,6 @@ export function setupMocksForJsFiles(mockData = {}) { if (mockData.router) mockData.router.navigate = jest.fn(); + + return { baseMixin }; } \ No newline at end of file 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 @@ - - - - - - - - - - - Street address - - - - - - - - City - - - - - - - - State - - - - Zip - - - - - - - An accurate match may not have have been located. Please verify your address before continuing - - - - - An accurate match could not be located. Please re-enter your street address before continuing - - - - - First name - - - - - - Last name - - - - - - Email address - - - - - - - - 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 @@ - - - List Buttons - - - - - - - - - - - (Selecting button with spinner will cause page overlay, page refresh needed to select buttons from other groups) - - List ButtonHorizontals - - - - - - List Cards - - - - - - - - - - - - - - Radio - - - - - - \ 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 ba9c7d34c..2bd9ea0e2 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 { loadReferralFromHeritageFunnelIfPresent, 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", @@ -55,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. @@ -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/router/router-constants/externalUrl-values.js b/src/router/router-constants/externalUrl-values.js deleted file mode 100644 index 7e9931f6e..000000000 --- a/src/router/router-constants/externalUrl-values.js +++ /dev/null @@ -1,5 +0,0 @@ -const externalUrls = { - HERITAGE_FUNNEL: process.env.VUE_APP_HERITAGE_FUNNEL, -}; - -export { externalUrls }; \ No newline at end of file diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index c6a758cef..060eadfc3 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -1,6 +1,6 @@ import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; -import { externalUrls } from "@/router/router-constants/externalUrl-values"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; +import { applicationConfig } from "../../constants/application-config"; const routingTable = [ { @@ -60,7 +60,7 @@ const routingTable = [ }, { scenario: navigationScenarios.MOVE_TO_HERITAGE_FUNNEL, - destinationUrl: externalUrls.HERITAGE_FUNNEL, + destinationUrl: applicationConfig.HERITAGE_FUNNEL, }, { scenario: navigationScenarios.SELECTED_DAMAGE_WITH_SINGLE_PART, diff --git a/src/store/index.js b/src/store/index.js index f453aa340..888ae41f4 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) { @@ -139,6 +144,29 @@ export const mutations = { }, resetState(state) { Object.assign(state, getDefaultState()); + }, + + // 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; } } @@ -287,6 +315,16 @@ export const actions = { }); }, + // Misc Actions + setReferralInformation(context, { referralNumber, referralDate, referralCorrelationId }) { + context.commit(storeMutations.UPDATE_REFERRAL_NUMBER, referralNumber); + context.commit(storeMutations.UPDATE_REFERRAL_DATE, referralDate); + context.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, referralCorrelationId); + }, + setLoadOrderData(context, { loadOrderData }) { + + }, + // Parts API Actions getPartsOrQuestions(context, { carId, glassArray, zipCode, vin = '' }) { return globalMethods.callHttpClient({ @@ -324,6 +362,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({