feat: client actions (reject) (#1071)

Fixes: #1070
This commit is contained in:
Karan Takalkar
2020-07-13 14:43:26 +05:30
committed by GitHub
parent 894b9afeb6
commit 20c29569f8
10 changed files with 170 additions and 2 deletions
@@ -1,3 +1,4 @@
<mifosx-client-assign-staff *ngIf="actions['Assign Staff']"></mifosx-client-assign-staff>
<mifosx-close-client *ngIf="actions['Close']"></mifosx-close-client>
<mifosx-view-survey *ngIf="actions['Survey']"></mifosx-view-survey>
<mifosx-reject-client *ngIf="actions['Reject']"></mifosx-reject-client>
@@ -15,11 +15,13 @@ export class ClientActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Assign Staff': boolean
'Close': boolean,
'Close': boolean
'Reject': boolean
'Survey': boolean
} = {
'Assign Staff': false,
'Close': false,
'Reject': false,
'Survey': false
};
@@ -0,0 +1,46 @@
<div class="container">
<mat-card>
<form [formGroup]="rejectClientForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Rejection Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="rejectionDatePicker" required formControlName="rejectionDate">
<mat-datepicker-toggle matSuffix [for]="rejectionDatePicker"></mat-datepicker-toggle>
<mat-datepicker #rejectionDatePicker></mat-datepicker>
<mat-error *ngIf="rejectClientForm.controls.rejectionDate.hasError('required')">
Rejection Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Rejection Reason</mat-label>
<mat-select formControlName="rejectionReasonId">
<mat-option *ngFor="let reason of rejectionData" [value]="reason.id">
{{ reason.description }}
</mat-option>
</mat-select>
<mat-error *ngIf="rejectClientForm.controls.rejectionReasonId.hasError('required')">
Rejection Reason is <strong>required</strong>
</mat-error>
</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]="!rejectClientForm.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 { RejectClientComponent } from './reject-client.component';
describe('RejectClientComponent', () => {
let component: RejectClientComponent;
let fixture: ComponentFixture<RejectClientComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RejectClientComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RejectClientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,84 @@
/** 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 { ClientsService } from 'app/clients/clients.service';
/**
* Reject Client Component
*/
@Component({
selector: 'mifosx-reject-client',
templateUrl: './reject-client.component.html',
styleUrls: ['./reject-client.component.scss']
})
export class RejectClientComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Reject Share Account form. */
rejectClientForm: FormGroup;
/** Client Data */
rejectionData: any;
/** Client Id */
clientId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {ClientsService} clientsService Clients Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private clientsService: ClientsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { clientActionData: any }) => {
this.rejectionData = data.clientActionData.narrations;
});
this.clientId = this.route.parent.snapshot.params['clientId'];
}
ngOnInit() {
this.createRejectClientForm();
}
/**
* Creates the reject client form.
*/
createRejectClientForm() {
this.rejectClientForm = this.formBuilder.group({
'rejectionDate': ['', Validators.required],
'rejectionReasonId': ['', Validators.required]
});
}
/**
* Submits the form and rejects the client.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevRejectedDate: Date = this.rejectClientForm.value.rejectionDate;
this.rejectClientForm.patchValue({
rejectionDate: this.datePipe.transform(prevRejectedDate, dateFormat),
});
const data = {
...this.rejectClientForm.value,
dateFormat,
locale
};
this.clientsService.executeClientCommand(this.clientId, 'reject', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -44,6 +44,7 @@
<span *ngIf="clientViewData.staffId"><button mat-menu-item (click)="doAction('Unassign Staff')">Unassign Staff</button></span>
<button mat-menu-item (click)="doAction('Close')">Close</button>
<button mat-menu-item (click)="doAction('Survey')"> Survey</button>
<span *ngIf="clientViewData.status.value === 'Pending'"><button mat-menu-item (click)="doAction('Reject')">Reject</button></span>
</mat-menu>
</mat-card-actions>
</mat-card-header>
@@ -53,6 +53,7 @@ export class ClientsViewComponent implements OnInit {
case 'Assign Staff':
case 'Close':
case 'Survey':
case 'Reject':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
+4 -1
View File
@@ -30,6 +30,8 @@ import { ClientAssignStaffComponent } from './clients-view/client-actions/client
import { UnassignStaffDialogComponent } from './clients-view/custom-dialogs/unassign-staff-dialog/unassign-staff-dialog.component';
import { CloseClientComponent } from './clients-view/client-actions/close-client/close-client.component';
import { ViewSurveyComponent } from './clients-view/client-actions/view-survey/view-survey.component';
import { RejectClientComponent } from './clients-view/client-actions/reject-client/reject-client.component';
/**
* Clients Module
@@ -64,7 +66,8 @@ import { ViewSurveyComponent } from './clients-view/client-actions/view-survey/v
ClientAssignStaffComponent,
UnassignStaffDialogComponent,
CloseClientComponent,
ViewSurveyComponent
ViewSurveyComponent,
RejectClientComponent
],
entryComponents: [
UploadDocumentDialogComponent,
@@ -34,6 +34,8 @@ export class ClientActionsResolver implements Resolve<Object> {
return this.clientsService.getClientCommandTemplate('close');
case 'Survey':
return this.clientsService.getSurveys(clientId);
case 'Reject':
return this.clientsService.getClientCommandTemplate('reject');
default:
return undefined;
}