Components: add delete-modal
This commit is contained in:
parent
353fec9fe0
commit
f4c344633a
4 changed files with 100 additions and 0 deletions
0
src/components/delete-modal/delete-modal.component.css
Normal file
0
src/components/delete-modal/delete-modal.component.css
Normal file
25
src/components/delete-modal/delete-modal.component.html
Normal file
25
src/components/delete-modal/delete-modal.component.html
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title text-truncate">Delete {{ showName }}?</h4>
|
||||||
|
<button type="button" class="btn-close" aria-label="Close" (click)="this.activeModal.dismiss()"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>Are you sure you want to delete this show?</p>
|
||||||
|
<b class="text-danger-emphasis">This cannot be reversed</b>
|
||||||
|
<div class="card" #collapse="ngbCollapse" [(ngbCollapse)]="formHidden">
|
||||||
|
<div class="card-body">
|
||||||
|
<form [formGroup]="confirmationForm" (ngSubmit)="formSubmitted()">
|
||||||
|
<label class="form-label">To avoid mistakes, please type the name of the show to continue:</label>
|
||||||
|
<input formControlName="name" type="text" class="form-control">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-danger"
|
||||||
|
(click)="deletePressed()"
|
||||||
|
[disabled]="confirmationForm.invalid && buttonDisabled"
|
||||||
|
>Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
23
src/components/delete-modal/delete-modal.component.spec.ts
Normal file
23
src/components/delete-modal/delete-modal.component.spec.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { DeleteModalComponent } from './delete-modal.component';
|
||||||
|
|
||||||
|
describe('DeleteModalComponent', () => {
|
||||||
|
let component: DeleteModalComponent;
|
||||||
|
let fixture: ComponentFixture<DeleteModalComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [DeleteModalComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(DeleteModalComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
52
src/components/delete-modal/delete-modal.component.ts
Normal file
52
src/components/delete-modal/delete-modal.component.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import {Component, inject} from '@angular/core';
|
||||||
|
import {NgbActiveModal, NgbCollapse} from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormGroup,
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
Validators
|
||||||
|
} from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-delete-modal',
|
||||||
|
imports: [
|
||||||
|
NgbCollapse,
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule
|
||||||
|
],
|
||||||
|
templateUrl: './delete-modal.component.html',
|
||||||
|
styleUrl: './delete-modal.component.css'
|
||||||
|
})
|
||||||
|
export class DeleteModalComponent {
|
||||||
|
protected activeModal: NgbActiveModal = inject(NgbActiveModal)
|
||||||
|
showName: string = ""
|
||||||
|
formHidden: boolean = true;
|
||||||
|
buttonDisabled: boolean = false;
|
||||||
|
confirmationForm: FormGroup
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.confirmationForm = new FormGroup({
|
||||||
|
name: new FormControl("",Validators.required)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
deletePressed() {
|
||||||
|
if (this.formHidden) {
|
||||||
|
const regex = new RegExp(this.showName)
|
||||||
|
const control = new FormControl("", [Validators.required, Validators.pattern(regex)])
|
||||||
|
this.confirmationForm.setControl("name", control)
|
||||||
|
this.formHidden = false;
|
||||||
|
this.buttonDisabled = true;
|
||||||
|
} else {
|
||||||
|
this.formSubmitted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formSubmitted() {
|
||||||
|
if (this.confirmationForm.valid) {
|
||||||
|
this.activeModal.close(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue