1 import { Subject } from 'rxjs'
2 import { Component, Input, OnInit } from '@angular/core'
3 import { Notifier, User, UserService } from '@app/core'
4 import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
8 selector: 'my-account-profile',
9 templateUrl: './my-account-profile.component.html',
10 styleUrls: [ './my-account-profile.component.scss' ]
12 export class MyAccountProfileComponent extends FormReactive implements OnInit {
13 @Input() user: User = null
14 @Input() userInformationLoaded: Subject<any>
19 protected formValidatorService: FormValidatorService,
20 private userValidatorsService: UserValidatorsService,
21 private notifier: Notifier,
22 private userService: UserService,
30 'display-name': this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
31 description: this.userValidatorsService.USER_DESCRIPTION
34 this.userInformationLoaded.subscribe(() => {
35 this.form.patchValue({
36 'display-name': this.user.account.displayName,
37 description: this.user.account.description
43 const displayName = this.form.value['display-name']
44 const description = this.form.value['description'] || null
48 this.userService.updateMyProfile({ displayName, description }).subscribe(
50 this.user.account.displayName = displayName
51 this.user.account.description = description
53 this.notifier.success(this.i18n('Profile updated.'))
56 err => this.error = err.message