diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.spec.js b/src/layouts/payment-method/promo-modal-question/promo-modal-question.spec.js index 94de72765..110ece01e 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.spec.js +++ b/src/layouts/payment-method/promo-modal-question/promo-modal-question.spec.js @@ -49,7 +49,9 @@ describe("promo-modal-question.vue", () => { // Assert expect(wrapper.vm.displayInvalidPromoAlert).toBe(false); - expect(wrapper.vm.displayInvalidOnOrderPromoAlert).toBe(false); + expect(wrapper.vm.displayStackingPromoAlert).toBe(false); + expect(wrapper.vm.displayInShopPromoAlert).toBe(false); + expect(wrapper.vm.displaySimilarPromoAlert).toBe(false); }); it("Should emit update:modelValue on Modal closed", async () => { // Arrange diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue index cde033066..8cc561b03 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue +++ b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue @@ -22,19 +22,34 @@ + v-bind:isDismissible="false" /> + v-bind:isDismissible="false" /> + +
Promo code "{{ promoCode }}" applied 1) { + if (additionalInfo?.length > 2) conflictingCodes += ","; + for (let i = 1; i < additionalInfo?.length - 1; i++) { + conflictingCodes += ` "${additionalInfo[i]}",`; + } + conflictingCodes += ` and "${additionalInfo?.slice(-1)[0]}"`; + } + return conflictingCodes; }, onInputIdAssigned(inputId) { this.promoTextInputId = inputId; @@ -171,6 +194,7 @@ export default { isValid: !("errorCode" in promoValidationResponse), promoCode: promoValidationResponse?.orderPromos, errorCode: promoValidationResponse?.errorCode, + additionalInfo: promoValidationResponse?.additionalInfo, }; }, removeItem(promo) { @@ -181,6 +205,38 @@ export default { getPromoCodeWithoutBundleIdentifier(lineItemsToKeep.promoCode) != promo ); }, + getErrorMessage(error, additionalInfo) { + switch (error) { + case promoErrorCodes.PROMO_STACKING_NOT_ALLOWED: + case promoErrorCodes.SIMILAR_PROMO_ALREADY_ON_ORDER: + return additionalInfo.length === 1 && + additionalInfo[0] === this.promoCode.toUpperCase() + ? (this.displaySimilarPromoAlert = true) + : ((this.errorMessage = this.StackPromoText?.replace( + /\{custom:(NEW|OLD)PROMOCODE\}/g, + (match, group) => + group === "NEW" + ? this.promoCode.toUpperCase() + : this.getConflictingPromoCode(additionalInfo) + )), + (this.displayStackingPromoAlert = true)); + case promoErrorCodes.INVALID_PROMO_ON_ORDER: + if (additionalInfo.some((x) => x.toUpperCase() === "APPOINTMENT_TYPE")) { + this.errorMessage = this.InShopPromoText?.replaceAll( + "{custom:INSHOPPROMOCODE}", + this.promoCode.toUpperCase() + ); + return (this.displayInShopPromoAlert = true); + } + break; + default: + this.errorMessage = this.PromoText?.replaceAll( + "{custom:PROMOCODE}", + this.promoCode.toUpperCase() + ); + return (this.displayInvalidPromoAlert = true); + } + }, async addPromoCode() { if (this.promoCode) { this.resetAlerts(); @@ -227,11 +283,7 @@ export default { this.lineItems.vaps?.push(...getVaps); this.closeModal(); } else { - if (promoCodeData.errorCode == promoErrorCodes.PROMO_STACKING_NOT_ALLOWED) { - this.displayInvalidOnOrderPromoAlert = true; - } else { - this.displayInvalidPromoAlert = true; - } + this.getErrorMessage(promoCodeData.errorCode, promoCodeData.additionalInfo); this.focusOnPromoInput(); this.resetModalButtonStyle(); } @@ -241,7 +293,9 @@ export default { watch: { promoCode() { this.displayInvalidPromoAlert = false; - this.displayInvalidOnOrderPromoAlert = false; + this.displayStackingPromoAlert = false; + this.displaySimilarPromoAlert = false; + this.displayInShopPromoAlert = false; }, modelValue: { handler(newValue) {