Merge pull request #1517 from Safelite/feature/skiener/CSR-1452
CSR-1452 | Inactive promos bug fix, related refactoring
This commit is contained in:
commit
7ef6c91177
2 changed files with 30 additions and 22 deletions
|
|
@ -246,6 +246,20 @@ export function getVapsThatNeedToBeAddedToSatisfyPromos(
|
|||
}
|
||||
}
|
||||
|
||||
export function removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||
activePromoObjects,
|
||||
inactivePromos
|
||||
) {
|
||||
activePromoObjects = activePromoObjects ?? [];
|
||||
inactivePromos = inactivePromos ?? [];
|
||||
const activePromoCodes = activePromoObjects.map((promoObject) =>
|
||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode).toUpperCase()
|
||||
);
|
||||
return inactivePromos.filter((inactivePromo) => {
|
||||
return !activePromoCodes.includes(inactivePromo.toUpperCase());
|
||||
});
|
||||
}
|
||||
|
||||
// bundle promos look like: "bundlePromo/###"" for each promo, this returns "bundlePromo" only
|
||||
export function getPromoCodeWithoutBundleIdentifier(promoCode) {
|
||||
return promoCode.split("/")[0];
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ import {
|
|||
getDisplayTextForDurationLength,
|
||||
} from "@/layouts/schedule/helpers/schedule-helper";
|
||||
import { paymentMethods } from "@/constants/payment-method-constants";
|
||||
import { getPromoCodeWithoutBundleIdentifier } from "@/helpers/promotions-helper";
|
||||
import {
|
||||
getPromoCodeWithoutBundleIdentifier,
|
||||
removeCurrentlyActivePromoCodesFromInactivePromos,
|
||||
} from "@/helpers/promotions-helper";
|
||||
import { getDateDifferenceInDays } from "@/helpers/date-helper";
|
||||
// Export State
|
||||
const getDefaultState = () => {
|
||||
|
|
@ -2120,14 +2123,6 @@ export const actions = {
|
|||
addGuidToLineItemsIfNotAlreadyThere(vaps);
|
||||
context.commit(storeMutations.UPDATE_VAPS, vaps);
|
||||
},
|
||||
// COMBINE THESE
|
||||
savePromos(context, promos) {
|
||||
addGuidToLineItemsIfNotAlreadyThere(promos);
|
||||
context.commit(storeMutations.UPDATE_PROMOS, promos);
|
||||
},
|
||||
saveInactivePromos(context, inactivePromos) {
|
||||
context.commit(storeMutations.UPDATE_INACTIVE_PROMOS, inactivePromos);
|
||||
},
|
||||
// Manage promo saving to ensure a promoCode never ends up in both active and inactive
|
||||
saveActiveAndOrInactivePromos(context, { activePromos = null, inactivePromos = null }) {
|
||||
let activePromosToSave;
|
||||
|
|
@ -2139,12 +2134,10 @@ export const actions = {
|
|||
} else if (activePromos && inactivePromos) {
|
||||
// Prioritize active promos when both inactive and active are supplied
|
||||
activePromosToSave = activePromos;
|
||||
const activePromoCodes = activePromos.map((promoObject) =>
|
||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
||||
inactivePromosToSave = removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||
activePromosToSave,
|
||||
inactivePromos
|
||||
);
|
||||
inactivePromosToSave = inactivePromos.filter((inactivePromo) => {
|
||||
return !activePromoCodes.includes(inactivePromo);
|
||||
});
|
||||
} else if (!activePromos) {
|
||||
// Only inactivePromos supplied
|
||||
inactivePromosToSave = inactivePromos;
|
||||
|
|
@ -2156,13 +2149,9 @@ export const actions = {
|
|||
} else if (!inactivePromos) {
|
||||
// Only activePromos supplied
|
||||
activePromosToSave = activePromos;
|
||||
const activePromoCodes = activePromos.map((promoObject) =>
|
||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
||||
);
|
||||
inactivePromosToSave = (context.getters.payment.inactivePromos ?? []).filter(
|
||||
(inactivePromo) => {
|
||||
return !activePromoCodes.includes(inactivePromo);
|
||||
}
|
||||
inactivePromosToSave = removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||
activePromosToSave,
|
||||
context.getters.payment.inactivePromos ?? []
|
||||
);
|
||||
}
|
||||
context.commit(storeMutations.UPDATE_PROMOS, activePromosToSave);
|
||||
|
|
@ -2361,10 +2350,15 @@ export const actions = {
|
|||
const order = context.getters.order;
|
||||
|
||||
activePromosToUse = activePromosToUse ?? order.lineItems.promos;
|
||||
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
||||
lineItemsToUse = lineItemsToUse ? deepClone(lineItemsToUse) : deepClone(order.lineItems);
|
||||
lineItemsToUse.promos = activePromosToUse;
|
||||
|
||||
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
||||
inactivePromosToUse = removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||
lineItemsToUse.promos,
|
||||
inactivePromosToUse
|
||||
);
|
||||
|
||||
let requestObject = {
|
||||
inactivePromos: inactivePromosToUse,
|
||||
order: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue