import { Component , OnDestroy } from '@angular/core' ; import { User } from '../../models/user' ; import { ActivatedRoute , Router } from '@angular/router' ; import { ReplaySubject } from 'rxjs' ; import { UserService } from '../../services/user.service' ; import { takeUntil } from 'rxjs/operators' ; import { ToastService } from '../../../layout/toast/toast.service' ; @ Component ( { selector : 'cmdb-user-delete' , templateUrl : './user-delete.component.html' , styleUrls : [ './user-delete.component.scss' ] } ) export class UserDeleteComponent implements OnDestroy { /**
     * Component un-subscriber.
     */ private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; /**
     * Selected user
     */ public user : User ; constructor ( private route , private router , private userService , private toastService ) { this . user = this . route . snapshot . data . user as User ; } public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } public delete ( ) { this . userService . deleteUser ( this . user . public_id ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( user ) => { this . toastService . success ( `User ${ user . user_name } was deleted` ) ; this . router . navigate ( [ '/' , 'management' , 'users' ] ) ; } ) ; } }