Committing to facilitate collab

This commit is contained in:
brydon1 2023-08-31 16:11:53 -04:00
parent 7442e48ba5
commit 81ec8d4d14
4 changed files with 190 additions and 125 deletions

View file

@ -112,7 +112,9 @@ function setISSCookieProperties(properties) {
Will update the cookie if present, or create a new one if not. Will update the cookie if present, or create a new one if not.
*/ */
export function updateOrCreateISSCookie() { export function updateOrCreateISSCookie() {
console.log('in cookie function');
const store = useMainStore(); const store = useMainStore();
console.log(store);
// Set up cookie with all the props. // Set up cookie with all the props.
setISSCookieProperties({ setISSCookieProperties({
@ -122,7 +124,8 @@ export function updateOrCreateISSCookie() {
ReferralNumber: store.order.referralNumber, ReferralNumber: store.order.referralNumber,
ReferralDate: store.order.referralDate, ReferralDate: store.order.referralDate,
ReferralCorrelationId: store.order.referralCorrelationId, ReferralCorrelationId: store.order.referralCorrelationId,
ReferralParentAccountNumber: store.order.accountNumber ReferralParentAccountNumber: store.order.accountNumber,
SavedSessionId: store.applicationUser.savedSessionId
}); });
} }

View file

@ -0,0 +1,60 @@
import { useMainStore } from '@/store';
import { updateOrCreateISSCookie } from '@/helpers/cookie-helper';
/*
Will call API to save existing order, or create new one depending where it's called from.
This will also set Referral information in the store after saving, and then
update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue
*/
// encapsulate when you transition back into heritage
// we need eon from first call to get pricing
// eon is a number that some services require
// save session takes time
// not necessary for much throughout the flow
// we want each save session call to happen sequentially, but asynchronously
export async function saveSession({ shouldAwaitSaveSessionQueue = false }) {
const store = useMainStore();
console.log('order helper');
console.log(store);
var saveSessionPromise;
if (store.applicationUser.saveSessionPromise){
console.log('if promise exists');
console.log(store.applicationUser.saveSessionPromise);
// .then returns another promise but waiting for another to finish
saveSessionPromise = store.applicationUser.saveSessionPromise
.then(() => {
console.log('then');
return saveSessionHelper(store);
})
.catch((error) => {
console.log("saveSessionPromise failed: " + error.message);
});
}
else {
console.log('else');
saveSessionPromise = saveSessionHelper(store);
}
// var saveSessionPromise =
// store.applicationUser.saveSessionPromise
// ? store.applicationUser.saveSessionPromise.then(() => { return saveSessionHelper(store); })
// : saveSessionHelper(store);
console.log('promise exists');
store.setSaveSessionPromise(saveSessionPromise);
console.log('set information');
if (!store.applicationUser.savedSessionId || shouldAwaitSaveSessionQueue) {
console.log('pre await');
await saveSessionPromise;
}
console.log('done');
}
/*
Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing
*/
async function saveSessionHelper(store) {
console.log('helper helper called');
const savedSessionInfo = await store.saveSession();
store.setSaveSessionInfo(savedSessionInfo.data);
updateOrCreateISSCookie();
}

View file

@ -16,6 +16,7 @@ import applicationConfig from '@/constants/application-config';
import analyticsMixin from '@/mixins/analytics-mixin'; import analyticsMixin from '@/mixins/analytics-mixin';
import navigationScenarios from './router-constants/navigation-scenarios'; import navigationScenarios from './router-constants/navigation-scenarios';
import { saveSession } from "@/helpers/order-helper.js";
const routes = [ const routes = [
{ {
@ -87,12 +88,18 @@ router.afterEach(async (to, from) => {
const store = useMainStore(); const store = useMainStore();
// Update lastPageVisited in the store // Update lastPageVisited in the store
store.updateLastPageVisited(to.name); store.updateLastPageVisited(to.name);
await store.saveSession()?.catch(() => { console.log('after each');
if(from.name === issPageValues.WELCOME_PAGE) {
await saveSession({shouldAwaitSaveSessionQueue: true}).then(() => {
console.log('then');
}).catch((error) => {
console.log(error);
console.log("catch");
if (from.name === issPageValues.WELCOME_PAGE) {
router.navigate(navigationScenarios.SAVE_SESSION_FAILED, {query: {issPage: issPageValues.WELCOME_PAGE}}) router.navigate(navigationScenarios.SAVE_SESSION_FAILED, {query: {issPage: issPageValues.WELCOME_PAGE}})
} }
}); });
if (to.query.issPage !== issPageValues.ENTRY_PAGE) { if (to.query.issPage !== issPageValues.ENTRY_PAGE) {
// Push page view to GA // Push page view to GA
analyticsMixin.methods.pushPageViewToGA(); analyticsMixin.methods.pushPageViewToGA();

View file

@ -109,7 +109,7 @@ const getDefaultState = () => ({
}, },
referralNumber: null, referralNumber: null,
referralDate: null, referralDate: null,
referralCorrelationId: null, referralCorrelationId: '00000000-0000-0000-0000-000000000000',
referralSequenceNumber: null, referralSequenceNumber: null,
eon: null, eon: null,
workOrderNumber: null workOrderNumber: null
@ -338,8 +338,6 @@ export const useMainStore = defineStore({
} }
}, },
getCoveragePolicyInfo({ accountNumber, policyNumber, dateOfLoss, zipCode }) { getCoveragePolicyInfo({ accountNumber, policyNumber, dateOfLoss, zipCode }) {
// TODO: replace place holder correlationId with the real thing
const placeHolderCorrelationId = '00000000-0000-0000-0000-000000000000';
const { policy } = this.order; const { policy } = this.order;
try { try {
const response = globalMethods.callHttpClient({ const response = globalMethods.callHttpClient({
@ -350,7 +348,7 @@ export const useMainStore = defineStore({
policyNumber, policyNumber,
dateOfLoss, dateOfLoss,
zipCode, zipCode,
correlationId: placeHolderCorrelationId correlationId: this.order.referralCorrelationId
} }
}).then((r) => { }).then((r) => {
const responsePolicy = r.data.policies?.[0]; const responsePolicy = r.data.policies?.[0];
@ -371,8 +369,6 @@ export const useMainStore = defineStore({
} }
}, },
registerClaim() { registerClaim() {
// TODO: replace place holder correlationId with the real thing
const placeHolderCorrelationId = '00000000-0000-0000-0000-000000000000';
const nonNumberCharRegex = /[^0-9]/g; const nonNumberCharRegex = /[^0-9]/g;
const { order } = this; const { order } = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -381,7 +377,7 @@ export const useMainStore = defineStore({
endpoint: endpoints.RegisterClaim.url, endpoint: endpoints.RegisterClaim.url,
payload: payload:
{ {
correlationId: placeHolderCorrelationId, correlationId: this.order.referralCorrelationId,
accountNumber: this.issConfig.accountNumber?.toString() ?? '', accountNumber: this.issConfig.accountNumber?.toString() ?? '',
insured: { insured: {
firstName: this.order.customer.firstName, firstName: this.order.customer.firstName,
@ -688,129 +684,128 @@ export const useMainStore = defineStore({
}); });
}, },
setSaveSessionInfo(response){
this.order.referralNumber = response.referralNumber;
this.order.referralSequenceNumber = response.referralSequenceNumber;
this.order.referralDate = response.referralDate;
this.order.referralCorrelationId = response.referralCorrelationId;
this.order.eon = response.eon;
this.order.workOrderNumber = response.workOrderNumber;
this.applicationUser.savedSessionId = response.savedSessionId;
this.applicationUser.crmCustomerId = response.crmCustomerId.toString();
},
saveSession() { saveSession() {
const { vehicle, damage, policy, customer, contactInfo, payment, const { vehicle, damage, policy, customer, contactInfo, payment,
lineItems, serviceLocation, schedule } = this.order; lineItems, serviceLocation, schedule } = this.order;
const newGlassToReplace = convertGlassPieceNamingForApi(damage.glassToReplace); const newGlassToReplace = convertGlassPieceNamingForApi(damage.glassToReplace);
return new Promise((resolve, reject) => { return globalMethods.callHttpClient({
globalMethods.callHttpClient({ method: endpoints.SaveSession.method,
method: endpoints.SaveSession.method, endpoint: endpoints.SaveSession.url,
endpoint: endpoints.SaveSession.url, payload: {
payload: { applicationUser: {
applicationUser: { crmCustomerId: this.applicationUser.crmCustomerId,
crmCustomerId: this.applicationUser.crmCustomerId, experiments: this.applicationUser.experiments,
experiments: this.applicationUser.experiments, lastPage: this.applicationUser.lastPageVisited,
lastPage: this.applicationUser.lastPageVisited, pageData: this.applicationUser.pageData,
pageData: this.applicationUser.pageData, savedSessionId: this.applicationUser.savedSessionId
savedSessionId: this.applicationUser.savedSessionId
},
vehicle: {
year: vehicle.year,
make: vehicle.make,
model: vehicle.model,
style: vehicle.style,
vin: vehicle.vin,
carId: vehicle.carId,
licensePlateNumber: vehicle.registration?.licensePlate
},
damage: {
numberOfChips: damage.numberOfChips,
glassToReplace: newGlassToReplace,
isRepair: damage.isRepair,
partQuestionAnswers: damage.partQuestionAnswers,
moldingQuestionAnswers: damage.moldingQuestionAnswers,
capabilityQuestionAnswers: damage.capabilityQuestionAnswers,
dateOfLoss: policy.dateOfLoss,
damageCause: policy.damageCause,
damageState: policy.damageState,
damageCity: policy.damageCity,
isDamageGlassOnly: policy.isDamageGlassOnly
},
policy: {
policyHolder: {
policyFirstName: customer.firstName,
policyLastName: customer.lastName,
policyPhoneNumber: customer.phoneNumber,
policyEmail: customer.emailAddress
},
policyNumber: policy.policyNumber,
policyZipCode: policy.policyZipCode,
noCoverage: policy.noCoverage,
policyLookupSuccessful: policy.policyLookupSuccessful,
originalDeductible: this.order.originalDeductible,
currentDeductible: this.order.currentDeductible
},
customer: {
address: {
streetAddress: customer.address?.streetAddress,
streetAddress2: customer.address?.streetAddress2,
city: customer.address?.city,
state: customer.address?.state,
zipCode: customer.address?.zipCode
},
emailAddress: contactInfo.emailAddress,
firstName: contactInfo.firstName,
lastName: contactInfo.lastName,
phoneNumber: contactInfo.phoneNumber,
optInSms: contactInfo.requestTextUpdates ?? false
},
lineItems: {
glassParts: lineItems.glassParts,
supportingItems: lineItems.supportingItems,
vaps: lineItems.vaps
},
payment: {
InsuranceCoverage: {
isVerified: payment.insuranceCoverage?.isVerified ?? false,
coverageStatus: payment.insuranceCoverage?.coverageStatus
},
isInsurance: payment.isInsurance ?? true,
parentAccountNumber: this.issConfig.accountNumber
},
serviceLocation: {
address: {
streetAddress: serviceLocation.address,
city: serviceLocation.city,
state: serviceLocation.state,
zipCode: serviceLocation.zipCode,
zipCodeCtu: serviceLocation.zipCodeCtu
},
techNotes: contactInfo.notesForTechnician
},
schedule: {
date: schedule.date,
startTime: schedule.startTime,
endTime: schedule.endTime,
routeCode: schedule.routeCode,
jobMaxMinutes: schedule.jobMaxMinutes
},
referralDate: this.order.referralDate,
referralNumber: this.order.referralNumber?.toString(),
referralCorrelationId: this.order.referralCorrelationId,
referralSequenceNumber: this.order.referralSequenceNumber,
eon: this.order.eon
}, },
additionalSuccessEventDataHandler: (response) => vehicle: {
`Email provided: ${customer.emailAddress ? 'true' : 'false'}` year: vehicle.year,
}).then((response) => { make: vehicle.make,
if (referralNumber === null) { model: vehicle.model,
this.order.referralNumber = response.referralNumber; style: vehicle.style,
this.order.referralSequenceNumber = response.referralSequenceNumber; vin: vehicle.vin,
this.order.referralDate = response.referralDate; carId: vehicle.carId,
this.order.referralCorrelationId = response.referralCorrelationId; licensePlateNumber: vehicle.registration?.licensePlate
this.order.eon = response.eon; },
this.order.workOrderNumber = response.workOrderNumber; damage: {
this.applicationUser.savedSessionId = response.savedSessionId; numberOfChips: damage.numberOfChips,
this.applicationUser.crmCustomerId = response.crmCustomerId; glassToReplace: newGlassToReplace,
} isRepair: damage.isRepair,
return resolve(response); partQuestionAnswers: damage.partQuestionAnswers,
}).catch((error) => { moldingQuestionAnswers: damage.moldingQuestionAnswers,
return reject(error); capabilityQuestionAnswers: damage.capabilityQuestionAnswers,
}); dateOfLoss: policy.dateOfLoss,
damageCause: policy.damageCause,
damageState: policy.damageState,
damageCity: policy.damageCity,
isDamageGlassOnly: policy.isDamageGlassOnly
},
policy: {
policyHolder: {
policyFirstName: customer.firstName,
policyLastName: customer.lastName,
policyPhoneNumber: customer.phoneNumber,
policyEmail: customer.emailAddress
},
policyNumber: policy.policyNumber,
policyZipCode: policy.policyZipCode,
noCoverage: policy.noCoverage,
policyLookupSuccessful: policy.policyLookupSuccessful,
originalDeductible: this.order.originalDeductible,
currentDeductible: this.order.currentDeductible
},
customer: {
address: {
streetAddress: customer.address?.streetAddress,
streetAddress2: customer.address?.streetAddress2,
city: customer.address?.city,
state: customer.address?.state,
zipCode: customer.address?.zipCode
},
emailAddress: contactInfo.emailAddress,
firstName: contactInfo.firstName,
lastName: contactInfo.lastName,
phoneNumber: contactInfo.phoneNumber,
optInSms: contactInfo.requestTextUpdates ?? false
},
lineItems: {
glassParts: lineItems.glassParts,
supportingItems: lineItems.supportingItems,
vaps: lineItems.vaps
},
payment: {
InsuranceCoverage: {
isVerified: payment.insuranceCoverage?.isVerified ?? false,
coverageStatus: payment.insuranceCoverage?.coverageStatus
},
isInsurance: payment.isInsurance ?? true,
parentAccountNumber: this.issConfig.accountNumber
},
serviceLocation: {
address: {
streetAddress: serviceLocation.address,
city: serviceLocation.city,
state: serviceLocation.state,
zipCode: serviceLocation.zipCode,
zipCodeCtu: serviceLocation.zipCodeCtu
},
techNotes: contactInfo.notesForTechnician
},
schedule: {
date: schedule.date,
startTime: schedule.startTime,
endTime: schedule.endTime,
routeCode: schedule.routeCode,
jobMaxMinutes: schedule.jobMaxMinutes
},
referralDate: this.order.referralDate,
referralNumber: this.order.referralNumber?.toString(),
referralCorrelationId: this.order.referralCorrelationId,
referralSequenceNumber: this.order.referralSequenceNumber,
eon: this.order.eon
},
additionalSuccessEventDataHandler: (response) =>
`Email provided: ${customer.emailAddress ? 'true' : 'false'}`
}); });
}, },
setSaveSessionPromise(promise){
this.applicationUser.saveSessionPromise = promise;
},
saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, selectedWindshieldChipCount) { saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, selectedWindshieldChipCount) {
const selectedGlassPassedInSorted = selectedGlassToReplace.slice().sort(); const selectedGlassPassedInSorted = selectedGlassToReplace.slice().sort();
const isGlassToReplaceTheSame const isGlassToReplaceTheSame