Merge pull request #2576 from Safelite/feature/CASH-804
CASH-804 - prevent First Available Appointment Date from Resetting
This commit is contained in:
commit
03ecb2743f
1 changed files with 156 additions and 129 deletions
|
|
@ -1072,33 +1072,6 @@ export const getters = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) {
|
|
||||||
return (array ?? []).map((x) => x[propertyName]).filter((x) => x);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTimeSlotsAdditionalEventData(
|
|
||||||
provisionalTriggers,
|
|
||||||
zipCode,
|
|
||||||
firstAvailableAppointmentDateString,
|
|
||||||
shopAppointmentType
|
|
||||||
) {
|
|
||||||
var numberOfDays = null;
|
|
||||||
if (firstAvailableAppointmentDateString)
|
|
||||||
numberOfDays = getDateDifferenceInDays(
|
|
||||||
new Date().toISOString().split("T")[0],
|
|
||||||
firstAvailableAppointmentDateString
|
|
||||||
);
|
|
||||||
|
|
||||||
if (shopAppointmentType)
|
|
||||||
return `FirstAvailableAppointment:${numberOfDays},Zip:${zipCode},ShopAppointmentType:${shopAppointmentType},ProvisionalTriggers:${provisionalTriggers.join(
|
|
||||||
","
|
|
||||||
)}`;
|
|
||||||
else
|
|
||||||
return `FirstAvailableAppointment:${numberOfDays},Zip:${zipCode},ProvisionalTriggers:${provisionalTriggers.join(
|
|
||||||
","
|
|
||||||
)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export Actions
|
// Export Actions
|
||||||
export const actions = {
|
export const actions = {
|
||||||
// Vehicle API Actions
|
// Vehicle API Actions
|
||||||
|
|
@ -2059,20 +2032,31 @@ export const actions = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return globalMethods.callHttpClient({
|
let hasCalled = timeSlotCallFlags.shop;
|
||||||
|
if (!hasCalled) {
|
||||||
|
timeSlotCallFlags.shop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
method: endpoints.GetShopTimeSlots.method,
|
method: endpoints.GetShopTimeSlots.method,
|
||||||
endpoint: endpoints.GetShopTimeSlots.url,
|
endpoint: endpoints.GetShopTimeSlots.url,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
logApiCall: true,
|
logApiCall: true,
|
||||||
pageNameToLog: pageNameToLog,
|
pageNameToLog: pageNameToLog,
|
||||||
additionalSuccessEventDataHandler: (response) =>
|
};
|
||||||
|
|
||||||
|
// Only set handler if this is the very first call in this session
|
||||||
|
if (!hasCalled) {
|
||||||
|
options.additionalSuccessEventDataHandler = (response) =>
|
||||||
getTimeSlotsAdditionalEventData(
|
getTimeSlotsAdditionalEventData(
|
||||||
response.data.provisionalTriggers,
|
response.data.provisionalTriggers,
|
||||||
order.serviceLocation.zipCode,
|
order.serviceLocation.zipCode,
|
||||||
response.data.days?.[0]?.date,
|
response.data.days?.[0]?.date,
|
||||||
shopAppointmentType
|
shopAppointmentType
|
||||||
),
|
);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
return globalMethods.callHttpClient(options);
|
||||||
},
|
},
|
||||||
|
|
||||||
getMobileTimeSlots(context, { payload: { startDate, endDate }, pageNameToLog }) {
|
getMobileTimeSlots(context, { payload: { startDate, endDate }, pageNameToLog }) {
|
||||||
|
|
@ -2116,19 +2100,30 @@ export const actions = {
|
||||||
zipCode: order.serviceLocation.zipCode,
|
zipCode: order.serviceLocation.zipCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
return globalMethods.callHttpClient({
|
let hasCalled = timeSlotCallFlags.mobile;
|
||||||
|
if (!hasCalled) {
|
||||||
|
timeSlotCallFlags.mobile = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
method: endpoints.GetMobileTimeSlots.method,
|
method: endpoints.GetMobileTimeSlots.method,
|
||||||
endpoint: endpoints.GetMobileTimeSlots.url,
|
endpoint: endpoints.GetMobileTimeSlots.url,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
logApiCall: true,
|
logApiCall: true,
|
||||||
pageNameToLog: pageNameToLog,
|
pageNameToLog: pageNameToLog,
|
||||||
additionalSuccessEventDataHandler: (response) =>
|
};
|
||||||
|
|
||||||
|
// Only set handler if this is the very first call in this session
|
||||||
|
if (!hasCalled) {
|
||||||
|
options.additionalSuccessEventDataHandler = (response) =>
|
||||||
getTimeSlotsAdditionalEventData(
|
getTimeSlotsAdditionalEventData(
|
||||||
response.data.provisionalTriggers,
|
response.data.provisionalTriggers,
|
||||||
order.serviceLocation.zipCode,
|
order.serviceLocation.zipCode,
|
||||||
response.data.days?.[0]?.date
|
response.data.days?.[0]?.date
|
||||||
),
|
);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
return globalMethods.callHttpClient(options);
|
||||||
},
|
},
|
||||||
|
|
||||||
getMobilePremiumFee(context, { pageNameToLog }) {
|
getMobilePremiumFee(context, { pageNameToLog }) {
|
||||||
|
|
@ -3457,100 +3452,6 @@ export default createStore({
|
||||||
actions,
|
actions,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Private Functions
|
|
||||||
|
|
||||||
function getHasRecalibrationPart(state) {
|
|
||||||
return containsRecalParts(state.order.lineItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
|
|
||||||
if (!arrayOfObjects) return null;
|
|
||||||
|
|
||||||
return arrayOfObjects.sort((a, b) => {
|
|
||||||
if (a[propertyName] < b[propertyName]) return -1;
|
|
||||||
else if (a[propertyName] > b[propertyName]) return 1;
|
|
||||||
else return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function convertGlassPieceNamingForApi(glassArray) {
|
|
||||||
if (!glassArray || glassArray.length === 0) return [];
|
|
||||||
|
|
||||||
// check if array already converted. (likely when a session has been saved previously and then reloaded)
|
|
||||||
if (glassArray[0].location !== undefined) {
|
|
||||||
return glassArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
const converted = [];
|
|
||||||
glassArray.forEach((glass) => {
|
|
||||||
converted.push({
|
|
||||||
location: glass.glassLocation,
|
|
||||||
name: glass.glassName,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return converted;
|
|
||||||
}
|
|
||||||
|
|
||||||
function convertResultsForApi(resultsArray) {
|
|
||||||
if (!resultsArray) return [];
|
|
||||||
const converted = [];
|
|
||||||
resultsArray.forEach((answer) => {
|
|
||||||
converted.push({
|
|
||||||
location: answer.glassLocation,
|
|
||||||
name: answer.glassName,
|
|
||||||
result: answer.result,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return converted;
|
|
||||||
}
|
|
||||||
|
|
||||||
function convertGlassPieceNamingFromApi(glassArray) {
|
|
||||||
glassArray.forEach((glass) => {
|
|
||||||
glass.glassLocation = glass.glassPiece.location;
|
|
||||||
glass.glassName = glass.glassPiece.name;
|
|
||||||
delete glass.glassPiece;
|
|
||||||
return glass;
|
|
||||||
});
|
|
||||||
return glassArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addPricesToLineItems(lineItems, pricingLineItems) {
|
|
||||||
lineItems.forEach((lineItem) => {
|
|
||||||
const lineItemIndex = pricingLineItems.findIndex(
|
|
||||||
(pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
if (lineItem.childParts) {
|
|
||||||
addPricesToLineItems(lineItem.childParts, pricingLineItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
const pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0];
|
|
||||||
lineItem.laborAmount = pricedLineItem.laborAmount;
|
|
||||||
lineItem.sellingPrice = pricedLineItem.sellingPrice;
|
|
||||||
lineItem.kitPrice = pricedLineItem.kitPrice;
|
|
||||||
lineItem.salesTax = pricedLineItem.salesTax;
|
|
||||||
});
|
|
||||||
|
|
||||||
return lineItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTaxesToPricedLineItems(pricedLineItems, taxingLineItems = []) {
|
|
||||||
pricedLineItems.forEach((pricedLineItem) => {
|
|
||||||
const lineItemIndex = taxingLineItems.findIndex(
|
|
||||||
(taxingLineItem) => taxingLineItem.partNumber === pricedLineItem.partNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
if (pricedLineItem.childParts) {
|
|
||||||
addTaxesToPricedLineItems(pricedLineItem.childParts, taxingLineItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
const taxedLineItem = taxingLineItems.splice(lineItemIndex, 1)[0];
|
|
||||||
pricedLineItem.salesTax = taxedLineItem?.salesTax ?? 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
return pricedLineItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mapTaxedLineItemsToStoreFormat(availableLineItems, storeLineItems) {
|
export function mapTaxedLineItemsToStoreFormat(availableLineItems, storeLineItems) {
|
||||||
// clone the lineItems array because what we're passing in is referencing the store directly
|
// clone the lineItems array because what we're passing in is referencing the store directly
|
||||||
const lineItems = deepClone(storeLineItems);
|
const lineItems = deepClone(storeLineItems);
|
||||||
|
|
@ -3658,6 +3559,127 @@ export function getArrayOfAllLineItemsAndChildParts(lineItems) {
|
||||||
return consolidatedLineItemsArray;
|
return consolidatedLineItemsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Private Functions
|
||||||
|
|
||||||
|
function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) {
|
||||||
|
return (array ?? []).map((x) => x[propertyName]).filter((x) => x);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTimeSlotsAdditionalEventData(
|
||||||
|
provisionalTriggers,
|
||||||
|
zipCode,
|
||||||
|
firstAvailableAppointmentDateString,
|
||||||
|
shopAppointmentType
|
||||||
|
) {
|
||||||
|
var numberOfDays = null;
|
||||||
|
if (firstAvailableAppointmentDateString)
|
||||||
|
numberOfDays = getDateDifferenceInDays(
|
||||||
|
new Date().toISOString().split("T")[0],
|
||||||
|
firstAvailableAppointmentDateString
|
||||||
|
);
|
||||||
|
|
||||||
|
if (shopAppointmentType)
|
||||||
|
return `FirstAvailableAppointment:${numberOfDays},Zip:${zipCode},ShopAppointmentType:${shopAppointmentType},ProvisionalTriggers:${provisionalTriggers.join(
|
||||||
|
","
|
||||||
|
)}`;
|
||||||
|
else
|
||||||
|
return `FirstAvailableAppointment:${numberOfDays},Zip:${zipCode},ProvisionalTriggers:${provisionalTriggers.join(
|
||||||
|
","
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHasRecalibrationPart(state) {
|
||||||
|
return containsRecalParts(state.order.lineItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
|
||||||
|
if (!arrayOfObjects) return null;
|
||||||
|
|
||||||
|
return arrayOfObjects.sort((a, b) => {
|
||||||
|
if (a[propertyName] < b[propertyName]) return -1;
|
||||||
|
else if (a[propertyName] > b[propertyName]) return 1;
|
||||||
|
else return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertGlassPieceNamingForApi(glassArray) {
|
||||||
|
if (!glassArray || glassArray.length === 0) return [];
|
||||||
|
|
||||||
|
// check if array already converted. (likely when a session has been saved previously and then reloaded)
|
||||||
|
if (glassArray[0].location !== undefined) {
|
||||||
|
return glassArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
const converted = [];
|
||||||
|
glassArray.forEach((glass) => {
|
||||||
|
converted.push({
|
||||||
|
location: glass.glassLocation,
|
||||||
|
name: glass.glassName,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertResultsForApi(resultsArray) {
|
||||||
|
if (!resultsArray) return [];
|
||||||
|
const converted = [];
|
||||||
|
resultsArray.forEach((answer) => {
|
||||||
|
converted.push({
|
||||||
|
location: answer.glassLocation,
|
||||||
|
name: answer.glassName,
|
||||||
|
result: answer.result,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertGlassPieceNamingFromApi(glassArray) {
|
||||||
|
glassArray.forEach((glass) => {
|
||||||
|
glass.glassLocation = glass.glassPiece.location;
|
||||||
|
glass.glassName = glass.glassPiece.name;
|
||||||
|
delete glass.glassPiece;
|
||||||
|
return glass;
|
||||||
|
});
|
||||||
|
return glassArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPricesToLineItems(lineItems, pricingLineItems) {
|
||||||
|
lineItems.forEach((lineItem) => {
|
||||||
|
const lineItemIndex = pricingLineItems.findIndex(
|
||||||
|
(pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber
|
||||||
|
);
|
||||||
|
|
||||||
|
if (lineItem.childParts) {
|
||||||
|
addPricesToLineItems(lineItem.childParts, pricingLineItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0];
|
||||||
|
lineItem.laborAmount = pricedLineItem.laborAmount;
|
||||||
|
lineItem.sellingPrice = pricedLineItem.sellingPrice;
|
||||||
|
lineItem.kitPrice = pricedLineItem.kitPrice;
|
||||||
|
lineItem.salesTax = pricedLineItem.salesTax;
|
||||||
|
});
|
||||||
|
|
||||||
|
return lineItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTaxesToPricedLineItems(pricedLineItems, taxingLineItems = []) {
|
||||||
|
pricedLineItems.forEach((pricedLineItem) => {
|
||||||
|
const lineItemIndex = taxingLineItems.findIndex(
|
||||||
|
(taxingLineItem) => taxingLineItem.partNumber === pricedLineItem.partNumber
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pricedLineItem.childParts) {
|
||||||
|
addTaxesToPricedLineItems(pricedLineItem.childParts, taxingLineItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
const taxedLineItem = taxingLineItems.splice(lineItemIndex, 1)[0];
|
||||||
|
pricedLineItem.salesTax = taxedLineItem?.salesTax ?? 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
return pricedLineItems;
|
||||||
|
}
|
||||||
|
|
||||||
function getFlattenedArrayOfLineItemsWithChildParts(lineItems, childPartRecursiveCall = false) {
|
function getFlattenedArrayOfLineItemsWithChildParts(lineItems, childPartRecursiveCall = false) {
|
||||||
let flattenedArray = [];
|
let flattenedArray = [];
|
||||||
lineItems?.forEach((lineItem) => {
|
lineItems?.forEach((lineItem) => {
|
||||||
|
|
@ -3966,3 +3988,8 @@ function getExternalParameterDefaultState() {
|
||||||
function saveExternalParameterState(externalParameterState) {
|
function saveExternalParameterState(externalParameterState) {
|
||||||
window.sessionStorage.setItem("externalParameterState", JSON.stringify(externalParameterState));
|
window.sessionStorage.setItem("externalParameterState", JSON.stringify(externalParameterState));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const timeSlotCallFlags = {
|
||||||
|
shop: false,
|
||||||
|
mobile: false,
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue