import { Component, OnInit } from '@angular/core'; import {AccountService} from "../../../../api"; import {UntypedFormControl, Validators} from "@angular/forms"; import {MatSnackBar as MatSnackBar} from "@angular/material/snack-bar"; @Component({ selector: 'app-manage-email', templateUrl: './manage-email.component.html', styleUrls: ['./manage-email.component.css'] }) export class ManageEmailComponent implements OnInit { email : string = ""; password: string = ""; emailControl = new UntypedFormControl('', [Validators.required, Validators.email]); passwordControl = new UntypedFormControl('', [Validators.required]) hide: boolean = true; pending: boolean = false; constructor(private accountService: AccountService, private snackBar: MatSnackBar) { } ngOnInit(): void { this.accountService.accountUserDetailsGet().subscribe({ next: response => { this.email = response.email; } }) } onChangeEmail() { this.pending = true; this.accountService.accountChangeEmailPost({ password: this.password, email: this.email }).subscribe({ next: resp => { if(resp.status == "success") { this.snackBar.open("Updated Email successfully!", "", {duration: 2000}) } this.pending = false; }, error : err => { if(err.status == 404) { this.snackBar.open("User could not be found in system!", "Please check your authentication!", {duration: 2000}) } else if(err.status == 409) { this.snackBar.open("Invalid Password", "", {duration: 2000}); } this.pending = false; } }) } }