|
1 | 1 | import { |
| 2 | + deliverableEmail, |
2 | 3 | ifValid, |
3 | 4 | NaturalAlertService, |
4 | 5 | NaturalErrorMessagePipe, |
5 | 6 | NaturalIconDirective, |
6 | 7 | validateAllFormControls, |
7 | 8 | } from '@ecodev/natural'; |
8 | 9 | import {Component, inject} from '@angular/core'; |
9 | | -import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms'; |
| 10 | +import {FormsModule, NonNullableFormBuilder, ReactiveFormsModule, Validators} from '@angular/forms'; |
10 | 11 | import {Router} from '@angular/router'; |
11 | 12 | import {UserService} from '../../../admin/users/services/user.service'; |
12 | 13 | import {MatButton} from '@angular/material/button'; |
@@ -36,22 +37,19 @@ export class RequestPasswordResetComponent { |
36 | 37 | private readonly alertService = inject(NaturalAlertService); |
37 | 38 | private readonly router = inject(Router); |
38 | 39 | private readonly userService = inject(UserService); |
| 40 | + private readonly fb = inject(NonNullableFormBuilder); |
39 | 41 |
|
40 | | - protected readonly form: FormGroup; |
| 42 | + protected readonly form = this.fb.group({ |
| 43 | + email: ['', [Validators.required, deliverableEmail, Validators.maxLength(191)]], |
| 44 | + }); |
41 | 45 | protected sending = false; |
42 | 46 |
|
43 | | - public constructor() { |
44 | | - const userService = this.userService; |
45 | | - |
46 | | - this.form = new FormGroup({email: new FormControl('', userService.getFormValidators().email)}); |
47 | | - } |
48 | | - |
49 | 47 | protected submit(): void { |
50 | 48 | validateAllFormControls(this.form); |
51 | 49 | ifValid(this.form).subscribe(() => { |
52 | 50 | this.sending = true; |
53 | 51 |
|
54 | | - this.userService.requestPasswordReset(this.form.value.email).subscribe({ |
| 52 | + this.userService.requestPasswordReset(this.form.getRawValue().email).subscribe({ |
55 | 53 | next: () => { |
56 | 54 | this.sending = false; |
57 | 55 |
|
|
0 commit comments