/** * Copyright since 2025 Mifos Initiative * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { Component, inject } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef, MatDialogTitle, MatDialogContent, MatDialogActions } from '@angular/material/dialog'; import { MatButton } from '@angular/material/button'; import { MatFormField, MatLabel, MatError } from '@angular/material/form-field'; import { MatInput } from '@angular/material/input'; import { MatProgressSpinner } from '@angular/material/progress-spinner'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; import { DscService } from '../dsc.service'; import { BankUserDsc } from '../dsc.model'; interface RevokeDialogData { dsc: BankUserDsc; } @Component({ selector: 'mifosx-revoke-dsc-dialog', templateUrl: './revoke-dsc-dialog.component.html', styleUrls: ['./revoke-dsc-dialog.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, FormsModule, MatDialogTitle, MatDialogContent, MatDialogActions, MatButton, MatFormField, MatLabel, MatError, MatInput, MatProgressSpinner, FaIconComponent ] }) export class RevokeDscDialogComponent { private service = inject(DscService); private dialogRef = inject(MatDialogRef); data = inject(MAT_DIALOG_DATA); reason = ''; submitting = false; errorMessage = ''; cancel(): void { this.dialogRef.close({ revoked: false }); } confirm(): void { if (!this.reason?.trim() || !this.data?.dsc?.id) return; this.submitting = true; this.errorMessage = ''; this.service.revokeDsc(this.data.dsc.id, this.reason.trim()).subscribe({ next: () => { this.submitting = false; this.dialogRef.close({ revoked: true }); }, error: (err) => { this.submitting = false; this.errorMessage = err?.error?.defaultUserMessage || err?.error?.message || err?.message || 'Could not revoke DSC.'; } }); } }