CSR-1452 | Formatting

This commit is contained in:
Scott Kiener 2023-11-15 11:13:51 -05:00
parent 8d9fbdf985
commit e2c86d0516
2 changed files with 34 additions and 16 deletions

View file

@ -173,7 +173,10 @@ export function buildToastMessagesFromRevalidateOrValidatePromoResponse(
alerts.push(createPromoSuccessAlert(newlyActivatedPromoCode));
});
const newlyInactivatedPromos = getNewlyInactivatedPromos(oldInactivePromos, promoResponse.errors);
const newlyInactivatedPromos = getNewlyInactivatedPromos(
oldInactivePromos,
promoResponse.errors
);
newlyInactivatedPromos.forEach((newlyInactivatedPromo) => {
alerts.push(createPromoErrorAlert(newlyInactivatedPromo));
});
@ -264,9 +267,8 @@ export function shouldStripPromoQueryString(fmgPageQueryValue) {
}
export function getNewlyInactivatedPromos(oldInactivePromos, newInactivePromos) {
const inactivePromoCodesFromResponse = getPromoCodesFromPromoObjectsWithoutDuplicates(
newInactivePromos
);
const inactivePromoCodesFromResponse =
getPromoCodesFromPromoObjectsWithoutDuplicates(newInactivePromos);
return inactivePromoCodesFromResponse.filter(
(errorPromoCode) => !oldInactivePromos.includes(errorPromoCode)
);
@ -275,7 +277,9 @@ export function getNewlyInactivatedPromos(oldInactivePromos, newInactivePromos)
export function createPromoSuccessAlert(promoCode) {
return {
messageHeadline: "Promo applied!",
messageCopy: `Promo "${getPromoCodeWithoutBundleIdentifier(promoCode.toUpperCase())}" was successfully applied to your cart.`,
messageCopy: `Promo "${getPromoCodeWithoutBundleIdentifier(
promoCode.toUpperCase()
)}" was successfully applied to your cart.`,
type: "alert-success",
isDismissible: true,
shouldAutoFade: true,
@ -290,9 +294,13 @@ export function createPromoErrorAlert(promoCode, errorCode = null, additionalInf
isDismissible: true,
};
if (stackingPromoErrorCodes.includes(errorCode)) {
alert.messageCopy = `Sorry, promo code "${getPromoCodeWithoutBundleIdentifier(promoCode.toUpperCase())}" cannot be combined with "${additionalInfo[0].toUpperCase()}"`;
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`;
alert.messageCopy = `Sorry, promo code "${getPromoCodeWithoutBundleIdentifier(
promoCode.toUpperCase()
)}" is not valid`;
}
return alert;
}
@ -318,5 +326,3 @@ function getPromoCodesFromPromoObjectsWithoutDuplicates(promos) {
return promoCodes;
}

View file

@ -225,7 +225,10 @@ export default {
vm.setCmsContent(resultMap.cmsContent);
vm.availableVaps = taxedVaps;
vm.lineItems = lineItems;
vm.inactivePromos = removeCurrentlyActivePromoCodesFromInactivePromos(vm.lineItems.promos, vm.inactivePromos);
vm.inactivePromos = removeCurrentlyActivePromoCodesFromInactivePromos(
vm.lineItems.promos,
vm.inactivePromos
);
vm.updateFooterButtonText(vm.customCtaCopy);
if (revalidatePromoResponse) {
@ -343,13 +346,18 @@ export default {
);
// Handle error alerts here, success alerts are handled in the watcher
if (revalidatePromoResponse.errors.length) {
getNewlyInactivatedPromos(this.inactivePromos, revalidatePromoResponse.errors).forEach(promoCode => {
getNewlyInactivatedPromos(
this.inactivePromos,
revalidatePromoResponse.errors
).forEach((promoCode) => {
const errorAlert = createPromoErrorAlert(promoCode);
this.$refs.funnelHeader.pushGlobalAlert(errorAlert, errorAlert.shouldAutoFade);
});
}
this.lineItems.promos = revalidatePromoResponse.promoLineItems;
this.inactivePromos = revalidatePromoResponse.errors.map((x) => getPromoCodeWithoutBundleIdentifier(x.promoCode));
this.inactivePromos = revalidatePromoResponse.errors.map((x) =>
getPromoCodeWithoutBundleIdentifier(x.promoCode)
);
this.$refs.loadingModal.hideModal();
},
backButtonAction() {
@ -484,14 +492,18 @@ export default {
return;
}
if (oldValue.promos.length < newValue.promos.length) {
const oldPromoCodes = oldValue.promos.map(promoObject => promoObject.promoCode);
const oldPromoCodes = oldValue.promos.map(
(promoObject) => promoObject.promoCode
);
const newlyActivatedPromoCodes = newValue.promos.filter(
(newPromo) => !oldPromoCodes.includes(newPromo.promoCode)
);
const alert = createPromoSuccessAlert(newlyActivatedPromoCodes[0].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) {
} else if (
oldValue.promos.length == newValue.promos.length &&
oldValue.vaps.length != newValue.vaps.length
) {
this.revalidatePromos();
}
},