Skip to content

Commit 82b3022

Browse files
adds delete user button to user administration (#669)
1 parent 64c2029 commit 82b3022

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/app/components/admin-app/admin-user-search/admin-user-search.component.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@
8686
</mat-cell>
8787
</ng-container>
8888

89+
<ng-container matColumnDef="actions">
90+
<mat-header-cell *matHeaderCellDef> Actions </mat-header-cell>
91+
<mat-cell *matCellDef="let element">
92+
<button
93+
mat-icon-button
94+
color="primary"
95+
(click)="deleteUser(element)"
96+
title="Delete User"
97+
>
98+
<mat-icon
99+
class="mdi-24px"
100+
fontIcon="mdi-delete-forever-outline"
101+
></mat-icon>
102+
</button>
103+
</mat-cell>
104+
</ng-container>
105+
89106
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
90107
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
91108
</mat-table>

src/app/components/admin-app/admin-user-search/admin-user-search.component.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MatSort, MatSortable } from '@angular/material/sort';
1010
import { MatTableDataSource } from '@angular/material/table';
1111
import { User, UserService, RoleService } from '../../../generated/player-api';
1212
import { RolesService } from '../../../services/roles/roles.service';
13+
import { DialogService } from '../../../services/dialog/dialog.service';
1314

1415
export interface Action {
1516
Value: string;
@@ -23,7 +24,7 @@ export interface Action {
2324
standalone: false
2425
})
2526
export class AdminUserSearchComponent implements OnInit, AfterViewInit {
26-
public displayedColumns: string[] = ['name', 'roleName'];
27+
public displayedColumns: string[] = ['name', 'roleName', 'actions'];
2728
public filterString: string;
2829

2930
public editUserText = 'Edit User';
@@ -42,7 +43,8 @@ export class AdminUserSearchComponent implements OnInit, AfterViewInit {
4243

4344
constructor(
4445
private userService: UserService,
45-
private rolesService: RolesService
46+
private rolesService: RolesService,
47+
private dialogService: DialogService
4648
) {}
4749

4850
/**
@@ -110,4 +112,28 @@ export class AdminUserSearchComponent implements OnInit, AfterViewInit {
110112
this.isLoading = false;
111113
});
112114
}
115+
116+
/**
117+
* Deletes a user after confirmation
118+
* @param user The user to delete
119+
*/
120+
deleteUser(user: User) {
121+
this.dialogService
122+
.confirm(
123+
'Delete User?',
124+
`Are you sure you want to delete ${user.name || user.id}?`,
125+
{
126+
buttonTrueText: 'Delete',
127+
buttonFalseText: 'Cancel',
128+
}
129+
)
130+
.subscribe((result) => {
131+
if (result.confirm) {
132+
this.userService.deleteUser(user.id).subscribe(() => {
133+
// Refresh the users list after successful deletion
134+
this.refreshUsers();
135+
});
136+
}
137+
});
138+
}
113139
}

0 commit comments

Comments
 (0)