feat: client actions (assign/unassign staff) (#1067)

Fixes: #1066
This commit is contained in:
Karan Takalkar
2020-07-13 11:18:10 +05:30
committed by GitHub
parent ac529dbae8
commit af32d481bf
29 changed files with 378 additions and 13 deletions
@@ -0,0 +1 @@
<mifosx-client-assign-staff *ngIf="actions['Assign Staff']"></mifosx-client-assign-staff>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClientActionsComponent } from './client-actions.component';
describe('ClientActionsComponent', () => {
let component: ClientActionsComponent;
let fixture: ComponentFixture<ClientActionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ClientActionsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ClientActionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,33 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
/**
* Client actions component.
*/
@Component({
selector: 'mifosx-client-actions',
templateUrl: './client-actions.component.html',
styleUrls: ['./client-actions.component.scss']
})
export class ClientActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Assign Staff': boolean
} = {
'Assign Staff': false,
};
/**
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private route: ActivatedRoute,
private router: Router) {
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
const name = this.route.snapshot.params['name'];
this.actions[name] = true;
}
}
@@ -0,0 +1,36 @@
<div class="container">
<mat-card>
<form [formGroup]="clientAssignStaffForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field fxFlex="48%">
<mat-label>Staff</mat-label>
<mat-select formControlName="staffId">
<mat-option *ngFor="let staff of staffData" [value]="staff.id">
{{ staff.displayName }}
</mat-option>
</mat-select>
<mat-error *ngIf="clientAssignStaffForm.controls.staffId.hasError('required')">
Staff 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="primary" [disabled]="!clientAssignStaffForm.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 { ClientAssignStaffComponent } from './client-assign-staff.component';
describe('ClientAssignStaffComponent', () => {
let component: ClientAssignStaffComponent;
let fixture: ComponentFixture<ClientAssignStaffComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ClientAssignStaffComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ClientAssignStaffComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,69 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { ClientsService } from 'app/clients/clients.service';
/**
* Clients Assign Staff Component
*/
@Component({
selector: 'mifosx-client-assign-staff',
templateUrl: './client-assign-staff.component.html',
styleUrls: ['./client-assign-staff.component.scss']
})
export class ClientAssignStaffComponent implements OnInit {
/** Client Assign Staff form. */
clientAssignStaffForm: FormGroup;
/** Field Officer Data */
staffData: any;
/** Client Data */
clientData: any;
/**
* Fetches Client Action Data from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {SavingsService} savingsService Savings Service
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private clientsService: ClientsService,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { clientActionData: any }) => {
this.clientData = data.clientActionData;
});
}
/**
* Creates the client assign staff form.
*/
ngOnInit() {
this.staffData = this.clientData.staffOptions;
this.createClientAssignStaffForm();
}
/**
* Creates the client assign staff form.
*/
createClientAssignStaffForm() {
this.clientAssignStaffForm = this.formBuilder.group({
'staffId': ['']
});
}
/**
* Submits the form and assigns staff for the client.
*/
submit() {
this.clientsService.executeClientCommand(this.clientData.id, 'assignStaff', this.clientAssignStaffForm.value)
.subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}