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 { SignupService } from '@app/+signup/shared/signup.service'
7 USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
9 USER_PASSWORD_VALIDATOR,
10 USER_USERNAME_VALIDATOR
11 } from '@app/shared/form-validators/user-validators'
12 import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
15 selector: 'my-register-step-user',
16 templateUrl: './register-step-user.component.html',
17 styleUrls: [ './step.component.scss' ]
19 export class RegisterStepUserComponent extends FormReactive implements OnInit {
20 @Input() videoUploadDisabled = false
21 @Input() requiresEmailVerification = false
23 @Output() formBuilt = new EventEmitter<FormGroup>()
26 protected formReactiveService: FormReactiveService,
27 private signupService: SignupService
33 return window.location.host
38 displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
39 username: USER_USERNAME_VALIDATOR,
40 password: USER_PASSWORD_VALIDATOR,
41 email: USER_EMAIL_VALIDATOR
44 setTimeout(() => this.formBuilt.emit(this.form))
48 this.form.get('displayName').valueChanges
50 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
53 getMinPasswordLengthMessage () {
54 return USER_PASSWORD_VALIDATOR.MESSAGES.minlength
57 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
58 const username = this.form.value['username'] || ''
60 const newUsername = this.signupService.getNewUsername(oldDisplayName, newDisplayName, username)
61 this.form.patchValue({ username: newUsername })