Browse Source

transferState added to setting management

feature/ssr-migration-schematic
erdemcaygor 1 year ago
parent
commit
5f2f131dee
  1. 21
      npm/ng-packs/packages/setting-management/config/src/lib/components/email-setting-group/email-setting-group.component.ts

21
npm/ng-packs/packages/setting-management/config/src/lib/components/email-setting-group/email-setting-group.component.ts

@ -6,7 +6,7 @@ import {
ModalComponent,
ToasterService,
} from '@abp/ng.theme.shared';
import { Component, inject, OnInit } from '@angular/core';
import { Component, inject, makeStateKey, OnInit, TransferState } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import {
ReactiveFormsModule,
@ -23,6 +23,7 @@ import {
LocalizationPipe,
LocalizationService,
PermissionDirective,
SSRService,
} from '@abp/ng.core';
import { NgxValidateCoreModule } from '@ngx-validate/core';
import { CommonModule } from '@angular/common';
@ -47,6 +48,7 @@ const { required, email } = Validators;
export class EmailSettingGroupComponent implements OnInit {
protected readonly localizationService = inject(LocalizationService);
protected readonly configStateSevice = inject(ConfigStateService);
protected readonly ssrService = inject(SSRService);
protected readonly currentUserEmail = toSignal(
this.configStateSevice.getDeep$(['currentUser', 'email']),
);
@ -57,11 +59,13 @@ export class EmailSettingGroupComponent implements OnInit {
emailingPolicy = SettingManagementPolicyNames.Emailing;
isEmailTestModalOpen = false;
modalSize: NgbModalOptions = { size: 'lg' };
EMAIL_SETTINGS_KEY = makeStateKey<any>('emailSettings');
constructor(
private emailSettingsService: EmailSettingsService,
private fb: UntypedFormBuilder,
private toasterService: ToasterService,
private transferState: TransferState,
) {}
ngOnInit() {
@ -69,9 +73,18 @@ export class EmailSettingGroupComponent implements OnInit {
}
private getData() {
this.emailSettingsService.get().subscribe(res => {
this.buildForm(res);
});
if (this.transferState.hasKey(this.EMAIL_SETTINGS_KEY)) {
const emailSettings = this.transferState.get<EmailSettingsDto>(this.EMAIL_SETTINGS_KEY, null);
this.buildForm(emailSettings);
this.transferState.remove(this.EMAIL_SETTINGS_KEY);
} else {
this.emailSettingsService.get().subscribe(res => {
this.buildForm(res);
if (this.ssrService.isSsr) {
this.transferState.set(this.EMAIL_SETTINGS_KEY, res);
}
});
}
}
private buildForm(emailSettings: EmailSettingsDto) {

Loading…
Cancel
Save