Skip to content

Commit

Permalink
Add HTML render feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tachojelev committed Jan 28, 2021
1 parent a71ca23 commit 62fae41
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/models/send-mail-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { RecipientRequest } from "./recipient-request";

export class SendMailRequest extends EmailTemplate {
recipients: Array<RecipientRequest>;
html: boolean;
}
9 changes: 7 additions & 2 deletions src/send-mail-template/email/email.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<button mat-raised-button
color="primary"
(click)="preview()"
[disabled]="!recipients?.length">
[disabled]="!recipients?.length || sending">
Preview
</button>
<button mat-raised-button
Expand All @@ -46,8 +46,13 @@
Send
</ng-container>
<ng-container *ngIf="sending">
<mat-spinner class="send-spinner" color="accent" diameter="24"></mat-spinner>
<mat-spinner class="send-spinner" color="accent" diameter="28"></mat-spinner>
</ng-container>
</button>
<mat-checkbox
required
[(ngModel)]="html">
As HTML
</mat-checkbox>
</mat-card-actions>
</mat-card>
5 changes: 5 additions & 0 deletions src/send-mail-template/email/email.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
display: flex;
flex-direction: column;
}

mat-card-actions {
display: flex;
align-items: center;
}
}

mat-form-field {
Expand Down
5 changes: 4 additions & 1 deletion src/send-mail-template/email/email.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class EmailComponent implements OnInit {
@Input()
recipients: Array<Recipient>;

html = false;

sending = false;

constructor(
Expand Down Expand Up @@ -49,8 +51,9 @@ export class EmailComponent implements OnInit {
}

send(): void {
console.log(this.html);
this.sending = true;
this.mailService.sendMail(this.emailTemplate, this.recipients).subscribe(
this.mailService.sendMail(this.emailTemplate, this.recipients, this.html).subscribe(
(response: number) => { this.handleSuccess(response); },
(response: HttpErrorResponse) => { this.handleFailure(response); }
);
Expand Down
4 changes: 3 additions & 1 deletion src/send-mail-template/send-mail-template.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MatInputModule } from '@angular/material/input';
import { MatChipsModule } from '@angular/material/chips';
import { MatDialogModule } from '@angular/material/dialog';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { EmailComponent } from './email/email.component';
import { RecipientComponent } from './recipient/recipient.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Expand All @@ -32,7 +33,8 @@ import { PreviewComponent } from './preview/preview.component';
MatChipsModule,
MatDialogModule,
MatSnackBarModule,
MatProgressSpinnerModule
MatProgressSpinnerModule,
MatCheckboxModule
]
})
export class SendMailTemplateModule { }
9 changes: 5 additions & 4 deletions src/services/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ export class MailService {

constructor(private httpClient: HttpClient) { }

sendMail(emailTemplate: EmailTemplate, recipients: Array<Recipient>): Observable<number> {
sendMail(emailTemplate: EmailTemplate, recipients: Array<Recipient>, html: boolean): Observable<number> {
const headers = new HttpHeaders().set('content-type', 'application/json');
const payload = this.buildSendMailRequest(emailTemplate, recipients);
const payload = this.buildSendMailRequest(emailTemplate, recipients, html);

return this.httpClient.post<number>(SkaikruApi.SEND_MAILS, payload, { headers });
}

previewMail(emailTemplate: EmailTemplate, recipients: Array<Recipient>): Observable<Array<PreviewRecipientEmail>> {
const headers = new HttpHeaders().set('content-type', 'application/json');
const payload = this.buildSendMailRequest(emailTemplate, recipients);
const payload = this.buildSendMailRequest(emailTemplate, recipients, false);

return this.httpClient.post<Array<PreviewRecipientEmail>>(SkaikruApi.PREVIEW_MAILS, payload, { headers });
}

private buildSendMailRequest(emailTemplate: EmailTemplate, recipients: Array<Recipient>): SendMailRequest {
private buildSendMailRequest(emailTemplate: EmailTemplate, recipients: Array<Recipient>, html: boolean): SendMailRequest {
const sendMailRequest = new SendMailRequest();
sendMailRequest.title = emailTemplate.title;
sendMailRequest.message = emailTemplate.message;
sendMailRequest.placeholders = emailTemplate.placeholders;
sendMailRequest.recipients = this.buildRecipientRequests(recipients);
sendMailRequest.html = html;

return sendMailRequest;
}
Expand Down

0 comments on commit 62fae41

Please sign in to comment.