diff --git a/src/app/system/configurations/global-configurations-tab/edit-configuration/edit-configuration.component.ts b/src/app/system/configurations/global-configurations-tab/edit-configuration/edit-configuration.component.ts index eea9d1c09..35bb17470 100644 --- a/src/app/system/configurations/global-configurations-tab/edit-configuration/edit-configuration.component.ts +++ b/src/app/system/configurations/global-configurations-tab/edit-configuration/edit-configuration.component.ts @@ -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 }); }); }