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'
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
22 validationMessages = {
23 'display-name': USER_DISPLAY_NAME.MESSAGES,
24 'description': USER_DESCRIPTION.MESSAGES
28 private formBuilder: FormBuilder,
29 private notificationsService: NotificationsService,
30 private userService: UserService
36 this.form = this.formBuilder.group({
37 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ],
38 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ]
41 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
49 const displayName = this.form.value['display-name']
50 const description = this.form.value['description']
54 this.userService.updateMyProfile({ displayName, description }).subscribe(
56 this.user.account.displayName = displayName
57 this.user.account.description = description
59 this.notificationsService.success('Success', 'Profile updated.')
62 err => this.error = err.message