Merge pull request #1662 from Safelite/feature/skiener/CSR-1862

CSR-1862 | Avoid clearing valid and active promo on page load
This commit is contained in:
scottkiener 2023-12-27 10:17:57 -05:00 committed by GitHub
commit 0c37dce7a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -149,16 +149,25 @@ export async function revalidatePromosAndValidateQueryStringPromo(
} else if (!excludeFromInactivePromoErrorCodes.includes(validatePromoResponse.errorCode)) {
// Save any valid query string promoCode (not applied) to inactivePromos
// in order to not lose the query string promoCode if back button is pressed
const inactivePromoCodes = store.getters.payment.inactivePromos ?? [];
if (!inactivePromoCodes.includes(newPromo)) {
inactivePromoCodes.push(newPromo);
baseMixin.methods.dispatchStoreAction(
storeActions.SAVE_ACTIVE_AND_OR_INACTIVE_PROMOS,
{
inactivePromos: inactivePromoCodes,
},
false
);
const activePromoCodes = store.getters.order.lineItems.promos.map((promoObject) => {
return promoObject.promoCode.toUpperCase();
});
const isErrorPromoAlreadyOnOrder = activePromoCodes.includes(
validatePromoResponse.promoCode.toUpperCase()
);
// Do not save an inactivePromo if it is already active on the order
if (!isErrorPromoAlreadyOnOrder) {
const inactivePromoCodes = store.getters.payment.inactivePromos ?? [];
if (!inactivePromoCodes.includes(newPromo)) {
inactivePromoCodes.push(newPromo);
baseMixin.methods.dispatchStoreAction(
storeActions.SAVE_ACTIVE_AND_OR_INACTIVE_PROMOS,
{
inactivePromos: inactivePromoCodes,
},
false
);
}
}
}
}