-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-editor-dialog.component.ts
More file actions
82 lines (75 loc) · 2.48 KB
/
email-editor-dialog.component.ts
File metadata and controls
82 lines (75 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// email-editor-dialog.component.ts
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-email-editor-dialog',
template: `
<h2 mat-dialog-title>Email Editor</h2>
<mat-dialog-content>
<form [formGroup]="emailForm" class="email-form">
<mat-form-field appearance="fill" class="full-width">
<mat-label>To</mat-label>
<input matInput formControlName="to" placeholder="recipient@example.com">
<mat-error *ngIf="emailForm.get('to')?.hasError('email')">
Please enter a valid email address
</mat-error>
</mat-form-field>
<mat-form-field appearance="fill" class="full-width">
<mat-label>Subject</mat-label>
<input matInput formControlName="subject">
</mat-form-field>
<mat-form-field appearance="fill" class="full-width">
<mat-label>Message</mat-label>
<textarea matInput formControlName="body" rows="5"></textarea>
</mat-form-field>
</form>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button (click)="onCancel()">Cancel</button>
<button mat-raised-button color="primary"
[disabled]="!emailForm.valid"
(click)="onSend()">Send</button>
</mat-dialog-actions>
`,
styles: [`
.email-form {
display: flex;
flex-direction: column;
min-width: 300px;
}
.full-width {
width: 100%;
margin-bottom: 15px;
}
`]
})
export class EmailEditorDialogComponent {
emailForm: FormGroup;
constructor(
public dialogRef: MatDialogRef<EmailEditorDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: { rowData: any },
private fb: FormBuilder
) {
this.emailForm = this.fb.group({
to: ['', [Validators.required, Validators.email]],
subject: ['', Validators.required],
body: ['', Validators.required]
});
// Pre-populate form with row data if available
if (data?.rowData) {
this.emailForm.patchValue({
subject: `Regarding Item ${data.rowData.id}`,
body: `Hello,\n\nThis email is regarding ${data.rowData.description} with value ${data.rowData.value}.\n\nRegards,`
});
}
}
onCancel(): void {
this.dialogRef.close();
}
onSend(): void {
if (this.emailForm.valid) {
this.dialogRef.close(this.emailForm.value);
}
}
}