import {Component, Inject, OnInit, Output} from '@angular/core'; import {MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA, MatLegacyDialogRef as MatDialogRef} from "@angular/material/legacy-dialog"; import {UserInfo, UsersService} from "../../../../api"; import {LoginInfoTypes} from "../../../auth/login/login.component"; import {MatLegacySnackBar as MatSnackBar} from "@angular/material/legacy-snack-bar"; @Component({ selector: 'app-delete-confirmation', templateUrl: './delete-confirmation.component.html', styleUrls: ['./delete-confirmation.component.css'] }) export class DeleteConfirmationComponent implements OnInit { pending: boolean = false; constructor( public dialogRef: MatDialogRef, private userService: UsersService, private snackbar: MatSnackBar, @Inject(MAT_DIALOG_DATA) public userInfo: UserInfo ) { } ngOnInit(): void { } onConfirmBtn() { this.pending = true; this.userService.usersUsernameDelete(this.userInfo.username).subscribe({ next: response => { if(response.status == "success") { this.dialogRef.close(this.userInfo); this.snackbar.open("User deleted successfull", "", {duration: 2000}); this.pending = false; } }, error: err => { if(err.status == 403) { this.snackbar.open("You have no authorization to perform this Operation!","", {duration: 2000}) this.pending = false; } else if(err.status == 404) { this.snackbar.open("The user could not be found", "", {duration: 2000}); this.pending = false; } } }) } onClose() { this.dialogRef.close() } }