import { Component, Inject, OnInit } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef, MatDialog, } from '@angular/material/dialog'; import { FormGroup, } from '@angular/forms'; import { ToastrService } from 'ngx-toastr'; import { DataService } from 'src/app/common/services/data.service'; import { FormService } from '../form.service'; import { GoalPlanAdd } from '../../goal-plan-inventory/add-goal-plan/goal-plan-add.model'; @Component({ selector: 'app-form-dialog', templateUrl: './form-dialog.component.html', styleUrls: ['./form-dialog.component.css'], }) export class FormDialogComponent implements OnInit { data: any = new GoalPlanAdd(); updatedDate = new Date(); userEmail: string; isEdited = false; isDisabled = false; form = new FormGroup({ }); constructor( private formService: FormService, public dialogRef: MatDialogRef, private toastr: ToastrService, private dataService: DataService, private dialog: MatDialog, @Inject(MAT_DIALOG_DATA) public value: any ) { this.data = value; } ngOnInit(): void { this.dataService.email.subscribe((email) => { this.userEmail = email; }); } // convenience getter for easy access to form fields get f() { return this.form.controls; } close() { this.dialogRef.close(); } update(form) { form.FormName = form.FormName.trim(); // stop here if form is invalid if (this.form.invalid) { return; } else { this.isDisabled = true; this.formService .updateForm(form, this.data.Id) .subscribe((data) => { this.dialogRef.close(data); this.toastr.success('Form Updated Successfully'); }); } } }