All files / app/pages/forgot-password-page forgot-password-page.component.ts

98.48% Statements 65/66
100% Branches 6/6
100% Functions 3/3
98.48% Lines 65/66

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 671x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x  
import { isPlatformBrowser, NgClass } from '@angular/common';
import { Component, inject, NgZone, PLATFORM_ID } from '@angular/core';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { HeaderElementComponent } from '@elements/header-element/header-element.component';
import { ValidationErrorsComponent } from '@elements/validation-errors/validation-errors.component';
import { ForgotForm } from '@forms/forgot.form';
import { NetworkService } from '@services/network.service';
import Swal from 'sweetalert2';
 
@Component({
	selector: 'grt-forgot-password-page',
	templateUrl: './forgot-password-page.component.html',
	styleUrls: ['./forgot-password-page.component.scss'],
	imports: [HeaderElementComponent, ReactiveFormsModule, NgClass, ValidationErrorsComponent],
})
export class ForgotPasswordPageComponent {
	private network = inject(NetworkService);
	private ngZone = inject(NgZone);
	protected router = inject(Router);
	formBuilder = inject(FormBuilder);
 
	form: ForgotForm;
	isBrowser: any;
 
	constructor() {
		const platformId = inject(PLATFORM_ID);
 
		this.isBrowser = isPlatformBrowser(platformId);
		this.form = new ForgotForm(this.formBuilder);
	}
 
	forgot(): void {
		if (this.form.validate()) {
			this.network
				.forgot(this.form.formData.value)
				.then(() => {
					if (this.isBrowser) {
						Swal.fire({
							toast: true,
							position: 'top-end',
							showConfirmButton: false,
							showCloseButton: true,
							timerProgressBar: true,
							didOpen: (toast) => {
								toast.onmouseenter = Swal.stopTimer;
								toast.onmouseleave = Swal.resumeTimer;
							},
							icon: 'success',
							text: 'We have sent you a email for password reset.',
							background: '#51a351',
							color: '#fff',
							width: '28em',
							timer: 5000,
						});
					}
					setTimeout(() => {
						this.ngZone.run(() => this.router.navigate(['/']));
					}, 5000);
				})
				.catch((error) => {
					alert(error);
				});
		}
	}
}