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

Add default values to test email form in setting-management module #18318

Merged
merged 1 commit into from
Dec 5, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ <h2>{{ 'AbpSettingManagement::Menu:Emailing' | abpLocalization }}</h2>

<hr class="my-3" />

<form *ngIf="form" [formGroup]="form" class="abp-md-form" (ngSubmit)="submit()" [validateOnSubmit]="true">
<form
*ngIf="form"
[formGroup]="form"
class="abp-md-form"
(ngSubmit)="submit()"
[validateOnSubmit]="true"
>
<div class="mb-3 form-group">
<label class="form-label"
>{{ 'AbpSettingManagement::DefaultFromDisplayName' | abpLocalization
Expand Down Expand Up @@ -79,10 +85,10 @@ <h2>{{ 'AbpSettingManagement::Menu:Emailing' | abpLocalization }}</h2>
{{ 'AbpSettingManagement::Save' | abpLocalization }}
</button>
<button
*abpPermission="emailingPolicy"
type="button"
(click)="openSendEmailModal()"
class="btn btn-primary mx-2"
*abpPermission="emailingPolicy"
>
<i class="fa f-send" aria-hidden="true"></i>
{{ 'AbpSettingManagement::SendTestEmail' | abpLocalization }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import { NgbModalOptions } from '@ng-bootstrap/ng-bootstrap';
import { collapse, ToasterService } from '@abp/ng.theme.shared';
import { Component, OnInit } from '@angular/core';
import { Component, inject, OnInit } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { finalize } from 'rxjs/operators';
import { SettingManagementPolicyNames } from '../../enums/policy-names';
import { EmailSettingsService } from '@abp/ng.setting-management/proxy';
import { EmailSettingsDto } from '../../proxy/models';
import { ConfigStateService, LocalizationService } from '@abp/ng.core';

const { required, email } = Validators;

@Component({
selector: 'abp-email-setting-group',
templateUrl: 'email-setting-group.component.html',
animations: [collapse],
})
export class EmailSettingGroupComponent implements OnInit {
protected readonly localizationService = inject(LocalizationService);
protected readonly configStateSevice = inject(ConfigStateService);
protected readonly currentUserEmail = toSignal(
this.configStateSevice.getDeep$(['currentUser', 'email']),
);

form!: UntypedFormGroup;
emailTestForm: UntypedFormGroup;
saving = false;
emailingPolicy = SettingManagementPolicyNames.Emailing;
isEmailTestModalOpen = false;
modalSize:NgbModalOptions= { size:"lg"}
modalSize: NgbModalOptions = { size: 'lg' };

constructor(
private emailSettingsService: EmailSettingsService,
Expand Down Expand Up @@ -62,30 +72,36 @@ export class EmailSettingGroupComponent implements OnInit {
this.getData();
});
}

openSendEmailModal() {
this.buildEmailTestForm();
this.isEmailTestModalOpen = true;
}

buildEmailTestForm() {
const { defaultFromAddress } = this.form.value || {};
const defaultSubject = this.localizationService.instant(
'AbpSettingManagement::TestEmailSubject',
...[Math.floor(Math.random() * 9999).toString()],
);
const defaultBody = this.localizationService.instant('AbpSettingManagement::TestEmailBody');

this.emailTestForm = this.fb.group({
senderEmailAddress: ['', [Validators.required, Validators.email]],
targetEmailAddress: ['', [Validators.required, Validators.email]],
subject: ['', [Validators.required]],
body: [''],
senderEmailAddress: [defaultFromAddress || '', [required, email]],
targetEmailAddress: [this.currentUserEmail(), [required, email]],
subject: [defaultSubject, [required]],
body: [defaultBody],
});
}

emailTestFormSubmit() {

if(this.emailTestForm.invalid){
if (this.emailTestForm.invalid) {
return;
}
this.emailSettingsService.sendTestEmail(this.emailTestForm.value).subscribe(res => {

this.emailSettingsService.sendTestEmail(this.emailTestForm.value).subscribe(res => {
this.toasterService.success('AbpSettingManagement::SuccessfullySent');
this.isEmailTestModalOpen = false;
})

});
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export const enum SettingManagementPolicyNames {
Emailing = 'SettingManagement.Emailing',
}

}
Loading