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'
6 USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
8 USER_PASSWORD_VALIDATOR,
9 USER_USERNAME_VALIDATOR
10 } from '@app/shared/form-validators/user-validators'
11 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
12 import { UserSignupService } from '@app/shared/shared-users'
15 selector: 'my-register-step-user',
16 templateUrl: './register-step-user.component.html',
17 styleUrls: [ './register.component.scss' ]
19 export class RegisterStepUserComponent extends FormReactive implements OnInit {
20 @Input() videoUploadDisabled = false
22 @Output() formBuilt = new EventEmitter<FormGroup>()
25 protected formValidatorService: FormValidatorService,
26 private userSignupService: UserSignupService
32 return window.location.host
37 displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
38 username: USER_USERNAME_VALIDATOR,
39 password: USER_PASSWORD_VALIDATOR,
40 email: USER_EMAIL_VALIDATOR
43 setTimeout(() => this.formBuilt.emit(this.form))
47 this.form.get('displayName').valueChanges
49 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
52 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
53 const username = this.form.value['username'] || ''
55 const newUsername = this.userSignupService.getNewUsername(oldDisplayName, newDisplayName, username)
56 this.form.patchValue({ username: newUsername })