From 1d7a2b6181e8a18082516563f0548293d5dd0427 Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Tue, 30 Sep 2025 11:44:31 -0400 Subject: [PATCH] Make promo modal work with new changes Got rid of a watcher in quote --- .../promo-modal-question.vue | 37 ++++++++----------- src/layouts/quote/quote.vue | 34 +++-------------- src/store/index.js | 11 ++++-- 3 files changed, 28 insertions(+), 54 deletions(-) diff --git a/src/fmg-components/promo-modal-question/promo-modal-question.vue b/src/fmg-components/promo-modal-question/promo-modal-question.vue index 8efad6f3e..c20f9af75 100644 --- a/src/fmg-components/promo-modal-question/promo-modal-question.vue +++ b/src/fmg-components/promo-modal-question/promo-modal-question.vue @@ -290,8 +290,18 @@ export default { ); if (promoCodeData.isValid) { if (this.taxPromos) { - const pricedLineItemsToTax = []; - pricedLineItemsToTax.push(...promoCodeData.promoCode); // promoCodeData.promoCode should be an array + const vapsToAdd = getVapsThatNeedToBeAddedToSatisfyPromos( + promoCodeData.promoCode, + this.addableVaps, + this.lineItems + ); + const pricedLineItemsToTax = { + glassParts: this.lineItems.glassParts, + promos: promoCodeData.promoCode, + supportingItems: this.lineItems.supportingItems, + vaps: [...this.lineItems.vaps, ...vapsToAdd], + }; + const taxedLineItems = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA, @@ -311,28 +321,13 @@ export default { "payment-method", false ); - + // Match all line items to the line items as they are in the store // and rebuild the original structure. - this.lineItems = mapTaxedLineItemsToStoreFormat( - taxedLineItems, - this.lineItems - ); - const taxedVaps = mapTaxedLineItemsToStoreFormat( - taxedLineItems, - this.addableVaps - ); - - const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos( - promoCodeData.promoCode, - taxedVaps, - this.lineItems - ); - - this.lineItems.vaps?.push(...getVaps); + this.lineItems = taxedLineItems; + } else { + this.lineItems?.promos.push(...promoCodeData.promoCode); } - this.lineItems?.promos.push(...promoCodeData.promoCode); - this.$emit("promoAdded", this.lineItems); this.closeModal(); diff --git a/src/layouts/quote/quote.vue b/src/layouts/quote/quote.vue index 18252e66f..501fb123f 100644 --- a/src/layouts/quote/quote.vue +++ b/src/layouts/quote/quote.vue @@ -63,6 +63,7 @@ pageName="quote" :taxPromos="false" :useDefaultCashParentAccount="true" + @promoAdded="promoAdded" modalWidgetName="PromoModalWidget" /> @@ -573,9 +574,6 @@ export default { isInsuranceContinueButtonText() { return this.getCmsContent("isInsuranceContinueButtonText", "Text"); }, - lineItemsCloneForWatcher() { - return Object.assign({}, this.lineItems); - }, isRecalibrationOnOrder() { return store.getters.isRecalibrationOnOrder; }, @@ -851,32 +849,10 @@ export default { await this.forwardButtonAction(); } }, - }, - watch: { - lineItemsCloneForWatcher: { - handler(newValue, oldValue) { - if ( - !oldValue || - oldValue.length == 0 || - !oldValue.vaps || - !newValue || - newValue.length == 0 - ) { - return; - } - 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); - } - }, - deep: true, - }, + promoAdded(lineItems) { + const alert = createPromoSuccessAlert(lineItems.promos[0].promoCode); + this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade); + } }, components: { funnelHeader, diff --git a/src/store/index.js b/src/store/index.js index 9c054c1ef..e8f15de8f 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2959,11 +2959,11 @@ export const actions = { } ) { const arrayOfLineItems = [ - ...pricedLineItems.glassParts ?? [], + ...(pricedLineItems.glassParts ?? []), ...pricedLineItems.promos, ...pricedLineItems.supportingItems, - ...pricedLineItems.vaps - ] + ...pricedLineItems.vaps, + ]; const flattenedLineItemsWithChildParts = getFlattenedArrayOfLineItemsWithChildParts(arrayOfLineItems); @@ -3015,7 +3015,10 @@ export const actions = { context.commit(storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA, response.data.serverData); Object.keys(pricedLineItems).forEach((key) => { - pricedLineItems[key] = addTaxesToPricedLineItems(pricedLineItems[key] ?? [], response.data.taxedLineItems); + pricedLineItems[key] = addTaxesToPricedLineItems( + pricedLineItems[key] ?? [], + response.data.taxedLineItems + ); }); return pricedLineItems;