[feat] - add delete user

This commit is contained in:
2024-08-21 16:46:55 +07:00
parent 3cc3d72eb5
commit fbf5b5d2e6
5 changed files with 26 additions and 6 deletions

View File

@@ -1,3 +1,3 @@
<app-user-list [userList]="userList$ | async" (edit)="edit($event)">
<app-user-list [userList]="userList$ | async" (edit)="edit($event)" (OnDeleteUser)="onDeleteUser($event)">
</app-user-list>

View File

@@ -19,10 +19,11 @@ export class UsersContainer {
constructor(
private sathonSV: SathonCathayPayService,
private dialog: MatDialog,
private appService: AppService,
private appSV: AppService,
private cdr: ChangeDetectorRef
) {
this.userList$ = this.sathonSV.getAllUsers()
}
@@ -38,4 +39,19 @@ export class UsersContainer {
})
).subscribe()
}
onDeleteUser(user) {
this.appSV.confirm(EAction.DELETE).pipe(
filter(r => r.isConfirmed),
switchMap(() => this.sathonSV.deleteUser(user.id)),
tap(() => {
this.userList$ = this.sathonSV.getAllUsers()
this.cdr.detectChanges()
}),
catchError(err => {
this.appSV.message('error', 'เกิดข้อผิดพลาด')
return throwError(err)
})
).subscribe()
}
}

View File

@@ -57,6 +57,7 @@
<div class="action flex justify-center">
<div class="item cursor-pointer">
<i class="bi bi-pencil-square icon-edit mr-2" (click)="onEdit(item)"></i>
<i class="bi bi-trash3 icon-delete mr-2" (click)="onDeleteUser(item)"></i>
</div>
</div>
</td>

View File

@@ -11,7 +11,7 @@ export class UserListComponent extends BaseList implements OnChanges {
@Input() userList: any = [];
@Output() edit = new EventEmitter();
@Output() search = new EventEmitter();
@Output() OnDelete = new EventEmitter<string>()
@Output() OnDeleteUser = new EventEmitter<string>()
query = {
name: null,
card: null
@@ -34,9 +34,8 @@ export class UserListComponent extends BaseList implements OnChanges {
this.edit.emit(user)
}
onDeleteKyc(uid: string) {
// console.log(uid)
this.OnDelete.emit(uid)
onDeleteUser(uid: string) {
this.OnDeleteUser.emit(uid)
}
onFilterCard($event) {

View File

@@ -16,6 +16,10 @@ export class SathonCathayPayService {
return this.http.get<[]>(`${this.endpoint}/v1/user`).pipe(map((d: any) => d.data))
}
deleteUser(userId) {
return this.http.delete<[]>(`${this.endpoint}/v1/user/${userId}`)
}
lockUnlockUser(id: string): Observable<any> {