1 import { Component, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
5 import { NotificationsService } from 'angular2-notifications'
7 import { UserService } from '../shared'
13 } from '../../../shared'
16 selector: 'my-user-add',
17 templateUrl: './user-add.component.html'
19 export class UserAddComponent extends FormReactive implements OnInit {
28 validationMessages = {
29 'username': USER_USERNAME.MESSAGES,
30 'email': USER_EMAIL.MESSAGES,
31 'password': USER_PASSWORD.MESSAGES
35 private formBuilder: FormBuilder,
36 private router: Router,
37 private notificationsService: NotificationsService,
38 private userService: UserService
44 this.form = this.formBuilder.group({
45 username: [ '', USER_USERNAME.VALIDATORS ],
46 email: [ '', USER_EMAIL.VALIDATORS ],
47 password: [ '', USER_PASSWORD.VALIDATORS ]
50 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
60 const { username, password, email } = this.form.value
62 this.userService.addUser(username, password, email).subscribe(
64 this.notificationsService.success('Success', `User ${username} created.`)
65 this.router.navigate([ '/admin/users/list' ])
68 err => this.error = err.text