diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index dc690516..8790332b 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -69,25 +69,17 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { } ngOnInit() { - this.filterForm = this.fb.group({ - active: this.fb.control(''), - pending: this.fb.control('') + this.initForm(); + this.updateLists(); + this.userManagementService.getUserInfo().subscribe(user => { + this.user = user; }); - this.subs.push(this.filterForm.get('active').valueChanges.subscribe(value => { - this.filterActiveBySearch(value); - })); - this.subs.push(this.filterForm.get('pending').valueChanges.subscribe(value => { - this.filterPendingBySearch(value); - })); - this.updateLists(); - this.userManagementService.getUserInfo().subscribe(user => { - this.user = user; - }); } ngOnChanges(changes: SimpleChanges) { - if(changes.role) { + if (changes.role) { this.unsubscribe(); + this.initForm(); this.updateLists(); } } @@ -104,11 +96,24 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { }); } + initForm() { + this.filterForm = this.fb.group({ + active: this.fb.control(''), + pending: this.fb.control('') + }); + this.subs.push(this.filterForm.get('active').valueChanges.subscribe(value => { + this.filterActiveBySearch(value); + })); + this.subs.push(this.filterForm.get('pending').valueChanges.subscribe(value => { + this.filterPendingBySearch(value); + })); + } + updateLists() { this.loadActive = true; this.loadPending = true; this.subs.push(this.userRegistryService.getActiveEmail(this.type, this.id, this.role).subscribe(users => { - if(this.role === 'member') { + if (this.role === 'member') { this.subs.push(this.userRegistryService.getActiveEmail(this.type, this.id, 'manager').subscribe(managers => { this.managers = managers; this.active = users; @@ -127,7 +132,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { } }, error => { this.active = []; - if(error.status === 404) { + if (error.status === 404) { this.exists = false; } this.loadActive = false; @@ -232,7 +237,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { this.pending.push(this.invited.value); this.filterPendingBySearch(this.filterForm.value.pending); } - if(this.notificationFn) { + if (this.notificationFn) { this.subs.push(this.notificationService.sendNotification(this.notificationFn(this.name, this.invited.value, this.role, invitation)).subscribe(notification => { UIkit.notification('A notification has been sent successfully', { status: 'success',