1 import { Component, OnInit, Input } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
5 import { NotificationsService } from 'angular2-notifications'
7 import { AuthService } from '../../core'
14 import { UserUpdate } from '../../../../../shared'
17 selector: 'my-account-details',
18 templateUrl: './account-details.component.html'
21 export class AccountDetailsComponent extends FormReactive implements OnInit {
22 @Input() user: User = null
28 validationMessages = {}
31 private authService: AuthService,
32 private formBuilder: FormBuilder,
33 private router: Router,
34 private notificationsService: NotificationsService,
35 private userService: UserService
41 this.form = this.formBuilder.group({
42 displayNSFW: [ this.user.displayNSFW ]
45 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
53 const displayNSFW = this.form.value['displayNSFW']
54 const details: UserUpdate = {
59 this.userService.updateDetails(details).subscribe(
61 this.notificationsService.success('Success', 'Informations updated.')
63 this.authService.refreshUserInformations()
66 err => this.error = err