[frontend] Add warning dialog to telegram delete

This commit is contained in:
Cathy Hu 2020-09-01 16:15:24 +02:00
parent d8ae3ff693
commit c8d439f019
6 changed files with 65 additions and 6 deletions

View file

@ -4,6 +4,7 @@ import { Observer, Observable } from 'rxjs';
import { TelegramInfoDialogComponent } from '../telegram-info-dialog/telegram-info-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { TelegramDialogComponent } from '../telegram-dialog/telegram-dialog.component';
import { YesNoDialogComponent } from 'src/app/shared/yes-no-dialog/yes-no-dialog.component';
@Component({
selector: 'app-telegram-settings',
@ -32,11 +33,23 @@ export class TelegramSettingsComponent implements OnInit {
}
onDelete(telegramId) {
this.telegramService
.deleteTelegram(telegramId, this.hoodId)
.subscribe(() => {
this.reload();
});
const dialogRef = this.dialog.open(YesNoDialogComponent, {
data: {
title: 'Warning',
content:
'This will also delete the list of subscribers of the telegram bot.',
},
});
dialogRef.afterClosed().subscribe((response) => {
if (response) {
this.telegramService
.deleteTelegram(telegramId, this.hoodId)
.subscribe(() => {
this.reload();
});
}
});
}
onCreate() {

View file

@ -6,9 +6,10 @@ import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { Ng2SearchPipeModule } from 'ng2-search-filter';
import { YesNoDialogComponent } from './yes-no-dialog/yes-no-dialog.component';
@NgModule({
declarations: [ToolbarComponent, NotFoundComponent],
declarations: [ToolbarComponent, NotFoundComponent, YesNoDialogComponent],
imports: [
MaterialModule,
ReactiveFormsModule,

View file

@ -0,0 +1,8 @@
<h2 mat-dialog-title>{{ data.title }}</h2>
<mat-dialog-content>{{ data.content }}</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Back</button>
<button mat-button [mat-dialog-close]="true" cdkFocusInitial>
I understand, delete
</button>
</mat-dialog-actions>

View file

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

View file

@ -0,0 +1,13 @@
import { Component, OnInit, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
@Component({
selector: 'app-yes-no-dialog',
templateUrl: './yes-no-dialog.component.html',
styleUrls: ['./yes-no-dialog.component.scss'],
})
export class YesNoDialogComponent implements OnInit {
constructor(@Inject(MAT_DIALOG_DATA) public data) {}
ngOnInit(): void {}
}