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));
|
||||
});
|
||||
|
||||
const inactivePromoCodesFromResponse = getPromoCodesFromPromoObjectsWithoutDuplicates(
|
||||
promoResponse.errors
|
||||
);
|
||||
const newlyInactivatedPromos = inactivePromoCodesFromResponse.filter(
|
||||
(errorPromoCode) => !oldInactivePromos.includes(errorPromoCode)
|
||||
);
|
||||
|
||||
const newlyInactivatedPromos = getNewlyInactivatedPromos(oldInactivePromos, promoResponse.errors);
|
||||
newlyInactivatedPromos.forEach((newlyInactivatedPromo) => {
|
||||
alerts.push(createPromoErrorAlert(newlyInactivatedPromo));
|
||||
});
|
||||
|
|
@ -269,6 +263,40 @@ export function shouldStripPromoQueryString(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
|
||||
function findLineItemsWithPartType(typeToFind, itemsToSearch) {
|
||||
const partTypeMatches = itemsToSearch?.filter(
|
||||
|
|
@ -291,27 +319,4 @@ function getPromoCodesFromPromoObjectsWithoutDuplicates(promos) {
|
|||
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,
|
||||
buildToastMessagesFromRevalidateOrValidatePromoResponse,
|
||||
getVapsThatNeedToBeAddedToSatisfyPromos,
|
||||
getPromoCodeWithoutBundleIdentifier,
|
||||
removeCurrentlyActivePromoCodesFromInactivePromos,
|
||||
createPromoSuccessAlert,
|
||||
createPromoErrorAlert,
|
||||
getNewlyInactivatedPromos,
|
||||
} from "@/helpers/promotions-helper";
|
||||
import { queryStrings } from "@/constants/query-strings";
|
||||
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
||||
|
|
@ -219,6 +224,7 @@ export default {
|
|||
vm.setCmsContent(resultMap.cmsContent);
|
||||
vm.availableVaps = taxedVaps;
|
||||
vm.lineItems = lineItems;
|
||||
vm.inactivePromos = removeCurrentlyActivePromoCodesFromInactivePromos(vm.lineItems.promos, vm.inactivePromos);
|
||||
vm.updateFooterButtonText(vm.customCtaCopy);
|
||||
|
||||
if (revalidatePromoResponse) {
|
||||
|
|
@ -334,17 +340,15 @@ export default {
|
|||
"payment-method",
|
||||
false
|
||||
);
|
||||
const revalidateAlerts = buildToastMessagesFromRevalidateOrValidatePromoResponse(
|
||||
revalidatePromoResponse,
|
||||
this.lineItems.promos,
|
||||
this.inactivePromos
|
||||
);
|
||||
revalidateAlerts.forEach((alert) => {
|
||||
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
||||
});
|
||||
|
||||
// Handle error alerts here, success alerts are handled in the watcher
|
||||
if (revalidatePromoResponse.errors.length) {
|
||||
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) => x.promoCode);
|
||||
this.inactivePromos = revalidatePromoResponse.errors.map((x) => getPromoCodeWithoutBundleIdentifier(x.promoCode));
|
||||
this.$refs.loadingModal.hideModal();
|
||||
},
|
||||
backButtonAction() {
|
||||
|
|
@ -479,7 +483,15 @@ export default {
|
|||
) {
|
||||
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();
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1317,7 +1317,6 @@ export const actions = {
|
|||
});
|
||||
|
||||
syncLineItemIds(response.data, context.getters.order.lineItems.vaps);
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
|
|
@ -2349,6 +2348,7 @@ export const actions = {
|
|||
|
||||
activePromosToUse = activePromosToUse ?? order.lineItems.promos;
|
||||
lineItemsToUse = lineItemsToUse ? deepClone(lineItemsToUse) : deepClone(order.lineItems);
|
||||
addGuidToLineItemsIfNotAlreadyThere(lineItemsToUse.vaps);
|
||||
lineItemsToUse.promos = activePromosToUse;
|
||||
|
||||
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
||||
|
|
|
|||
Loading…
Reference in a new issue