]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
967e21f0bd8c2b93be68f6241a01321d23127d7d
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-profile / my-account-profile.component.ts
1 import { Component, Input, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { FormReactive, UserService } from '../../../shared'
4 import { User } from '@app/shared'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7 import { Subject } from 'rxjs'
8 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
9
10 @Component({
11 selector: 'my-account-profile',
12 templateUrl: './my-account-profile.component.html',
13 styleUrls: [ './my-account-profile.component.scss' ]
14 })
15 export class MyAccountProfileComponent extends FormReactive implements OnInit {
16 @Input() user: User = null
17 @Input() userInformationLoaded: Subject<any>
18
19 error: string = null
20
21 constructor (
22 protected formValidatorService: FormValidatorService,
23 private userValidatorsService: UserValidatorsService,
24 private notificationsService: NotificationsService,
25 private userService: UserService,
26 private i18n: I18n
27 ) {
28 super()
29 }
30
31 ngOnInit () {
32 this.buildForm({
33 'display-name': this.userValidatorsService.USER_DISPLAY_NAME,
34 description: this.userValidatorsService.USER_DESCRIPTION
35 })
36
37 this.userInformationLoaded.subscribe(() => {
38 this.form.patchValue({
39 'display-name': this.user.account.displayName,
40 description: this.user.account.description
41 })
42 })
43 }
44
45 updateMyProfile () {
46 const displayName = this.form.value['display-name']
47 const description = this.form.value['description'] || null
48
49 this.error = null
50
51 this.userService.updateMyProfile({ displayName, description }).subscribe(
52 () => {
53 this.user.account.displayName = displayName
54 this.user.account.description = description
55
56 this.notificationsService.success(this.i18n('Success'), this.i18n('Profile updated.'))
57 },
58
59 err => this.error = err.message
60 )
61 }
62 }