Merge pull request #1582 from Safelite/feature/skiener/CSR-1841

CSR-1841 | Ensure saving promos cleans up inactivePromos
This commit is contained in:
scottkiener 2023-11-29 09:52:24 -05:00 committed by GitHub
commit 840153ccdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2130,6 +2130,17 @@ export const actions = {
},
// Manage promo saving to ensure a promoCode never ends up in both active and inactive
saveActiveAndOrInactivePromos(context, { activePromos = null, inactivePromos = null }) {
if (inactivePromos) {
// Clean up inactivePromos
// Remove bundle identifier
inactivePromos = inactivePromos.map((promoCode) =>
getPromoCodeWithoutBundleIdentifier(promoCode)
);
// Remove duplicates
inactivePromos = inactivePromos.filter(
(promoCode, index) => inactivePromos.indexOf(promoCode) === index
);
}
activePromos = activePromos?.slice(0);
inactivePromos = inactivePromos?.slice(0);
let activePromosToSave;