feat: add recurring deposit actions (activate) (#1002)

Fixes: #1000
This commit is contained in:
Muskan Khedia
2020-07-07 14:20:59 +05:30
committed by GitHub
parent 3b7406057a
commit a472d886dd
14 changed files with 314 additions and 48 deletions
@@ -0,0 +1,31 @@
<div class="container">
<mat-card>
<form [formGroup]="activateRecurringDepositsAccountForm" (ngSubmit)="submit()">
<mat-card-content>
<mat-form-field fxFlex>
<mat-label>Activated On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="activatedOnDatePicker" required
formControlName="activatedOnDate">
<mat-datepicker-toggle matSuffix [for]="activatedOnDatePicker"></mat-datepicker-toggle>
<mat-datepicker #activatedOnDatePicker></mat-datepicker>
<mat-error *ngIf="activateRecurringDepositsAccountForm.controls.activatedOnDate.hasError('required')">
Activated On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../../']">Cancel</button>
<button mat-raised-button color="accent" [disabled]="!activateRecurringDepositsAccountForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivateRecurringDepositsAccountComponent } from './activate-recurring-deposits-account.component';
describe('ActivateRecurringDepositsAccountComponent', () => {
let component: ActivateRecurringDepositsAccountComponent;
let fixture: ComponentFixture<ActivateRecurringDepositsAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ActivateRecurringDepositsAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivateRecurringDepositsAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,81 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { RecurringDepositsService } from '../../recurring-deposits.service';
/**
* Activate Recurring Deposits Account Component
*/
@Component({
selector: 'mifosx-activate-recurring-deposits-account',
templateUrl: './activate-recurring-deposits-account.component.html',
styleUrls: ['./activate-recurring-deposits-account.component.scss']
})
export class ActivateRecurringDepositsAccountComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Activate Recurring Deposits Account form. */
activateRecurringDepositsAccountForm: FormGroup;
/** Recurring Deposits Account Id */
accountId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {recurringDepositsService} recurringDepositsService Recurring Deposits Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private recurringDepositsService: RecurringDepositsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.accountId = this.route.parent.snapshot.params['recurringDepositAccountId'];
}
/**
* Creates the activate recurring deposits form.
*/
ngOnInit() {
this.createActivateRecurringDepositsAccountForm();
}
/**
* Creates the activate recurring deposits account form.
*/
createActivateRecurringDepositsAccountForm() {
this.activateRecurringDepositsAccountForm = this.formBuilder.group({
'activatedOnDate': ['', Validators.required]
});
}
/**
* Submits the form and activates the recurring deposit account,
* if successful redirects to the recurring deposit account.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevActivatedOnDate: Date = this.activateRecurringDepositsAccountForm.value.activatedOnDate;
this.activateRecurringDepositsAccountForm.patchValue({
activatedOnDate: this.datePipe.transform(prevActivatedOnDate, dateFormat),
});
const data = {
...this.activateRecurringDepositsAccountForm.value,
dateFormat,
locale
};
this.recurringDepositsService.executeRecurringDepositsAccountCommand(this.accountId, 'activate', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -0,0 +1 @@
<mifosx-activate-recurring-deposits-account *ngIf="actions['Activate']"></mifosx-activate-recurring-deposits-account>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RecurringDepositsAccountActionsComponent } from './recurring-deposits-account-actions.component';
describe('RecurringDepositsAccountActionsComponent', () => {
let component: RecurringDepositsAccountActionsComponent;
let fixture: ComponentFixture<RecurringDepositsAccountActionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RecurringDepositsAccountActionsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RecurringDepositsAccountActionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,26 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'mifosx-recurring-deposits-account-actions',
templateUrl: './recurring-deposits-account-actions.component.html',
styleUrls: ['./recurring-deposits-account-actions.component.scss']
})
export class RecurringDepositsAccountActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Activate': boolean
} = {
'Activate': false,
};
/**
* @param {ActivatedRoute} route Activated Route
*/
constructor(private route: ActivatedRoute) {
const name = this.route.snapshot.params['name'];
this.actions[name] = true;
}
}