feat: shares account actions (activate) (#898)

Fixes: #897
This commit is contained in:
Karan Takalkar
2020-06-23 21:36:50 +05:30
committed by GitHub
parent 4e2f9ce2ee
commit 3e4f3e514c
9 changed files with 145 additions and 4 deletions
@@ -310,7 +310,7 @@
<i class="fa fa-undo"></i>
</button>
<button *ngIf="!element.status.submittedAndPendingApproval && !element.status.active"
class="account-action-button" mat-raised-button color="primary">
class="account-action-button" mat-raised-button color="primary" [routerLink]="['../','sharesaccounts', element.id, 'actions', 'Activate']">
<i class="fa fa-check-circle"></i>
</button>
</td>
@@ -0,0 +1,30 @@
<div class="container">
<mat-card>
<form [formGroup]="activateSharesAccountForm" (ngSubmit)="submit()">
<mat-card-content>
<mat-form-field fxFlex>
<mat-label>Activated On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="activatedDatePicker" required formControlName="activatedDate">
<mat-datepicker-toggle matSuffix [for]="activatedDatePicker"></mat-datepicker-toggle>
<mat-datepicker #activatedDatePicker></mat-datepicker>
<mat-error *ngIf="activateSharesAccountForm.controls.activatedDate.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]="!activateSharesAccountForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivateSharesAccountComponent } from './activate-shares-account.component';
describe('ActivateSharesAccountComponent', () => {
let component: ActivateSharesAccountComponent;
let fixture: ComponentFixture<ActivateSharesAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ActivateSharesAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivateSharesAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,75 @@
/** 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';
/**
* Activate Shares Account Component
*/
@Component({
selector: 'mifosx-activate-shares-account',
templateUrl: './activate-shares-account.component.html',
styleUrls: ['./activate-shares-account.component.scss']
})
export class ActivateSharesAccountComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Activate Share Account form. */
activateSharesAccountForm: 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 activate shares form.
*/
ngOnInit() {
this.createActivateSharesAccountForm();
}
/**
* Creates the activate shares account form.
*/
createActivateSharesAccountForm() {
this.activateSharesAccountForm = this.formBuilder.group({
'activatedDate': ['', Validators.required]
});
}
/**
* Submits the form and activates 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 prevActivatedDate: Date = this.activateSharesAccountForm.value.activatedDate;
this.activateSharesAccountForm.patchValue({
activatedDate: this.datePipe.transform(prevActivatedDate, dateFormat),
});
const data = {
...this.activateSharesAccountForm.value,
dateFormat,
locale
};
this.sharesService.executeSharesAccountCommand(this.accountId, 'activate', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -1,3 +1,4 @@
<mifosx-approve-shares-account *ngIf="actions.Approve"></mifosx-approve-shares-account>
<mifosx-reject-shares-account *ngIf="actions.Reject"></mifosx-reject-shares-account>
<mifosx-close-shares-account *ngIf="actions.Close"></mifosx-close-shares-account>
<mifosx-close-shares-account *ngIf="actions.Close"></mifosx-close-shares-account>
<mifosx-activate-shares-account *ngIf="actions.Activate"></mifosx-activate-shares-account>
@@ -17,10 +17,12 @@ export class SharesAccountActionsComponent {
Approve: boolean
Reject: boolean
Close: boolean
Activate: boolean
} = {
Approve: false,
Reject: false,
Close: false
Close: false,
Activate: false
};
constructor(private route: ActivatedRoute) {
@@ -94,6 +94,9 @@ export class SharesAccountViewComponent implements OnInit {
case 'Close':
this.router.navigate(['actions/Close'], { relativeTo: this.route });
break;
case 'Activate':
this.router.navigate(['actions/Activate'], { relativeTo: this.route });
break;
case 'Delete':
this.deleteSharesAccount();
break;
+3 -1
View File
@@ -21,6 +21,7 @@ import { SharesAccountActionsComponent } from './shares-account-actions/shares-a
import { ApproveSharesAccountComponent } from './shares-account-actions/approve-shares-account/approve-shares-account.component';
import { RejectSharesAccountComponent } from './shares-account-actions/reject-shares-account/reject-shares-account.component';
import { CloseSharesAccountComponent } from './shares-account-actions/close-shares-account/close-shares-account.component';
import { ActivateSharesAccountComponent } from './shares-account-actions/activate-shares-account/activate-shares-account.component';
/**
* Shares Module
@@ -48,7 +49,8 @@ import { CloseSharesAccountComponent } from './shares-account-actions/close-shar
SharesAccountActionsComponent,
ApproveSharesAccountComponent,
RejectSharesAccountComponent,
CloseSharesAccountComponent
CloseSharesAccountComponent,
ActivateSharesAccountComponent
],
providers: [DatePipe]
})