+import { Subject } from 'rxjs'
import { Component, Input, OnInit } from '@angular/core'
-import { FormBuilder, FormGroup } from '@angular/forms'
-import { NotificationsService } from 'angular2-notifications'
-import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared'
-import { User } from '@app/shared'
+import { Notifier, User, UserService } from '@app/core'
+import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
@Component({
selector: 'my-account-profile',
})
export class MyAccountProfileComponent extends FormReactive implements OnInit {
@Input() user: User = null
+ @Input() userInformationLoaded: Subject<any>
error: string = null
- form: FormGroup
- formErrors = {
- 'display-name': '',
- 'description': ''
- }
- validationMessages = {
- 'display-name': USER_DISPLAY_NAME.MESSAGES,
- 'description': USER_DESCRIPTION.MESSAGES
- }
-
constructor (
- private formBuilder: FormBuilder,
- private notificationsService: NotificationsService,
+ protected formValidatorService: FormValidatorService,
+ private userValidatorsService: UserValidatorsService,
+ private notifier: Notifier,
private userService: UserService
- ) {
+ ) {
super()
}
- buildForm () {
- this.form = this.formBuilder.group({
- 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ],
- 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ]
+ ngOnInit () {
+ this.buildForm({
+ 'display-name': this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
+ description: this.userValidatorsService.USER_DESCRIPTION
})
- this.form.valueChanges.subscribe(data => this.onValueChanged(data))
- }
-
- ngOnInit () {
- this.buildForm()
+ this.userInformationLoaded.subscribe(() => {
+ this.form.patchValue({
+ 'display-name': this.user.account.displayName,
+ description: this.user.account.description
+ })
+ })
}
updateMyProfile () {
const displayName = this.form.value['display-name']
- const description = this.form.value['description']
+ const description = this.form.value['description'] || null
this.error = null
this.user.account.displayName = displayName
this.user.account.description = description
- this.notificationsService.success('Success', 'Profile updated.')
+ this.notifier.success($localize`Profile updated.`)
},
err => this.error = err.message