]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/register-step-user.component.ts
Fix viewers for lives
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / register-step-user.component.ts
CommitLineData
67ed6552
C
1import { concat, of } from 'rxjs'
2import { pairwise } from 'rxjs/operators'
421d935d 3import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
1d5342ab 4import { FormGroup } from '@angular/forms'
67ed6552 5import { UserService } from '@app/core'
7ed1edbb
C
6import {
7 USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
8 USER_EMAIL_VALIDATOR,
9 USER_PASSWORD_VALIDATOR,
10 USER_TERMS_VALIDATOR,
11 USER_USERNAME_VALIDATOR
12} from '@app/shared/form-validators/user-validators'
13import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
1d5342ab
C
14
15@Component({
b247a132
C
16 selector: 'my-register-step-user',
17 templateUrl: './register-step-user.component.html',
18 styleUrls: [ './register.component.scss' ]
1d5342ab 19})
b247a132 20export class RegisterStepUserComponent extends FormReactive implements OnInit {
421d935d 21 @Input() hasCodeOfConduct = false
09c55770 22 @Input() videoUploadDisabled = false
421d935d 23
1d5342ab 24 @Output() formBuilt = new EventEmitter<FormGroup>()
421d935d
C
25 @Output() termsClick = new EventEmitter<void>()
26 @Output() codeOfConductClick = new EventEmitter<void>()
1d5342ab
C
27
28 constructor (
29 protected formValidatorService: FormValidatorService,
7ed1edbb 30 private userService: UserService
1d5342ab
C
31 ) {
32 super()
33 }
34
35 get instanceHost () {
36 return window.location.host
37 }
38
39 ngOnInit () {
40 this.buildForm({
7ed1edbb
C
41 displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
42 username: USER_USERNAME_VALIDATOR,
43 password: USER_PASSWORD_VALIDATOR,
44 email: USER_EMAIL_VALIDATOR,
45 terms: USER_TERMS_VALIDATOR
1d5342ab
C
46 })
47
48 setTimeout(() => this.formBuilt.emit(this.form))
1f20622f
C
49
50 concat(
51 of(''),
52 this.form.get('displayName').valueChanges
53 ).pipe(pairwise())
54 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
55 }
56
421d935d
C
57 onTermsClick (event: Event) {
58 event.preventDefault()
59 this.termsClick.emit()
60 }
61
62 onCodeOfConductClick (event: Event) {
63 event.preventDefault()
64 this.codeOfConductClick.emit()
65 }
66
1f20622f
C
67 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
68 const username = this.form.value['username'] || ''
69
70 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
71 this.form.patchValue({ username: newUsername })
1d5342ab
C
72 }
73}