Skip to content

Commit

Permalink
refactor: migrate the confirmation-model component - updates
Browse files Browse the repository at this point in the history
  • Loading branch information
s223749059 committed May 14, 2024
1 parent 6c4434a commit 8154bee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable prettier/prettier */
/* eslint-disable @angular-eslint/component-selector */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Component, OnInit, Input, Inject} from '@angular/core';
import { alertService } from 'src/app/ajs-upgraded-providers';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { AlertService } from '../../services/alert.service';
import { MatDialogRef } from '@angular/material/dialog';

@Component({
selector: 'confirmation-modal',
Expand All @@ -13,29 +16,26 @@ export class ConfirmationModalComponent implements OnInit {
@Input() action: () => void;

constructor(
@Inject(alertService) private alertService: any,
@Inject(AlertService) private alertService: any,
public dialogRef: MatDialogRef<ConfirmationModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
) {}

ngOnInit(): void {
console.log('confirmation-model ngOnInit()');
}

public confirmAction() {
console.log('confirmAction');
if (typeof this.action === 'function') {
this.action();
} else {
this.alertService.add("danger", `${this.title} action failed`, 3000);
this.alertService.error(`${this.title} action failed.`);
}
/** note - page reload after closing **/

this.dialogRef.close();
}

public cancelAction() {
console.log('cancelAction');
this.alertService.add("info", `${this.title} action cancelled`, 3000);
this.alertService.success(`${this.title} action cancelled.`);
this.dialogRef.close();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable prefer-const */
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Injectable } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog';
import { MatDialogRef, MatDialog } from '@angular/material/dialog';
import { ConfirmationModalComponent } from './confirmation-modal.component';

@Injectable({
Expand All @@ -11,7 +14,7 @@ export class ConfirmationModalService {
public show(title: string, message: string, action?: any) {
let dialogRef: MatDialogRef<ConfirmationModalComponent, any>;
dialogRef = this.dialog.open(ConfirmationModalComponent, {position: {top: '2.5%'}});
dialogRef.updateSize("42.5%", "");
dialogRef.updateSize('42.5%', '');
dialogRef.componentInstance.title = title;
dialogRef.componentInstance.message = message;
dialogRef.componentInstance.action = action;
Expand Down

0 comments on commit 8154bee

Please sign in to comment.