]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
add username information in profile settings
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-profile / my-account-profile.component.ts
index 468be022c905c17e7b95b07219cd466935dcd057..957abe5555b6b5029cd63adcb0cf452a47fd2a5a 100644 (file)
@@ -1,8 +1,8 @@
+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 { USER_DESCRIPTION_VALIDATOR, USER_DISPLAY_NAME_REQUIRED_VALIDATOR } from '@app/shared/form-validators/user-validators'
+import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
 
 @Component({
   selector: 'my-account-profile',
@@ -11,38 +11,37 @@ import { User } from '@app/shared'
 })
 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 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({
+      'user-name': null,
+      'display-name': USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
+      description: USER_DESCRIPTION_VALIDATOR
     })
+    this.form.controls['user-name'].disable()
 
-    this.form.valueChanges.subscribe(data => this.onValueChanged(data))
+    this.userInformationLoaded.subscribe(() => {
+      this.form.patchValue({
+        'user-name': this.user.username,
+        'display-name': this.user.account.displayName,
+        description: this.user.account.description
+      })
+    })
   }
 
-  ngOnInit () {
-    this.buildForm()
+  get instanceHost () {
+    return window.location.host
   }
 
   updateMyProfile () {
@@ -56,7 +55,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($localize`Profile updated.`)
       },
 
       err => this.error = err.message