feat: add create savings account page (#883)

Fixes: #882
This commit is contained in:
Karan Takalkar
2020-06-19 21:14:07 +05:30
committed by GitHub
parent 21c54d0baa
commit 2418e2ed02
28 changed files with 1424 additions and 16 deletions
@@ -0,0 +1,77 @@
<div class="container">
<mat-horizontal-stepper class="mat-elevation-z8" labelPosition="bottom" #savingProductStepper>
<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]="savingsAccountDetailsForm">
<ng-template matStepLabel>DETAILS</ng-template>
<mifosx-savings-account-details-step
[savingsAccountTemplate]="savingsAccountTemplate"
(savingsAccountProductTemplate)="setTemplate($event)"
>
</mifosx-savings-account-details-step>
</mat-step>
<mat-step [stepControl]="savingsAccountTermsForm">
<ng-template matStepLabel>TERMS</ng-template>
<mifosx-savings-account-terms-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
></mifosx-savings-account-terms-step>
</mat-step>
<mat-step>
<ng-template matStepLabel>CHARGES</ng-template>
<mifosx-savings-account-charges-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
[savingsAccountTemplate]="savingsAccountTemplate"
[currencyCode]="savingsAccountTermsForm.get('currencyCode')"
>
</mifosx-savings-account-charges-step>
</mat-step>
<mat-step *ngIf="savingsAccountFormValid" completed>
<ng-template matStepLabel>PREVIEW</ng-template>
<mifosx-savings-account-preview-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
[savingsAccountTemplate]="savingsAccountTemplate"
[savingsAccountTermsForm]="savingsAccountTermsForm"
[savingsAccount]="savingsAccount"
(submit)="submit()"
>
</mifosx-savings-account-preview-step>
</mat-step>
</mat-horizontal-stepper>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateSavingsAccountComponent } from './create-savings-account.component';
describe('CreateSavingsAccountComponent', () => {
let component: CreateSavingsAccountComponent;
let fixture: ComponentFixture<CreateSavingsAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateSavingsAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreateSavingsAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,124 @@
/** Angular Imports */
import { Component, ViewChild } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Components */
import { SavingsAccountDetailsStepComponent } from '../savings-account-stepper/savings-account-details-step/savings-account-details-step.component';
import { SavingsAccountTermsStepComponent } from '../savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component';
import { SavingsAccountChargesStepComponent } from '../savings-account-stepper/savings-account-charges-step/savings-account-charges-step.component';
/** Custom Services */
import { SavingsService } from '../savings.service';
/**
* Create Savings Account Component
*/
@Component({
selector: 'mifosx-create-savings-account',
templateUrl: './create-savings-account.component.html',
styleUrls: ['./create-savings-account.component.scss']
})
export class CreateSavingsAccountComponent {
/** Savings Account Template */
savingsAccountTemplate: any;
/** Savings Account Product Template */
savingsAccountProductTemplate: any;
/** Savings Account Details Step */
@ViewChild(SavingsAccountDetailsStepComponent) savingsAccountDetailsStep: SavingsAccountDetailsStepComponent;
/** Savings Account Terms Step */
@ViewChild(SavingsAccountTermsStepComponent) savingsAccountTermsStep: SavingsAccountTermsStepComponent;
/** Savings Account Charges Step */
@ViewChild(SavingsAccountChargesStepComponent) savingsAccountChargesStep: SavingsAccountChargesStepComponent;
/**
* Fetches savings account template from `resolve`
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {DatePipe} datePipe Date Pipe
* @param {SavingsService} savingsService Savings Service
*/
constructor(private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe,
private savingsService: SavingsService
) {
this.route.data.subscribe((data: { savingsAccountTemplate: any }) => {
this.savingsAccountTemplate = data.savingsAccountTemplate;
});
}
/**
* Sets savings account product template.
* @param {any} $event API response
*/
setTemplate($event: any) {
this.savingsAccountProductTemplate = $event;
}
/**
* Retrieves savings account details form.
*/
get savingsAccountDetailsForm() {
return this.savingsAccountDetailsStep.savingsAccountDetailsForm;
}
/**
* Retrieves savings account terms form.
*/
get savingsAccountTermsForm() {
return this.savingsAccountTermsStep.savingsAccountTermsForm;
}
/**
* Checks validity of overall savings account form.
*/
get savingsAccountFormValid() {
return (
this.savingsAccountDetailsForm.valid &&
this.savingsAccountTermsForm.valid
);
}
/**
* Retrieves savings account object.
*/
get savingsAccount() {
return {
...this.savingsAccountDetailsStep.savingsAccountDetails,
...this.savingsAccountTermsStep.savingsAccountTerms,
...this.savingsAccountChargesStep.savingsAccountCharges
};
}
/**
* Creates a new share account.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const monthDayFormat = 'dd MMMM';
const savingsAccount = {
...this.savingsAccount,
clientId: this.savingsAccountTemplate.clientId,
charges: this.savingsAccount.charges.map((charge: any) => ({
chargeId: charge.id,
amount: charge.amount,
dueDate: charge.dueDate,
feeOnMonthDay: charge.feeOnMonthDay,
feeInterval: charge.feeInterval
})),
submittedOnDate: this.datePipe.transform(this.savingsAccount.submittedOnDate, dateFormat),
dateFormat,
monthDayFormat,
locale
};
this.savingsService.createSavingsAccount(savingsAccount).subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
});
}
}