feat: client actions (activate) (#1075)

Fixes: #1074
This commit is contained in:
Karan Takalkar
2020-07-13 15:15:02 +05:30
committed by GitHub
parent 7bd79fb498
commit 9a6791d713
8 changed files with 146 additions and 1 deletions
@@ -0,0 +1,30 @@
<div class="container">
<mat-card>
<form [formGroup]="activateClientForm" (ngSubmit)="submit()">
<mat-card-content>
<mat-form-field fxFlex>
<mat-label>Activated On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="activationDatePicker" required formControlName="activationDate">
<mat-datepicker-toggle matSuffix [for]="activationDatePicker"></mat-datepicker-toggle>
<mat-datepicker #activationDatePicker></mat-datepicker>
<mat-error *ngIf="activateClientForm.controls.activationDate.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]="!activateClientForm.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 { ActivateClientComponent } from './activate-client.component';
describe('ActivateClientComponent', () => {
let component: ActivateClientComponent;
let fixture: ComponentFixture<ActivateClientComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ActivateClientComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivateClientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,82 @@
/** 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';
/**
* Activate Client Component
*/
@Component({
selector: 'mifosx-activate-client',
templateUrl: './activate-client.component.html',
styleUrls: ['./activate-client.component.scss']
})
export class ActivateClientComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Activate client form. */
activateClientForm: FormGroup;
/** Client Account Id */
clientId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {clientsService} clientsService Cliens 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.clientId = this.route.parent.snapshot.params['clientId'];
}
/**
* Creates the activate client form.
*/
ngOnInit() {
this.createActivateClientForm();
}
/**
* Creates the activate client form.
*/
createActivateClientForm() {
this.activateClientForm = this.formBuilder.group({
'activationDate': ['', Validators.required]
});
}
/**
* Submits the form and activates the client,
* if successful redirects to the client.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevactivationDate: Date = this.activateClientForm.value.activationDate;
this.activateClientForm.patchValue({
activationDate: this.datePipe.transform(prevactivationDate, dateFormat),
});
const data = {
...this.activateClientForm.value,
dateFormat,
locale
};
this.clientsService.executeClientCommand(this.clientId, 'activate', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -2,3 +2,4 @@
<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>
<mifosx-activate-client *ngIf="actions['Activate']"></mifosx-activate-client>
@@ -42,6 +42,7 @@
<button mat-menu-item [routerLink]="['fixed-deposits-accounts', 'create-fixed-deposit-account']">New Fixed Deposits Account</button>
<span *ngIf="!clientViewData.staffId"><button mat-menu-item (click)="doAction('Assign Staff')">Assign Staff</button></span>
<span *ngIf="clientViewData.staffId"><button mat-menu-item (click)="doAction('Unassign Staff')">Unassign Staff</button></span>
<span *ngIf="clientViewData.status.value === 'Pending'"><button mat-menu-item (click)="doAction('Activate')">Activate</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>
@@ -55,6 +55,7 @@ export class ClientsViewComponent implements OnInit {
case 'Close':
case 'Survey':
case 'Reject':
case 'Activate':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
+3 -1
View File
@@ -31,6 +31,7 @@ import { UnassignStaffDialogComponent } from './clients-view/custom-dialogs/unas
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';
import { ActivateClientComponent } from './clients-view/client-actions/activate-client/activate-client.component';
/**
@@ -67,7 +68,8 @@ import { RejectClientComponent } from './clients-view/client-actions/reject-clie
UnassignStaffDialogComponent,
CloseClientComponent,
ViewSurveyComponent,
RejectClientComponent
RejectClientComponent,
ActivateClientComponent
],
entryComponents: [
UploadDocumentDialogComponent,