Make promo modal work with new changes

Got rid of a watcher in quote
This commit is contained in:
Scott Kiener 2025-09-30 11:44:31 -04:00
parent 9aa2a95bcc
commit 1d7a2b6181
3 changed files with 28 additions and 54 deletions

View file

@ -290,8 +290,18 @@ export default {
); );
if (promoCodeData.isValid) { if (promoCodeData.isValid) {
if (this.taxPromos) { if (this.taxPromos) {
const pricedLineItemsToTax = []; const vapsToAdd = getVapsThatNeedToBeAddedToSatisfyPromos(
pricedLineItemsToTax.push(...promoCodeData.promoCode); // promoCodeData.promoCode should be an array 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 = const taxedLineItems =
await baseMixin.methods.dispatchStoreActionWithLogging( await baseMixin.methods.dispatchStoreActionWithLogging(
storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA, storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
@ -314,25 +324,10 @@ export default {
// Match all line items to the line items as they are in the store // Match all line items to the line items as they are in the store
// and rebuild the original structure. // and rebuild the original structure.
this.lineItems = mapTaxedLineItemsToStoreFormat( this.lineItems = taxedLineItems;
taxedLineItems, } else {
this.lineItems this.lineItems?.promos.push(...promoCodeData.promoCode);
);
const taxedVaps = mapTaxedLineItemsToStoreFormat(
taxedLineItems,
this.addableVaps
);
const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
promoCodeData.promoCode,
taxedVaps,
this.lineItems
);
this.lineItems.vaps?.push(...getVaps);
} }
this.lineItems?.promos.push(...promoCodeData.promoCode);
this.$emit("promoAdded", this.lineItems); this.$emit("promoAdded", this.lineItems);
this.closeModal(); this.closeModal();

View file

@ -63,6 +63,7 @@
pageName="quote" pageName="quote"
:taxPromos="false" :taxPromos="false"
:useDefaultCashParentAccount="true" :useDefaultCashParentAccount="true"
@promoAdded="promoAdded"
modalWidgetName="PromoModalWidget" /> modalWidgetName="PromoModalWidget" />
</div> </div>
</div> </div>
@ -573,9 +574,6 @@ export default {
isInsuranceContinueButtonText() { isInsuranceContinueButtonText() {
return this.getCmsContent("isInsuranceContinueButtonText", "Text"); return this.getCmsContent("isInsuranceContinueButtonText", "Text");
}, },
lineItemsCloneForWatcher() {
return Object.assign({}, this.lineItems);
},
isRecalibrationOnOrder() { isRecalibrationOnOrder() {
return store.getters.isRecalibrationOnOrder; return store.getters.isRecalibrationOnOrder;
}, },
@ -851,32 +849,10 @@ export default {
await this.forwardButtonAction(); await this.forwardButtonAction();
} }
}, },
}, promoAdded(lineItems) {
watch: { const alert = createPromoSuccessAlert(lineItems.promos[0].promoCode);
lineItemsCloneForWatcher: { this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
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,
},
}, },
components: { components: {
funnelHeader, funnelHeader,

View file

@ -2959,11 +2959,11 @@ export const actions = {
} }
) { ) {
const arrayOfLineItems = [ const arrayOfLineItems = [
...pricedLineItems.glassParts ?? [], ...(pricedLineItems.glassParts ?? []),
...pricedLineItems.promos, ...pricedLineItems.promos,
...pricedLineItems.supportingItems, ...pricedLineItems.supportingItems,
...pricedLineItems.vaps ...pricedLineItems.vaps,
] ];
const flattenedLineItemsWithChildParts = const flattenedLineItemsWithChildParts =
getFlattenedArrayOfLineItemsWithChildParts(arrayOfLineItems); getFlattenedArrayOfLineItemsWithChildParts(arrayOfLineItems);
@ -3015,7 +3015,10 @@ export const actions = {
context.commit(storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA, response.data.serverData); context.commit(storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA, response.data.serverData);
Object.keys(pricedLineItems).forEach((key) => { Object.keys(pricedLineItems).forEach((key) => {
pricedLineItems[key] = addTaxesToPricedLineItems(pricedLineItems[key] ?? [], response.data.taxedLineItems); pricedLineItems[key] = addTaxesToPricedLineItems(
pricedLineItems[key] ?? [],
response.data.taxedLineItems
);
}); });
return pricedLineItems; return pricedLineItems;