[feat] - add delete kyc

This commit is contained in:
2024-08-13 17:14:28 +07:00
parent 288beac65d
commit 57b9371d2a
4 changed files with 196 additions and 164 deletions

View File

@@ -1,4 +1,2 @@
<app-list
(edit)="edit($event)"
[kycList]="kyc$ | async">
<app-list (edit)="edit($event)" (OnDelete)="onDelete($event)" [kycList]="kyc$ | async">
</app-list>

View File

@@ -1,5 +1,5 @@
import { ChangeDetectorRef, Component } from '@angular/core';
import { Observable, catchError, switchMap, tap, throwError } from 'rxjs';
import { Observable, catchError, concatMap, filter, switchMap, tap, throwError } from 'rxjs';
import { IDialogConfig, CDialogConfig } from 'src/app/@common/interface/Dialog';
import { EAction, EText } from 'src/app/@config/app';
import { KycService } from 'src/app/core/service/common/kyc.service';
@@ -7,6 +7,8 @@ import { DialogComponent } from '../../presenter/dialog/dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { AppService } from 'src/app/app.service';
@Component({
selector: 'app-kyc',
templateUrl: './kyc.container.html',
@@ -24,13 +26,13 @@ export class KycContainer {
this.kyc$ = this.kycService.getAll();
}
edit(uid){
edit(uid) {
this.dialogConfig.data.action = EAction.UPDATE;
this.dialogConfig.data.ids = uid
const dialogRef = this.dialog.open(DialogComponent,this.dialogConfig);
const dialogRef = this.dialog.open(DialogComponent, this.dialogConfig);
const edit$ = dialogRef.afterClosed().pipe(
switchMap((res) => {
if(res === 'success'){
if (res === 'success') {
return this.kyc$ = this.kycService.getAll().pipe(
catchError((err) => {
this.appService.message(EAction.ERROR, EText.ERROR);
@@ -43,4 +45,28 @@ export class KycContainer {
);
return edit$.subscribe();
}
onDelete(uid) {
// console.log(uid)
this.appService.confirm(
EAction.DELETE
).pipe(
filter(event => event.isConfirmed),
switchMap(event => {
return this.kycService.deleteData(uid).pipe(
concatMap(() => {
return this.kyc$ = this.kycService.getAll().pipe(
catchError((err) => {
this.appService.message(EAction.ERROR, EText.ERROR);
return throwError(() => err)
}),
tap(() => this.cdr.detectChanges())
)
})
)
})
).subscribe()
}
}

View File

@@ -5,7 +5,8 @@
<div class="col-span-3 md:col-span-5 md:order-2">
<mat-form-field>
<i matTextPrefix class="bi bi-search"></i>
<input matInput placeholder="เลขบัตรประชาชน/เลขหลังบัตร" [(ngModel)]="query.card" (ngModelChange)="onFilterCard($event)">
<input matInput placeholder="เลขบัตรประชาชน/เลขหลังบัตร" [(ngModel)]="query.card"
(ngModelChange)="onFilterCard($event)">
</mat-form-field>
</div>
<div class="col-span-5 md:col-span-7 md:order-2">
@@ -86,6 +87,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.kyc_uid)"></i>
<i class="bi bi-trash3 icon-delete mr-2" (click)="onDeleteKyc(item.kyc_uid)"></i>
</div>
</div>
</td>

View File

@@ -11,6 +11,7 @@ export class ListComponent extends BaseList implements OnChanges {
@Input() kycList: any = [];
@Output() edit = new EventEmitter();
@Output() search = new EventEmitter();
@Output() OnDelete = new EventEmitter<string>()
query = {
name: null,
card: null
@@ -26,24 +27,29 @@ export class ListComponent extends BaseList implements OnChanges {
}
ngOnChanges(): void {
this.kycList = this.updateMatTable(this.kycList? this.kycList:[])
this.kycList = this.updateMatTable(this.kycList ? this.kycList : [])
}
onEdit(uid){
onEdit(uid) {
this.edit.emit(uid)
}
onDeleteKyc(uid: string) {
// console.log(uid)
this.OnDelete.emit(uid)
}
onFilterCard($event) {
const filterValue = this.query.card;
this.kycList.filter = filterValue.trim().toLowerCase();
}
onFilterName($event){
onFilterName($event) {
const filterValue = this.query.name;
this.kycList.filter = filterValue.trim().toLowerCase();
}
onSearch(){
onSearch() {
const filterValue = this.query.card;
this.kycList.filter = filterValue.trim().toLowerCase();
}