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

96.51% Statements 83/86
88.88% Branches 8/9
75% Functions 3/4
96.51% Lines 83/86

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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 871x 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 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 2x 2x 1x   1x 1x 1x 2x 2x 3x 1x  
import { isPlatformBrowser, NgClass } from '@angular/common';
import { Component, inject, OnInit, PLATFORM_ID } from '@angular/core';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { HeaderElementComponent } from '@elements/header-element/header-element.component';
import { ValidationErrorsComponent } from '@elements/validation-errors/validation-errors.component';
import { environment } from '@environments/environment';
import { ResetPasswordForm } from '@forms/resetpassword.form';
import { AnalyticsIntegrationService } from '@services/analyticsIntegration.service';
import { NetworkService } from '@services/network.service';
import { NgxIntlTelInputModule } from 'ngx-intl-tel-input';
import Swal from 'sweetalert2';
 
@Component({
	selector: 'grt-reset-password-page',
	templateUrl: './reset-password-page.component.html',
	styleUrls: ['./reset-password-page.component.scss'],
	imports: [HeaderElementComponent, ReactiveFormsModule, NgxIntlTelInputModule, NgClass, ValidationErrorsComponent],
})
export class ResetPasswordPageComponent implements OnInit {
	private network = inject(NetworkService);
	private route = inject(ActivatedRoute);
	private analyticsIntegrationService = inject(AnalyticsIntegrationService);
	protected router = inject(Router);
	formBuilder = inject(FormBuilder);
 
	form: ResetPasswordForm;
	token: any = '';
	isBrowser: any;
 
	constructor() {
		const platformId = inject(PLATFORM_ID);
 
		this.isBrowser = isPlatformBrowser(platformId);
		this.form = new ResetPasswordForm(this.formBuilder);
	}
 
	ngOnInit() {
		this.network.getIpCliente().then(() => {});
		this.token = this.route.snapshot.paramMap.get('token');
		if (this.isBrowser) {
			this.analyticsIntegrationService.loadScript();
		}
	}
 
	resetPassword(): void {
		if (this.form.validate()) {
			this.network
				.resetPassword(this.form.formData.value, this.token)
				.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: 'Password has been reset successfully.',
							background: '#51a351',
							color: '#fff',
							width: '28em',
							timer: 5000,
						});
					}
				})
				.then(() => {
					if (this.isBrowser) {
						window.location.href =
							environment.backendUrl + '/client/itineraries';
					}
				})
				.catch((error) => {
					if (typeof error === 'string') {
						alert(error);
					} else {
						this.form.setErrors(error);
					}
				});
		}
	}
}