]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
1d5342ab
C
1import { Component, EventEmitter, OnInit, Output } from '@angular/core'
2import { AuthService } from '@app/core'
1f20622f 3import { FormReactive, UserService, UserValidatorsService } from '@app/shared'
1d5342ab
C
4import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5import { FormGroup } from '@angular/forms'
1f20622f
C
6import { pairwise } from 'rxjs/operators'
7import { concat, of } from 'rxjs'
1d5342ab
C
8
9@Component({
b247a132
C
10 selector: 'my-register-step-user',
11 templateUrl: './register-step-user.component.html',
12 styleUrls: [ './register.component.scss' ]
1d5342ab 13})
b247a132 14export class RegisterStepUserComponent extends FormReactive implements OnInit {
1d5342ab
C
15 @Output() formBuilt = new EventEmitter<FormGroup>()
16
17 constructor (
18 protected formValidatorService: FormValidatorService,
19 private authService: AuthService,
1f20622f 20 private userService: UserService,
1d5342ab
C
21 private userValidatorsService: UserValidatorsService
22 ) {
23 super()
24 }
25
26 get instanceHost () {
27 return window.location.host
28 }
29
30 ngOnInit () {
31 this.buildForm({
1f20622f 32 displayName: this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
1d5342ab
C
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))
1f20622f
C
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 })
1d5342ab
C
53 }
54}