Browse Source

Task/improve type safety in user account registration dialog component (#7301)

* fix(client): resolve type errors

* feat(client): enforce encapsulation

* feat(client): replace constructor based DI with inject functions

* feat(client): implement viewChild signal
pull/7303/head
Kenrick Tandrian 4 days ago
committed by GitHub
parent
commit
9cea437b2c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 40
      apps/client/src/app/pages/register/user-account-registration-dialog/user-account-registration-dialog.component.ts

40
apps/client/src/app/pages/register/user-account-registration-dialog/user-account-registration-dialog.component.ts

@ -9,8 +9,8 @@ import {
Component, Component,
CUSTOM_ELEMENTS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA,
DestroyRef, DestroyRef,
Inject, inject,
ViewChild viewChild
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@ -53,26 +53,28 @@ import { UserAccountRegistrationDialogParams } from './interfaces/interfaces';
templateUrl: 'user-account-registration-dialog.html' templateUrl: 'user-account-registration-dialog.html'
}) })
export class GfUserAccountRegistrationDialogComponent { export class GfUserAccountRegistrationDialogComponent {
@ViewChild(MatStepper) stepper!: MatStepper; protected readonly stepper = viewChild.required(MatStepper);
public accessToken: string; protected accessToken: string | undefined;
public authToken: string; protected authToken: string;
public isCreateAccountButtonDisabled = true; protected isCreateAccountButtonDisabled = true;
public isDisclaimerChecked = false; protected isDisclaimerChecked = false;
public role: string; protected role: string;
public routerLinkAboutTermsOfService = protected readonly routerLinkAboutTermsOfService =
publicRoutes.about.subRoutes.termsOfService.routerLink; publicRoutes.about.subRoutes.termsOfService.routerLink;
public constructor( protected readonly data =
private changeDetectorRef: ChangeDetectorRef, inject<UserAccountRegistrationDialogParams>(MAT_DIALOG_DATA);
@Inject(MAT_DIALOG_DATA) public data: UserAccountRegistrationDialogParams,
private dataService: DataService, private readonly changeDetectorRef = inject(ChangeDetectorRef);
private destroyRef: DestroyRef private readonly dataService = inject(DataService);
) { private readonly destroyRef = inject(DestroyRef);
public constructor() {
addIcons({ arrowForwardOutline, checkmarkOutline, copyOutline }); addIcons({ arrowForwardOutline, checkmarkOutline, copyOutline });
} }
public createAccount() { protected createAccount() {
this.dataService this.dataService
.postUser() .postUser()
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
@ -81,17 +83,17 @@ export class GfUserAccountRegistrationDialogComponent {
this.authToken = authToken; this.authToken = authToken;
this.role = role; this.role = role;
this.stepper.next(); this.stepper().next();
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}); });
} }
public enableCreateAccountButton() { protected enableCreateAccountButton() {
this.isCreateAccountButtonDisabled = false; this.isCreateAccountButtonDisabled = false;
} }
public onChangeDislaimerChecked() { protected onChangeDislaimerChecked() {
this.isDisclaimerChecked = !this.isDisclaimerChecked; this.isDisclaimerChecked = !this.isDisclaimerChecked;
} }
} }

Loading…
Cancel
Save