mirror of
https://github.com/openMF/web-app.git
synced 2026-02-06 14:11:48 +00:00
WEB-614 fix: format date value according to dateFormat before sending to backend
When adding a configuration for custom account number length, the system shows a warning about the date format being sent with an incorrect value. The date picker was sending dates in ISO format but the backend expected them formatted according to the dateFormat setting. Changes: - Import and use Dates.formatDate service for consistent date formatting - Format dates according to the user's dateFormat setting before sending to backend - Date values are now formatted as strings matching the dateFormat pattern - Includes locale and dateFormat in the payload for proper backend processing
This commit is contained in:
parent
ba47f04b62
commit
84ca84ee43
@ -11,6 +11,7 @@ import { Component, OnInit, inject } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/** Custom Services */
|
||||
import { SystemService } from '../../../system.service';
|
||||
@ -35,6 +36,7 @@ export class EditConfigurationComponent implements OnInit {
|
||||
private settingsService = inject(SettingsService);
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private dateUtils = inject(Dates);
|
||||
|
||||
/** Minimum transaction date allowed. */
|
||||
minDate = new Date(2000, 0, 1);
|
||||
@ -94,20 +96,33 @@ export class EditConfigurationComponent implements OnInit {
|
||||
this.configurationForm.value.stringValue != null ||
|
||||
this.configurationForm.value.dateValue != null
|
||||
) {
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
...this.configurationForm.value
|
||||
};
|
||||
|
||||
if (!this.configurationForm.value.stringValue) {
|
||||
delete payload.stringValue;
|
||||
}
|
||||
|
||||
if (this.configurationForm.value.dateValue != null) {
|
||||
payload.locale = this.settingsService.language.code;
|
||||
payload.dateFormat = this.settingsService.dateFormat;
|
||||
// Format the date according to the dateFormat setting
|
||||
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 {
|
||||
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 });
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user