]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+signup/+register/register-step-user.component.ts
Fix broken follow notification
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / register-step-user.component.ts
1 import { Component, EventEmitter, 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'
8
9 @Component({
10 selector: 'my-register-step-user',
11 templateUrl: './register-step-user.component.html',
12 styleUrls: [ './register.component.scss' ]
13 })
14 export class RegisterStepUserComponent extends FormReactive implements OnInit {
15 @Output() formBuilt = new EventEmitter<FormGroup>()
16
17 constructor (
18 protected formValidatorService: FormValidatorService,
19 private authService: AuthService,
20 private userService: UserService,
21 private userValidatorsService: UserValidatorsService
22 ) {
23 super()
24 }
25
26 get instanceHost () {
27 return window.location.host
28 }
29
30 ngOnInit () {
31 this.buildForm({
32 displayName: this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
33 username: this.userValidatorsService.USER_USERNAME,
34 password: this.userValidatorsService.USER_PASSWORD,
35 email: this.userValidatorsService.USER_EMAIL,
36 terms: this.userValidatorsService.USER_TERMS
37 })
38
39 setTimeout(() => this.formBuilt.emit(this.form))
40
41 concat(
42 of(''),
43 this.form.get('displayName').valueChanges
44 ).pipe(pairwise())
45 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
46 }
47
48 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
49 const username = this.form.value['username'] || ''
50
51 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
52 this.form.patchValue({ username: newUsername })
53 }
54 }