1 import { concat, of } from 'rxjs'
2 import { pairwise } from 'rxjs/operators'
3 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
4 import { FormGroup } from '@angular/forms'
5 import { UserService } from '@app/core'
6 import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
9 selector: 'my-register-step-user',
10 templateUrl: './register-step-user.component.html',
11 styleUrls: [ './register.component.scss' ]
13 export class RegisterStepUserComponent extends FormReactive implements OnInit {
14 @Input() hasCodeOfConduct = false
16 @Output() formBuilt = new EventEmitter<FormGroup>()
17 @Output() termsClick = new EventEmitter<void>()
18 @Output() codeOfConductClick = new EventEmitter<void>()
21 protected formValidatorService: FormValidatorService,
22 private userService: UserService,
23 private userValidatorsService: UserValidatorsService
29 return window.location.host
34 displayName: this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
35 username: this.userValidatorsService.USER_USERNAME,
36 password: this.userValidatorsService.USER_PASSWORD,
37 email: this.userValidatorsService.USER_EMAIL,
38 terms: this.userValidatorsService.USER_TERMS
41 setTimeout(() => this.formBuilt.emit(this.form))
45 this.form.get('displayName').valueChanges
47 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
50 onTermsClick (event: Event) {
51 event.preventDefault()
52 this.termsClick.emit()
55 onCodeOfConductClick (event: Event) {
56 event.preventDefault()
57 this.codeOfConductClick.emit()
60 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
61 const username = this.form.value['username'] || ''
63 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
64 this.form.patchValue({ username: newUsername })