Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@
</mat-cell>
</ng-container>

<ng-container matColumnDef="actions">
<mat-header-cell *matHeaderCellDef> Actions </mat-header-cell>
<mat-cell *matCellDef="let element">
<button
mat-icon-button
color="primary"
(click)="deleteUser(element)"
title="Delete User"
>
<mat-icon
class="mdi-24px"
fontIcon="mdi-delete-forever-outline"
></mat-icon>
</button>
</mat-cell>
</ng-container>

<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MatSort, MatSortable } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { User, UserService, RoleService } from '../../../generated/player-api';
import { RolesService } from '../../../services/roles/roles.service';
import { DialogService } from '../../../services/dialog/dialog.service';

export interface Action {
Value: string;
Expand All @@ -23,7 +24,7 @@ export interface Action {
standalone: false
})
export class AdminUserSearchComponent implements OnInit, AfterViewInit {
public displayedColumns: string[] = ['name', 'roleName'];
public displayedColumns: string[] = ['name', 'roleName', 'actions'];
public filterString: string;

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

constructor(
private userService: UserService,
private rolesService: RolesService
private rolesService: RolesService,
private dialogService: DialogService
) {}

/**
Expand Down Expand Up @@ -110,4 +112,28 @@ export class AdminUserSearchComponent implements OnInit, AfterViewInit {
this.isLoading = false;
});
}

/**
* Deletes a user after confirmation
* @param user The user to delete
*/
deleteUser(user: User) {
this.dialogService
.confirm(
'Delete User?',
`Are you sure you want to delete ${user.name || user.id}?`,
{
buttonTrueText: 'Delete',
buttonFalseText: 'Cancel',
}
)
.subscribe((result) => {
if (result.confirm) {
this.userService.deleteUser(user.id).subscribe(() => {
// Refresh the users list after successful deletion
this.refreshUsers();
});
}
});
}
}
Loading