1 import { Component, EventEmitter, Input, 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 @Input() hasCodeOfConduct = false
17 @Output() formBuilt = new EventEmitter<FormGroup>()
18 @Output() termsClick = new EventEmitter<void>()
19 @Output() codeOfConductClick = new EventEmitter<void>()
22 protected formValidatorService: FormValidatorService,
23 private authService: AuthService,
24 private userService: UserService,
25 private userValidatorsService: UserValidatorsService
31 return window.location.host
36 displayName: this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
37 username: this.userValidatorsService.USER_USERNAME,
38 password: this.userValidatorsService.USER_PASSWORD,
39 email: this.userValidatorsService.USER_EMAIL,
40 terms: this.userValidatorsService.USER_TERMS
43 setTimeout(() => this.formBuilt.emit(this.form))
47 this.form.get('displayName').valueChanges
49 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
52 onTermsClick (event: Event) {
53 event.preventDefault()
54 this.termsClick.emit()
57 onCodeOfConductClick (event: Event) {
58 event.preventDefault()
59 this.codeOfConductClick.emit()
62 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
63 const username = this.form.value['username'] || ''
65 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
66 this.form.patchValue({ username: newUsername })