1 import { Component, Input, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { NotificationsService } from 'angular2-notifications'
4 import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared'
5 import { User } from '@app/shared'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
9 selector: 'my-account-profile',
10 templateUrl: './my-account-profile.component.html',
11 styleUrls: [ './my-account-profile.component.scss' ]
13 export class MyAccountProfileComponent extends FormReactive implements OnInit {
14 @Input() user: User = null
23 validationMessages = {
24 'display-name': USER_DISPLAY_NAME.MESSAGES,
25 'description': USER_DESCRIPTION.MESSAGES
29 private formBuilder: FormBuilder,
30 private notificationsService: NotificationsService,
31 private userService: UserService,
38 this.form = this.formBuilder.group({
39 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ],
40 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ]
43 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
51 const displayName = this.form.value['display-name']
52 const description = this.form.value['description'] || null
56 this.userService.updateMyProfile({ displayName, description }).subscribe(
58 this.user.account.displayName = displayName
59 this.user.account.description = description
61 this.notificationsService.success(this.i18n('Success'), this.i18n('Profile updated.'))
64 err => this.error = err.message