Skip to content

Commit 2a0472e

Browse files
committed
TT-97 fix: refactor code
1 parent e9bb5fb commit 2a0472e

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/app/modules/users/components/users-list/users-list.component.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
<td class="col">{{ user.name }}</td>
1919
<td class="col text-center" *ngIf="isFlagOn">
2020
<div>
21-
<ui-switch size="small" (change)="revokeOrGrantRole(user.id, user.role)" [checked]="isAdmin(user.role)"></ui-switch>
22-
Admin
23-
</div>
24-
<div>
25-
<ui-switch size="small"></ui-switch>
26-
Test
21+
<ui-switch
22+
size="small"
23+
(change)="switchRole(user.id, user.roles, 'admin', 'time-tracker-admin')"
24+
[checked]="user.roles.includes('time-tracker-admin')"
25+
></ui-switch>
26+
admin
27+
<ui-switch
28+
size="small"
29+
(change)="switchRole(user.id, user.roles, 'test', 'time-tracker-tester')"
30+
[checked]="user.roles.includes('time-tracker-tester')"
31+
></ui-switch>
32+
test
2733
</div>
2834
</td>
2935
</tr>

src/app/modules/users/components/users-list/users-list.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('UsersListComponent', () => {
6969
expect(component.users).toEqual(state.data);
7070
});
7171
/*
72-
TODO: blocke commented on purpose so that when the tests pass and the Feature toggle is removed,
72+
TODO: block commented on purpose so that when the tests pass and the Feature toggle is removed,
7373
the table will be rendered again with dtInstance and not with dtOptions
7474
7575
it('on success load users, the data of roles should be an array and role null', () => {

src/app/modules/users/components/users-list/users-list.component.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
3131
this.isLoading$ = store.pipe(delay(0), select(getIsLoading));
3232
this.isFeatureToggleAactivated().subscribe((flag) => {
3333
this.isFlagOn = flag;
34-
console.log(this.isFlagOn);
3534
});
3635
}
3736

@@ -78,14 +77,10 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
7877
}
7978
}
8079

81-
isAdmin(role) {
82-
return role ? true : false;
83-
}
84-
85-
revokeOrGrantRole(userId: string, userRole: string) {
86-
userRole
87-
? this.store.dispatch(new RevokeRoleUser(userId, 'admin'))
88-
: this.store.dispatch(new GrantRoleUser(userId, 'admin'));
80+
switchRole(userId: string, userRoles: string[], roleId: string, roleValue: string) {
81+
userRoles.includes(roleValue)
82+
? this.store.dispatch(new RevokeRoleUser(userId, roleId))
83+
: this.store.dispatch(new GrantRoleUser(userId, roleId));
8984
}
9085

9186
isFeatureToggleAactivated() {

0 commit comments

Comments
 (0)