member_webapp/@overflow/member/component/member-profile.component.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-05-28 05:41:56 +00:00
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
import { Member } from '@overflow/commons-typescript/model/member';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
2018-05-28 11:16:00 +00:00
import { DomainMember } from '@overflow/commons-typescript/model/domain';
2018-05-28 05:41:56 +00:00
@Component({
selector: 'of-member-profile',
templateUrl: './member-profile.component.html',
})
export class MemberProfileComponent implements OnInit, OnDestroy {
2018-05-28 11:16:00 +00:00
@Input() domainMember: DomainMember;
2018-05-28 05:41:56 +00:00
@Output() modify = new EventEmitter<Member>();
form: FormGroup;
constructor(
private formBuilder: FormBuilder,
) {
}
ngOnInit() {
this.initForm();
}
ngOnDestroy() {
}
initForm() {
this.form = this.formBuilder.group({
2018-05-28 11:16:00 +00:00
'email': ['',
2018-05-28 05:41:56 +00:00
[
Validators.required,
Validators.email
]],
2018-05-28 11:16:00 +00:00
'name': ['', []],
'companyName': ['', []],
'phone': ['', []],
2018-05-28 05:41:56 +00:00
});
}
2018-05-28 11:16:00 +00:00
profileFormSubmit() {
2018-05-28 05:41:56 +00:00
const formValue = Object.assign({}, this.form.value);
const member: Member = {
2018-05-28 11:16:00 +00:00
email: this.domainMember.member.email,
2018-05-28 05:41:56 +00:00
name: formValue.name,
phone: formValue.phone,
companyName: formValue.companyName,
};
this.modify.emit(member);
}
}