Files
we_bstly-web/src/app/pages/account/voucher/voucher.component.ts
T
2025-05-11 18:05:06 +02:00

68 lines
1.8 KiB
TypeScript

import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatTableDataSource } from '@angular/material/table';
import { QuotaService } from './../../../services/quota.service';
import { VoucherService } from './../../../services/voucher.service';
@Component({
standalone: false,
selector: 'app-account-voucher',
templateUrl: './voucher.component.html',
styleUrls: ['./voucher.component.scss']
})
export class VoucherComponent implements OnInit {
public hasRegistration: boolean = false;
model: any = {};
available = [];
vouchers = [];
voucherSource = new MatTableDataSource<any>();
voucherColumns = ['type', 'code'];
constructor(private voucherService: VoucherService, private quotaService: QuotaService, public dialog: MatDialog) { }
ngOnInit(): void {
this.voucherSource.data = this.vouchers;
this.voucherService.get().subscribe({
next: (data: any) => {
this.available = data;
}
})
}
create(name: string) {
this.voucherService.create(name).toPromise().then(data => {
this.model.type = name;
this.model.code = data;
this.vouchers.push(this.model);
this.voucherSource.data = this.vouchers;
const dialogRef = this.dialog.open(VoucherDialog, {
closeOnNavigation: false,
disableClose: true,
data: this.model
});
}, error => {
})
}
}
@Component({
standalone: false,
selector: 'app-voucher-dialog',
templateUrl: 'voucher.dialog.html',
styleUrls: ['./voucher.dialog.scss']
})
export class VoucherDialog {
constructor(public dialogRef: MatDialogRef<VoucherDialog>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
onOkClick(): void {
this.dialogRef.close();
}
}