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

95.29% Statements 81/85
66.66% Branches 8/12
75% Functions 3/4
95.29% Lines 81/85

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 861x 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 3x 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 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 { 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);
	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');
	}
 
	resetPassword(event?: Event): void {
		if (event) event.preventDefault();
		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) {
						if (this.network.user?.roles?.includes('vendor')) {
							window.location.href = environment.backendUrl + '/client/vendors';
						} else {
							window.location.href = environment.backendUrl + '/client/itineraries';
						}
					}
				})
				.catch((error) => {
					if (typeof error === 'string') {
						alert(error);
					} else {
						this.form.setErrors(error);
					}
				});
		}
	}
}