diff --git a/src/constants/error-messages.js b/src/constants/error-messages.js index 0c8d4719..39543b5f 100644 --- a/src/constants/error-messages.js +++ b/src/constants/error-messages.js @@ -32,17 +32,21 @@ const errorMessages = Object.freeze({ OPTION_REQUIRED: 'Please select an option', VEHICLE_REQUIRED: 'Please select a vehicle', POLICY_NUMBER_REQUIRED: 'Please enter your policy number', + POLICY_NUMBER_FORMAT: 'Please enter an alpha-numeric string', PHONE_NUMBER_REQUIRED: 'Please enter phone number', PHONE_NUMBER_FORMAT: 'Please enter your phone number. The format must be ###-###-####', POLICY_ZIP_REQUIRED: 'Please enter your policy ZIP', POLICY_ZIP_FORMAT: 'Please enter a valid ZIP', LOSS_CAUSE_REQUIRED: 'Please enter loss cause', LOSS_CITY_REQUIRED: 'Please enter a city', + LOSS_CITY_FORMAT: 'Please enter only alpha characters', LOSS_STATE_REQUIRED: 'Please select an option', LOSS_DATE_REQUIRED: 'Please select a date. Format must be MM/DD/YYYY and the date must be not in the future', DAMAGE_DATE_REQUIREMENT: 'Damage date must be within the past 10 years', + DAMAGE_DATE_NO_FUTURE_DATE: + 'Damage date may not be in the future', DAMAGE_OPTION_REQUIRED: 'Please select an option', POLICYHOLDER_FIRST_NAME_REQUIRED: 'Please enter the policyholder first name', diff --git a/src/layouts/welcome-page/welcome-page.vue b/src/layouts/welcome-page/welcome-page.vue index 77a60a5f..b9cac195 100644 --- a/src/layouts/welcome-page/welcome-page.vue +++ b/src/layouts/welcome-page/welcome-page.vue @@ -85,7 +85,7 @@ cmsWidgetName="PhoneNumberQuestion" :validationRules="rules.phoneNumber" isRequired - mask="###-###-####" + :mask="mask" disableAutoFill /> @@ -153,7 +153,15 @@ id="welcomeFooter" class="row position-sticky top-100">
+ { return true; }); +defineRule('loss-date-lt-tomorrow', (value) => { + const lossDate = new Date(Date.parse(`${value}T00:00:00`)); + const today = new Date(); + const tomorrow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1, 0, 0, 0, 0); + if (lossDate >= tomorrow) { + return errorMessages.DAMAGE_DATE_NO_FUTURE_DATE; + } + + return true; +}); export default { name: 'welcome-page', components: { siteHeader, siteSubHeader, + alert, buttonQuestion, textboxQuestion, dropdownQuestion, @@ -260,15 +288,16 @@ export default { data() { return { welcomePageModel: this.getWelcomePageModelFromStore(), + displayInvalidZipAlert: false, duplicates: [], rules: { - policyNumber: 'policy-number-required', + policyNumber: 'policy-number-required|policy-number-format', policyZip: 'policy-zip-required|policy-zip-format', - lossDate: 'loss-date-required|loss-date-gt-10-years', + lossDate: 'loss-date-required|loss-date-gt-10-years|loss-date-lt-tomorrow', damageOption: 'damage-option-required', phoneNumber: `${globalRules.PHONE_NUMBER_REQUIRED}|${globalRules.PHONE_NUMBER_FORMAT}`, email: `${globalRules.EMAIL_ADDRESS_REQUIRED}|${globalRules.EMAIL_ADDRESS_FORMAT}`, - lossCity: 'loss-city-required', + lossCity: 'loss-city-required|loss-city-format', lossState: 'loss-state-required' } }; @@ -319,20 +348,42 @@ export default { }, maxCoverageLookupAttemptsReached() { return this.mainStore.applicationUser.coverageLookupAttempts >= 11; + }, + mask() { + return { + mask: 'x##-###-####', + tokens: { + x: { + pattern: /[2-9]/ + } + } + }; } }, methods: { async forwardButtonAction() { - this.mainStore.updatePolicyData(this.welcomePageModel); - await this.mainStore.getDuplicateReferrals() - .then(() => {}, () => {}) - .finally(async () => { - if (this.isCoverageEnabled && !this.maxCoverageLookupAttemptsReached) { - await this.mainStore.getCoveragePolicyInfo()?.then(() => {}, () => {}); + console.log('zip code...'); + console.log(this.welcomePageModel.policyZipCode); + await this.mainStore.validateZip({ zip: this.welcomePageModel.policyZipCode }) + .then(async (zipInfo) => { + if (zipInfo?.data?.isValid === true) { + this.mainStore.updatePolicyData(this.welcomePageModel); + await this.mainStore.getDuplicateReferrals() + .then(() => {}, () => {}) + .finally(async () => { + if (this.isCoverageEnabled && !this.maxCoverageLookupAttemptsReached) { + await this.mainStore.getCoveragePolicyInfo()?.then(() => {}, () => {}); + } else { + this.mainStore.order.policy.policyLookupSuccessful = false; + } + return this.navigateForward(); + }); } else { - this.mainStore.order.policy.policyLookupSuccessful = false; + // set manual error message + console.log('zip invalid...'); + this.displayInvalidZipAlert = true; + return this.$refs.siteFooter.removeLoader(); } - this.navigateForward(); }); }, navigateForward() {