Merge pull request #1128 from Safelite/feature/CSR-1137

CSR-1137 | Refactor
This commit is contained in:
CarlNation 2023-05-30 10:09:09 -04:00 committed by GitHub
commit 499ef25f0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 34 deletions

View file

@ -235,7 +235,8 @@ export default {
date: this.selectedDate.dateString, date: this.selectedDate.dateString,
startTime: timeSlotSelectedObject.startTime, startTime: timeSlotSelectedObject.startTime,
endTime: timeSlotSelectedObject.endTime, endTime: timeSlotSelectedObject.endTime,
id: this.selectedTimeSlotData.id, routeCode: this.selectedTimeSlotData.id,
jobMaxMinutes: this.selectableDatesData.estimatedServiceMinutesMaximum,
}; };
} else { } else {
return null; return null;
@ -320,11 +321,11 @@ export default {
// Ex: April 25 // Ex: April 25
return dateObject.toLocaleDateString("en-us", { month: "short", day: "numeric" }); return dateObject.toLocaleDateString("en-us", { month: "short", day: "numeric" });
}, },
// Expected input: "HH:MM:SS" // Expected input: "HH:MM"
getDisplayTextForMilitaryTime(militaryTimeInput, shouldTrimMinutesIfEmpty = false) { getDisplayTextForMilitaryTime(militaryTimeInput, shouldTrimMinutesIfEmpty = false) {
let hours = parseInt(militaryTimeInput.split(":")[0]); let hours = parseInt(militaryTimeInput.split(":")[0]);
const minutes = militaryTimeInput.split(":")[1]; const minutes = militaryTimeInput.split(":")[1];
let meridianNotation = hours > 11 ? "PM" : "AM"; const meridianNotation = hours > 11 ? "PM" : "AM";
if (hours > 12) { if (hours > 12) {
hours -= 12; hours -= 12;
} }
@ -338,15 +339,9 @@ export default {
this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);
}, },
async forwardButtonAction() { async forwardButtonAction() {
//TODO: replace properties with real values once they are available
await this.dispatchStoreAction( await this.dispatchStoreAction(
this.storeActions.SAVE_SCHEDULE, this.storeActions.SAVE_SCHEDULE,
{ this.appointmentDateAndTime,
date: "2023-07-04T00:00:00",
startTime: "2023-07-04T12:00:00",
endTime: "2023-07-04T17:00:00",
routeCode: "03341-01820-S-B*20232*11 AM",
},
false false
); );

View file

@ -44,7 +44,6 @@ import buttonQuestion from "@/digital-components/button-question/button-question
import timeSlotModalListButton from "./time-slot-modal-list-button/time-slot-modal-list-button"; import timeSlotModalListButton from "./time-slot-modal-list-button/time-slot-modal-list-button";
// TODO: Move this somewhere more global // TODO: Move this somewhere more global
import { DAYS_OF_WEEK, MONTHS_OF_YEAR } from "@/digital-components/date-picker/mixins/constants.js";
import { defineRule, useField } from "vee-validate"; import { defineRule, useField } from "vee-validate";
import { errorMessages } from "@/constants/error-messages"; import { errorMessages } from "@/constants/error-messages";
import { required } from "@/helpers/validation-rules"; import { required } from "@/helpers/validation-rules";
@ -80,7 +79,6 @@ export default {
data() { data() {
return { return {
selectedTimeSlotId: null, selectedTimeSlotId: null,
isSelectedAppointmentPremium: null,
timeSlotModalListButton: timeSlotModalListButton, timeSlotModalListButton: timeSlotModalListButton,
}; };
}, },
@ -96,7 +94,7 @@ export default {
// Run component validation that is used at parent level // Run component validation that is used at parent level
this.handleChange(this.modelValue.id); this.handleChange(this.modelValue.id);
}, },
dateAndTimeSlotData(newValue, oldValue) { availableTimeSlots(newValue) {
this.autoSelectTimeSlotIfOnlyOneIsAvailable(newValue); this.autoSelectTimeSlotIfOnlyOneIsAvailable(newValue);
}, },
}, },
@ -190,34 +188,33 @@ export default {
}, },
// fires any time the footer button is used, is fired before "onModalClosed" // fires any time the footer button is used, is fired before "onModalClosed"
closeModal() { closeModal() {
if (this.selectedTimeSlotId.toString().includes(PREMIUM_TIME_SLOT_ID_FLAG)) { let isSelectedAppointmentPremium = false;
if (this.selectedTimeSlotId.includes(PREMIUM_TIME_SLOT_ID_FLAG)) {
this.selectedTimeSlotId = this.removePremiumFlagFromInput(this.selectedTimeSlotId); this.selectedTimeSlotId = this.removePremiumFlagFromInput(this.selectedTimeSlotId);
this.isSelectedAppointmentPremium = true; isSelectedAppointmentPremium = true;
} else {
this.isSelectedAppointmentPremium = false;
} }
const selectedTimeSlotData = { const selectedTimeSlotData = {
id: this.selectedTimeSlotId, id: this.selectedTimeSlotId,
isPremiumAppointment: this.isSelectedAppointmentPremium, isPremiumAppointment: isSelectedAppointmentPremium,
}; };
this.$emit("update:modelValue", selectedTimeSlotData); this.$emit("update:modelValue", selectedTimeSlotData);
this.$refs["timeSlots"].closeModal(); this.$refs["timeSlots"].closeModal();
}, },
// fires any time the modal is closed, AFTER "closeModal" fires if footer button is used // fires any time the modal is closed, AFTER "closeModal" fires if footer button is used
onModalClosed() { onModalClosed() {
this.isSelectedAppointmentPremium = this.modelValue.isPremiumAppointment; // Reset component state to parent's state
if (this.isSelectedAppointmentPremium) { if (this.modelValue.isPremiumAppointment) {
this.selectedTimeSlotId = this.addPremiumFlagToInput(this.modelValue.id); this.selectedTimeSlotId = this.addPremiumFlagToInput(this.modelValue.id);
} else { } else {
this.selectedTimeSlotId = this.modelValue.id; this.selectedTimeSlotId = this.modelValue.id;
} }
this.$emit("time-slot-modal-closed"); this.$emit("time-slot-modal-closed");
}, },
// Expected input: "HH:MM:SS" // Expected input: "HH:MM"
getDisplayTextForMilitaryTime(militaryTimeInput) { getDisplayTextForMilitaryTime(militaryTimeInput) {
let hours = parseInt(militaryTimeInput.split(":")[0]); let hours = parseInt(militaryTimeInput.split(":")[0]);
const minutes = militaryTimeInput.split(":")[1]; const minutes = militaryTimeInput.split(":")[1];
let meridianNotation = hours > 11 ? "PM" : "AM"; const meridianNotation = hours > 11 ? "PM" : "AM";
if (hours > 12) { if (hours > 12) {
hours -= 12; hours -= 12;
} }
@ -286,24 +283,17 @@ export default {
}, },
}; };
}, },
autoSelectTimeSlotIfOnlyOneIsAvailable(newdateAndTimeSlotDataValue) { autoSelectTimeSlotIfOnlyOneIsAvailable(newAvailableTimeSlotsValue) {
const numberOfOptions = newdateAndTimeSlotDataValue?.timeSlots.length; const numberOfOptions = newAvailableTimeSlotsValue?.length;
if ( if (numberOfOptions === 1) {
numberOfOptions === 1 && this.selectedTimeSlotId = newAvailableTimeSlotsValue[0].value;
!(
this.appointmentType === AppointmentTypeStrings.MOBILE &&
this.premiumAppointmentFee &&
newdateAndTimeSlotDataValue.timeSlots[0].offerPremium
)
) {
this.selectedTimeSlotId = newdateAndTimeSlotDataValue.timeSlots[0].id;
} }
}, },
addPremiumFlagToInput(timeSlotId) { addPremiumFlagToInput(timeSlotId) {
return (timeSlotId += PREMIUM_TIME_SLOT_ID_FLAG); return (timeSlotId += PREMIUM_TIME_SLOT_ID_FLAG);
}, },
removePremiumFlagFromInput(timeSlotId) { removePremiumFlagFromInput(timeSlotId) {
return parseInt(timeSlotId.trim(PREMIUM_TIME_SLOT_ID_FLAG.length)); return timeSlotId.substring(0, timeSlotId.length - PREMIUM_TIME_SLOT_ID_FLAG.length);
}, },
}, },
components: { components: {