]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/register-step-user.component.ts
Hide generic channel display name and avatar on watch view (#2988)
[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
C
5import { UserService } from '@app/core'
6import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
1d5342ab
C
7
8@Component({
b247a132
C
9 selector: 'my-register-step-user',
10 templateUrl: './register-step-user.component.html',
11 styleUrls: [ './register.component.scss' ]
1d5342ab 12})
b247a132 13export class RegisterStepUserComponent extends FormReactive implements OnInit {
421d935d
C
14 @Input() hasCodeOfConduct = false
15
1d5342ab 16 @Output() formBuilt = new EventEmitter<FormGroup>()
421d935d
C
17 @Output() termsClick = new EventEmitter<void>()
18 @Output() codeOfConductClick = new EventEmitter<void>()
1d5342ab
C
19
20 constructor (
21 protected formValidatorService: FormValidatorService,
1f20622f 22 private userService: UserService,
1d5342ab
C
23 private userValidatorsService: UserValidatorsService
24 ) {
25 super()
26 }
27
28 get instanceHost () {
29 return window.location.host
30 }
31
32 ngOnInit () {
33 this.buildForm({
1f20622f 34 displayName: this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
1d5342ab
C
35 username: this.userValidatorsService.USER_USERNAME,
36 password: this.userValidatorsService.USER_PASSWORD,
37 email: this.userValidatorsService.USER_EMAIL,
38 terms: this.userValidatorsService.USER_TERMS
39 })
40
41 setTimeout(() => this.formBuilt.emit(this.form))
1f20622f
C
42
43 concat(
44 of(''),
45 this.form.get('displayName').valueChanges
46 ).pipe(pairwise())
47 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
48 }
49
421d935d
C
50 onTermsClick (event: Event) {
51 event.preventDefault()
52 this.termsClick.emit()
53 }
54
55 onCodeOfConductClick (event: Event) {
56 event.preventDefault()
57 this.codeOfConductClick.emit()
58 }
59
1f20622f
C
60 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
61 const username = this.form.value['username'] || ''
62
63 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
64 this.form.patchValue({ username: newUsername })
1d5342ab
C
65 }
66}