Format date fields without patch form
This commit is contained in:
committed by
Arnold Gálovics
parent
9d43181cea
commit
6ea3d97538
+16
-1
@@ -5,6 +5,8 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { ClientsService } from 'app/clients/clients.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
* Accept Client Transfer Component
|
||||
@@ -26,11 +28,15 @@ export class AcceptClientTransferComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {ClientsService} clientsService Clients Service
|
||||
* @param {SettingsService} settingsService Settings Service.
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private settingsService: SettingsService,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { clientActionData: any }) => {
|
||||
@@ -61,8 +67,17 @@ export class AcceptClientTransferComponent implements OnInit {
|
||||
* if successful redirects to the client.
|
||||
*/
|
||||
submit() {
|
||||
const acceptClientTransferFormData = this.acceptClientTransferForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevTransferDate: Date = this.acceptClientTransferForm.value.transferDate;
|
||||
if (acceptClientTransferFormData.transferDate instanceof Date) {
|
||||
acceptClientTransferFormData.transferDate = this.dateUtils.formatDate(prevTransferDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.acceptClientTransferForm.value,
|
||||
...acceptClientTransferFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
this.clientsService.executeClientCommand(this.clientId, 'acceptTransfer', data).subscribe(() => {
|
||||
this.router.navigate(['../../'], { relativeTo: this.route });
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -30,14 +30,14 @@ export class ActivateClientComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {clientsService} clientsService Cliens Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {DatePipe} datePipe Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService Settings Service
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -65,15 +65,15 @@ export class ActivateClientComponent implements OnInit {
|
||||
* if successful redirects to the client.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const activateClientFormData = this.activateClientForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevActivationDate: Date = this.activateClientForm.value.activationDate;
|
||||
this.activateClientForm.patchValue({
|
||||
activationDate: this.datePipe.transform(prevActivationDate, dateFormat),
|
||||
});
|
||||
if (activateClientFormData.activationDate instanceof Date) {
|
||||
activateClientFormData.activationDate = this.dateUtils.formatDate(prevActivationDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.activateClientForm.value,
|
||||
...activateClientFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Amount</mat-label>
|
||||
<input type=number required matInput formControlName="amount" />
|
||||
<input type="number" required matInput formControlName="amount" />
|
||||
<mat-error *ngIf="clientChargeForm.controls.amount.hasError('required')">
|
||||
Amount is <strong>required</strong>
|
||||
</mat-error>
|
||||
|
||||
+5
-5
@@ -2,10 +2,10 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { ClientsService } from 'app/clients/clients.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ export class AddClientChargeComponent implements OnInit {
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {DatePipe} datePipe Date Utils
|
||||
* @param {ClientsService} clientsService Clients Service
|
||||
* @param {SettingsService} settingsService Setting service
|
||||
*/
|
||||
@@ -44,7 +44,7 @@ export class AddClientChargeComponent implements OnInit {
|
||||
private formBuilder: FormBuilder,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private clientsService: ClientsService,
|
||||
private settingsService: SettingsService
|
||||
) {
|
||||
@@ -124,14 +124,14 @@ export class AddClientChargeComponent implements OnInit {
|
||||
clientCharge.monthDayFormat = monthDayFormat;
|
||||
if (clientCharge.feeOnMonthDay) {
|
||||
const prevDate = this.clientChargeForm.value.feeOnMonthDay;
|
||||
clientCharge.feeOnMonthDay = this.datePipe.transform(prevDate, monthDayFormat);
|
||||
clientCharge.feeOnMonthDay = this.dateUtils.formatDate(prevDate, monthDayFormat);
|
||||
}
|
||||
} else {
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
clientCharge.dateFormat = dateFormat;
|
||||
if (clientCharge.dueDate) {
|
||||
const prevDate = this.clientChargeForm.value.dueDate;
|
||||
clientCharge.dueDate = this.datePipe.transform(prevDate, dateFormat);
|
||||
clientCharge.dueDate = this.dateUtils.formatDate(prevDate, dateFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -32,14 +32,14 @@ export class CloseClientComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {ClientsService} clientsService Clients Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {DatePipe} datePipe Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService Setting service
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -67,15 +67,15 @@ export class CloseClientComponent implements OnInit {
|
||||
* Submits the form and closes the client.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const closeClientFormData = this.closeClientForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevClosedDate: Date = this.closeClientForm.value.closureDate;
|
||||
this.closeClientForm.patchValue({
|
||||
closureDate: this.datePipe.transform(prevClosedDate, dateFormat),
|
||||
});
|
||||
if (closeClientFormData.closureDate instanceof Date) {
|
||||
closeClientFormData.closureDate = this.dateUtils.formatDate(prevClosedDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.closeClientForm.value,
|
||||
...closeClientFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -30,14 +30,14 @@ export class ReactivateClientComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {clientsService} clientsService Clients Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService Setting service
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -65,15 +65,15 @@ export class ReactivateClientComponent implements OnInit {
|
||||
* if successful redirects to the client.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const reactivateClientFormData = this.reactivateClientForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevReactivationDate: Date = this.reactivateClientForm.value.reactivationDate;
|
||||
this.reactivateClientForm.patchValue({
|
||||
reactivationDate: this.datePipe.transform(prevReactivationDate, dateFormat),
|
||||
});
|
||||
if (reactivateClientFormData.closureDate instanceof Date) {
|
||||
reactivateClientFormData.reactivationDate = this.dateUtils.formatDate(prevReactivationDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.reactivateClientForm.value,
|
||||
...reactivateClientFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+14
-1
@@ -5,6 +5,8 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { ClientsService } from 'app/clients/clients.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
* Reject Client Transfer Component
|
||||
@@ -31,6 +33,8 @@ export class RejectClientTransferComponent implements OnInit {
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private settingsService: SettingsService,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { clientActionData: any }) => {
|
||||
@@ -58,8 +62,17 @@ export class RejectClientTransferComponent implements OnInit {
|
||||
* if successful redirects to the client.
|
||||
*/
|
||||
submit() {
|
||||
const rejectClientTransferFormData = this.rejectClientTransferForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevTransferDate: Date = this.rejectClientTransferForm.value.transferDate;
|
||||
if (rejectClientTransferFormData.transferDate instanceof Date) {
|
||||
rejectClientTransferFormData.transferDate = this.dateUtils.formatDate(prevTransferDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.rejectClientTransferForm.value,
|
||||
...rejectClientTransferFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
this.clientsService.executeClientCommand(this.clientId, 'rejectTransfer', data).subscribe(() => {
|
||||
this.router.navigate(['../../'], { relativeTo: this.route });
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -32,14 +32,14 @@ export class RejectClientComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {ClientsService} clientsService Clients Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService Setting service
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -67,15 +67,15 @@ export class RejectClientComponent implements OnInit {
|
||||
* Submits the form and rejects the client.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const rejectClientFormData = this.rejectClientForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevRejectedDate: Date = this.rejectClientForm.value.rejectionDate;
|
||||
this.rejectClientForm.patchValue({
|
||||
rejectionDate: this.datePipe.transform(prevRejectedDate, dateFormat),
|
||||
});
|
||||
if (rejectClientFormData.rejectionDate instanceof Date) {
|
||||
rejectClientFormData.rejectionDate = this.dateUtils.formatDate(prevRejectedDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.rejectClientForm.value,
|
||||
...rejectClientFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+9
-9
@@ -1,11 +1,11 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -32,14 +32,14 @@ export class TransferClientComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {ClientsService} clientsService Clients Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService Setting service
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -68,15 +68,15 @@ export class TransferClientComponent implements OnInit {
|
||||
* Submits the form and transfers the client.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const transferClientFormData = this.transferClientForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevClosedDate: Date = this.transferClientForm.value.transferDate;
|
||||
this.transferClientForm.patchValue({
|
||||
transferDate: this.datePipe.transform(prevClosedDate, dateFormat),
|
||||
});
|
||||
const prevTransferDate: Date = this.transferClientForm.value.transferDate;
|
||||
if (transferClientFormData.transferDate instanceof Date) {
|
||||
transferClientFormData.transferDate = this.dateUtils.formatDate(prevTransferDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.transferClientForm.value,
|
||||
...transferClientFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -30,13 +30,13 @@ export class UndoClientRejectionComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {clientsService} clientsService Cliens Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -64,15 +64,15 @@ export class UndoClientRejectionComponent implements OnInit {
|
||||
* if successful redirects to the client.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const undoClientRejectionFormData = this.undoClientRejectionForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevReopenedDate: Date = this.undoClientRejectionForm.value.reopenedDate;
|
||||
this.undoClientRejectionForm.patchValue({
|
||||
reopenedDate: this.datePipe.transform(prevReopenedDate, dateFormat),
|
||||
});
|
||||
if (undoClientRejectionFormData.reopenedDate instanceof Date) {
|
||||
undoClientRejectionFormData.reopenedDate = this.dateUtils.formatDate(prevReopenedDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.undoClientRejectionForm.value,
|
||||
...undoClientRejectionFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+14
-1
@@ -5,6 +5,8 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { ClientsService } from 'app/clients/clients.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
* Undo Client Transfer Component
|
||||
@@ -31,6 +33,8 @@ export class UndoClientTransferComponent implements OnInit {
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private settingsService: SettingsService,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { clientActionData: any }) => {
|
||||
@@ -61,8 +65,17 @@ export class UndoClientTransferComponent implements OnInit {
|
||||
* if successful redirects to the client.
|
||||
*/
|
||||
submit() {
|
||||
const undoClientTransferFormData = this.undoClientTransferForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevTransferDate: Date = this.undoClientTransferForm.value.transferDate;
|
||||
if (undoClientTransferFormData.transferDate instanceof Date) {
|
||||
undoClientTransferFormData.transferDate = this.dateUtils.formatDate(prevTransferDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.undoClientTransferForm.value,
|
||||
...undoClientTransferFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
this.clientsService.executeClientCommand(this.clientId, 'withdrawTransfer', data).subscribe(() => {
|
||||
this.router.navigate(['../../'], { relativeTo: this.route });
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
@@ -32,14 +32,14 @@ export class WithdrawClientComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {ClientsService} clientsService Clients Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService Setting service
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private clientsService: ClientsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -67,15 +67,15 @@ export class WithdrawClientComponent implements OnInit {
|
||||
* Submits the form and withdraws the client.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const withdrawClientFormData = this.withdrawClientForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevWithdrawalDate: Date = this.withdrawClientForm.value.withdrawalDate;
|
||||
this.withdrawClientForm.patchValue({
|
||||
withdrawalDate: this.datePipe.transform(prevWithdrawalDate, dateFormat),
|
||||
});
|
||||
if (withdrawClientFormData.withdrawalDate instanceof Date) {
|
||||
withdrawClientFormData.withdrawalDate = this.dateUtils.formatDate(prevWithdrawalDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.withdrawClientForm.value,
|
||||
...withdrawClientFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user