@@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
2
2
import { UserDataService } from '../../shared/services/data.service' ;
3
3
import { Router } from '@angular/router' ;
4
4
import { ShowProgressService } from '../../shared/services/show-progress.service' ;
5
- import { MatSnackBar } from '@angular/material ' ;
5
+ import { SnackBarService } from '../../shared/services/snack-bar.service ' ;
6
6
import { IUser } from '../../../../../../shared/models/IUser' ;
7
7
import { DialogService } from '../../shared/services/dialog.service' ;
8
8
import { UserService } from '../../shared/services/user.service' ;
@@ -20,7 +20,7 @@ export class UserAdminComponent implements OnInit {
20
20
constructor ( private userDataService : UserDataService ,
21
21
private router : Router ,
22
22
private showProgress : ShowProgressService ,
23
- public snackBar : MatSnackBar ,
23
+ public snackBar : SnackBarService ,
24
24
public dialogService : DialogService ,
25
25
private userService : UserService ) {
26
26
}
@@ -46,18 +46,15 @@ export class UserAdminComponent implements OnInit {
46
46
} ) ;
47
47
}
48
48
49
- updateRole ( userIndex : number ) {
49
+ async updateRole ( userIndex : number ) {
50
50
this . showProgress . toggleLoadingGlobal ( true ) ;
51
- this . userDataService . updateItem ( this . allUsers [ userIndex ] ) . then (
52
- ( val ) => {
53
- this . showProgress . toggleLoadingGlobal ( false ) ;
54
- this . snackBar . open ( 'Role of user ' + val . email + ' successfully updated to ' + val . role , '' , { duration : 3000 } ) ;
55
- } ,
56
- ( error ) => {
57
- this . snackBar . open ( error . error . message , '' , { duration : 3000 } ) ;
58
- this . showProgress . toggleLoadingGlobal ( false ) ;
59
- }
60
- ) ;
51
+ try {
52
+ const user = await this . userDataService . updateItem ( this . allUsers [ userIndex ] ) ;
53
+ this . snackBar . open ( 'Role of user ' + user . email + ' successfully updated to ' + user . role ) ;
54
+ } catch ( err ) {
55
+ this . snackBar . open ( err . error . message ) ;
56
+ }
57
+ this . showProgress . toggleLoadingGlobal ( false ) ;
61
58
}
62
59
63
60
editUser ( userIndex : number ) {
@@ -66,22 +63,24 @@ export class UserAdminComponent implements OnInit {
66
63
}
67
64
68
65
deleteUser ( userIndex : number ) {
69
- this . dialogService
70
- . confirmDelete ( 'user' , this . allUsers [ userIndex ] . email )
71
- . subscribe ( res => {
72
- if ( res ) {
66
+ this . dialogService . confirmDelete ( 'user' , this . allUsers [ userIndex ] . email )
67
+ . subscribe ( async res => {
68
+ if ( ! res ) {
69
+ return ;
70
+ }
71
+
73
72
this . showProgress . toggleLoadingGlobal ( true ) ;
74
- this . userDataService . deleteItem ( this . allUsers [ userIndex ] ) . then (
75
- ( val ) => {
76
- this . showProgress . toggleLoadingGlobal ( false ) ;
77
- this . snackBar . open ( 'User ' + val + ' was successfully deleted.' , '' , { duration : 3000 } ) ;
78
- } ,
79
- ( error ) => {
80
- this . showProgress . toggleLoadingGlobal ( false ) ;
81
- this . snackBar . open ( error , '' , { duration : 3000 } ) ;
82
- }
83
- ) ;
84
- }
73
+ const user = this . allUsers [ userIndex ] ;
74
+
75
+ try {
76
+ await this . userDataService . deleteItem ( user ) ;
77
+ this . snackBar . open ( 'User ' + user . email + ' was successfully deleted.' ) ;
78
+ } catch ( err ) {
79
+ this . snackBar . open ( err . error . message ) ;
80
+ }
81
+
82
+ this . getUsers ( ) ;
83
+ this . showProgress . toggleLoadingGlobal ( false ) ;
85
84
} ) ;
86
85
}
87
86
}
0 commit comments