229 lines
7.9 KiB
Vue
229 lines
7.9 KiB
Vue
<template>
|
|
<Form
|
|
ref="duplicate-check-form"
|
|
v-slot="{ meta }"
|
|
@submit="onSubmit"
|
|
@invalidSubmit="onInvalidSubmit">
|
|
<div class="container-fluid fade-on-route-transition">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 px-0 px-md-2">
|
|
<siteHeader
|
|
ref="siteHeader"
|
|
:cmsWidgetName="widget.siteHeader" />
|
|
</div>
|
|
</div>
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 col-xl-4">
|
|
<siteSubHeader
|
|
id="sub-header"
|
|
ref="siteSubHeader"
|
|
class="mt-5 duplicate-check-subheader"
|
|
:cmsWidgetName="widget.siteSubHeader" />
|
|
<buttonQuestion
|
|
ref="buttonQuestion"
|
|
v-model="selectedAnswer"
|
|
class="duplicate-check-question"
|
|
:cmsWidgetName="widget.existingOrNewQuestion"
|
|
:questionText="questionText"
|
|
:answers="answers"
|
|
groupName="existingOrNewQuestionOption"
|
|
buttonTypeString="listButton"
|
|
isRequired
|
|
:validationRules="rules.selectionRequired" />
|
|
<siteFooter
|
|
ref="siteFooter"
|
|
class="my-5"
|
|
:cmsWidgetName="widget.siteFooter"
|
|
:isForwardActionDisabled="!meta.valid"
|
|
@forwardClicked="forwardButtonAction"
|
|
@backClicked="navigateBack" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Form>
|
|
</template>
|
|
|
|
<script>
|
|
// Components
|
|
import { Form } from 'vee-validate';
|
|
import siteHeader from '@/iss-components/site-header/site-header.vue';
|
|
import siteFooter from '@/iss-components/site-footer/site-footer.vue';
|
|
import siteSubHeader from '@/iss-components/site-sub-header/site-sub-header.vue';
|
|
import buttonQuestion from '@/digital-components/button-question/button-question.vue';
|
|
|
|
// Supporting files
|
|
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper.js';
|
|
import BaseFormMixin from '@/mixins/base-form-mixin.js';
|
|
import { useMainStore } from '@/store/index.js';
|
|
import globalRules from '@/constants/global-rules.js';
|
|
import { toTitleCase } from '@/helpers/text-helper.js';
|
|
|
|
export default {
|
|
name: 'duplicate-check',
|
|
components: {
|
|
siteHeader,
|
|
siteSubHeader,
|
|
buttonQuestion,
|
|
siteFooter,
|
|
// eslint-disable-next-line vue/no-reserved-component-names
|
|
Form
|
|
},
|
|
mixins: [BaseFormMixin],
|
|
async beforeRouteEnter(to, from, next) {
|
|
const cmsContent = await fetchCmsContentForPage(to.query.issPage);
|
|
|
|
next((vm) => {
|
|
vm.setCmsContent(cmsContent);
|
|
});
|
|
},
|
|
setup() {
|
|
const mainStore = useMainStore();
|
|
return { mainStore };
|
|
},
|
|
data() {
|
|
return {
|
|
selectedAnswer: null,
|
|
widget: {
|
|
siteHeader: 'SiteHeaderWidget',
|
|
siteSubHeader: 'SiteSubHeaderWidget',
|
|
existingOrNewQuestion: 'ExistingOrNewQuestion',
|
|
siteFooter: 'SiteFooterWidget'
|
|
},
|
|
rules: {
|
|
selectionRequired: globalRules.OPTION_REQUIRED
|
|
}
|
|
};
|
|
},
|
|
computed: {
|
|
questionText() {
|
|
return this.getCmsContent(this.widget.existingOrNewQuestion, 'QuestionText');
|
|
},
|
|
answersFromCms() {
|
|
return (
|
|
this.getCmsContent(this.widget.existingOrNewQuestion, 'Answers') ?? []
|
|
);
|
|
},
|
|
getNewOrderSelectionName() {
|
|
return this.answersFromCms?.[0]?.Name ?? '';
|
|
},
|
|
duplicateOrders() {
|
|
const duplicateOrderText = 'Finish Existing Claim';
|
|
const orders = useMainStore().applicationUser.duplicateOrders;
|
|
return (
|
|
orders?.map((o) => {
|
|
const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel
|
|
? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}`
|
|
: null;
|
|
const dateOfLoss = o.responseDate == null
|
|
? ''
|
|
: new Date(o.responseDate).toLocaleDateString();
|
|
const subtext = vehicle && o.responseDate
|
|
? `${vehicle}, ${dateOfLoss}`
|
|
: (vehicle ?? '').concat(dateOfLoss);
|
|
|
|
return {
|
|
Text: duplicateOrderText,
|
|
Name: o.referralNumber,
|
|
SubText: toTitleCase(subtext),
|
|
value: o.correlationId
|
|
};
|
|
}) ?? []
|
|
);
|
|
},
|
|
answers() {
|
|
return [...this.duplicateOrders, ...this.answersFromCms];
|
|
}
|
|
},
|
|
methods: {
|
|
/**
|
|
* @summary Steps to perform when forward button clicked.
|
|
*/
|
|
async forwardButtonAction() {
|
|
if (this.selectedAnswer == null) {
|
|
this.navigateForward();
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const selectedReferral =
|
|
this.mainStore.applicationUser.duplicateOrders.find((o) => o.correlationId === this.selectedAnswer);
|
|
|
|
if (selectedReferral) {
|
|
await this.mainStore.loadSession(selectedReferral);
|
|
}
|
|
} catch (err) {
|
|
console.error(`Error on loading session from duplicate check ${err}`);
|
|
} finally {
|
|
this.navigateForward();
|
|
}
|
|
},
|
|
navigateForward() {
|
|
if (!this.mainStore.isPolicyLookupSuccessful) {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED,
|
|
this.$route
|
|
);
|
|
return;
|
|
}
|
|
|
|
const policyVehicles = useMainStore().order.policy.vehicles ?? [];
|
|
|
|
if (!this.mainStore.order.loadedFromDupeCheck) {
|
|
if (policyVehicles.length !== 0) {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES,
|
|
this.$route
|
|
);
|
|
} else {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES,
|
|
this.$route
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (this.mainStore.order.vehicle.vin) {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_LOADED_DUPLICATE_WITH_POLICY_VEHICLE,
|
|
this.$route
|
|
);
|
|
} else if (policyVehicles.length !== 0) {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_LOADED_DUPLICATE_WITH_NON_POLICY_VEHICLE,
|
|
this.$route
|
|
);
|
|
} else {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_LOADED_DUPLICATE_WITH_NO_POLICY_VEHICLES,
|
|
this.$route
|
|
);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.duplicate-check-subheader {
|
|
.subheader-secondary {
|
|
margin-top: map-get($spacers, 2);
|
|
}
|
|
p {
|
|
span {
|
|
font-size: $h6-font-size;
|
|
}
|
|
}
|
|
}
|
|
.duplicate-check-question {
|
|
.question-text {
|
|
justify-content: left;
|
|
display: inline-flex !important;
|
|
margin-top: map-get($spacers, 4);
|
|
margin-bottom: map-get($spacers, 2);
|
|
}
|
|
.form-test-error {
|
|
margin-top: 0 !important;
|
|
}
|
|
}
|
|
</style>
|