From ab0775a706584c107c004029d48833541da1c5c3 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Wed, 26 Mar 2025 13:58:40 +0100 Subject: [PATCH] frontend: Set default username if authenticated in ParticipantNameComponent and clean up form initialization --- .../participant-name-form.component.html | 1 - .../participant-name-form.component.ts | 26 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.html b/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.html index 2dd6582..f294016 100644 --- a/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.html +++ b/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.html @@ -11,7 +11,6 @@ @if (name?.hasError('required')) { The name is required } - @if (name?.hasError('participantExists')) { The name is already taken. Please choose another name } diff --git a/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.ts b/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.ts index 3546f96..ecff005 100644 --- a/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.ts +++ b/frontend/projects/shared-meet-components/src/lib/pages/participant-name-form/participant-name-form.component.ts @@ -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);