[feat] - add user lsit , convert to coop and lock unlock user

This commit is contained in:
2024-08-19 17:05:10 +07:00
parent 57b9371d2a
commit 3cc3d72eb5
24 changed files with 617 additions and 91 deletions

View File

@@ -0,0 +1,80 @@
<form class="dialog-main form-dialog" autocomplete="off">
<div class="dialog-main">
<div class="dialog-header flex justify-between">
<h2>More Detail</h2>
<mat-icon mat-dialog-close class="cursor-pointer">clear</mat-icon>
</div>
<div class="dialog-body">
<div class="grid grid-cols-12 gap-4 md:gap-2 ">
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label
class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">เลขประจำตัวประชาชน</mat-label>
<mat-form-field class="col-span-3">
<input matInput required type="text" [value]="dialog?.personalCardId" readonly>
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">ชื่อ นามสกุล</mat-label>
<mat-form-field class="col-span-3">
<input matInput required type="text" readonly [value]="dialog?.fullName">
</mat-form-field>
<span class="col-span-5"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">Username</mat-label>
<mat-form-field class="col-span-3">
<input matInput required type="text" readonly [value]="dialog?.userName">
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">เบอร์โทร</mat-label>
<mat-form-field class="col-span-3">
<input matInput required type="text" readonly [value]="dialog?.phoneNumber">
</mat-form-field>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">อีเมล</mat-label>
<mat-form-field class="col-span-3">
<input matInput required type="text" readonly [value]="dialog?.normalizedEmail">
</mat-form-field>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">Lock/Unlock</mat-label>
<mat-slide-toggle [checked]="dialog.lockoutEnabled" (change)="changeUserLock($event)"></mat-slide-toggle>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4"></mat-label>
<button type="submit" mat-raised-button class="btn btn-submit" (click)="save()">บันทึก</button>
</div>
</div>
</div>
</div>
</div>
</form>
<!-- <pre>{{form.getRawValue() | json}}</pre> -->

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ModalComponent } from './modal.component';
describe('ModalComponent', () => {
let component: ModalComponent;
let fixture: ComponentFixture<ModalComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ModalComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(ModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,70 @@
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Router, ActivatedRoute } from '@angular/router';
import { tap, catchError, throwError, lastValueFrom, filter, switchMap } from 'rxjs';
import { IDialogConfigData } from 'src/app/@common/interface/Dialog';
import { EAction, EText } from 'src/app/@config/app';
import { AppService } from 'src/app/app.service';
import { BaseForm } from 'src/app/core/base/base-form';
import { PromotionService } from 'src/app/core/service/common/promotion.service';
import { UploadService } from 'src/app/core/service/common/upload.service';
import { DialogComponent } from '../../../kyc/presenter/dialog/dialog.component';
import { Location } from '@angular/common';
import { SathonCathayPayService } from 'src/app/sathon-cathay-pay.service';
@Component({
selector: 'app-modal',
templateUrl: './modal.component.html',
styleUrls: ['./modal.component.scss']
})
export class ModalComponent implements OnInit {
IsRefresh: boolean = false
constructor(
public dialogRef: MatDialogRef<DialogComponent>,
@Inject(MAT_DIALOG_DATA) public dialog: any,
private sathonSV: SathonCathayPayService,
private appsv: AppService
) { }
ngOnInit(): void {
}
changeUserLock({ checked },) {
let userId = this.dialog.id
console.log(checked)
const msg = checked ? 'Unlock' : 'Lock'
this.sathonSV.lockUnlockUser(userId).pipe(
tap(event => {
this.appsv.message(EAction.SUCCESS, `${msg} สำเร็จแล้ว`)
this.IsRefresh = true
}),
tap(() => this.closeDialog()),
catchError(err => {
this.IsRefresh = false
return throwError(err)
})
).subscribe()
}
save() {
let userId = this.dialog.id
this.appsv.confirm(EAction.UPDATE).pipe(
filter(r => r.isConfirmed),
switchMap(() => this.sathonSV.convertToCoperate(userId)),
tap(() => this.IsRefresh = true),
tap(() => this.closeDialog()),
catchError(err => {
this.IsRefresh = false
this.appsv.message('error', 'เกิดข้อผิดพลาด')
return throwError(err)
})
).subscribe()
// this.sathonSV.convertToCoperate(userId).subscribe()
}
closeDialog() {
this.dialogRef.close(this.IsRefresh)
}
}