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'
7 USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
9 USER_PASSWORD_VALIDATOR,
11 USER_USERNAME_VALIDATOR
12 } from '@app/shared/form-validators/user-validators'
13 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
16 selector: 'my-register-step-user',
17 templateUrl: './register-step-user.component.html',
18 styleUrls: [ './register.component.scss' ]
20 export class RegisterStepUserComponent extends FormReactive implements OnInit {
21 @Input() hasCodeOfConduct = false
22 @Input() videoUploadDisabled = false
24 @Output() formBuilt = new EventEmitter<FormGroup>()
25 @Output() termsClick = new EventEmitter<void>()
26 @Output() codeOfConductClick = new EventEmitter<void>()
29 protected formValidatorService: FormValidatorService,
30 private userService: UserService
36 return window.location.host
41 displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
42 username: USER_USERNAME_VALIDATOR,
43 password: USER_PASSWORD_VALIDATOR,
44 email: USER_EMAIL_VALIDATOR,
45 terms: USER_TERMS_VALIDATOR
48 setTimeout(() => this.formBuilt.emit(this.form))
52 this.form.get('displayName').valueChanges
54 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
57 onTermsClick (event: Event) {
58 event.preventDefault()
59 this.termsClick.emit()
62 onCodeOfConductClick (event: Event) {
63 event.preventDefault()
64 this.codeOfConductClick.emit()
67 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
68 const username = this.form.value['username'] || ''
70 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
71 this.form.patchValue({ username: newUsername })