Merge pull request #18318 from abpframework/issue-18314

Add default values to test email form in setting-management module
pull/18380/head
Masum ULU 1 year ago committed by GitHub
commit 27b65a17f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,13 @@
<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
@ -79,10 +85,10 @@
{{ '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 }}

@ -1,11 +1,15 @@
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',
@ -13,12 +17,18 @@ import { EmailSettingsDto } from '../../proxy/models';
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,
@ -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;
})
});
}
}

@ -1,4 +1,3 @@
export const enum SettingManagementPolicyNames {
Emailing = 'SettingManagement.Emailing',
}
}

Loading…
Cancel
Save