]> 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
Fix i18n in components
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-profile / my-account-profile.component.ts
CommitLineData
ed56ad11
C
1import { Component, Input, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { NotificationsService } from 'angular2-notifications'
4import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared'
5import { User } from '@app/shared'
b1d40cff 6import { I18n } from '@ngx-translate/i18n-polyfill'
ed56ad11
C
7
8@Component({
9 selector: 'my-account-profile',
10 templateUrl: './my-account-profile.component.html',
11 styleUrls: [ './my-account-profile.component.scss' ]
12})
13export class MyAccountProfileComponent extends FormReactive implements OnInit {
14 @Input() user: User = null
15
16 error: string = null
17
18 form: FormGroup
19 formErrors = {
20 'display-name': '',
21 'description': ''
22 }
23 validationMessages = {
24 'display-name': USER_DISPLAY_NAME.MESSAGES,
25 'description': USER_DESCRIPTION.MESSAGES
26 }
27
28 constructor (
29 private formBuilder: FormBuilder,
30 private notificationsService: NotificationsService,
b1d40cff
C
31 private userService: UserService,
32 private i18n: I18n
ed56ad11
C
33 ) {
34 super()
35 }
36
37 buildForm () {
38 this.form = this.formBuilder.group({
39 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ],
40 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ]
41 })
42
43 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
44 }
45
46 ngOnInit () {
47 this.buildForm()
48 }
49
50 updateMyProfile () {
51 const displayName = this.form.value['display-name']
360329cc 52 const description = this.form.value['description'] || null
ed56ad11
C
53
54 this.error = null
55
56 this.userService.updateMyProfile({ displayName, description }).subscribe(
57 () => {
58 this.user.account.displayName = displayName
59 this.user.account.description = description
60
b1d40cff 61 this.notificationsService.success(this.i18n('Success'), this.i18n('Profile updated.'))
ed56ad11
C
62 },
63
64 err => this.error = err.message
65 )
66 }
67}