]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+signup/+register/register-step-user.component.ts
register: hide channel step if upload quota is 0
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / register-step-user.component.ts
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 { UserService } from '@app/core'
6 import {
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'
13 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
14
15 @Component({
16 selector: 'my-register-step-user',
17 templateUrl: './register-step-user.component.html',
18 styleUrls: [ './register.component.scss' ]
19 })
20 export class RegisterStepUserComponent extends FormReactive implements OnInit {
21 @Input() hasCodeOfConduct = false
22 @Input() videoUploadDisabled = false
23
24 @Output() formBuilt = new EventEmitter<FormGroup>()
25 @Output() termsClick = new EventEmitter<void>()
26 @Output() codeOfConductClick = new EventEmitter<void>()
27
28 constructor (
29 protected formValidatorService: FormValidatorService,
30 private userService: UserService
31 ) {
32 super()
33 }
34
35 get instanceHost () {
36 return window.location.host
37 }
38
39 ngOnInit () {
40 this.buildForm({
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
46 })
47
48 setTimeout(() => this.formBuilt.emit(this.form))
49
50 concat(
51 of(''),
52 this.form.get('displayName').valueChanges
53 ).pipe(pairwise())
54 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
55 }
56
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
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 })
72 }
73 }