Format date fields without patch form

This commit is contained in:
Jose Alberto Hernandez
2022-06-10 10:34:19 +02:00
committed by Arnold Gálovics
parent 9d43181cea
commit 6ea3d97538
191 changed files with 1408 additions and 1173 deletions
@@ -1,12 +1,12 @@
/** 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';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/**
* Close Shares Account Component
@@ -30,14 +30,14 @@ export class CloseSharesAccountComponent implements OnInit {
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {SharesService} sharesService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {Dates} dateUtils Date Utils
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SettingsService} settingsService Settings Service.
*/
constructor(private formBuilder: FormBuilder,
private sharesService: SharesService,
private datePipe: DatePipe,
private dateUtils: Dates,
private route: ActivatedRoute,
private router: Router,
private settingsService: SettingsService) {
@@ -66,15 +66,15 @@ export class CloseSharesAccountComponent implements OnInit {
* if successful redirects to the share account.
*/
submit() {
// TODO: Update once language and date settings are setup
const closeSharesAccountFormData = this.closeSharesAccountForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const prevClosedDate: Date = this.closeSharesAccountForm.value.closedDate;
this.closeSharesAccountForm.patchValue({
closedDate: this.datePipe.transform(prevClosedDate, dateFormat),
});
if (closeSharesAccountFormData.closedDate instanceof Date) {
closeSharesAccountFormData.closedDate = this.dateUtils.formatDate(prevClosedDate, dateFormat);
}
const data = {
...this.closeSharesAccountForm.value,
...closeSharesAccountFormData,
dateFormat,
locale
};