|
|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
import { ProfileService } from '@abp/ng.account.core/proxy';
|
|
|
|
|
import { ToasterService } from '@abp/ng.theme.shared';
|
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { ProfileDto, ProfileService } from '@abp/ng.account.core/proxy';
|
|
|
|
|
import { Confirmation, ConfirmationService, ToasterService } from '@abp/ng.theme.shared';
|
|
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
|
import { finalize } from 'rxjs/operators';
|
|
|
|
|
import { finalize, filter } from 'rxjs/operators';
|
|
|
|
|
import { Account } from '../../models/account';
|
|
|
|
|
import { ManageProfileStateService } from '../../services/manage-profile.state.service';
|
|
|
|
|
import { AuthService } from '@abp/ng.core';
|
|
|
|
|
import { RE_LOGIN_CONFIRMATION_TOKEN } from '../../tokens';
|
|
|
|
|
|
|
|
|
|
const { maxLength, required, email } = Validators;
|
|
|
|
|
|
|
|
|
|
@ -22,12 +24,17 @@ export class PersonalSettingsComponent
|
|
|
|
|
form: FormGroup;
|
|
|
|
|
|
|
|
|
|
inProgress: boolean;
|
|
|
|
|
private profile: ProfileDto;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private fb: FormBuilder,
|
|
|
|
|
private toasterService: ToasterService,
|
|
|
|
|
private profileService: ProfileService,
|
|
|
|
|
private manageProfileState: ManageProfileStateService,
|
|
|
|
|
private readonly authService: AuthService,
|
|
|
|
|
private confirmationService: ConfirmationService,
|
|
|
|
|
@Inject(RE_LOGIN_CONFIRMATION_TOKEN)
|
|
|
|
|
private isPersonalSettingsChangedConfirmationActive: boolean,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
@ -35,18 +42,19 @@ export class PersonalSettingsComponent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm() {
|
|
|
|
|
const profile = this.manageProfileState.getProfile();
|
|
|
|
|
this.profile = this.manageProfileState.getProfile();
|
|
|
|
|
this.form = this.fb.group({
|
|
|
|
|
userName: [profile.userName, [required, maxLength(256)]],
|
|
|
|
|
email: [profile.email, [required, email, maxLength(256)]],
|
|
|
|
|
name: [profile.name || '', [maxLength(64)]],
|
|
|
|
|
surname: [profile.surname || '', [maxLength(64)]],
|
|
|
|
|
phoneNumber: [profile.phoneNumber || '', [maxLength(16)]],
|
|
|
|
|
userName: [this.profile.userName, [required, maxLength(256)]],
|
|
|
|
|
email: [this.profile.email, [required, email, maxLength(256)]],
|
|
|
|
|
name: [this.profile.name || '', [maxLength(64)]],
|
|
|
|
|
surname: [this.profile.surname || '', [maxLength(64)]],
|
|
|
|
|
phoneNumber: [this.profile.phoneNumber || '', [maxLength(16)]],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
submit() {
|
|
|
|
|
if (this.form.invalid) return;
|
|
|
|
|
const isLogOutConfirmMessageVisible = this.isLogoutConfirmMessageActive();
|
|
|
|
|
this.inProgress = true;
|
|
|
|
|
this.profileService
|
|
|
|
|
.update(this.form.value)
|
|
|
|
|
@ -54,6 +62,39 @@ export class PersonalSettingsComponent
|
|
|
|
|
.subscribe(profile => {
|
|
|
|
|
this.manageProfileState.setProfile(profile);
|
|
|
|
|
this.toasterService.success('AbpAccount::PersonalSettingsSaved', 'Success', { life: 5000 });
|
|
|
|
|
if (isLogOutConfirmMessageVisible) {
|
|
|
|
|
this.showLogoutConfirmMessage();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isDataSame(oldValue, newValue) {
|
|
|
|
|
return Object.entries(oldValue).some(([key, value]) => {
|
|
|
|
|
if (key in newValue) {
|
|
|
|
|
return value !== newValue[key];
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logoutConfirmation = () => {
|
|
|
|
|
this.authService.logout().subscribe();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private isLogoutConfirmMessageActive() {
|
|
|
|
|
if (!this.isPersonalSettingsChangedConfirmationActive) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return this.isDataSame(this.profile, this.form.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private showLogoutConfirmMessage() {
|
|
|
|
|
this.confirmationService
|
|
|
|
|
.info(
|
|
|
|
|
'AbpAccount::PersonalSettingsChangedConfirmationModalDescription',
|
|
|
|
|
'AbpAccount::PersonalSettingsChangedConfirmationModalTitle',
|
|
|
|
|
)
|
|
|
|
|
.pipe(filter(status => status === Confirmation.Status.confirm))
|
|
|
|
|
.subscribe(this.logoutConfirmation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|