import {Component, OnInit} from '@angular/core'; import {FieldType} from '@ngx-formly/material'; import {AllService} from '../../../all.service'; import {ActivatedRoute, Router} from '@angular/router'; import {faCheck} from '@fortawesome/free-solid-svg-icons'; @Component({ selector: 'jhi-step-finalisation', templateUrl: './step-finalisation.component.html', styleUrls: ['./step-finalisation.component.scss'] }) export class StepFinalisationComponent extends FieldType implements OnInit { isForever = false; faCheck = faCheck; isEligibleCancellation = false; contractid = ''; showCancelButton = false; contract: any = null; session: any = null; constructor(public allService: AllService, private route: ActivatedRoute, private router: Router) { super(); } ngOnInit(): void { const productcollectionid = this.route.snapshot.paramMap.get('productcollectionid') ? this.route.snapshot.paramMap.get('productcollectionid') : ''; this.isForever = productcollectionid === 'foreverC1'; this.contractid = this.route.snapshot.paramMap.get('contractid'); // Tell to Zuko that's the form is completed this.allService.getStepsSubjectAsObserVable().subscribe((data) => { if (data && data.step && data.step.fields && data.step.fields[0].fieldGroup[0].type === 'stepFinalisation') { this.allService['trackingService'].submitForm(); } }); this.checkIfCancellable(); } async checkIfCancellable(): Promise { this.isEligibleCancellation = await this.allService.contractManagerService.cancellationEligibility(this.contractid).toPromise(); const response = await this.allService.contractService.find(this.contractid).toPromise(); this.contract = response.body; this.session = this.contract.signatureSessions.find(session => session.signatureType === 'CANCELLATION'); if (this.contract && this.session && this.isEligibleCancellation) { this.showCancelButton = true; } return true; } goToResiliation() { const url = `/loan/quotes/${this.contract.productId}/${this.contract.customerId}/${this.session.id}/${this.contract.id}/${this.contract.source}/resiliation`; window.location.href = url; } }