Merge pull request #3076 from Anshudh/WEB-614-fix-config-date-validation
WEB-614 Fix dateValue formatting in configuration edit
This commit is contained in:
+19
-4
@@ -11,6 +11,7 @@ import { Component, OnInit, inject } from '@angular/core';
|
|||||||
import { UntypedFormBuilder, UntypedFormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
import { UntypedFormBuilder, UntypedFormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||||
import { SettingsService } from 'app/settings/settings.service';
|
import { SettingsService } from 'app/settings/settings.service';
|
||||||
|
import { Dates } from 'app/core/utils/dates';
|
||||||
|
|
||||||
/** Custom Services */
|
/** Custom Services */
|
||||||
import { SystemService } from '../../../system.service';
|
import { SystemService } from '../../../system.service';
|
||||||
@@ -35,6 +36,7 @@ export class EditConfigurationComponent implements OnInit {
|
|||||||
private settingsService = inject(SettingsService);
|
private settingsService = inject(SettingsService);
|
||||||
private route = inject(ActivatedRoute);
|
private route = inject(ActivatedRoute);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
|
private dateUtils = inject(Dates);
|
||||||
|
|
||||||
/** Minimum transaction date allowed. */
|
/** Minimum transaction date allowed. */
|
||||||
minDate = new Date(2000, 0, 1);
|
minDate = new Date(2000, 0, 1);
|
||||||
@@ -94,20 +96,33 @@ export class EditConfigurationComponent implements OnInit {
|
|||||||
this.configurationForm.value.stringValue != null ||
|
this.configurationForm.value.stringValue != null ||
|
||||||
this.configurationForm.value.dateValue != null
|
this.configurationForm.value.dateValue != null
|
||||||
) {
|
) {
|
||||||
const payload = {
|
const payload: any = {
|
||||||
...this.configurationForm.value
|
...this.configurationForm.value
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.configurationForm.value.stringValue) {
|
if (!this.configurationForm.value.stringValue) {
|
||||||
delete payload.stringValue;
|
delete payload.stringValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.configurationForm.value.dateValue != null) {
|
if (this.configurationForm.value.dateValue != null) {
|
||||||
payload.locale = this.settingsService.language.code;
|
// Format the date according to the dateFormat setting
|
||||||
payload.dateFormat = this.settingsService.dateFormat;
|
const dateFormat = this.settingsService.dateFormat || 'dd MMMM yyyy';
|
||||||
|
|
||||||
|
const formattedDate = this.dateUtils.formatDate(this.configurationForm.value.dateValue, dateFormat);
|
||||||
|
|
||||||
|
if (formattedDate) {
|
||||||
|
payload.dateValue = formattedDate;
|
||||||
|
payload.locale = this.settingsService.language.code;
|
||||||
|
payload.dateFormat = dateFormat;
|
||||||
|
} else {
|
||||||
|
// Avoid sending invalid/null date to backend
|
||||||
|
delete payload.dateValue;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
delete payload.dateValue;
|
delete payload.dateValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.systemService.updateConfiguration(this.configuration.id, payload).subscribe((response: any) => {
|
this.systemService.updateConfiguration(this.configuration.id, payload).subscribe(() => {
|
||||||
this.router.navigate(['../../'], { relativeTo: this.route });
|
this.router.navigate(['../../'], { relativeTo: this.route });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user