From 1945bb02d98de6453d1f62127e10020110c359cd Mon Sep 17 00:00:00 2001 From: Sneha Date: Fri, 24 Nov 2023 11:35:44 +0530 Subject: [PATCH] CSR-1827 --- .../promo-modal-question.spec.js | 4 +- .../promo-modal-question.vue | 85 ++++++++++++++----- 2 files changed, 66 insertions(+), 23 deletions(-) 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 3f7e4368a..bf0359b37 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,7 +22,7 @@ +
@@ -78,9 +86,11 @@ export default { return { promoCode: "", promoTextInputId: "", + errorMessage: "", displayInvalidPromoAlert: false, displaySimilarPromoAlert: false, - displayInvalidOnOrderPromoAlert: false, + displayStackingPromoAlert: false, + displayInShopPromoAlert: false, lineItems: deepClone(this.modelValue), }; }, @@ -105,20 +115,14 @@ export default { modal() { return this.$refs[this.modalName]; }, - PromoOnOrderText() { - return this.getCmsContent("AlertInvalidPromoOnOrderWidget", "HeadlineText"); - }, - InvalidPromoOnOrderText() { - return this.PromoOnOrderText?.replaceAll( - "{custom:NEWPROMOCODE}", - this.promoCode.toUpperCase() - ).replaceAll("{custom:OLDPROMOCODE}", this.getPromoCode()?.toUpperCase()); + StackPromoText() { + return this.getCmsContent("AlertStackingPromoWidget", "HeadlineText"); }, PromoText() { return this.getCmsContent("AlertInvalidPromoWidget", "HeadlineText"); }, - InvalidPromoText() { - return this.PromoText?.replaceAll("{custom:PROMOCODE}", this.promoCode.toUpperCase()); + InShopPromoText() { + return this.getCmsContent("AlertInshopPromoWidget", "HeadlineText"); }, removeLinkText() { return this.getCmsContent("RemoveCartItemTextWidget", "Text"); @@ -126,8 +130,11 @@ export default { }, methods: { resetAlerts() { - this.displayInvalidOnOrderPromoAlert = false; + this.displayStackingPromoAlert = false; this.displayInvalidPromoAlert = false; + this.displaySimilarPromoAlert = false; + this.displayInShopPromoAlert = false; + this.errorMessage = ""; }, resetsOnPromoInput() { this.resetAlerts(); @@ -138,8 +145,16 @@ export default { ); return promosToDisplay; }, - getPromoCode() { - return this.lineItems.promos?.[0]?.promoCode; + getConflictingPromoCode(additionalInfo) { + var conflictingCodes = additionalInfo?.[0]; + if (additionalInfo?.length > 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; @@ -194,10 +209,35 @@ export default { switch (error) { case promoErrorCodes.PROMO_STACKING_NOT_ALLOWED: case promoErrorCodes.SIMILAR_PROMO_ALREADY_ON_ORDER: - if (additionalInfo[0] === this.promoCode.toUpperCase()) + if ( + additionalInfo.length === 1 && + additionalInfo[0] === this.promoCode.toUpperCase() + ) { return (this.displaySimilarPromoAlert = true); - return (this.displayInvalidOnOrderPromoAlert = true); + } else { + this.errorMessage = this.StackPromoText?.replaceAll( + "{custom:NEWPROMOCODE}", + this.promoCode.toUpperCase() + ).replaceAll( + "{custom:OLDPROMOCODE}", + this.getConflictingPromoCode(additionalInfo) + ); + return (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); } }, @@ -257,8 +297,9 @@ export default { watch: { promoCode() { this.displayInvalidPromoAlert = false; - this.displayInvalidOnOrderPromoAlert = false; + this.displayStackingPromoAlert = false; this.displaySimilarPromoAlert = false; + this.displayInShopPromoAlert = false; }, modelValue: { handler(newValue) {