import { Component, OnInit } from '@angular/core'; import { MatDialogRef, MatSnackBar } from '@angular/material'; import { FormBuilder, FormGroup, FormControl, Validators, FormArray, AbstractControl, } from '@angular/forms'; @Component({ selector: 'cse-new-audit-options', templateUrl: './new-audit-options.component.html', styleUrls: ['./new-audit-options.component.scss'], }) export class NewAuditOptionsComponent implements OnInit { public newAuditForm: FormGroup; get formArray(): AbstractControl | null { return this.newAuditForm.get('formArray'); } constructor( private fb: FormBuilder, private dialogRef: MatDialogRef<NewAuditOptionsComponent>, private snackBar: MatSnackBar, ) {} ngOnInit() { this.newAuditForm = this.fb.group({ formArray: this.fb.array([ this.fb.group({ auditType: new FormControl(''), }), this.fb.group({ programOfStudy: new FormControl(''), academicProgram: new FormControl(''), }), this.fb.group({ honors: new FormControl(''), includeCoursesFrom: new FormControl(''), runAgainst: new FormControl(''), }), this.fb.group({ credits: new FormControl(''), }), ]), }); } public runDARSAudit() { const { auditType, programOfStudy, academicProgram, honors, includeCoursesFrom, runAgainst, credits, } = this.newAuditForm.value; this.dialogRef.close(); this.snackBar.open( 'Audit in progress. You will be notified when the audit is ready to be viewed.', ); } }