]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/register-step-user.component.ts
Bidi support
[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,
7ed1edbb
C
10 USER_USERNAME_VALIDATOR
11} from '@app/shared/form-validators/user-validators'
12import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
1d5342ab
C
13
14@Component({
b247a132
C
15 selector: 'my-register-step-user',
16 templateUrl: './register-step-user.component.html',
17 styleUrls: [ './register.component.scss' ]
1d5342ab 18})
b247a132 19export class RegisterStepUserComponent extends FormReactive implements OnInit {
09c55770 20 @Input() videoUploadDisabled = false
421d935d 21
1d5342ab
C
22 @Output() formBuilt = new EventEmitter<FormGroup>()
23
24 constructor (
25 protected formValidatorService: FormValidatorService,
7ed1edbb 26 private userService: UserService
1d5342ab
C
27 ) {
28 super()
29 }
30
31 get instanceHost () {
32 return window.location.host
33 }
34
35 ngOnInit () {
36 this.buildForm({
7ed1edbb
C
37 displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
38 username: USER_USERNAME_VALIDATOR,
39 password: USER_PASSWORD_VALIDATOR,
40360c17 40 email: USER_EMAIL_VALIDATOR
1d5342ab
C
41 })
42
43 setTimeout(() => this.formBuilt.emit(this.form))
1f20622f
C
44
45 concat(
46 of(''),
47 this.form.get('displayName').valueChanges
48 ).pipe(pairwise())
49 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
50 }
51
52 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
53 const username = this.form.value['username'] || ''
54
55 const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username)
56 this.form.patchValue({ username: newUsername })
1d5342ab
C
57 }
58}