feat: shares account actions (close) (#896)

Fixes: #895
This commit is contained in:
Karan Takalkar
2020-06-23 20:40:46 +05:30
committed by GitHub
parent d719d9a4cf
commit 4e2f9ce2ee
8 changed files with 155 additions and 4 deletions
@@ -0,0 +1,76 @@
/** 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 { SharesService } from 'app/shares/shares.service';
/**
* Close Shares Account Component
*/
@Component({
selector: 'mifosx-close-shares-account',
templateUrl: './close-shares-account.component.html',
styleUrls: ['./close-shares-account.component.scss']
})
export class CloseSharesAccountComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Close Share Account form. */
closeSharesAccountForm: FormGroup;
/** Shares Account Id */
accountId: any;
constructor(private formBuilder: FormBuilder,
private sharesService: SharesService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.accountId = this.route.parent.parent.snapshot.params['shareAccountId'];
}
/**
* Creates the close shares form.
*/
ngOnInit() {
this.createCloseSharesAccountForm();
}
/**
* Creates the close shares account form.
*/
createCloseSharesAccountForm() {
this.closeSharesAccountForm = this.formBuilder.group({
'closedDate': ['', Validators.required],
'note': ['']
});
}
/**
* Submits the form and closes the share account,
* if successful redirects to the share account.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevClosedDate: Date = this.closeSharesAccountForm.value.closedDate;
this.closeSharesAccountForm.patchValue({
closedDate: this.datePipe.transform(prevClosedDate, dateFormat),
});
const data = {
...this.closeSharesAccountForm.value,
dateFormat,
locale
};
this.sharesService.executeSharesAccountCommand(this.accountId, 'close', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}