diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-14 13:54:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-15 13:31:53 +0200 |
commit | 6f03f944c34f78b38a68128413b55186e0676949 (patch) | |
tree | 81a0c79184cb5ac800c31f1d5334471ee506ac19 /client/src/app/+signup/+register/steps/register-step-user.component.ts | |
parent | 936ce6e5635f3a52acbc799e1fcba9a948a7e390 (diff) | |
download | PeerTube-6f03f944c34f78b38a68128413b55186e0676949.tar.gz PeerTube-6f03f944c34f78b38a68128413b55186e0676949.tar.zst PeerTube-6f03f944c34f78b38a68128413b55186e0676949.zip |
Redesign register steps
Diffstat (limited to 'client/src/app/+signup/+register/steps/register-step-user.component.ts')
-rw-r--r-- | client/src/app/+signup/+register/steps/register-step-user.component.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/client/src/app/+signup/+register/steps/register-step-user.component.ts b/client/src/app/+signup/+register/steps/register-step-user.component.ts new file mode 100644 index 000000000..b89e38a28 --- /dev/null +++ b/client/src/app/+signup/+register/steps/register-step-user.component.ts | |||
@@ -0,0 +1,63 @@ | |||
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 { | ||
6 | USER_DISPLAY_NAME_REQUIRED_VALIDATOR, | ||
7 | USER_EMAIL_VALIDATOR, | ||
8 | USER_PASSWORD_VALIDATOR, | ||
9 | USER_USERNAME_VALIDATOR | ||
10 | } from '@app/shared/form-validators/user-validators' | ||
11 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | ||
12 | import { UserSignupService } from '@app/shared/shared-users' | ||
13 | |||
14 | @Component({ | ||
15 | selector: 'my-register-step-user', | ||
16 | templateUrl: './register-step-user.component.html', | ||
17 | styleUrls: [ './step.component.scss' ] | ||
18 | }) | ||
19 | export class RegisterStepUserComponent extends FormReactive implements OnInit { | ||
20 | @Input() videoUploadDisabled = false | ||
21 | @Input() requiresEmailVerification = false | ||
22 | |||
23 | @Output() formBuilt = new EventEmitter<FormGroup>() | ||
24 | |||
25 | constructor ( | ||
26 | protected formValidatorService: FormValidatorService, | ||
27 | private userSignupService: UserSignupService | ||
28 | ) { | ||
29 | super() | ||
30 | } | ||
31 | |||
32 | get instanceHost () { | ||
33 | return window.location.host | ||
34 | } | ||
35 | |||
36 | ngOnInit () { | ||
37 | this.buildForm({ | ||
38 | displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR, | ||
39 | username: USER_USERNAME_VALIDATOR, | ||
40 | password: USER_PASSWORD_VALIDATOR, | ||
41 | email: USER_EMAIL_VALIDATOR | ||
42 | }) | ||
43 | |||
44 | setTimeout(() => this.formBuilt.emit(this.form)) | ||
45 | |||
46 | concat( | ||
47 | of(''), | ||
48 | this.form.get('displayName').valueChanges | ||
49 | ).pipe(pairwise()) | ||
50 | .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue)) | ||
51 | } | ||
52 | |||
53 | getMinPasswordLengthMessage () { | ||
54 | return USER_PASSWORD_VALIDATOR.MESSAGES.minlength | ||
55 | } | ||
56 | |||
57 | private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) { | ||
58 | const username = this.form.value['username'] || '' | ||
59 | |||
60 | const newUsername = this.userSignupService.getNewUsername(oldDisplayName, newDisplayName, username) | ||
61 | this.form.patchValue({ username: newUsername }) | ||
62 | } | ||
63 | } | ||