CSR-1452 | Working on integrating promo-modal
This commit is contained in:
parent
4556e28457
commit
f9332b1028
3 changed files with 59 additions and 42 deletions
|
|
@ -173,13 +173,7 @@ export function buildToastMessagesFromRevalidateOrValidatePromoResponse(
|
||||||
alerts.push(createPromoSuccessAlert(newlyActivatedPromoCode));
|
alerts.push(createPromoSuccessAlert(newlyActivatedPromoCode));
|
||||||
});
|
});
|
||||||
|
|
||||||
const inactivePromoCodesFromResponse = getPromoCodesFromPromoObjectsWithoutDuplicates(
|
const newlyInactivatedPromos = getNewlyInactivatedPromos(oldInactivePromos, promoResponse.errors);
|
||||||
promoResponse.errors
|
|
||||||
);
|
|
||||||
const newlyInactivatedPromos = inactivePromoCodesFromResponse.filter(
|
|
||||||
(errorPromoCode) => !oldInactivePromos.includes(errorPromoCode)
|
|
||||||
);
|
|
||||||
|
|
||||||
newlyInactivatedPromos.forEach((newlyInactivatedPromo) => {
|
newlyInactivatedPromos.forEach((newlyInactivatedPromo) => {
|
||||||
alerts.push(createPromoErrorAlert(newlyInactivatedPromo));
|
alerts.push(createPromoErrorAlert(newlyInactivatedPromo));
|
||||||
});
|
});
|
||||||
|
|
@ -269,6 +263,40 @@ export function shouldStripPromoQueryString(fmgPageQueryValue) {
|
||||||
return pagesToStripPromoQueryStringFrom.includes(fmgPageQueryValue);
|
return pagesToStripPromoQueryStringFrom.includes(fmgPageQueryValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getNewlyInactivatedPromos(oldInactivePromos, newInactivePromos) {
|
||||||
|
const inactivePromoCodesFromResponse = getPromoCodesFromPromoObjectsWithoutDuplicates(
|
||||||
|
newInactivePromos
|
||||||
|
);
|
||||||
|
return inactivePromoCodesFromResponse.filter(
|
||||||
|
(errorPromoCode) => !oldInactivePromos.includes(errorPromoCode)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createPromoSuccessAlert(promoCode) {
|
||||||
|
return {
|
||||||
|
messageHeadline: "Promo applied!",
|
||||||
|
messageCopy: `Promo "${getPromoCodeWithoutBundleIdentifier(promoCode.toUpperCase())}" was successfully applied to your cart.`,
|
||||||
|
type: "alert-success",
|
||||||
|
isDismissible: true,
|
||||||
|
shouldAutoFade: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createPromoErrorAlert(promoCode, errorCode = null, additionalInfo) {
|
||||||
|
const alert = {
|
||||||
|
messageHeadline: "Promo error",
|
||||||
|
type: "alert-danger",
|
||||||
|
shouldAutoFade: false,
|
||||||
|
isDismissible: true,
|
||||||
|
};
|
||||||
|
if (stackingPromoErrorCodes.includes(errorCode)) {
|
||||||
|
alert.messageCopy = `Sorry, promo code "${getPromoCodeWithoutBundleIdentifier(promoCode.toUpperCase())}" cannot be combined with "${additionalInfo[0].toUpperCase()}"`;
|
||||||
|
} else {
|
||||||
|
alert.messageCopy = `Sorry, promo code "${getPromoCodeWithoutBundleIdentifier(promoCode.toUpperCase())}" is not valid`;
|
||||||
|
}
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
function findLineItemsWithPartType(typeToFind, itemsToSearch) {
|
function findLineItemsWithPartType(typeToFind, itemsToSearch) {
|
||||||
const partTypeMatches = itemsToSearch?.filter(
|
const partTypeMatches = itemsToSearch?.filter(
|
||||||
|
|
@ -291,27 +319,4 @@ function getPromoCodesFromPromoObjectsWithoutDuplicates(promos) {
|
||||||
return promoCodes;
|
return promoCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPromoSuccessAlert(promoCode) {
|
|
||||||
return {
|
|
||||||
messageHeadline: "Promo applied!",
|
|
||||||
messageCopy: `Promo "${promoCode.toUpperCase()}" was successfully applied to your cart.`,
|
|
||||||
type: "alert-success",
|
|
||||||
isDismissible: true,
|
|
||||||
shouldAutoFade: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createPromoErrorAlert(promoCode, errorCode = null, additionalInfo) {
|
|
||||||
const alert = {
|
|
||||||
messageHeadline: "Promo error",
|
|
||||||
type: "alert-danger",
|
|
||||||
shouldAutoFade: false,
|
|
||||||
isDismissible: true,
|
|
||||||
};
|
|
||||||
if (stackingPromoErrorCodes.includes(errorCode)) {
|
|
||||||
alert.messageCopy = `Sorry, promo code "${promoCode.toUpperCase()}" cannot be combined with "${additionalInfo[0].toUpperCase()}"`;
|
|
||||||
} else {
|
|
||||||
alert.messageCopy = `Sorry, promo code "${promoCode.toUpperCase()}" is not valid`;
|
|
||||||
}
|
|
||||||
return alert;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,11 @@ import {
|
||||||
revalidatePromosAndValidateQueryStringPromo,
|
revalidatePromosAndValidateQueryStringPromo,
|
||||||
buildToastMessagesFromRevalidateOrValidatePromoResponse,
|
buildToastMessagesFromRevalidateOrValidatePromoResponse,
|
||||||
getVapsThatNeedToBeAddedToSatisfyPromos,
|
getVapsThatNeedToBeAddedToSatisfyPromos,
|
||||||
|
getPromoCodeWithoutBundleIdentifier,
|
||||||
|
removeCurrentlyActivePromoCodesFromInactivePromos,
|
||||||
|
createPromoSuccessAlert,
|
||||||
|
createPromoErrorAlert,
|
||||||
|
getNewlyInactivatedPromos,
|
||||||
} from "@/helpers/promotions-helper";
|
} from "@/helpers/promotions-helper";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
import { queryStrings } from "@/constants/query-strings";
|
||||||
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
||||||
|
|
@ -219,6 +224,7 @@ export default {
|
||||||
vm.setCmsContent(resultMap.cmsContent);
|
vm.setCmsContent(resultMap.cmsContent);
|
||||||
vm.availableVaps = taxedVaps;
|
vm.availableVaps = taxedVaps;
|
||||||
vm.lineItems = lineItems;
|
vm.lineItems = lineItems;
|
||||||
|
vm.inactivePromos = removeCurrentlyActivePromoCodesFromInactivePromos(vm.lineItems.promos, vm.inactivePromos);
|
||||||
vm.updateFooterButtonText(vm.customCtaCopy);
|
vm.updateFooterButtonText(vm.customCtaCopy);
|
||||||
|
|
||||||
if (revalidatePromoResponse) {
|
if (revalidatePromoResponse) {
|
||||||
|
|
@ -334,17 +340,15 @@ export default {
|
||||||
"payment-method",
|
"payment-method",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
const revalidateAlerts = buildToastMessagesFromRevalidateOrValidatePromoResponse(
|
// Handle error alerts here, success alerts are handled in the watcher
|
||||||
revalidatePromoResponse,
|
if (revalidatePromoResponse.errors.length) {
|
||||||
this.lineItems.promos,
|
getNewlyInactivatedPromos(this.inactivePromos, revalidatePromoResponse.errors).forEach(promoCode => {
|
||||||
this.inactivePromos
|
const errorAlert = createPromoErrorAlert(promoCode);
|
||||||
);
|
this.$refs.funnelHeader.pushGlobalAlert(errorAlert, errorAlert.shouldAutoFade);
|
||||||
revalidateAlerts.forEach((alert) => {
|
});
|
||||||
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
this.lineItems.promos = revalidatePromoResponse.promoLineItems;
|
this.lineItems.promos = revalidatePromoResponse.promoLineItems;
|
||||||
this.inactivePromos = revalidatePromoResponse.errors.map((x) => x.promoCode);
|
this.inactivePromos = revalidatePromoResponse.errors.map((x) => getPromoCodeWithoutBundleIdentifier(x.promoCode));
|
||||||
this.$refs.loadingModal.hideModal();
|
this.$refs.loadingModal.hideModal();
|
||||||
},
|
},
|
||||||
backButtonAction() {
|
backButtonAction() {
|
||||||
|
|
@ -479,7 +483,15 @@ export default {
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (oldValue.vaps.length != newValue.vaps.length) {
|
if (oldValue.promos.length < newValue.promos.length) {
|
||||||
|
const oldPromoCodes = oldValue.promos.map(promoObject => promoObject.promoCode);
|
||||||
|
const newlyActivatedPromoCodes = newValue.promos.filter(
|
||||||
|
(newPromo) => !oldPromoCodes.includes(newPromo.promoCode)
|
||||||
|
);
|
||||||
|
const alert = createPromoSuccessAlert(newlyActivatedPromoCodes[0].promoCode)
|
||||||
|
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
||||||
|
}
|
||||||
|
else if (oldValue.promos.length == newValue.promos.length && oldValue.vaps.length != newValue.vaps.length) {
|
||||||
this.revalidatePromos();
|
this.revalidatePromos();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1317,7 +1317,6 @@ export const actions = {
|
||||||
});
|
});
|
||||||
|
|
||||||
syncLineItemIds(response.data, context.getters.order.lineItems.vaps);
|
syncLineItemIds(response.data, context.getters.order.lineItems.vaps);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -2349,6 +2348,7 @@ export const actions = {
|
||||||
|
|
||||||
activePromosToUse = activePromosToUse ?? order.lineItems.promos;
|
activePromosToUse = activePromosToUse ?? order.lineItems.promos;
|
||||||
lineItemsToUse = lineItemsToUse ? deepClone(lineItemsToUse) : deepClone(order.lineItems);
|
lineItemsToUse = lineItemsToUse ? deepClone(lineItemsToUse) : deepClone(order.lineItems);
|
||||||
|
addGuidToLineItemsIfNotAlreadyThere(lineItemsToUse.vaps);
|
||||||
lineItemsToUse.promos = activePromosToUse;
|
lineItemsToUse.promos = activePromosToUse;
|
||||||
|
|
||||||
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue