Untitled

mail@pastecode.io avatar
unknown
plain_text
8 days ago
8.7 kB
2
Indexable
Never
import { Component, Inject, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { UtilsService } from '@shared/services/utils.service';
import { InterviewInfoService } from '../../services/interview-info.service';
import { SecondaryModalComponent } from '@shared/components/secondary-modal/secondary-modal.component';
import { ToasterService } from '@shared/services/toaster.service';
import { StorageService } from '@shared/services/storage.service';

@Component({
  selector: 'einterview-modal-modal',
  templateUrl: './einterview-modal.component.html',
  styleUrls: [
    './einterview-modal.component.scss',
    '../../contact-attempt-log/add-contact-log-modal/add-contact-log.component.scss',
  ],
})
export class EinterviewModalComponent implements OnInit {
  lstClientDetailsFA: UntypedFormGroup;
  selectedRow: any = 0;
  interviewers = [];
  interviewDateControl: UntypedFormControl;
  timeList = [];
  disableAction: boolean = false;
  formCtrlDate: any;
  formCtrlClientTime: UntypedFormControl;
  addContactFg: any;
  resultTypeList: any = [];
  buttonList: any = [];
  isMoneyGaurdPolicy: any = false;
  activeIndexButton;
  callInProgress = false;
  isJointInsuredExist = false;
  constructor(
    private interviewInfoService: InterviewInfoService,
    private utilService: UtilsService,
    public fb: UntypedFormBuilder,
    public secondaryModal: MatDialogRef<EinterviewModalComponent>,
    public messageModel: MatDialog,
    public toaster: ToasterService,
    private storageService : StorageService,
    @Inject(MAT_DIALOG_DATA) public secondaryModalData: any
  ) {}

  ngOnInit(): void {
    this.buttonList = this.secondaryModalData.data;

    this.isMoneyGaurdPolicy = this.secondaryModalData.isMoneyGaurdPolicy;
    this.lstClientDetailsFA = this.secondaryModalData.lstClientDetailsFA;
    this.isJointInsuredExist= this.secondaryModalData.isJointInsuredExist;
  }

  public onSecondaryModalClose() {
    this.secondaryModal.close();
    this.toaster.isToaster = false;
    this.toaster.isModal = false;
  }

  cancelInterviewSchedule() {
    this.secondaryModal.close({ success: false, data: null });
    this.toaster.isToaster = false;
    this.toaster.isModal = false;
  }
  processButtonFunctionality(buttonName, serviceName, i) {
    this.activeIndexButton = i;
    if (buttonName?.toUpperCase() == 'SEND LINK' || buttonName?.toUpperCase() == 'INITIATE EINTERVIEW') {
      this.startEinterviewProcess('', this.activeIndexButton);
    }
    if (buttonName?.toUpperCase() == 'RE-SEND WELCOME EMAIL') {
      let message = 'Are you sure you want to resend the welcome packet email for this eInterview case? ';
      this.openMailModal(message, serviceName, false);
    }
    if (buttonName?.toUpperCase() == 'UNLOCK EINTERVIEW') {
      let message = 'Are you sure you want to unlock this eInterview case? ';
      this.openMailModal(message, serviceName, false);
    }
    if (buttonName?.toUpperCase() == 'EXPIRE EINTERVIEW') {
      let message = 'Are you sure you want to expire this eInterview case? ';
      this.openMailModal(message, serviceName, false);
    }
    if (buttonName?.toUpperCase() == 'CANCEL EINTERVIEW') {
      let message = 'Are you sure you want to cancel this eInterview case? ';
      this.openMailModal(message, serviceName, false);
    }
    if (buttonName?.toUpperCase() == 'VIEW CLIENT EINTERVIEW') {
      let message = "Are you sure you want to view the client's eInterview?";
      this.openMailModal(message, serviceName, false);
    }
  }
  processEInterviewDashboardActivitiesModel(buttonName, serviceName, index) {}

  eInterviewAdmButtons(buttonName, serviceName, index) {
    let policyType = '';
    if (this.isMoneyGaurdPolicy){
      policyType = 'MG'
    }
    let policyNo = this.secondaryModalData.baseFG?.policyNo;
    let companyCode = this.secondaryModalData.baseFG?.companyCode;
    let insuredId = this.lstClientDetailsFA?.get(this.selectedRow + '.insuredId')?.value;
    let underId = this.secondaryModalData.baseFG?.underId;
    this.buttonList[this.activeIndexButton].callInProgress = true;
    this.interviewInfoService.processEinterviewDashboardActivities(policyNo, underId, serviceName, policyType).subscribe(
      (resp: any) => {
        this.buttonList[this.activeIndexButton].callInProgress = false;
        if (!Boolean(resp.data?.data?.isErrorMessage)) {
          if (serviceName == 'VIEW_CLIENT_EINTERVIEW') {
            window.open(resp.data?.data?.redirectUrl);
          } else {
            this.toaster.isToaster = true;
            this.toaster.isModal = true;
            this.toaster.showToaster('success', resp.data.data.message);
          }
        } else {
          this.openMailModal(resp.data?.data?.message, 'No Action', true);
        }
      },
      (err) => {
        this.buttonList[this.activeIndexButton].callInProgress = false;
      }
    );
  }
  private startEinterviewProcess(action, i) {
    let policyNo = this.secondaryModalData.baseFG?.policyNo;
    let companyCode = this.secondaryModalData.baseFG?.companyCode;
    let insuredId = this.lstClientDetailsFA?.get(this.selectedRow + '.insuredId')?.value;
    let underId = this.secondaryModalData.baseFG?.underId;
    this.buttonList[this.activeIndexButton].callInProgress = true;
    
if(this.storageService.isJointInsuredExist){
  this.isJointInsuredExist = this.storageService.isJointInsuredExist;
  this.toaster.isToaster = true;
  this.toaster.isModal = true;
  this.buttonList[this.activeIndexButton].callInProgress = false;
  this.toaster.showToaster('info', "A secondary insured is present on this policy. eInterview is not currently allowed.");
}
else{
    this.interviewInfoService.initiateInterview(policyNo, companyCode, insuredId, underId, action).subscribe(
      (resp: any) => {
        this.buttonList[this.activeIndexButton].callInProgress = false;
        if (resp?.data?.data && !(resp?.data?.data?.message?.length > 0) && action != 'Yes') {
          resp.data.data.message = 'Are you sure you want to send the eInterview link?';
        }
        if (action == 'Yes' && !Boolean(resp.data?.data?.isErrorMessage)) {
          this.toaster.isToaster = true;
          this.toaster.isModal = true;
          let msgList = resp.data?.data?.message?.toLowerCase().split(' ');
          if (msgList.includes('successfully')) {
            this.toaster.showToaster('success', resp.data.data.message);
          } else {
            this.toaster.showToaster('info', resp.data.data.message);
          }
        } else if (
          action != 'Yes' &&
          Boolean(resp.data?.data?.isErrorMessage) &&
          resp?.data?.data?.message?.length > 0
        ) {
          this.openMailModal(resp.data?.data?.message, 'OK', true);
        } else {
          this.openMailModal(resp.data?.data?.message, action, action == 'Yes');
        }
      },
      (error) => {
        this.buttonList[this.activeIndexButton].callInProgress = false;
      }
    );
  }
  }

  public openMailModal(message, action, isWarning) {
    // Secondary Modal
    const secondaryModalConfig = new MatDialogConfig();
    secondaryModalConfig.disableClose = true;
    secondaryModalConfig.autoFocus = true;
    secondaryModalConfig.height = 'auto';
    secondaryModalConfig.width = '500px';
    if (isWarning) {
      secondaryModalConfig.data = {
        title: 'eInterview Warning',
        message: message,
        buttonOneText: 'OK',
      };
    } else {
      secondaryModalConfig.data = {
        title: 'eInterview Confirmation',
        message: message,
        buttonOneText: 'YES',
        buttonTwoText: 'No',
      };
    }

    const modal = this.messageModel?.open(SecondaryModalComponent, secondaryModalConfig);

    modal.afterClosed().subscribe((result) => {
      if (result.event == true && action == '') {
        this.startEinterviewProcess('Yes', this.activeIndexButton);
      }
      if (
        result.event == true &&
        [
          'RESEND_WELCOME_PACKET',
          'UNLOCK_EINTERVIEW',
          'EXPIRE_EINTERVIEW',
          'CANCEL_EINTERVIEW',
          'VIEW_CLIENT_EINTERVIEW',
        ].includes(action)
      ) {
        this.eInterviewAdmButtons('', action, this.activeIndexButton);
      }

    });
  }
}
Leave a Comment