1 import { Component, EventEmitter, OnInit, Output } from '@angular/core'
2 import { AuthService } from '@app/core'
3 import { FormReactive, UserService, UserValidatorsService } from '@app/shared'
4 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5 import { FormGroup } from '@angular/forms'
6 import { pairwise } from 'rxjs/operators'
7 import { concat, of } from 'rxjs'
10 selector: 'my-register-step-user',
11 templateUrl: './register-step-user.component.html',
12 styleUrls: [ './register.component.scss' ]
14 export class RegisterStepUserComponent extends FormReactive implements OnInit {
15 @Output() formBuilt = new EventEmitter<FormGroup>()
18 protected formValidatorService: FormValidatorService,
19 private authService: AuthService,
20 private userService: UserService,
21 private userValidatorsService: UserValidatorsService
27 return window.location.host
32 displayName: this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
33 username: this.userValidatorsService.USER_USERNAME,
34 password: this.userValidatorsService.USER_PASSWORD,
35 email: this.userValidatorsService.USER_EMAIL,
36 terms: this.userValidatorsService.USER_TERMS
39 setTimeout(() => this.formBuilt.emit(this.form))
43 this.form.get('displayName').valueChanges
45 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
48 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
49 const username = this.form.value['username'] || ''
51 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
52 this.form.patchValue({ username: newUsername })