Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#803delete teacher guard #878

Merged
merged 4 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/shared/enum/modal-confirmation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum ModalConfirmationType {
delete = 'delete',
deleteTeacher = 'deleteTeacher',
leaveWorkshop = 'leaveWorkshop',
deleteChild = 'deleteChild',
leavePage = 'leavePage',
Expand All @@ -11,6 +12,7 @@ export enum ModalConfirmationType {
export enum ModalConfirmationTitle {
delete = 'ВИДАЛИТИ ГУРТОК',
deleteChild = 'ВИЛУЧИТИ ДАНІ ПРО ДИТИНУ?',
deleteTeacher = 'ВИЛУЧИТИ ДАНІ ПРО ВЧИТЕЛЯ',
leaveWorkshop = 'ЗАЛИШИТИ ГУРТОК?',
leavePage = 'ЗАЛИШИТИ СТОРІНКУ?',
createApplication = 'ПОДАТИ ЗАЯВКУ?',
Expand All @@ -21,6 +23,7 @@ export enum ModalConfirmationTitle {
export enum ModalConfirmationText {
delete = 'Ви впевнені, що хочете видалити гурток',
deleteChild = 'Ви впевнені, що хочете вилучити дані про дитину',
deleteTeacher = 'Ви впевнені, що хочете вилучити дані про вчителя ?',
leaveWorkshop = 'Ви впевнені, що хочете залишити гурток',
leavePage = 'Ви впевнені, що хочете залишити сторінку?',
rate = 'Поставте будь ласка оцінку цьому гуртку',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</mat-form-field>

<div fxLayout='row' fxLayoutAlign='center' *ngIf="childrenAmount > 1" class="addChild">
<button class="btn-reset" type="reset" mat-button (click)="delete()">
<button class="btn-reset" mat-button (click)="delete()">
<mat-icon class="mat-icon-delete">delete</mat-icon>Вилучити дані про дитину
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('CreateChildComponent', () => {
MatIconModule,
RouterTestingModule,
HttpClientTestingModule,
MatCheckboxModule
MatCheckboxModule,
MatDialogModule
],
declarations: [
CreateChildComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { CreateChildren, UpdateChild } from 'src/app/shared/store/user.actions';
import { TEXT_REGEX, TEXT_WITH_DIGITS_REGEX } from 'src/app/shared/constants/regex-constants';
import { Constants } from 'src/app/shared/constants/constants';
import { CreateFormComponent } from '../../create-form/create-form.component';
import { MatDialog } from '@angular/material/dialog';
import { ConfirmationModalWindowComponent } from 'src/app/shared/components/confirmation-modal-window/confirmation-modal-window.component';
import { ModalConfirmationType } from 'src/app/shared/enum/modal-confirmation';

@Component({
selector: 'app-create-child',
Expand All @@ -40,7 +43,8 @@ export class CreateChildComponent extends CreateFormComponent implements OnInit,
private fb: FormBuilder,
store: Store,
route: ActivatedRoute,
navigationBarService: NavigationBarService) {
navigationBarService: NavigationBarService,
private matDialog: MatDialog) {
super(store, route, navigationBarService);
}

Expand Down Expand Up @@ -146,9 +150,26 @@ export class CreateChildComponent extends CreateFormComponent implements OnInit,
* @param index
*/
onDeleteForm(index: number): void {
this.ChildrenFormArray.removeAt(index);
const status: string = this.ChildrenFormArray.controls[index].status;
const isTouched: boolean = this.ChildrenFormArray.controls[index].touched;

if(status !== 'INVALID' || isTouched) {
const dialogRef = this.matDialog.open(ConfirmationModalWindowComponent, {
width: '330px',
data: {
type: ModalConfirmationType.deleteChild,
property: ''
}
});

dialogRef.afterClosed().subscribe((result: boolean) => {
result && this.ChildrenFormArray.removeAt(index);;
});
} else {
this.ChildrenFormArray.removeAt(index);
}
}

/**
* This method create or edit Child and distpatch CreateChild action
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { Component, Input } from '@angular/core';
import { MatGridListModule } from '@angular/material/grid-list';
import { MatDialogModule } from '@angular/material/dialog';

describe('CreateTeacherComponent', () => {
let component: CreateTeacherComponent;
Expand All @@ -16,7 +17,8 @@ describe('CreateTeacherComponent', () => {
MatFormFieldModule,
ReactiveFormsModule,
MatIconModule,
MatGridListModule
MatGridListModule,
MatDialogModule
],
declarations: [
CreateTeacherComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Teacher } from 'src/app/shared/models/teacher.model';
import { TEXT_REGEX } from 'src/app/shared/constants/regex-constants'
import { MatDialog } from '@angular/material/dialog';
import { ConfirmationModalWindowComponent } from 'src/app/shared/components/confirmation-modal-window/confirmation-modal-window.component';
import { ModalConfirmationType } from 'src/app/shared/enum/modal-confirmation';


@Component({
Expand All @@ -15,7 +18,7 @@ export class CreateTeacherComponent implements OnInit {
@Input() teachers: Teacher[];
@Output() passTeacherFormArray = new EventEmitter();

constructor(private fb: FormBuilder) { }
constructor(private fb: FormBuilder, private matDialog: MatDialog) { }

ngOnInit(): void {
if (this.teachers?.length) {
Expand Down Expand Up @@ -56,6 +59,25 @@ export class CreateTeacherComponent implements OnInit {
* @param index: number
*/
onDeleteForm(index: number): void {
this.TeacherFormArray.removeAt(index);
const status: string = this.TeacherFormArray.controls[index].status;
const isTouched: boolean = this.TeacherFormArray.controls[index].touched;

if(status !== 'INVALID' || isTouched) {
const dialogRef = this.matDialog.open(ConfirmationModalWindowComponent, {
width: '330px',
data: {
type: ModalConfirmationType.deleteTeacher,
property: ''
}
});

dialogRef.afterClosed().subscribe((result: boolean) => {
result && this.TeacherFormArray.removeAt(index);
});
}
else {
this.TeacherFormArray.removeAt(index);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</app-validation-hint-for-input>

<div fxLayout='row' fxLayoutAlign='center' *ngIf="teacherAmount > 1">
<button class=" btn-reset" type="reset" mat-button (click)="onDeleteTeacher()">
<button class=" btn-reset" mat-button (click)="onDeleteTeacher()">
<mat-icon class="mat-icon-delete">delete</mat-icon>Вилучити дані про викладача
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Output, EventEmitter } from '@angular/core';
import { emit } from 'process';
import { Constants } from 'src/app/shared/constants/constants';

@Component({
Expand Down