CASH-462 | Add applicationUser information to submittedState
Refactor experiment mixin
This commit is contained in:
parent
fe666f381a
commit
14165f72fd
4 changed files with 80 additions and 37 deletions
20
src/helpers/experiment-helper.js
Normal file
20
src/helpers/experiment-helper.js
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
export function getExperimentSettingsFromExperimentList(experimentList) {
|
||||||
|
return (
|
||||||
|
experimentList
|
||||||
|
.filter((x) => !!x.isActive)
|
||||||
|
.map((x) => x.settings)
|
||||||
|
.reduce((r, c) => Object.assign(r, c), {}) ?? {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSettingValue(settingName, experimentSettings) {
|
||||||
|
return hasSetting(settingName, experimentSettings) ? experimentSettings[settingName] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasSettingEqualTo(settingName, settingValue, experimentSettings) {
|
||||||
|
return experimentSettings[settingName] == settingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasSetting(settingName, experimentSettings) {
|
||||||
|
return Object.hasOwn(experimentSettings, settingName);
|
||||||
|
}
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
:isNoComp="isNoComp"
|
:isNoComp="isNoComp"
|
||||||
:isMSRFeeApplicable="isMSRFeeApplicable" />
|
:isMSRFeeApplicable="isMSRFeeApplicable" />
|
||||||
|
|
||||||
<div class="mt-3" v-if="DisplayFosterLove">
|
<div class="mt-3" v-if="shouldDisplayFosterLove">
|
||||||
<donationBlock
|
<donationBlock
|
||||||
cmsWidgetName="DonationWidget"
|
cmsWidgetName="DonationWidget"
|
||||||
v-model="donationAmount"
|
v-model="donationAmount"
|
||||||
|
|
@ -116,8 +116,6 @@ import { coverageStatus } from "@/constants/insurance";
|
||||||
import { getDisplayTextForDurationLength } from "@/helpers/duration-length-helper";
|
import { getDisplayTextForDurationLength } from "@/helpers/duration-length-helper";
|
||||||
import { experimentSettings } from "@/constants/experiments";
|
import { experimentSettings } from "@/constants/experiments";
|
||||||
import experimentMixin from "@/mixins/experiment-mixin.js";
|
import experimentMixin from "@/mixins/experiment-mixin.js";
|
||||||
import { partTypeStrings } from "@/constants/part-type-strings";
|
|
||||||
import { containsLineItemWithPartType } from "@/helpers/service-package-helper";
|
|
||||||
import { containsRecalParts } from "@/helpers/recal-helper.js";
|
import { containsRecalParts } from "@/helpers/recal-helper.js";
|
||||||
import donationBlock from "@/experiment-components/donation-block.vue";
|
import donationBlock from "@/experiment-components/donation-block.vue";
|
||||||
import { partNumberStrings } from "@/constants/part-number-strings";
|
import { partNumberStrings } from "@/constants/part-number-strings";
|
||||||
|
|
@ -125,7 +123,16 @@ import { partNumberStrings } from "@/constants/part-number-strings";
|
||||||
export default {
|
export default {
|
||||||
name: "confirmation",
|
name: "confirmation",
|
||||||
async beforeRouteEnter(to, from, next) {
|
async beforeRouteEnter(to, from, next) {
|
||||||
|
// Experiments
|
||||||
const hasRecalPriceRemoveExperiment = await store.getters.shouldHideRecalibration;
|
const hasRecalPriceRemoveExperiment = await store.getters.shouldHideRecalibration;
|
||||||
|
let applicationUser = baseMixin.methods.hasSubmittedApplicationUser()
|
||||||
|
? baseMixin.methods.getSubmittedApplicationUser()
|
||||||
|
: store.getters.applicationUser;
|
||||||
|
let hasFosterLoveExperiment = experimentMixin.methods.hasSettingEqualTo(
|
||||||
|
experimentSettings.FOSTER_LOVE,
|
||||||
|
"true",
|
||||||
|
applicationUser.experiments
|
||||||
|
);
|
||||||
|
|
||||||
// send part question data to SPS API for logging
|
// send part question data to SPS API for logging
|
||||||
const orderFromStore = await deepClone(store.getters.order);
|
const orderFromStore = await deepClone(store.getters.order);
|
||||||
|
|
@ -213,7 +220,6 @@ export default {
|
||||||
if (isNoComp || isItac) {
|
if (isNoComp || isItac) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasRecalPriceRemoveExperiment && isRecalibrationOnOrder;
|
return hasRecalPriceRemoveExperiment && isRecalibrationOnOrder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -229,6 +235,7 @@ export default {
|
||||||
vm.vaps = availableVaps;
|
vm.vaps = availableVaps;
|
||||||
vm.submittedOrder = submittedOrder;
|
vm.submittedOrder = submittedOrder;
|
||||||
vm.shouldHideRecalibration = shouldHideRecalibration();
|
vm.shouldHideRecalibration = shouldHideRecalibration();
|
||||||
|
vm.shouldDisplayFosterLove = hasFosterLoveExperiment;
|
||||||
vm.donationAmount = donationAmount;
|
vm.donationAmount = donationAmount;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -238,18 +245,13 @@ export default {
|
||||||
vaps: [],
|
vaps: [],
|
||||||
submittedOrder: null,
|
submittedOrder: null,
|
||||||
shouldHideRecalibration: null,
|
shouldHideRecalibration: null,
|
||||||
|
shouldDisplayFosterLove: null,
|
||||||
donationAmount: 0,
|
donationAmount: 0,
|
||||||
showDonationSuccess: null,
|
showDonationSuccess: null,
|
||||||
showDonationError: null,
|
showDonationError: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
DisplayFosterLove() {
|
|
||||||
return experimentMixin.methods.hasSettingEqualTo(
|
|
||||||
experimentSettings.FOSTER_LOVE,
|
|
||||||
"true"
|
|
||||||
);
|
|
||||||
},
|
|
||||||
isRecalibrationOnOrder() {
|
isRecalibrationOnOrder() {
|
||||||
return containsRecalParts(this?.lineItems);
|
return containsRecalParts(this?.lineItems);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,33 @@
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
import * as experimentHelper from "../helpers/experiment-helper";
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is a wrapper around experiment-helper.js methods that allows an override
|
||||||
|
to provide a custom list of experiments. At the time of implementation this
|
||||||
|
was necessary for checking submittedState for experiments
|
||||||
|
*/
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
hasSettingEqualTo(settingName, settingValue) {
|
hasSettingEqualTo(
|
||||||
return store.getters.experimentSettings[settingName] == settingValue;
|
settingName,
|
||||||
|
settingValue,
|
||||||
|
experimentList = store.getters.applicationUser.experiments
|
||||||
|
) {
|
||||||
|
const experimentSettings = experimentHelper.getExperimentSettingsFromExperimentList(experimentList);
|
||||||
|
return experimentHelper.hasSettingEqualTo(
|
||||||
|
settingName,
|
||||||
|
settingValue,
|
||||||
|
experimentSettings
|
||||||
|
);
|
||||||
},
|
},
|
||||||
hasSetting(settingName) {
|
hasSetting(settingName, experimentList = store.getters.applicationUser.experiments) {
|
||||||
return Object.hasOwn(store.getters.experimentSettings, settingName);
|
const experimentSettings = experimentHelper.getExperimentSettingsFromExperimentList(experimentList);
|
||||||
|
return experimentHelper.hasSetting(settingName, experimentSettings);
|
||||||
},
|
},
|
||||||
getSettingValue(settingName) {
|
getSettingValue(settingName, experimentList = store.getters.applicationUser.experiments) {
|
||||||
return this.hasSetting(settingName)
|
const experimentSettings = experimentHelper.getExperimentSettingsFromExperimentList(experimentList);
|
||||||
? store.getters.experimentSettings[settingName]
|
return experimentHelper.getSettingValue(settingName, experimentSettings);
|
||||||
: null;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ import {
|
||||||
} from "@/constants/schedule-constants";
|
} from "@/constants/schedule-constants";
|
||||||
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
||||||
import { deepClone } from "@/helpers/object-helper";
|
import { deepClone } from "@/helpers/object-helper";
|
||||||
|
import {
|
||||||
|
getExperimentSettingsFromExperimentList,
|
||||||
|
hasSettingEqualTo
|
||||||
|
} from "../helpers/experiment-helper";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
import { queryStrings } from "@/constants/query-strings";
|
||||||
import { partTypeStrings } from "@/constants/part-type-strings";
|
import { partTypeStrings } from "@/constants/part-type-strings";
|
||||||
import {
|
import {
|
||||||
|
|
@ -824,7 +828,9 @@ export const getters = {
|
||||||
coverageIsVerified: (state) => {
|
coverageIsVerified: (state) => {
|
||||||
let order;
|
let order;
|
||||||
if (window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE) !== null) {
|
if (window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE) !== null) {
|
||||||
order = JSON.parse(window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE)).order;
|
order = JSON.parse(
|
||||||
|
window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE)
|
||||||
|
).order;
|
||||||
} else {
|
} else {
|
||||||
order = state.order;
|
order = state.order;
|
||||||
}
|
}
|
||||||
|
|
@ -854,29 +860,24 @@ export const getters = {
|
||||||
isRecalibrationOnSubmittedState: (state) => {
|
isRecalibrationOnSubmittedState: (state) => {
|
||||||
if (window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE) !== null) {
|
if (window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE) !== null) {
|
||||||
return getHasRecalibrationPart({
|
return getHasRecalibrationPart({
|
||||||
order: JSON.parse(window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE)).order,
|
order: JSON.parse(
|
||||||
|
window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE)
|
||||||
|
).order,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
shouldHideRecalibration: (state) => {
|
shouldHideRecalibration: (state) => {
|
||||||
var order;
|
|
||||||
if (window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE) !== null) {
|
if (window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE) !== null) {
|
||||||
order = JSON.parse(window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE)).order;
|
state = JSON.parse(window.sessionStorage.getItem(sessionStorageKeyConstants.SUBMITTED_STATE));
|
||||||
} else {
|
|
||||||
order = state.order;
|
|
||||||
}
|
}
|
||||||
|
let order = state.order;
|
||||||
|
let applicationUser = state.applicationUser;
|
||||||
if (order.payment.isInsurance) {
|
if (order.payment.isInsurance) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (hasSettingEqualTo(experimentSettings.RECAL_PRICE_REMOVE, "true", getExperimentSettingsFromExperimentList(applicationUser.experiments)) && getters.isRecalibrationOnOrder(state))
|
||||||
experimentMixin.methods
|
|
||||||
.getSettingValue(experimentSettings.RECAL_PRICE_REMOVE)
|
|
||||||
?.toLowerCase() === "true" && getters.isRecalibrationOnOrder(state)
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
areRearWipersOnOrder: (state) => {
|
areRearWipersOnOrder: (state) => {
|
||||||
return !!state.order.lineItems.vaps?.some(
|
return !!state.order.lineItems.vaps?.some(
|
||||||
|
|
@ -975,10 +976,7 @@ export const getters = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
experimentSettings: (state) =>
|
experimentSettings: (state) =>
|
||||||
state.applicationUser.experiments
|
getExperimentSettingsFromExperimentList(state.applicationUser.experiments),
|
||||||
.filter((x) => !!x.isActive)
|
|
||||||
.map((x) => x.settings)
|
|
||||||
.reduce((r, c) => Object.assign(r, c), {}) ?? {},
|
|
||||||
|
|
||||||
isVerifiedAndDeductibleZeroConfirmed: (state) => {
|
isVerifiedAndDeductibleZeroConfirmed: (state) => {
|
||||||
// used in CMS on /payment-method in Header Sub Text, for FunnelSubHeaderWidget on cart pages
|
// used in CMS on /payment-method in Header Sub Text, for FunnelSubHeaderWidget on cart pages
|
||||||
|
|
@ -1855,6 +1853,7 @@ export const actions = {
|
||||||
if (windshieldPartWithRecal) {
|
if (windshieldPartWithRecal) {
|
||||||
url += `/${windshieldPartWithRecal.partNumber}`;
|
url += `/${windshieldPartWithRecal.partNumber}`;
|
||||||
}
|
}
|
||||||
|
url += "/false";
|
||||||
|
|
||||||
return globalMethods.callHttpClient({
|
return globalMethods.callHttpClient({
|
||||||
method: endpoints.GetProviders.method,
|
method: endpoints.GetProviders.method,
|
||||||
|
|
@ -3273,7 +3272,10 @@ export const actions = {
|
||||||
const affiliateCookies = context.state.applicationUser.affiliateCookies;
|
const affiliateCookies = context.state.applicationUser.affiliateCookies;
|
||||||
|
|
||||||
// set to local storage
|
// set to local storage
|
||||||
window.sessionStorage.setItem(sessionStorageKeyConstants.SUBMITTED_STATE, JSON.stringify(submittedState));
|
window.sessionStorage.setItem(
|
||||||
|
sessionStorageKeyConstants.SUBMITTED_STATE,
|
||||||
|
JSON.stringify(submittedState)
|
||||||
|
);
|
||||||
window.sessionStorage.setItem("createNewSessionForHeritage", true);
|
window.sessionStorage.setItem("createNewSessionForHeritage", true);
|
||||||
|
|
||||||
// clear vuex
|
// clear vuex
|
||||||
|
|
@ -3331,7 +3333,10 @@ export const actions = {
|
||||||
applicationUser: submittedApplicationUser,
|
applicationUser: submittedApplicationUser,
|
||||||
};
|
};
|
||||||
// set to local storage
|
// set to local storage
|
||||||
window.sessionStorage.setItem(sessionStorageKeyConstants.SUBMITTED_STATE, JSON.stringify(submittedState));
|
window.sessionStorage.setItem(
|
||||||
|
sessionStorageKeyConstants.SUBMITTED_STATE,
|
||||||
|
JSON.stringify(submittedState)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
resetSubmittedState(context) {
|
resetSubmittedState(context) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue