1 import { Component, Input, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { FormReactive, UserService } from '../../../shared'
4 import { User } from '@app/shared'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7 import { Subject } from 'rxjs'
8 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
11 selector: 'my-account-profile',
12 templateUrl: './my-account-profile.component.html',
13 styleUrls: [ './my-account-profile.component.scss' ]
15 export class MyAccountProfileComponent extends FormReactive implements OnInit {
16 @Input() user: User = null
17 @Input() userInformationLoaded: Subject<any>
22 protected formValidatorService: FormValidatorService,
23 private userValidatorsService: UserValidatorsService,
24 private notificationsService: NotificationsService,
25 private userService: UserService,
33 'display-name': this.userValidatorsService.USER_DISPLAY_NAME,
34 description: this.userValidatorsService.USER_DESCRIPTION
37 this.userInformationLoaded.subscribe(() => {
38 this.form.patchValue({
39 'display-name': this.user.account.displayName,
40 description: this.user.account.description
46 const displayName = this.form.value['display-name']
47 const description = this.form.value['description'] || null
51 this.userService.updateMyProfile({ displayName, description }).subscribe(
53 this.user.account.displayName = displayName
54 this.user.account.description = description
56 this.notificationsService.success(this.i18n('Success'), this.i18n('Profile updated.'))
59 err => this.error = err.message