X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Bsignup%2F%2Bregister%2Fregister-step-user.component.ts;h=6c96f20b448af548bd9112a2fb828c37e822bb0b;hb=1d17d86349fd2b3a9bc85145d02383ba4aea4dc0;hp=3825ae371cfbc70be6004c9f031b1a6f3c95f03a;hpb=a41b9da1a9ce49df82ea10c82de4c2fbc6d1b189;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+signup/+register/register-step-user.component.ts b/client/src/app/+signup/+register/register-step-user.component.ts index 3825ae371..6c96f20b4 100644 --- a/client/src/app/+signup/+register/register-step-user.component.ts +++ b/client/src/app/+signup/+register/register-step-user.component.ts @@ -1,8 +1,10 @@ -import { Component, EventEmitter, OnInit, Output } from '@angular/core' +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' import { AuthService } from '@app/core' -import { FormReactive, UserValidatorsService } from '@app/shared' +import { FormReactive, UserService, UserValidatorsService } from '@app/shared' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { FormGroup } from '@angular/forms' +import { pairwise } from 'rxjs/operators' +import { concat, of } from 'rxjs' @Component({ selector: 'my-register-step-user', @@ -10,11 +12,16 @@ import { FormGroup } from '@angular/forms' styleUrls: [ './register.component.scss' ] }) export class RegisterStepUserComponent extends FormReactive implements OnInit { + @Input() hasCodeOfConduct = false + @Output() formBuilt = new EventEmitter() + @Output() termsClick = new EventEmitter() + @Output() codeOfConductClick = new EventEmitter() constructor ( protected formValidatorService: FormValidatorService, private authService: AuthService, + private userService: UserService, private userValidatorsService: UserValidatorsService ) { super() @@ -26,6 +33,7 @@ export class RegisterStepUserComponent extends FormReactive implements OnInit { ngOnInit () { this.buildForm({ + displayName: this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED, username: this.userValidatorsService.USER_USERNAME, password: this.userValidatorsService.USER_PASSWORD, email: this.userValidatorsService.USER_EMAIL, @@ -33,5 +41,28 @@ export class RegisterStepUserComponent extends FormReactive implements OnInit { }) setTimeout(() => this.formBuilt.emit(this.form)) + + concat( + of(''), + this.form.get('displayName').valueChanges + ).pipe(pairwise()) + .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue)) + } + + onTermsClick (event: Event) { + event.preventDefault() + this.termsClick.emit() + } + + onCodeOfConductClick (event: Event) { + event.preventDefault() + this.codeOfConductClick.emit() + } + + private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) { + const username = this.form.value['username'] || '' + + const newUsername = this.userService.getNewUsername(oldDisplayName, newDisplayName, username) + this.form.patchValue({ username: newUsername }) } }