Cleaning up supportingItems setting

This commit is contained in:
Michaela Brydon 2024-03-04 15:08:51 -05:00
parent 7a8c685cec
commit 881a79c7eb
5 changed files with 49 additions and 82 deletions

View file

@ -369,7 +369,7 @@ export default {
}, },
async navigateForward() { async navigateForward() {
if (this.unverified || this.verifiedDeductible) { if (this.unverified || this.verifiedDeductible) {
this.mainStore.saveSupportingItems(this.supportingItems); this.mainStore.updateSupportingItems(this.supportingItems);
this.$router.navigate( this.$router.navigate(
navigationScenarios.CLICKED_FORWARD, navigationScenarios.CLICKED_FORWARD,
this.$route, this.$route,
@ -379,7 +379,8 @@ export default {
} else if (this.verifiedITAC || this.verifiedNoComp) { } else if (this.verifiedITAC || this.verifiedNoComp) {
useMainStore().updateIsSafeliteProvider(this.selectedProvider === 'Safelite'); useMainStore().updateIsSafeliteProvider(this.selectedProvider === 'Safelite');
if (this.selectedProvider === 'Safelite') { if (this.selectedProvider === 'Safelite') {
this.mainStore.saveSupportingItems(this.supportingItems); // TODO maybe don't save supporting items on this page
this.mainStore.updateSupportingItems(this.supportingItems);
this.$router.navigate( this.$router.navigate(
navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE,
this.$route, this.$route,

View file

@ -268,7 +268,9 @@ export default {
return { mainStore }; return { mainStore };
}, },
data() { data() {
const { supportingItems } = useMainStore().lineItems;
return { return {
supportingItems,
selectedDate: this.getSelectedDate(), selectedDate: this.getSelectedDate(),
selectedTimeSlotInfo: this.getSelectedTimeSlotInfo(), selectedTimeSlotInfo: this.getSelectedTimeSlotInfo(),
selectableDatesData: [], selectableDatesData: [],
@ -324,7 +326,7 @@ export default {
&& ((serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE && ((serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE
|| serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP) || serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP)
|| serviceLocation.provider.providerNumber); || serviceLocation.provider.providerNumber);
const supportingItems = useMainStore().lineItems.supportingItems !== null; const supportingItems = this.supportingItems !== null;
const damageInfo = const damageInfo =
useMainStore().order.damage.isRepair useMainStore().order.damage.isRepair
|| (useMainStore().order.lineItems?.glassParts != null || (useMainStore().order.lineItems?.glassParts != null
@ -360,9 +362,8 @@ export default {
return this.mainStore.order.schedule.date; return this.mainStore.order.schedule.date;
}, },
getSelectedTimeSlotInfo() { getSelectedTimeSlotInfo() {
const supportingItems = this.getSupportingItems();
const isPremiumAppointment = const isPremiumAppointment =
!!supportingItems.filter((lineItem) => lineItem.partType === PREMIUM_FEE_PART_TYPE) !!this.supportingItems.filter((lineItem) => lineItem.partType === PREMIUM_FEE_PART_TYPE)
.length > 0; .length > 0;
const selectedTimeSlotInfo = { const selectedTimeSlotInfo = {
@ -372,9 +373,6 @@ export default {
return selectedTimeSlotInfo; return selectedTimeSlotInfo;
}, },
getSupportingItems() {
return this.mainStore.lineItems.supportingItems;
},
timeSlotModalClosed() { timeSlotModalClosed() {
// Clear the selectedDate if no timeSlot has been selected // Clear the selectedDate if no timeSlot has been selected
if (this.selectedTimeSlotInfo.timeSlot.routeCode == null) { if (this.selectedTimeSlotInfo.timeSlot.routeCode == null) {
@ -424,40 +422,7 @@ export default {
} }
return `${hours}:${minutes} ${meridianNotation}`; return `${hours}:${minutes} ${meridianNotation}`;
}, },
updateSupportingItems() {
const supportingItems = this.getSupportingItems();
// if we have a premium fee(early bird), then save/update supporting items
if (
this.appointmentType === AppointmentTypeStrings.MOBILE
&& this.selectedTimeSlotInfo?.isPremiumAppointment
) {
const premiumFeeIndex = supportingItems.findIndex((item) => item.partType === PREMIUM_FEE_PART_TYPE);
if (premiumFeeIndex >= 0) {
supportingItems[premiumFeeIndex].laborAmount =
this.mobilePremiumAppointmentFee.laborAmount;
supportingItems[premiumFeeIndex].sellingPrice =
this.mobilePremiumAppointmentFee.sellingPrice;
supportingItems[premiumFeeIndex].kitPrice =
this.mobilePremiumAppointmentFee.kitPrice;
} else {
supportingItems.push(this.mobilePremiumAppointmentFee);
}
this.mainStore.saveSupportingItemsSuppressingStateResetting(supportingItems);
} else {
// if it's not a mobile and/or premium early bird, then make sure we remove any that may have been added
const removePremiumFeeIndex = supportingItems.findIndex((item) => item.partType === PREMIUM_FEE_PART_TYPE);
if (removePremiumFeeIndex >= 0) {
supportingItems.splice(removePremiumFeeIndex, 1);
this.mainStore.saveSupportingItemsSuppressingStateResetting(supportingItems);
}
}
},
forwardButtonAction() { forwardButtonAction() {
this.updateSupportingItems();
this.mainStore.saveSchedule(this.selectedTimeSlotInfo.timeSlot); this.mainStore.saveSchedule(this.selectedTimeSlotInfo.timeSlot);
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route); this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route);

View file

@ -90,6 +90,7 @@ export default {
const wipersPromise = await store.getWipers(); const wipersPromise = await store.getWipers();
const rainDefensePromise = await store.getRainDefense(); const rainDefensePromise = await store.getRainDefense();
// TODO does this call need to happen here?
const supportingItemsPromise = await store.getSupportingItems(); const supportingItemsPromise = await store.getSupportingItems();
const promiseResultMap = [ const promiseResultMap = [
{ {
@ -124,7 +125,13 @@ export default {
let hasBailedOut = false; let hasBailedOut = false;
const pricingResults = await store.getPriceOrderItems(availableLineItems) const pricingResults = await store.getPriceOrderItems(availableLineItems)
.catch((err) => { .catch((err) => {
useMainStore().setBailout(to, bailoutMessage.pricingResponseError(availableLineItems.map((li) => li.partNumber), { code: err.code, message: err.message, data: err.data })); useMainStore().setBailout(
to,
bailoutMessage.pricingResponseError(
availableLineItems.map((li) => li.partNumber),
{ code: err.code, message: err.message, data: err.data }
)
);
hasBailedOut = true; hasBailedOut = true;
next(`/?issPage=${issPageValues.BAILOUT_PAGE}`); next(`/?issPage=${issPageValues.BAILOUT_PAGE}`);
}); });
@ -179,15 +186,22 @@ export default {
this.selectedVaps = vapsItemsSelected; this.selectedVaps = vapsItemsSelected;
}, },
forwardButtonAction() { forwardButtonAction() {
const parts = { glassParts: this.pricedGlassParts, supportingItems: this.supportingItems, vaps: this.selectedVaps }; const parts = {
glassParts: this.pricedGlassParts,
supportingItems: this.supportingItems,
vaps: this.selectedVaps
};
if (!allGlassPartsAndItemsHavePrices(parts)) { if (!allGlassPartsAndItemsHavePrices(parts)) {
window.console.error('One or more items have no price assigned!'); window.console.error('One or more items have no price assigned!');
} }
if (this.pricedGlassParts.length > 0) { if (this.pricedGlassParts.length > 0) {
store.saveGlassParts(this.pricedGlassParts); // TODO saving glass parts here
store.updateGlassParts(this.pricedGlassParts);
} }
store.saveSupportingItems(this.supportingItems); // TODO saving supporting items on service packages page
store.saveVaps(this.selectedVaps); // TODO does the glass parts array change?
store.updateSupportingItems(this.supportingItems);
store.updateVaps(this.selectedVaps);
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route); this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route);
} }

View file

@ -360,8 +360,9 @@ export default {
); );
if (this.isWindshieldRepair) { if (this.isWindshieldRepair) {
// TODO only save supporting items on vehicle damage page if windshield repair
const supportingItems = await useMainStore().getSupportingItems(); const supportingItems = await useMainStore().getSupportingItems();
this.mainStore.saveSupportingItems(supportingItems.data); useMainStore().updateSupportingItems(supportingItems.data);
} }
if (this.mainStore.damage.isRepair) { if (this.mainStore.damage.isRepair) {

View file

@ -947,11 +947,12 @@ export const useMainStore = defineStore({
}); });
}, },
// TODO this needs called when vehicle, damage, or glass parts changes
async getSupportingItems() { async getSupportingItems() {
const glassPartsArray = this.order.lineItems.glassParts ?? []; const { glassParts } = this.lineItems;
const { carId } = this.order.vehicle; const { carId } = this.vehicle;
const { isRepair } = this.order.damage; const { isRepair, numberOfChips } = this.damage;
const { numberOfChips } = this.order.damage; const { parentAccountNumber } = this.issConfig;
return globalMethods return globalMethods
.callHttpClient({ .callHttpClient({
@ -960,8 +961,8 @@ export const useMainStore = defineStore({
payload: { payload: {
carId, carId,
damageType: isRepair ? 'Repair' : 'Replace', damageType: isRepair ? 'Repair' : 'Replace',
parentAccountNumber: applicationConfig.CASH_PARENT_ACCOUNT_NUMBER, parentAccountNumber,
parts: glassPartsArray, parts: glassParts ?? [],
numberOfRepairChips: isRepair ? numberOfChips : 0 numberOfRepairChips: isRepair ? numberOfChips : 0
} }
}); });
@ -1434,8 +1435,9 @@ export const useMainStore = defineStore({
this.order.payment.insuranceCoverage.isVerified = false; this.order.payment.insuranceCoverage.isVerified = false;
}, },
// Note that this is only used in the store
updateSupportingItems(partsData) { updateSupportingItems(partsData) {
this.order.lineItems.supportingItems = partsData; this.lineItems.supportingItems = partsData;
}, },
updateVaps(partsData) { updateVaps(partsData) {
@ -1473,8 +1475,8 @@ export const useMainStore = defineStore({
this.order.originalDeductible = vehicle.deductible; this.order.originalDeductible = vehicle.deductible;
this.order.currentDeductible = vehicle.deductible; this.order.currentDeductible = vehicle.deductible;
this.resetSupportingItemsState(); this.updateSupportingItems(null);
this.resetVapsState(); this.updateVaps(null);
}, },
updateVehicleVin(vin) { updateVehicleVin(vin) {
@ -1497,6 +1499,7 @@ export const useMainStore = defineStore({
resetGlassPartsState() { resetGlassPartsState() {
this.order.lineItems.glassParts = null; this.order.lineItems.glassParts = null;
this.order.lineItems.supportingItems = null;
this.order.damage.partQuestionAnswers = null; this.order.damage.partQuestionAnswers = null;
this.order.damage.moldingQuestionAnswers = null; this.order.damage.moldingQuestionAnswers = null;
this.order.damage.capabilityQuestionAnswers = null; this.order.damage.capabilityQuestionAnswers = null;
@ -1505,6 +1508,7 @@ export const useMainStore = defineStore({
this.applicationUser.pageData[issPageValues.MOLDING_QUESTIONS] = null; this.applicationUser.pageData[issPageValues.MOLDING_QUESTIONS] = null;
this.applicationUser.pageData[issPageValues.CAPABILITY_QUESTIONS] = null; this.applicationUser.pageData[issPageValues.CAPABILITY_QUESTIONS] = null;
}, },
// TODO when schedule reset, supporting items modified
resetSchedule() { resetSchedule() {
this.order.schedule.date = null; this.order.schedule.date = null;
this.order.schedule.startTime = null; this.order.schedule.startTime = null;
@ -1522,12 +1526,6 @@ export const useMainStore = defineStore({
state.order.lineItems.supportingItems = supportingItems; state.order.lineItems.supportingItems = supportingItems;
} }
}, },
resetSupportingItemsState() {
this.order.lineItems.supportingItems = null;
},
resetVapsState() {
this.order.lineItems.vaps = null;
},
resetDamageState() { resetDamageState() {
this.order.damage.isRepair = null; this.order.damage.isRepair = null;
this.order.damage.numberOfChips = null; this.order.damage.numberOfChips = null;
@ -1686,8 +1684,8 @@ export const useMainStore = defineStore({
this.updateGlassParts(null); this.updateGlassParts(null);
this.updateMoldingQuestionAnswers(null); this.updateMoldingQuestionAnswers(null);
this.updateCapabilityQuestionAnswers(null); this.updateCapabilityQuestionAnswers(null);
this.resetSupportingItemsState(); this.updateSupportingItems(null);
this.resetVapsState(); this.updateVaps(null);
this.updatePageData({ page: issPageValues.VEHICLE_PARTS, data: null }); this.updatePageData({ page: issPageValues.VEHICLE_PARTS, data: null });
this.updatePageData({ page: issPageValues.MOLDING_QUESTIONS, data: null }); this.updatePageData({ page: issPageValues.MOLDING_QUESTIONS, data: null });
@ -1731,18 +1729,6 @@ export const useMainStore = defineStore({
// Save new values // Save new values
this.updateCapabilityQuestionAnswers(capabilityQuestionAnswersArray); this.updateCapabilityQuestionAnswers(capabilityQuestionAnswersArray);
}, },
saveGlassParts(glassParts) {
this.order.lineItems.glassParts = glassParts;
},
saveSupportingItems(supportingItems) {
this.order.lineItems.supportingItems = supportingItems;
},
saveSupportingItemsSuppressingStateResetting(supportingItems) {
this.order.lineItems.supportingItems = supportingItems;
},
saveVaps(vaps) {
this.order.lineItems.vaps = vaps;
},
// Price order actions // Price order actions
async priceOrderItemsAndSaveServerData(availableLineItems, serviceZipCode, serviceZipCodeCtu) { async priceOrderItemsAndSaveServerData(availableLineItems, serviceZipCode, serviceZipCodeCtu) {
@ -2044,6 +2030,7 @@ export const useMainStore = defineStore({
if (!isSelectedGlassAvailableForVehicle) { if (!isSelectedGlassAvailableForVehicle) {
this.resetDamageState(); this.resetDamageState();
this.resetGlassPartsState(); this.resetGlassPartsState();
// TODO probably reset supporting items
} }
// Save new values // Save new values
@ -2062,6 +2049,7 @@ export const useMainStore = defineStore({
if (!isSelectedGlassAvailableForVehicle) { if (!isSelectedGlassAvailableForVehicle) {
this.resetDamageState(); this.resetDamageState();
this.resetGlassPartsState(); this.resetGlassPartsState();
// TODO probably reset supporting items
} }
// Save new values // Save new values
@ -2078,6 +2066,7 @@ export const useMainStore = defineStore({
// Dependencies already cleared in above statement // Dependencies already cleared in above statement
this.resetDamageState(); this.resetDamageState();
this.resetGlassPartsState(); this.resetGlassPartsState();
// TODO reset supporting items state
} }
// Save new values // Save new values
@ -2111,21 +2100,18 @@ export const useMainStore = defineStore({
resetRegistrationAndDependencies() { resetRegistrationAndDependencies() {
this.resetRegistrationState(); this.resetRegistrationState();
this.resetGlassPartsState(); this.resetGlassPartsState();
this.resetSupportingItemsState(); this.updateVaps(null);
this.resetVapsState();
}, },
resetDamageAndDependencies() { resetDamageAndDependencies() {
this.resetDamageState(); this.resetDamageState();
this.resetGlassPartsState(); this.resetGlassPartsState();
this.resetSupportingItemsState(); this.updateVaps(null);
this.resetVapsState();
}, },
resetPartsAndDependencies() { resetPartsAndDependencies() {
this.resetGlassPartsState(); this.resetGlassPartsState();
this.resetSupportingItemsState(); this.updateVaps(null);
this.resetVapsState();
this.resetServiceLocationAndDependencies(); this.resetServiceLocationAndDependencies();
}, },