frontend: Set default username if authenticated in ParticipantNameComponent and clean up form initialization
This commit is contained in:
parent
2b776ac181
commit
ab0775a706
@ -11,7 +11,6 @@
|
||||
@if (name?.hasError('required')) {
|
||||
<mat-error> The name is <strong>required</strong> </mat-error>
|
||||
}
|
||||
|
||||
@if (name?.hasError('participantExists')) {
|
||||
<mat-error> The name is already taken. <strong> Please choose another name </strong> </mat-error>
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { FormGroup, Validators, FormsModule, ReactiveFormsModule, FormControl } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { AuthService } from 'shared-meet-components';
|
||||
|
||||
@Component({
|
||||
selector: 'ov-participant-name-form',
|
||||
@ -22,21 +23,19 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
styleUrl: './participant-name-form.component.scss'
|
||||
})
|
||||
export class ParticipantNameFormComponent implements OnInit {
|
||||
participantForm: FormGroup;
|
||||
participantForm = new FormGroup({
|
||||
name: new FormControl('', [Validators.required, Validators.minLength(4)])
|
||||
});
|
||||
protected originUrl: string = '';
|
||||
protected error = '';
|
||||
|
||||
constructor(
|
||||
protected fb: FormBuilder,
|
||||
protected router: Router,
|
||||
protected route: ActivatedRoute
|
||||
) {
|
||||
this.participantForm = this.fb.group({
|
||||
name: ['', [Validators.required, Validators.minLength(4)]]
|
||||
});
|
||||
}
|
||||
protected route: ActivatedRoute,
|
||||
protected authService: AuthService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
ngOnInit() {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
if (params['originUrl']) {
|
||||
this.originUrl = params['originUrl'];
|
||||
@ -44,6 +43,12 @@ export class ParticipantNameFormComponent implements OnInit {
|
||||
this.applyErrorToForm();
|
||||
}
|
||||
});
|
||||
|
||||
// Set the username if authenticated as default value
|
||||
const username = this.authService.getUsername();
|
||||
if (username) {
|
||||
this.participantForm.get('name')?.setValue(username);
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
@ -55,7 +60,6 @@ export class ParticipantNameFormComponent implements OnInit {
|
||||
const participantName = this.participantForm.value.name;
|
||||
|
||||
let urlTree = this.router.parseUrl(this.originUrl);
|
||||
|
||||
urlTree.queryParams = { ...urlTree.queryParams, 'participant-name': participantName };
|
||||
|
||||
await this.router.navigateByUrl(urlTree);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user