]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
Redirect to local route when getting peertube account
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-profile / my-account-profile.component.ts
CommitLineData
ed56ad11 1import { Component, Input, OnInit } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
e309822b 3import { FormReactive, UserService } from '../../../shared'
ed56ad11 4import { User } from '@app/shared'
b1d40cff 5import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
4d089429 7import { Subject } from 'rxjs'
e309822b 8import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
ed56ad11
C
9
10@Component({
11 selector: 'my-account-profile',
12 templateUrl: './my-account-profile.component.html',
13 styleUrls: [ './my-account-profile.component.scss' ]
14})
15export class MyAccountProfileComponent extends FormReactive implements OnInit {
16 @Input() user: User = null
d18d6478 17 @Input() userInformationLoaded: Subject<any>
ed56ad11
C
18
19 error: string = null
20
ed56ad11 21 constructor (
d18d6478 22 protected formValidatorService: FormValidatorService,
e309822b 23 private userValidatorsService: UserValidatorsService,
f8b2c1b4 24 private notifier: Notifier,
b1d40cff
C
25 private userService: UserService,
26 private i18n: I18n
ed56ad11
C
27 ) {
28 super()
29 }
30
d18d6478
C
31 ngOnInit () {
32 this.buildForm({
e309822b
C
33 'display-name': this.userValidatorsService.USER_DISPLAY_NAME,
34 description: this.userValidatorsService.USER_DESCRIPTION
ed56ad11
C
35 })
36
d18d6478
C
37 this.userInformationLoaded.subscribe(() => {
38 this.form.patchValue({
39 'display-name': this.user.account.displayName,
40 description: this.user.account.description
41 })
42 })
ed56ad11
C
43 }
44
45 updateMyProfile () {
46 const displayName = this.form.value['display-name']
360329cc 47 const description = this.form.value['description'] || null
ed56ad11
C
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
f8b2c1b4 56 this.notifier.success(this.i18n('Profile updated.'))
ed56ad11
C
57 },
58
59 err => this.error = err.message
60 )
61 }
62}