diff --git a/jest.config.js b/jest.config.js index 28c5557cb..c712c24da 100644 --- a/jest.config.js +++ b/jest.config.js @@ -26,7 +26,7 @@ module.exports = { testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"], coverageThreshold: { global: { - statements: 78, + statements: 77, // Got the go ahead from Mark to temporarily lower this. Taking out initialize component made the year,make,model and style coverage drop a bit. Once unit tests for license plate lookup, vin lookup and address lookup are in the coverage should go back up to 90 }, }, diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index 68ccd593c..8abd2ca5b 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -68,7 +68,7 @@ import { getRouterLinkRouteFromCopy, getRouterLinkDisplayTextFromCopy, } from "@/helpers/cms-content-helper"; -import { AppointmentTypeStrings } from "@/constants/schedule-constants"; +import { AppointmentTypeStrings, PREMIUM_FEE_PART_TYPE } from "@/constants/schedule-constants"; import { errorMessages } from "@/constants/error-messages"; import { required } from "@/helpers/validation-rules"; import store from "@/store"; @@ -338,7 +338,8 @@ export default { backButtonAction() { this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route); }, - async forwardButtonAction() { + forwardButtonAction() { + this.updateSupportingItems(); this.dispatchStoreAction( this.storeActions.SAVE_SCHEDULE, this.appointmentDateAndTime, @@ -346,6 +347,51 @@ export default { ); navigateToHeritageFunnel({ loadingModal: this.$refs.loadingModal }); }, + + updateSupportingItems() { + const supportingItems = store.getters.lineItems.supportingItems; + + // if we have a premium fee(early bird), then save/update supporting items + if ( + this.appointmentType === AppointmentTypeStrings.MOBILE && + this.selectedTimeSlotData?.isPremiumAppointment + ) { + const earlyBirdIndex = supportingItems.findIndex( + (item) => item.partNumber == PREMIUM_FEE_PART_TYPE + ); + + if (earlyBirdIndex >= 0) { + supportingItems[earlyBirdIndex].laborAmount = + this.mobilePremiumAppointmentFee.laborAmount; + supportingItems[earlyBirdIndex].selingPrice = + this.mobilePremiumAppointmentFee.selingPrice; + supportingItems[earlyBirdIndex].kitPrice = + this.mobilePremiumAppointmentFee.kitPrice; + } else { + supportingItems.push(this.mobilePremiumAppointmentFee); + } + + this.dispatchStoreAction( + this.storeActions.SAVE_SUPPORTING_ITEMS, + supportingItems, + false + ); + } else { + // if it's not a mobile and/or premium early bird, then make sure we remove any that may have been added + const removeEarlyBirdIndex = supportingItems.findIndex( + (item) => item.partNumber == PREMIUM_FEE_PART_TYPE + ); + + if (removeEarlyBirdIndex >= 0) { + supportingItems.splice(removeEarlyBirdIndex, 1); + this.dispatchStoreAction( + this.storeActions.SAVE_SUPPORTING_ITEMS, + supportingItems, + false + ); + } + } + }, }, watch: { selectedDate(newValue, oldValue) { diff --git a/src/store/index.js b/src/store/index.js index 64838564e..b70faf5ed 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -11,7 +11,7 @@ import { damageLocationsSelected } from "@/constants/damage-locations-selected"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import router from "@/router"; import { deleteFunnelCookie } from "@/helpers/heritage-integration/cookie-helper.js"; -import { AppointmentTypeStrings } from "@/constants/schedule-constants"; +import { AppointmentTypeStrings, PREMIUM_FEE_PART_TYPE } from "@/constants/schedule-constants"; // Export State const getDefaultState = () => { @@ -351,6 +351,17 @@ export const mutations = { state.order.schedule.endTime = null; state.order.schedule.routeCode = null; state.order.schedule.jobMaxMinutes = null; + + //early bird fee used on schedule page also needs reset when schedule is reset + const supportingItems = state.order.lineItems.supportingItems; + const removeEarlyBirdIndex = supportingItems.findIndex( + (item) => item.partNumber == PREMIUM_FEE_PART_TYPE + ); + + if (removeEarlyBirdIndex >= 0) { + supportingItems.splice(removeEarlyBirdIndex, 1); + state.order.lineItems.supportingItems = supportingItems; + } }, resetState(state) { Object.assign(state, getDefaultState()); @@ -1411,6 +1422,7 @@ export const actions = { if (context.state.order.eon && context.state.order.eon != response.data.eon) { context.commit(storeMutations.RESET_STATE); } + context.commit( storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, response.data @@ -2074,6 +2086,40 @@ async function validateAppointment(context, order) { }, false ); + + if (newTimeSlotsResponse?.data.days?.length === 0) { + context.commit(storeMutations.RESET_SCHEDULE); + return; + } + + var mobileRouteCodeFound = false; + // if early bird fee is in supporting items then need to check the timeslot to see if offer premium is also still available + if ( + order.lineItem?.supportingItems?.findIndex( + (item) => item.partNumber == PREMIUM_FEE_PART_TYPE + ) + ) { + newTimeSlotsResponse.data.days?.forEach((day) => { + day.timeSlots.forEach((ts) => { + if (ts.id === order.schedule.routeCode && ts.offerPremium) { + mobileRouteCodeFound = true; + } + }); + }); + } else { + newTimeSlotsResponse.data.days?.forEach((day) => { + day.timeSlots.forEach((ts) => { + if (ts.id === order.schedule.routeCode) { + mobileRouteCodeFound = true; + } + }); + }); + } + + if (!mobileRouteCodeFound) { + context.commit(storeMutations.RESET_SCHEDULE); + return; + } } else { newTimeSlotsResponse = await context.dispatch( storeActions.GET_SHOP_TIME_SLOTS, @@ -2085,24 +2131,24 @@ async function validateAppointment(context, order) { }, false ); - } - if (newTimeSlotsResponse?.data.days?.length === 0) { - context.commit(storeMutations.RESET_SCHEDULE); - return; - } + if (newTimeSlotsResponse?.data.days?.length === 0) { + context.commit(storeMutations.RESET_SCHEDULE); + return; + } - var routeCodeFound = false; - newTimeSlotsResponse.data.days?.forEach((day) => { - day.timeSlots.forEach((ts) => { - if (ts.id === order.schedule.routeCode) { - routeCodeFound = true; - } + var routeCodeFound = false; + newTimeSlotsResponse.data.days?.forEach((day) => { + day.timeSlots.forEach((ts) => { + if (ts.id === order.schedule.routeCode) { + routeCodeFound = true; + } + }); }); - }); - if (!routeCodeFound) { - context.commit(storeMutations.RESET_SCHEDULE); - return; + if (!routeCodeFound) { + context.commit(storeMutations.RESET_SCHEDULE); + return; + } } }