]>
Commit | Line | Data |
---|---|---|
ed56ad11 | 1 | import { Component, Input, OnInit } from '@angular/core' |
ed56ad11 | 2 | import { NotificationsService } from 'angular2-notifications' |
e309822b | 3 | import { FormReactive, UserService } from '../../../shared' |
ed56ad11 | 4 | import { User } from '@app/shared' |
b1d40cff | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 6 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
4d089429 | 7 | import { Subject } from 'rxjs' |
e309822b | 8 | import { 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 | }) | |
15 | export 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, |
ed56ad11 | 24 | private notificationsService: NotificationsService, |
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 | ||
b1d40cff | 56 | this.notificationsService.success(this.i18n('Success'), this.i18n('Profile updated.')) |
ed56ad11 C |
57 | }, |
58 | ||
59 | err => this.error = err.message | |
60 | ) | |
61 | } | |
62 | } |