Skip to content
Snippets Groups Projects
Commit 7cc46964 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Adjust error-messange to notification instead of formControl

parent 2c8def57
1 merge request!70Resolve "Adjust join room when room is not existing"
<form (ngSubmit)="joinRoom(roomId.value)"> <form (ngSubmit)="joinRoom(roomId.value)">
<div fxLayout="row" fxLayoutAlign="center" fxLayoutGap="10px"> <div fxLayout="row" fxLayoutAlign="center" fxLayoutGap="10px">
<mat-form-field class="input-block"> <mat-form-field class="input-block">
<input matInput #roomId placeholder="Room-Id" (keypress)="reset()"/> <input matInput #roomId placeholder="Room-Id" [formControl]="roomFormControl" [errorStateMatcher]="matcher"/>
</mat-form-field> <mat-error *ngIf="roomFormControl.hasError('required')">Please enter a room-id.</mat-error>
<button mat-fab color="primary" (click)="joinRoom(roomId.value)"> </mat-form-field>
<mat-icon>send</mat-icon> <button mat-fab color="primary" (click)="joinRoom(roomId.value)">
</button> <mat-icon>send</mat-icon>
</div> </button>
<mat-error *ngIf="!isExisting" class="errorForm">No room was found with this id.</mat-error> </div>
<mat-error *ngIf="noInput" class="errorForm">Please enter a room-id.</mat-error>
</form> </form>
.errorForm {
font-size: 80%;
}
...@@ -2,6 +2,17 @@ import { Component, OnInit } from '@angular/core'; ...@@ -2,6 +2,17 @@ import { Component, OnInit } from '@angular/core';
import { Room } from '../room'; import { Room } from '../room';
import { RoomService } from '../room.service'; import { RoomService } from '../room.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { RegisterErrorStateMatcher } from '../register/register.component';
import { FormControl, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { ErrorStateMatcher } from '@angular/material';
import { NotificationService } from '../notification.service';
export class JoinErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return (control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}
@Component({ @Component({
selector: 'app-join-room', selector: 'app-join-room',
...@@ -12,11 +23,15 @@ export class JoinRoomComponent implements OnInit { ...@@ -12,11 +23,15 @@ export class JoinRoomComponent implements OnInit {
room: Room; room: Room;
isExisting = true; isExisting = true;
noInput = false;
roomFormControl = new FormControl('', [Validators.required]);
matcher = new RegisterErrorStateMatcher();
constructor(private roomService: RoomService, constructor(private roomService: RoomService,
private router: Router private router: Router,
) { public notificationService: NotificationService
) {
} }
ngOnInit() { ngOnInit() {
...@@ -24,25 +39,17 @@ export class JoinRoomComponent implements OnInit { ...@@ -24,25 +39,17 @@ export class JoinRoomComponent implements OnInit {
} }
joinRoom(id: string): void { joinRoom(id: string): void {
if (id) { if (!this.roomFormControl.hasError('required')) {
this.roomService.getRoom(id) this.roomService.getRoom(id)
.subscribe( room => { .subscribe(room => {
this.room = room; this.room = room;
if (!room) { if (!room) {
this.isExisting = false; this.notificationService.show(`No room was found with id: ${id}`);
this.noInput = false; } else {
} else { this.router.navigate([`/participant/room/${this.room.id}`]);
this.router.navigate([`/participant/room/${this.room.id}`]); }
} });
});
} else {
this.noInput = true;
this.isExisting = true;
} }
} }
reset(): void {
this.isExisting = true;
this.noInput = false;
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment