Merge pull request #1852 from Safelite/feature/CSR-2076

CSR-2076 | Fix line item IDs mismatch
This commit is contained in:
scottkiener 2024-05-20 10:27:57 -04:00 committed by GitHub
commit ee6250d40f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2172,7 +2172,8 @@ export const actions = {
},
saveSupportingItems(context, supportingItems) {
if (!deepEqual(supportingItems, context.state.order.lineItems.supportingItems)) {
syncLineItemIds(supportingItems, context.state.order.lineItems.supportingItems);
if (!supportingItemsEqual(supportingItems, context.state.order.lineItems.supportingItems)) {
context.dispatch(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES);
}
addGuidToLineItemsIfNotAlreadyThere(supportingItems);
@ -2969,6 +2970,7 @@ function syncLineItemIds(lineItemsWithoutIds, lineItemsWithIds) {
}
});
if (matchedLineItemIndex > -1) {
// Remove the matched line item
clonedLineItemsWithIds.splice(matchedLineItemIndex, 1);
}
});
@ -2985,6 +2987,29 @@ function providersEqual(providerA, providerB) {
//TODO: Change back to deepEqual once zipCodeCtu is added to saveSession.
}
function supportingItemsEqual(supportingItemsA, supportingItemsB) {
if (typeof supportingItemsA !== typeof supportingItemsB) {
return false;
}
if (supportingItemsA === null || supportingItemsB === null) {
return supportingItemsA === supportingItemsB;
}
if (supportingItemsA.length != supportingItemsB.length) {
return false;
}
const sortedA = supportingItemsA.slice().sort();
const sortedB = supportingItemsB.slice().sort();
for (let i = 0; i < sortedA.length; i++) {
if (
sortedA[i].partNumber != sortedB[i].partNumber ||
sortedA[i].partType != sortedB[i].partType
) {
return false;
}
}
return true;
}
// This function will verify schedule info is still valid.
// check to see if we have an appointment date on the order object.
// if so, make sure it's not in the past. if in the past, clear schedule info in store.