refactor: make JournalEntryForm reusable with embedded mode

Add props for initialLines, initialDate, initialDescription, sourceType,
sourceId, submitUrl, embedded, and onEntryCreated to support embedding the
form in dialogs. Auto-fill line description from account name. Improve
AccountCombobox to only emit valid account numbers and reset on blur.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Emil
2026-02-23 12:59:21 +01:00
co-authored by Claude Opus 4.6
parent 2f953c1031
commit 3ec0884de4
2 changed files with 257 additions and 206 deletions
+16 -4
View File
@@ -139,7 +139,10 @@ export default function AccountCombobox({ value, accounts, onChange }: AccountCo
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value
setSearch(newValue)
onChange(newValue)
// Only emit valid account numbers to parent
if (/^\d{4}$/.test(newValue) && accounts.some(a => a.account_number === newValue)) {
onChange(newValue)
}
if (!isOpen) {
setIsOpen(true)
}
@@ -149,6 +152,15 @@ export default function AccountCombobox({ value, accounts, onChange }: AccountCo
setIsOpen(true)
}
const handleBlur = () => {
// Small delay to allow dropdown click to fire first
setTimeout(() => {
if (!accounts.some(a => a.account_number === search)) {
setSearch(value)
}
}, 150)
}
// Find matching account for helper text
const matchedAccount = useMemo(() => {
if (!value || value.length !== 4) return null
@@ -162,16 +174,16 @@ export default function AccountCombobox({ value, accounts, onChange }: AccountCo
value={search}
onChange={handleInputChange}
onFocus={handleFocus}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
placeholder="1930"
className="font-mono h-8"
maxLength={4}
autoComplete="off"
/>
{/* Account name helper text (md+ screens only) */}
{/* Account name helper text */}
{matchedAccount && (
<p className="hidden md:block text-[11px] text-muted-foreground truncate mt-0.5 leading-tight">
<p className="text-[11px] text-muted-foreground truncate mt-0.5 leading-tight">
{matchedAccount.account_name}
</p>
)}
File diff suppressed because it is too large Load Diff