feat: shares account actions (reject) (#892)

Fixes: #891
This commit is contained in:
Karan Takalkar
2020-06-23 16:38:15 +05:30
committed by GitHub
parent 5701bd1ed0
commit 8c032fc3ef
9 changed files with 160 additions and 5 deletions
@@ -0,0 +1,39 @@
<div class="container">
<mat-card>
<form [formGroup]="rejectSharesAccountForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Rejected On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="rejectedDatePicker" required formControlName="rejectedDate">
<mat-datepicker-toggle matSuffix [for]="rejectedDatePicker"></mat-datepicker-toggle>
<mat-datepicker #rejectedDatePicker></mat-datepicker>
<mat-error *ngIf="rejectSharesAccountForm.controls.rejectedDate.hasError('required')">
Rejected On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Note</mat-label>
<textarea matInput formControlName="note"></textarea>
</mat-form-field>
</div>
</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="warn" [disabled]="!rejectSharesAccountForm.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 { RejectSharesAccountComponent } from './reject-shares-account.component';
describe('RejectSharesAccountComponent', () => {
let component: RejectSharesAccountComponent;
let fixture: ComponentFixture<RejectSharesAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RejectSharesAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RejectSharesAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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';
/**
* Reject Shares Account Component
*/
@Component({
selector: 'mifosx-reject-shares-account',
templateUrl: './reject-shares-account.component.html',
styleUrls: ['./reject-shares-account.component.scss']
})
export class RejectSharesAccountComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Reject Share Account form. */
rejectSharesAccountForm: 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 reject shares form.
*/
ngOnInit() {
this.createRejectSharesAccountForm();
}
/**
* Creates the reject shares account form.
*/
createRejectSharesAccountForm() {
this.rejectSharesAccountForm = this.formBuilder.group({
'rejectedDate': ['', Validators.required],
'note': ['']
});
}
/**
* Submits the form and rejects 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 prevRejectedDate: Date = this.rejectSharesAccountForm.value.rejectedDate;
this.rejectSharesAccountForm.patchValue({
rejectedDate: this.datePipe.transform(prevRejectedDate, dateFormat),
});
const data = {
...this.rejectSharesAccountForm.value,
dateFormat,
locale
};
this.sharesService.executeSharesAccountCommand(this.accountId, 'reject', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -1 +1,2 @@
<mifosx-approve-shares-account *ngIf="actions.Approve"></mifosx-approve-shares-account>
<mifosx-approve-shares-account *ngIf="actions.Approve"></mifosx-approve-shares-account>
<mifosx-reject-shares-account *ngIf="actions.Reject"></mifosx-reject-shares-account>
@@ -13,7 +13,13 @@ import { ActivatedRoute } from '@angular/router';
export class SharesAccountActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: { Approve: boolean } = { Approve: false };
actions: {
Approve: boolean
Reject: boolean
} = {
Approve: false ,
Reject: false
};
constructor(private route: ActivatedRoute) {
const name = this.route.snapshot.params['name'];
@@ -41,8 +41,8 @@
<ng-container *ngIf="buttonConfig.options">
<button mat-raised-button [matMenuTriggerFor]="More">More</button>
<mat-menu #More="matMenu">
<span *ngFor="let button of buttonConfig.options">
<button mat-menu-item *mifosxHasPermission="button.taskPermissionName">{{button.name}}</button>
<span *ngFor="let option of buttonConfig.options">
<button mat-menu-item *mifosxHasPermission="option.taskPermissionName" (click)="doAction(option.name)">{{option.name}}</button>
</span>
</mat-menu>
</ng-container>
@@ -79,6 +79,9 @@ export class SharesAccountViewComponent implements OnInit {
case 'Approve':
this.router.navigate(['actions/Approve'], { relativeTo: this.route });
break;
case 'Reject':
this.router.navigate(['actions/Reject'], { relativeTo: this.route });
break;
}
}
+3 -1
View File
@@ -19,6 +19,7 @@ import { SharesAccountPreviewStepComponent } from './shares-account-stepper/shar
import { EditSharesAccountComponent } from './edit-shares-account/edit-shares-account.component';
import { SharesAccountActionsComponent } from './shares-account-actions/shares-account-actions.component';
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';
/**
* Shares Module
@@ -44,7 +45,8 @@ import { ApproveSharesAccountComponent } from './shares-account-actions/approve-
SharesAccountPreviewStepComponent,
EditSharesAccountComponent,
SharesAccountActionsComponent,
ApproveSharesAccountComponent
ApproveSharesAccountComponent,
RejectSharesAccountComponent
],
providers: [DatePipe]
})