X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Bmy-account%2Fmy-account-settings%2Fmy-account-profile%2Fmy-account-profile.component.ts;h=a9503ed1b8eb9769fb5292b357df98b3024490f7;hb=1a03bea0c42fa1064ce4770157b4fd2e3edd5565;hp=2b7ba353c1e7350e236907bd49a50316769c28ca;hpb=62e62f118d5da57acd3494fece2e8ed357564ffe;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts index 2b7ba353c..a9503ed1b 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts @@ -1,8 +1,11 @@ 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 { Notifier } from '@app/core' +import { FormReactive, UserService } from '../../../shared' import { User } from '@app/shared' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' +import { Subject } from 'rxjs' +import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' @Component({ selector: 'my-account-profile', @@ -11,43 +14,37 @@ import { User } from '@app/shared' }) export class MyAccountProfileComponent extends FormReactive implements OnInit { @Input() user: User = null + @Input() userInformationLoaded: Subject 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, - private userService: UserService + protected formValidatorService: FormValidatorService, + private userValidatorsService: UserValidatorsService, + private notifier: Notifier, + private userService: UserService, + private i18n: I18n ) { 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, + 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 @@ -56,7 +53,7 @@ export class MyAccountProfileComponent extends FormReactive implements OnInit { this.user.account.displayName = displayName this.user.account.description = description - this.notificationsService.success('Success', 'Profile updated.') + this.notifier.success(this.i18n('Profile updated.')) }, err => this.error = err.message