1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
import { concat, of } from 'rxjs'
import { pairwise } from 'rxjs/operators'
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { FormGroup } from '@angular/forms'
import { UserService } from '@app/core'
import {
USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
USER_EMAIL_VALIDATOR,
USER_PASSWORD_VALIDATOR,
USER_TERMS_VALIDATOR,
USER_USERNAME_VALIDATOR
} from '@app/shared/form-validators/user-validators'
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
@Component({
selector: 'my-register-step-user',
templateUrl: './register-step-user.component.html',
styleUrls: [ './register.component.scss' ]
})
export class RegisterStepUserComponent extends FormReactive implements OnInit {
@Input() hasCodeOfConduct = false
@Output() formBuilt = new EventEmitter<FormGroup>()
@Output() termsClick = new EventEmitter<void>()
@Output() codeOfConductClick = new EventEmitter<void>()
constructor (
protected formValidatorService: FormValidatorService,
private userService: UserService
) {
super()
}
get instanceHost () {
return window.location.host
}
ngOnInit () {
this.buildForm({
displayName: USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
username: USER_USERNAME_VALIDATOR,
password: USER_PASSWORD_VALIDATOR,
email: USER_EMAIL_VALIDATOR,
terms: USER_TERMS_VALIDATOR
})
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 })
}
}
|