1 import { Subject } from 'rxjs'
2 import { Component, Input, OnInit } from '@angular/core'
3 import { Notifier, User, UserService } from '@app/core'
4 import { USER_DESCRIPTION_VALIDATOR, USER_DISPLAY_NAME_REQUIRED_VALIDATOR } from '@app/shared/form-validators/user-validators'
5 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
8 selector: 'my-account-profile',
9 templateUrl: './my-account-profile.component.html',
10 styleUrls: [ './my-account-profile.component.scss' ]
12 export class MyAccountProfileComponent extends FormReactive implements OnInit {
13 @Input() user: User = null
14 @Input() userInformationLoaded: Subject<any>
19 protected formValidatorService: FormValidatorService,
20 private notifier: Notifier,
21 private userService: UserService
29 'display-name': USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
30 description: USER_DESCRIPTION_VALIDATOR
32 this.form.controls['username'].disable()
34 this.userInformationLoaded.subscribe(() => {
35 this.form.patchValue({
36 username: this.user.username,
37 'display-name': this.user.account.displayName,
38 description: this.user.account.description
44 return window.location.host
48 const displayName = this.form.value['display-name']
49 const description = this.form.value['description'] || null
53 this.userService.updateMyProfile({ displayName, description })
56 this.user.account.displayName = displayName
57 this.user.account.description = description
59 this.notifier.success($localize`Profile updated.`)
62 error: err => this.error = err.message