feat: add create shares account page (#877)

Fixes: #223
This commit is contained in:
Karan Takalkar
2020-06-15 21:18:14 +05:30
committed by GitHub
parent 5304774e26
commit d51bd6466a
26 changed files with 1103 additions and 5 deletions
@@ -0,0 +1,46 @@
<form [formGroup]="sharesAccountDetailsForm">
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
<mat-form-field fxFlex="48%">
<mat-label>Product Name</mat-label>
<mat-select formControlName="productId" required>
<mat-option *ngFor="let product of productData" [value]="product.id">
{{ product.name }}
</mat-option>
</mat-select>
<mat-error>
Product Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Submitted On</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="submittedOnDatePicker"
formControlName="submittedDate" required>
<mat-datepicker-toggle matSuffix [for]="submittedOnDatePicker"></mat-datepicker-toggle>
<mat-datepicker #submittedOnDatePicker></mat-datepicker>
<mat-error>
Submission Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>External ID</mat-label>
<input matInput formControlName="externalId">
</mat-form-field>
</div>
<div fxLayout="row" class="margin-t" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="2%">
<button mat-raised-button matStepperPrevious disabled>
<fa-icon icon="arrow-left"></fa-icon>&nbsp;&nbsp;
Previous
</button>
<button mat-raised-button matStepperNext>
Next&nbsp;&nbsp;
<fa-icon icon="arrow-right"></fa-icon>
</button>
</div>
</form>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SharesAccountDetailsStepComponent } from './shares-account-details-step.component';
describe('SharesAccountDetailsStepComponent', () => {
let component: SharesAccountDetailsStepComponent;
let fixture: ComponentFixture<SharesAccountDetailsStepComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SharesAccountDetailsStepComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SharesAccountDetailsStepComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,78 @@
/** Angular Imports */
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
/** Custom Services */
import { SharesService } from 'app/shares/shares.service';
/**
* Shares Account Details Step
*/
@Component({
selector: 'mifosx-shares-account-details-step',
templateUrl: './shares-account-details-step.component.html',
styleUrls: ['./shares-account-details-step.component.scss']
})
export class SharesAccountDetailsStepComponent implements OnInit {
/** Shares Account Template */
@Input() sharesAccountTemplate: any;
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Product Data */
productData: any;
/** Shares Account Details Form */
sharesAccountDetailsForm: FormGroup;
/** Shares Account Template with product data */
@Output() sharesAccountProductTemplate = new EventEmitter();
/**
* Sets share account details form.
* @param {FormBuilder} formBuilder Form Builder.
* @param {SharesService} sharesService Shares Service.
*/
constructor(private formBuilder: FormBuilder,
private sharesService: SharesService) {
this.createSharesAccountDetailsForm();
}
ngOnInit() {
this.productData = this.sharesAccountTemplate.productOptions;
this.buildDependencies();
}
/**
* Creates shares account details form.
*/
createSharesAccountDetailsForm() {
this.sharesAccountDetailsForm = this.formBuilder.group({
'productId': ['', Validators.required],
'submittedDate': ['', Validators.required],
'externalId': ['']
});
}
/**
* Fetches shares account product template on productId value changes
*/
buildDependencies() {
const clientId = this.sharesAccountTemplate.clientId;
this.sharesAccountDetailsForm.get('productId').valueChanges.subscribe((productId: string) => {
this.sharesService.getSharesAccountTemplate(clientId, productId).subscribe((response: any) => {
this.sharesAccountProductTemplate.emit(response);
});
});
}
/**
* Returns shares account form value.
*/
get sharesAccountDetails() {
return this.sharesAccountDetailsForm.value;
}
}