feat: add create client page (#1153)

Fixes: #215
This commit is contained in:
Karan Takalkar
2020-07-24 16:32:58 +05:30
committed by GitHub
parent cb62fefbfa
commit 9c15545cd4
28 changed files with 1713 additions and 6 deletions
@@ -0,0 +1,84 @@
/** Angular Imports */
import { Component, ViewChild } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */
import { ClientsService } from '../clients.service';
/** Custom Components */
import { ClientGeneralStepComponent } from '../client-stepper/client-general-step/client-general-step.component';
import { ClientFamilyMembersStepComponent } from '../client-stepper/client-family-members-step/client-family-members-step.component';
import { ClientAddressStepComponent } from '../client-stepper/client-address-step/client-address-step.component';
/**
* Create Client Component.
*/
@Component({
selector: 'mifosx-create-client',
templateUrl: './create-client.component.html',
styleUrls: ['./create-client.component.scss']
})
export class CreateClientComponent {
/** Client General Step */
@ViewChild(ClientGeneralStepComponent) clientGeneralStep: ClientGeneralStepComponent;
/** Client Family Members Step */
@ViewChild(ClientFamilyMembersStepComponent) clientFamilyMembersStep: ClientFamilyMembersStepComponent;
/** Client Address Step */
@ViewChild(ClientAddressStepComponent) clientAddressStep: ClientAddressStepComponent;
/** Client Template */
clientTemplate: any;
/** Client Address Field Config */
clientAddressFieldConfig: any;
/**
* Fetches client and address template from `resolve`
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {ClientsService} clientsService Clients Service
*/
constructor(private route: ActivatedRoute,
private router: Router,
private clientsService: ClientsService) {
this.route.data.subscribe((data: { clientTemplate: any, clientAddressFieldConfig: any }) => {
this.clientTemplate = data.clientTemplate;
this.clientAddressFieldConfig = data.clientAddressFieldConfig;
});
}
/**
* Retrieves general information about client.
*/
get clientGeneralForm() {
return this.clientGeneralStep.createClientForm;
}
/**
* Retrieves the client object
*/
get client() {
return {
...this.clientGeneralStep.clientGeneralDetails,
...this.clientFamilyMembersStep.familyMembers,
...this.clientAddressStep.address
};
}
/**
* Submits the create client form.
*/
submit() {
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
// TODO: Update once language and date settings are setup
const clientData = {
...this.client,
dateFormat,
locale
};
this.clientsService.createClient(clientData).subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
});
}
}