]> 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
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-profile / my-account-profile.component.ts
CommitLineData
67ed6552 1import { Subject } from 'rxjs'
ed56ad11 2import { Component, Input, OnInit } from '@angular/core'
67ed6552
C
3import { Notifier, User, UserService } from '@app/core'
4import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
ed56ad11
C
5
6@Component({
7 selector: 'my-account-profile',
8 templateUrl: './my-account-profile.component.html',
9 styleUrls: [ './my-account-profile.component.scss' ]
10})
11export class MyAccountProfileComponent extends FormReactive implements OnInit {
12 @Input() user: User = null
d18d6478 13 @Input() userInformationLoaded: Subject<any>
ed56ad11
C
14
15 error: string = null
16
ed56ad11 17 constructor (
d18d6478 18 protected formValidatorService: FormValidatorService,
e309822b 19 private userValidatorsService: UserValidatorsService,
f8b2c1b4 20 private notifier: Notifier,
66357162
C
21 private userService: UserService
22 ) {
ed56ad11
C
23 super()
24 }
25
d18d6478
C
26 ngOnInit () {
27 this.buildForm({
1f20622f 28 'display-name': this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
e309822b 29 description: this.userValidatorsService.USER_DESCRIPTION
ed56ad11
C
30 })
31
d18d6478
C
32 this.userInformationLoaded.subscribe(() => {
33 this.form.patchValue({
34 'display-name': this.user.account.displayName,
35 description: this.user.account.description
36 })
37 })
ed56ad11
C
38 }
39
40 updateMyProfile () {
41 const displayName = this.form.value['display-name']
360329cc 42 const description = this.form.value['description'] || null
ed56ad11
C
43
44 this.error = null
45
46 this.userService.updateMyProfile({ displayName, description }).subscribe(
47 () => {
48 this.user.account.displayName = displayName
49 this.user.account.description = description
50
66357162 51 this.notifier.success($localize`Profile updated.`)
ed56ad11
C
52 },
53
54 err => this.error = err.message
55 )
56 }
57}