Skip to content

Commit

Permalink
refactor: use firstValueFrom instead of subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
katyastan committed Aug 17, 2024
1 parent f0de08d commit 53fc1db
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/app/auth/pages/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { InputTextModule } from 'primeng/inputtext';
import { MessageModule } from 'primeng/message';
import { MessagesModule } from 'primeng/messages';
import { PasswordModule } from 'primeng/password';
import { firstValueFrom } from 'rxjs';

import { OverriddenHttpErrorResponse } from '@/app/api/models/errorResponse';
import { User } from '@/app/api/models/user';
Expand Down Expand Up @@ -44,8 +45,8 @@ export class RegisterComponent {
private messageService = inject(MessageService);
private signUpService = inject(SignUpService);
private router = inject(Router);

private fb = inject(FormBuilder);

public registrationForm = this.fb.group(
{
email: this.fb.control<string>('', [Validators.required.bind(this), Validators.email.bind(this)]),
Expand All @@ -59,16 +60,15 @@ export class RegisterComponent {

public submitForm(): void {
if (this.registrationForm.valid) {
this.signUpService.signUp(this.userData).subscribe({
next: () => {
firstValueFrom(this.signUpService.signUp(this.userData))
.then(() => {
this.messageService.add({ severity: 'success', summary: 'Success', detail: 'Registration successful!' });
this.router.navigate(['/sign-in']);
this.registrationForm.reset();
},
error: (err: OverriddenHttpErrorResponse) => {
})
.catch((err: OverriddenHttpErrorResponse) => {
this.registrationForm.setErrors({ [err.error.reason]: true });
},
});
});
} else {
Object.values(this.registrationForm.controls).forEach((control) => {
if (control.invalid) {
Expand Down

0 comments on commit 53fc1db

Please sign in to comment.