1 import { Component, Input, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { NotificationsService } from 'angular2-notifications'
4 import { UserUpdateMe } from '../../../../../../shared'
5 import { AuthService } from '../../../core'
6 import { FormReactive, User, UserService } from '../../../shared'
9 selector: 'my-account-details',
10 templateUrl: './account-details.component.html',
11 styleUrls: [ './account-details.component.scss' ]
14 export class AccountDetailsComponent extends FormReactive implements OnInit {
15 @Input() user: User = null
21 validationMessages = {}
24 private authService: AuthService,
25 private formBuilder: FormBuilder,
26 private notificationsService: NotificationsService,
27 private userService: UserService
33 this.form = this.formBuilder.group({
34 displayNSFW: [ this.user.displayNSFW ]
37 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
45 const displayNSFW = this.form.value['displayNSFW']
46 const details: UserUpdateMe = {
51 this.userService.updateMyDetails(details).subscribe(
53 this.notificationsService.success('Success', 'Information updated.')
55 this.authService.refreshUserInformation()
58 err => this.error = err.message