From ed56ad1193bb5bb0a81fb843a11eb90d3fed9861 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 26 Apr 2018 10:03:40 +0200 Subject: Add ability to update the user display name/description --- .../my-account-profile.component.ts | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts (limited to 'client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts') diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts new file mode 100644 index 000000000..2b7ba353c --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts @@ -0,0 +1,65 @@ +import { Component, Input, OnInit } from '@angular/core' +import { FormBuilder, FormGroup } from '@angular/forms' +import { NotificationsService } from 'angular2-notifications' +import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared' +import { User } from '@app/shared' + +@Component({ + selector: 'my-account-profile', + templateUrl: './my-account-profile.component.html', + styleUrls: [ './my-account-profile.component.scss' ] +}) +export class MyAccountProfileComponent extends FormReactive implements OnInit { + @Input() user: User = null + + error: string = null + + form: FormGroup + formErrors = { + 'display-name': '', + 'description': '' + } + validationMessages = { + 'display-name': USER_DISPLAY_NAME.MESSAGES, + 'description': USER_DESCRIPTION.MESSAGES + } + + constructor ( + private formBuilder: FormBuilder, + private notificationsService: NotificationsService, + private userService: UserService + ) { + super() + } + + buildForm () { + this.form = this.formBuilder.group({ + 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ], + 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ] + }) + + this.form.valueChanges.subscribe(data => this.onValueChanged(data)) + } + + ngOnInit () { + this.buildForm() + } + + updateMyProfile () { + const displayName = this.form.value['display-name'] + const description = this.form.value['description'] + + this.error = null + + this.userService.updateMyProfile({ displayName, description }).subscribe( + () => { + this.user.account.displayName = displayName + this.user.account.description = description + + this.notificationsService.success('Success', 'Profile updated.') + }, + + err => this.error = err.message + ) + } +} -- cgit v1.2.3