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 { VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, VIDEO_CHANNEL_NAME_VALIDATOR } from '@app/shared/form-validators/video-channel-validators'
6 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
7 import { UserSignupService } from '@app/shared/shared-users'
10 selector: 'my-register-step-channel',
11 templateUrl: './register-step-channel.component.html',
12 styleUrls: [ './step.component.scss' ]
14 export class RegisterStepChannelComponent extends FormReactive implements OnInit {
15 @Input() username: string
16 @Input() instanceName: string
17 @Input() videoQuota: number
19 @Output() formBuilt = new EventEmitter<FormGroup>()
22 protected formValidatorService: FormValidatorService,
23 private userSignupService: UserSignupService
29 return window.location.host
34 displayName: VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
35 name: VIDEO_CHANNEL_NAME_VALIDATOR
38 setTimeout(() => this.formBuilt.emit(this.form))
42 this.form.get('displayName').valueChanges
44 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
47 isSameThanUsername () {
48 return this.username && this.username === this.form.value['name']
51 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
52 const name = this.form.value['name'] || ''
54 const newName = this.userSignupService.getNewUsername(oldDisplayName, newDisplayName, name)
55 this.form.patchValue({ name: newName })