Newer
Older
import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import {
CustomtextService, MessageDialogComponent, MessageDialogData, MessageType
} from 'iqb-components';
import { MatDialog } from '@angular/material/dialog';
import { MainDataService } from '../../maindata.service';
import { AuthData } from '../../app.interfaces';
import { BackendService } from '../../backend.service';

mechtelm
committed
templateUrl: './code-input.component.html',
styles: [
'mat-card {margin: 10px;}',
'.mat-card-gray {background-color: lightgray}'
]
@ViewChild('codeInputControl') codeInputControl: FormControl;
problemText = '';
codeinputform = new FormGroup({
code: new FormControl('', [Validators.required, Validators.minLength(2)])
});
constructor(
private router: Router,
public messageDialog: MatDialog,
public cts: CustomtextService,
public mds: MainDataService
) { }
ngOnInit(): void {
setTimeout(() => {
const element = <HTMLElement>document.querySelector('.mat-input-element[formControlName="code"]');
if (element) {
element.focus();
}
const codeData = this.codeinputform.value;
this.messageDialog.open(MessageDialogComponent, {
width: '400px',
data: <MessageDialogData>{
content: this.cts.getCustomText('login_codeInputPrompt'),
type: MessageType.error
}
});
} else {
this.problemText = '';
if (typeof authData === 'number') {
const errCode = authData as number;
if (errCode === 400) {
this.problemText = 'Der Code ist leider nicht gültig. Bitte noch einmal versuchen';
} else {
this.problemText = 'Problem bei der Anmeldung.';
// app.interceptor will show error message
}
} else {
const authDataTyped = authData as AuthData;
this.mds.setAuthData(authDataTyped);
this.router.navigate(['/r']);
}
this.router.navigate(['/']);
}
}