cic-staff-client/src/app/pages/accounts/create-account/create-account.component.ts

71 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-05-10 18:15:25 +02:00
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LocationService, UserService } from '@app/_services';
import { CustomErrorStateMatcher } from '@app/_helpers';
import { first } from 'rxjs/operators';
2020-11-25 08:57:17 +01:00
@Component({
selector: 'app-create-account',
templateUrl: './create-account.component.html',
styleUrls: ['./create-account.component.scss'],
2021-05-10 18:15:25 +02:00
changeDetection: ChangeDetectionStrategy.OnPush,
2020-11-25 08:57:17 +01:00
})
export class CreateAccountComponent implements OnInit {
2021-02-08 12:47:07 +01:00
createForm: FormGroup;
2021-04-30 14:50:16 +02:00
matcher: CustomErrorStateMatcher = new CustomErrorStateMatcher();
2021-02-08 12:47:07 +01:00
submitted: boolean = false;
categories: Array<string>;
areaNames: Array<string>;
2021-04-30 14:50:16 +02:00
accountTypes: Array<string>;
genders: Array<string>;
2020-11-25 08:57:17 +01:00
constructor(
2021-02-08 12:47:07 +01:00
private formBuilder: FormBuilder,
private locationService: LocationService,
private userService: UserService
2021-05-10 18:15:25 +02:00
) {}
2020-11-25 08:57:17 +01:00
ngOnInit(): void {
2021-02-08 12:47:07 +01:00
this.createForm = this.formBuilder.group({
accountType: ['', Validators.required],
idNumber: ['', Validators.required],
phoneNumber: ['', Validators.required],
givenName: ['', Validators.required],
surname: ['', Validators.required],
directoryEntry: ['', Validators.required],
location: ['', Validators.required],
gender: ['', Validators.required],
referrer: ['', Validators.required],
2021-05-10 18:15:25 +02:00
businessCategory: ['', Validators.required],
2021-02-08 12:47:07 +01:00
});
this.userService.getCategories();
this.userService.categoriesSubject.subscribe((res) => {
this.categories = Object.keys(res);
});
this.locationService.getAreaNames();
this.locationService.areaNamesSubject.subscribe((res) => {
this.areaNames = Object.keys(res);
});
2021-05-10 18:15:25 +02:00
this.userService
.getAccountTypes()
.pipe(first())
.subscribe((res) => (this.accountTypes = res));
this.userService
.getGenders()
.pipe(first())
.subscribe((res) => (this.genders = res));
2020-11-25 08:57:17 +01:00
}
2021-05-10 18:15:25 +02:00
get createFormStub(): any {
return this.createForm.controls;
}
2021-02-08 12:47:07 +01:00
onSubmit(): void {
2021-02-08 12:47:07 +01:00
this.submitted = true;
2021-05-10 18:15:25 +02:00
if (this.createForm.invalid || !confirm('Create account?')) {
return;
}
2021-02-08 12:47:07 +01:00
this.submitted = false;
}
2020-11-25 08:57:17 +01:00
}