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,68 @@
<div class="container">
<mat-horizontal-stepper class="mat-elevation-z8" labelPosition="bottom" #clientStepper>
<ng-template matStepperIcon="number">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>
<ng-template matStepperIcon="edit">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>
<ng-template matStepperIcon="done">
<fa-icon icon="check" size="sm"></fa-icon>
</ng-template>
<ng-template matStepperIcon="error">
<fa-icon icon="exclamation-triangle" size="lg"></fa-icon>
</ng-template>
<ng-template matStepperIcon="preview">
<fa-icon icon="eye" size="sm"></fa-icon>
</ng-template>
<mat-step [stepControl]="clientGeneralForm">
<ng-template matStepLabel>GENERAL</ng-template>
<mifosx-client-general-step [clientTemplate]="clientTemplate"></mifosx-client-general-step>
</mat-step>
<mat-step>
<ng-template matStepLabel>FAMILY MEMBERS</ng-template>
<mifosx-client-family-members-step [clientTemplate]="clientTemplate"></mifosx-client-family-members-step>
</mat-step>
<mat-step>
<ng-template matStepLabel>ADDRESS</ng-template>
<mifosx-client-address-step
[clientTemplate]="clientTemplate"
[clientAddressFieldConfig]="clientAddressFieldConfig"
>
</mifosx-client-address-step>
</mat-step>
<mat-step *ngIf="clientGeneralForm.valid" completed>
<ng-template matStepLabel>PREVIEW</ng-template>
<mifosx-client-preview-step
[clientTemplate]="clientTemplate"
[clientAddressFieldConfig]="clientAddressFieldConfig"
[client]="client" (submit)="submit()"
>
</mifosx-client-preview-step>
</mat-step>
</mat-horizontal-stepper>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateClientComponent } from './create-client.component';
describe('CreateClientComponent', () => {
let component: CreateClientComponent;
let fixture: ComponentFixture<CreateClientComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateClientComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreateClientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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 });
});
}
}