fix(crm): commit LocalizedDateInput value live, not only on blur

The historical-invoice import (and any form whose date field has a non-empty
default like today) lost a typed date: the value was only pushed to the parent
on blur, so submitting while the field was focused — or before React
re-rendered after the blur-time setState — sent the stale default. Issued/
event dates came out as 'today' instead of the entered date.

Now commit as soon as a complete, valid date is entered (toIso returns '' for
partial input, so intermediate keystrokes emit nothing); blur still normalises
display + handles clearing. Applies to every LocalizedDateInput consumer.
This commit is contained in:
Luca
2026-06-03 17:50:13 +02:00
parent db3e3270f3
commit 0b4690afab
@@ -123,7 +123,19 @@ export const LocalizedDateInput: React.FC<LocalizedDateInputProps> = ({
value={text}
placeholder={placeholder}
disabled={disabled}
onChange={(e) => setText(e.target.value)}
onChange={(e) => {
const next = e.target.value;
setText(next);
// Commit live as soon as a complete, valid date is typed —
// don't wait for blur. Otherwise a value entered then submitted
// without blurring (or before React re-renders after the
// blur-time setState) is lost and the parent keeps its previous
// value (e.g. the import form's "today" default). toIso returns
// '' for partial/invalid input, so intermediate keystrokes emit
// nothing.
const iso = toIso(next);
if (iso) onChange(iso);
}}
onBlur={() => {
const iso = toIso(text);
if (iso) {