Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a service class to get this format:

dateUtils.formatDate
That method receives the date value to be formatted and the format to be used that usually comes from the user settings

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I’ve updated the implementation to use dateUtils.formatDate for date formatting, ensuring consistency with user settings, and kept the necessary guards to avoid sending invalid dates to the backend.

I’ve also squashed the commits so the Pull Request now contains a single commit as requested. Please have a look.


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 });
});
}
Expand Down
Loading