]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { concat, of } from 'rxjs' |
2 | import { pairwise } from 'rxjs/operators' | |
421d935d | 3 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' |
1d5342ab | 4 | import { FormGroup } from '@angular/forms' |
9589907c | 5 | import { SignupService } from '@app/+signup/shared/signup.service' |
7ed1edbb C |
6 | import { |
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' | |
5c5bcea2 | 12 | import { FormReactive, FormReactiveService } 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', | |
6f03f944 | 17 | styleUrls: [ './step.component.scss' ] |
1d5342ab | 18 | }) |
b247a132 | 19 | export class RegisterStepUserComponent extends FormReactive implements OnInit { |
09c55770 | 20 | @Input() videoUploadDisabled = false |
6f03f944 | 21 | @Input() requiresEmailVerification = false |
421d935d | 22 | |
1d5342ab C |
23 | @Output() formBuilt = new EventEmitter<FormGroup>() |
24 | ||
25 | constructor ( | |
5c5bcea2 | 26 | protected formReactiveService: FormReactiveService, |
9589907c | 27 | private signupService: SignupService |
1d5342ab C |
28 | ) { |
29 | super() | |
30 | } | |
31 | ||
32 | get instanceHost () { | |
33 | return window.location.host | |
34 | } | |
35 | ||
36 | ngOnInit () { | |
37 | this.buildForm({ | |
7ed1edbb C |
38 | displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR, |
39 | username: USER_USERNAME_VALIDATOR, | |
40 | password: USER_PASSWORD_VALIDATOR, | |
40360c17 | 41 | email: USER_EMAIL_VALIDATOR |
1d5342ab C |
42 | }) |
43 | ||
44 | setTimeout(() => this.formBuilt.emit(this.form)) | |
1f20622f C |
45 | |
46 | concat( | |
47 | of(''), | |
48 | this.form.get('displayName').valueChanges | |
49 | ).pipe(pairwise()) | |
50 | .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue)) | |
51 | } | |
52 | ||
6f03f944 C |
53 | getMinPasswordLengthMessage () { |
54 | return USER_PASSWORD_VALIDATOR.MESSAGES.minlength | |
55 | } | |
56 | ||
1f20622f C |
57 | private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) { |
58 | const username = this.form.value['username'] || '' | |
59 | ||
9589907c | 60 | const newUsername = this.signupService.getNewUsername(oldDisplayName, newDisplayName, username) |
1f20622f | 61 | this.form.patchValue({ username: newUsername }) |
1d5342ab C |
62 | } |
63 | } |