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

69 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-04-02 11:50:52 +02:00
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {CustomErrorStateMatcher} from '@app/_helpers';
import {UserService} from '@app/_services';
2021-04-02 11:50:52 +02:00
@Component({
selector: 'app-account-search',
templateUrl: './account-search.component.html',
styleUrls: ['./account-search.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AccountSearchComponent implements OnInit {
nameSearchForm: FormGroup;
nameSearchSubmitted: boolean = false;
nameSearchLoading: boolean = false;
phoneSearchForm: FormGroup;
phoneSearchSubmitted: boolean = false;
phoneSearchLoading: boolean = false;
addressSearchForm: FormGroup;
addressSearchSubmitted: boolean = false;
addressSearchLoading: boolean = false;
matcher = new CustomErrorStateMatcher();
2021-04-02 11:50:52 +02:00
constructor(
private formBuilder: FormBuilder,
private userService: UserService,
) { }
2021-04-02 11:50:52 +02:00
ngOnInit(): void {
this.nameSearchForm = this.formBuilder.group({
name: ['', Validators.required],
});
this.phoneSearchForm = this.formBuilder.group({
phoneNumber: ['', Validators.required],
});
this.addressSearchForm = this.formBuilder.group({
address: ['', Validators.required],
});
2021-04-02 11:50:52 +02:00
}
get nameSearchFormStub(): any { return this.nameSearchForm.controls; }
get phoneSearchFormStub(): any { return this.phoneSearchForm.controls; }
get addressSearchFormStub(): any { return this.addressSearchForm.controls; }
onNameSearch(): void {
this.nameSearchSubmitted = true;
if (this.nameSearchForm.invalid) { return; }
this.nameSearchLoading = true;
this.userService.searchAccountByName(this.nameSearchFormStub.name.value);
this.nameSearchLoading = false;
}
onPhoneSearch(): void {
this.phoneSearchSubmitted = true;
if (this.phoneSearchForm.invalid) { return; }
this.phoneSearchLoading = true;
this.userService.searchAccountByPhone(this.phoneSearchFormStub.phoneNumber.value);
this.phoneSearchLoading = false;
}
onAddressSearch(): void {
this.addressSearchSubmitted = true;
if (this.addressSearchForm.invalid) { return; }
this.addressSearchLoading = true;
this.userService.searchAccountByAddress(this.addressSearchFormStub.address.value);
this.addressSearchLoading = false;
}
2021-04-02 11:50:52 +02:00
}